1
0

raspberry.patch 2.9 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293792947929579296792977929879299793007930179302793037930479305793067930779308793097931079311793127931379314793157931679317793187931979320793217932279323793247932579326793277932879329793307933179332793337933479335793367933779338793397934079341793427934379344793457934679347793487934979350793517935279353793547935579356793577935879359793607936179362793637936479365793667936779368793697937079371793727937379374793757937679377793787937979380793817938279383793847938579386793877938879389793907939179392793937939479395793967939779398793997940079401794027940379404794057940679407794087940979410794117941279413794147941579416794177941879419794207942179422794237942479425794267942779428794297943079431794327943379434794357943679437794387943979440794417944279443794447944579446794477944879449794507945179452794537945479455794567945779458794597946079461794627946379464794657946679467794687946979470794717947279473794747947579476794777947879479794807948179482794837948479485794867948779488794897949079491794927949379494794957949679497794987949979500795017950279503795047950579506795077950879509795107951179512795137951479515795167951779518795197952079521795227952379524795257952679527795287952979530795317953279533795347953579536795377953879539795407954179542795437954479545795467954779548795497955079551795527955379554795557955679557795587955979560795617956279563795647956579566795677956879569795707957179572795737957479575795767957779578795797958079581795827958379584795857958679587795887958979590795917959279593795947959579596795977959879599796007960179602796037960479605796067960779608796097961079611796127961379614796157961679617796187961979620796217962279623796247962579626796277962879629796307963179632796337963479635796367963779638796397964079641796427964379644796457964679647796487964979650796517965279653796547965579656796577965879659796607966179662796637966479665796667966779668796697967079671796727967379674796757967679677796787967979680796817968279683796847968579686796877968879689796907969179692796937969479695796967969779698796997970079701797027970379704797057970679707797087970979710797117971279713797147971579716797177971879719797207972179722797237972479725797267972779728797297973079731797327973379734797357973679737797387973979740797417974279743797447974579746797477974879749797507975179752797537975479755797567975779758797597976079761797627976379764797657976679767797687976979770797717977279773797747977579776797777977879779797807978179782797837978479785797867978779788797897979079791797927979379794797957979679797797987979979800798017980279803798047980579806798077980879809798107981179812798137981479815798167981779818798197982079821798227982379824798257982679827798287982979830798317983279833798347983579836798377983879839798407984179842798437984479845798467984779848798497985079851798527985379854798557985679857798587985979860798617986279863798647986579866798677986879869798707987179872798737987479875798767987779878798797988079881798827988379884798857988679887798887988979890798917989279893798947989579896798977989879899799007990179902799037990479905799067990779908799097991079911799127991379914799157991679917799187991979920799217992279923799247992579926799277992879929799307993179932799337993479935799367993779938799397994079941799427994379944799457994679947799487994979950799517995279953799547995579956799577995879959799607996179962799637996479965799667996779968799697997079971799727997379974799757997679977799787997979980799817998279983799847998579986799877998879989799907999179992799937999479995799967999779998799998000080001800028000380004800058000680007800088000980010800118001280013800148001580016800178001880019800208002180022800238002480025800268002780028800298003080031800328003380034800358003680037800388003980040800418004280043800448004580046800478004880049800508005180052800538005480055800568005780058800598006080061800628006380064800658006680067800688006980070800718007280073800748007580076800778007880079800808008180082800838008480085800868008780088800898009080091800928009380094800958009680097800988009980100801018010280103801048010580106801078010880109801108011180112801138011480115801168011780118801198012080121801228012380124801258012680127801288012980130801318013280133801348013580136801378013880139801408014180142801438014480145801468014780148801498015080151801528015380154801558015680157801588015980160801618016280163801648016580166801678016880169801708017180172801738017480175801768017780178801798018080181801828018380184801858018680187801888018980190801918019280193801948019580196801978019880199802008020180202802038020480205802068020780208802098021080211802128021380214802158021680217802188021980220802218022280223802248022580226802278022880229802308023180232802338023480235802368023780238802398024080241802428024380244802458024680247802488024980250802518025280253802548025580256802578025880259802608026180262802638026480265802668026780268802698027080271802728027380274802758027680277802788027980280802818028280283802848028580286802878028880289802908029180292802938029480295802968029780298802998030080301803028030380304803058030680307803088030980310803118031280313803148031580316803178031880319803208032180322803238032480325803268032780328803298033080331803328033380334803358033680337803388033980340803418034280343803448034580346803478034880349803508035180352803538035480355803568035780358803598036080361803628036380364803658036680367803688036980370803718037280373803748037580376803778037880379803808038180382803838038480385803868038780388803898039080391803928039380394803958039680397803988039980400804018040280403804048040580406804078040880409804108041180412804138041480415804168041780418804198042080421804228042380424804258042680427804288042980430804318043280433804348043580436804378043880439804408044180442804438044480445804468044780448804498045080451804528045380454804558045680457804588045980460804618046280463804648046580466804678046880469804708047180472804738047480475804768047780478804798048080481804828048380484804858048680487804888048980490804918049280493804948049580496804978049880499805008050180502805038050480505805068050780508805098051080511805128051380514805158051680517805188051980520805218052280523805248052580526805278052880529805308053180532805338053480535805368053780538805398054080541805428054380544805458054680547805488054980550805518055280553805548055580556805578055880559805608056180562805638056480565805668056780568805698057080571805728057380574805758057680577805788057980580805818058280583805848058580586805878058880589805908059180592805938059480595805968059780598805998060080601806028060380604806058060680607806088060980610806118061280613806148061580616806178061880619806208062180622806238062480625806268062780628806298063080631806328063380634806358063680637806388063980640806418064280643806448064580646806478064880649806508065180652806538065480655806568065780658806598066080661806628066380664806658066680667806688066980670806718067280673806748067580676806778067880679806808068180682806838068480685806868068780688806898069080691806928069380694806958069680697806988069980700807018070280703807048070580706807078070880709807108071180712807138071480715807168071780718807198072080721807228072380724807258072680727807288072980730807318073280733807348073580736807378073880739807408074180742807438074480745807468074780748807498075080751807528075380754807558075680757807588075980760807618076280763807648076580766807678076880769807708077180772807738077480775807768077780778807798078080781807828078380784807858078680787807888078980790807918079280793807948079580796807978079880799808008080180802808038080480805808068080780808808098081080811808128081380814808158081680817808188081980820808218082280823808248082580826808278082880829808308083180832808338083480835808368083780838808398084080841808428084380844808458084680847808488084980850808518085280853808548085580856808578085880859808608086180862808638086480865808668086780868808698087080871808728087380874808758087680877808788087980880808818088280883808848088580886808878088880889808908089180892808938089480895808968089780898808998090080901809028090380904809058090680907809088090980910809118091280913809148091580916809178091880919809208092180922809238092480925809268092780928809298093080931809328093380934809358093680937809388093980940809418094280943809448094580946809478094880949809508095180952809538095480955809568095780958809598096080961809628096380964809658096680967809688096980970809718097280973809748097580976809778097880979809808098180982809838098480985809868098780988809898099080991809928099380994809958099680997809988099981000810018100281003810048100581006810078100881009810108101181012810138101481015810168101781018810198102081021810228102381024810258102681027810288102981030810318103281033810348103581036810378103881039810408104181042810438104481045810468104781048810498105081051810528105381054810558105681057810588105981060810618106281063810648106581066810678106881069810708107181072810738107481075810768107781078810798108081081810828108381084810858108681087810888108981090810918109281093810948109581096810978109881099811008110181102811038110481105811068110781108811098111081111811128111381114811158111681117811188111981120811218112281123811248112581126811278112881129811308113181132811338113481135811368113781138811398114081141811428114381144811458114681147811488114981150811518115281153811548115581156811578115881159811608116181162811638116481165811668116781168811698117081171811728117381174811758117681177811788117981180811818118281183811848118581186811878118881189811908119181192811938119481195811968119781198811998120081201812028120381204812058120681207812088120981210812118121281213812148121581216812178121881219812208122181222812238122481225812268122781228812298123081231812328123381234812358123681237812388123981240812418124281243812448124581246812478124881249812508125181252812538125481255812568125781258812598126081261812628126381264812658126681267812688126981270812718127281273812748127581276812778127881279812808128181282812838128481285812868128781288812898129081291812928129381294812958129681297812988129981300813018130281303813048130581306813078130881309813108131181312813138131481315813168131781318813198132081321813228132381324813258132681327813288132981330813318133281333813348133581336813378133881339813408134181342813438134481345813468134781348813498135081351813528135381354813558135681357813588135981360813618136281363813648136581366813678136881369813708137181372813738137481375813768137781378813798138081381813828138381384813858138681387813888138981390813918139281393813948139581396813978139881399814008140181402814038140481405814068140781408814098141081411814128141381414814158141681417814188141981420814218142281423814248142581426814278142881429814308143181432814338143481435814368143781438814398144081441814428144381444814458144681447814488144981450814518145281453814548145581456814578145881459814608146181462814638146481465814668146781468814698147081471814728147381474814758147681477814788147981480814818148281483814848148581486814878148881489814908149181492814938149481495814968149781498814998150081501815028150381504815058150681507815088150981510815118151281513815148151581516815178151881519815208152181522815238152481525815268152781528815298153081531815328153381534815358153681537815388153981540815418154281543815448154581546815478154881549815508155181552815538155481555815568155781558815598156081561815628156381564815658156681567815688156981570815718157281573815748157581576815778157881579815808158181582815838158481585815868158781588815898159081591815928159381594815958159681597815988159981600816018160281603816048160581606816078160881609816108161181612816138161481615816168161781618816198162081621816228162381624816258162681627816288162981630816318163281633816348163581636816378163881639816408164181642816438164481645816468164781648816498165081651816528165381654816558165681657816588165981660816618166281663816648166581666816678166881669816708167181672816738167481675816768167781678816798168081681816828168381684816858168681687816888168981690816918169281693816948169581696816978169881699817008170181702817038170481705817068170781708817098171081711817128171381714817158171681717817188171981720817218172281723817248172581726817278172881729817308173181732817338173481735817368173781738817398174081741817428174381744817458174681747817488174981750817518175281753817548175581756817578175881759817608176181762817638176481765817668176781768817698177081771817728177381774817758177681777817788177981780817818178281783817848178581786817878178881789817908179181792817938179481795817968179781798817998180081801818028180381804818058180681807818088180981810818118181281813818148181581816818178181881819818208182181822818238182481825818268182781828818298183081831818328183381834818358183681837818388183981840818418184281843818448184581846818478184881849818508185181852818538185481855818568185781858818598186081861818628186381864818658186681867818688186981870818718187281873818748187581876818778187881879818808188181882818838188481885818868188781888818898189081891818928189381894818958189681897818988189981900819018190281903819048190581906819078190881909819108191181912819138191481915819168191781918819198192081921819228192381924819258192681927819288192981930819318193281933819348193581936819378193881939819408194181942819438194481945819468194781948819498195081951819528195381954819558195681957819588195981960819618196281963819648196581966819678196881969819708197181972819738197481975819768197781978819798198081981819828198381984819858198681987819888198981990819918199281993819948199581996819978199881999820008200182002820038200482005820068200782008820098201082011820128201382014820158201682017820188201982020820218202282023820248202582026820278202882029820308203182032820338203482035820368203782038820398204082041820428204382044820458204682047820488204982050820518205282053820548205582056820578205882059820608206182062820638206482065820668206782068820698207082071820728207382074820758207682077820788207982080820818208282083820848208582086820878208882089820908209182092820938209482095820968209782098820998210082101821028210382104821058210682107821088210982110821118211282113821148211582116821178211882119821208212182122821238212482125821268212782128821298213082131821328213382134821358213682137821388213982140821418214282143821448214582146821478214882149821508215182152821538215482155821568215782158821598216082161821628216382164821658216682167821688216982170821718217282173821748217582176821778217882179821808218182182821838218482185821868218782188821898219082191821928219382194821958219682197821988219982200822018220282203822048220582206822078220882209822108221182212822138221482215822168221782218822198222082221822228222382224822258222682227822288222982230822318223282233822348223582236822378223882239822408224182242822438224482245822468224782248822498225082251822528225382254822558225682257822588225982260822618226282263822648226582266822678226882269822708227182272822738227482275822768227782278822798228082281822828228382284822858228682287822888228982290822918229282293822948229582296822978229882299823008230182302823038230482305823068230782308823098231082311823128231382314823158231682317823188231982320823218232282323823248232582326823278232882329823308233182332823338233482335823368233782338823398234082341823428234382344823458234682347823488234982350823518235282353823548235582356823578235882359823608236182362823638236482365823668236782368823698237082371823728237382374823758237682377823788237982380823818238282383823848238582386823878238882389823908239182392823938239482395823968239782398823998240082401824028240382404824058240682407824088240982410824118241282413824148241582416824178241882419824208242182422824238242482425824268242782428824298243082431824328243382434824358243682437824388243982440824418244282443824448244582446824478244882449824508245182452824538245482455824568245782458824598246082461824628246382464824658246682467824688246982470824718247282473824748247582476824778247882479824808248182482824838248482485824868248782488824898249082491824928249382494824958249682497824988249982500825018250282503825048250582506825078250882509825108251182512825138251482515825168251782518825198252082521825228252382524825258252682527825288252982530825318253282533825348253582536825378253882539825408254182542825438254482545825468254782548825498255082551825528255382554825558255682557825588255982560825618256282563825648256582566825678256882569825708257182572825738257482575825768257782578825798258082581825828258382584825858258682587825888258982590825918259282593825948259582596825978259882599826008260182602826038260482605826068260782608826098261082611826128261382614826158261682617826188261982620826218262282623826248262582626826278262882629826308263182632826338263482635826368263782638826398264082641826428264382644826458264682647826488264982650826518265282653826548265582656826578265882659826608266182662826638266482665826668266782668826698267082671826728267382674826758267682677826788267982680826818268282683826848268582686826878268882689826908269182692826938269482695826968269782698826998270082701827028270382704827058270682707827088270982710827118271282713827148271582716827178271882719827208272182722827238272482725827268272782728827298273082731827328273382734827358273682737827388273982740827418274282743827448274582746827478274882749827508275182752827538275482755827568275782758827598276082761827628276382764827658276682767827688276982770827718277282773827748277582776827778277882779827808278182782827838278482785827868278782788827898279082791827928279382794827958279682797827988279982800828018280282803828048280582806828078280882809828108281182812828138281482815828168281782818828198282082821828228282382824828258282682827828288282982830828318283282833828348283582836828378283882839828408284182842828438284482845828468284782848828498285082851828528285382854828558285682857828588285982860828618286282863828648286582866828678286882869828708287182872828738287482875828768287782878828798288082881828828288382884828858288682887828888288982890828918289282893828948289582896828978289882899829008290182902829038290482905829068290782908829098291082911829128291382914829158291682917829188291982920829218292282923829248292582926829278292882929829308293182932829338293482935829368293782938829398294082941829428294382944829458294682947829488294982950829518295282953829548295582956829578295882959829608296182962829638296482965829668296782968829698297082971829728297382974829758297682977829788297982980829818298282983829848298582986829878298882989829908299182992829938299482995829968299782998829998300083001830028300383004830058300683007830088300983010830118301283013830148301583016830178301883019830208302183022830238302483025830268302783028830298303083031830328303383034830358303683037830388303983040830418304283043830448304583046830478304883049830508305183052830538305483055830568305783058830598306083061830628306383064830658306683067830688306983070830718307283073830748307583076830778307883079830808308183082830838308483085830868308783088830898309083091830928309383094830958309683097830988309983100831018310283103831048310583106831078310883109831108311183112831138311483115831168311783118831198312083121831228312383124831258312683127831288312983130831318313283133831348313583136831378313883139831408314183142831438314483145831468314783148831498315083151831528315383154831558315683157831588315983160831618316283163831648316583166831678316883169831708317183172831738317483175831768317783178831798318083181831828318383184831858318683187831888318983190831918319283193831948319583196831978319883199832008320183202832038320483205832068320783208832098321083211832128321383214832158321683217832188321983220832218322283223832248322583226832278322883229832308323183232832338323483235832368323783238832398324083241832428324383244832458324683247832488324983250832518325283253832548325583256832578325883259832608326183262832638326483265832668326783268832698327083271832728327383274832758327683277832788327983280832818328283283832848328583286832878328883289832908329183292832938329483295832968329783298832998330083301833028330383304833058330683307833088330983310833118331283313833148331583316833178331883319833208332183322833238332483325833268332783328833298333083331833328333383334833358333683337833388333983340833418334283343833448334583346833478334883349833508335183352833538335483355833568335783358833598336083361833628336383364833658336683367833688336983370833718337283373833748337583376833778337883379833808338183382833838338483385833868338783388833898339083391833928339383394833958339683397833988339983400834018340283403834048340583406834078340883409834108341183412834138341483415834168341783418834198342083421834228342383424834258342683427834288342983430834318343283433834348343583436834378343883439834408344183442834438344483445834468344783448834498345083451834528345383454834558345683457834588345983460834618346283463834648346583466834678346883469834708347183472834738347483475834768347783478834798348083481834828348383484834858348683487834888348983490834918349283493834948349583496834978349883499835008350183502835038350483505835068350783508835098351083511835128351383514835158351683517835188351983520835218352283523835248352583526835278352883529835308353183532835338353483535835368353783538835398354083541835428354383544835458354683547835488354983550835518355283553835548355583556835578355883559835608356183562835638356483565835668356783568835698357083571835728357383574835758357683577835788357983580835818358283583835848358583586835878358883589835908359183592835938359483595835968359783598835998360083601836028360383604836058360683607836088360983610836118361283613836148361583616836178361883619836208362183622836238362483625836268362783628836298363083631836328363383634836358363683637836388363983640836418364283643836448364583646836478364883649836508365183652836538365483655836568365783658836598366083661836628366383664836658366683667836688366983670836718367283673836748367583676836778367883679836808368183682836838368483685836868368783688836898369083691836928369383694836958369683697836988369983700837018370283703837048370583706837078370883709837108371183712837138371483715837168371783718837198372083721837228372383724837258372683727837288372983730837318373283733837348373583736837378373883739837408374183742837438374483745837468374783748837498375083751837528375383754837558375683757837588375983760837618376283763837648376583766837678376883769837708377183772837738377483775837768377783778837798378083781837828378383784837858378683787837888378983790837918379283793837948379583796837978379883799838008380183802838038380483805838068380783808838098381083811838128381383814838158381683817838188381983820838218382283823838248382583826838278382883829838308383183832838338383483835838368383783838838398384083841838428384383844838458384683847838488384983850838518385283853838548385583856838578385883859838608386183862838638386483865838668386783868838698387083871838728387383874838758387683877838788387983880838818388283883838848388583886838878388883889838908389183892838938389483895838968389783898838998390083901839028390383904839058390683907839088390983910839118391283913839148391583916839178391883919839208392183922839238392483925839268392783928839298393083931839328393383934839358393683937839388393983940839418394283943839448394583946839478394883949839508395183952839538395483955839568395783958839598396083961839628396383964839658396683967839688396983970839718397283973839748397583976839778397883979839808398183982839838398483985839868398783988839898399083991839928399383994839958399683997839988399984000840018400284003840048400584006840078400884009840108401184012840138401484015840168401784018840198402084021840228402384024840258402684027840288402984030840318403284033840348403584036840378403884039840408404184042840438404484045840468404784048840498405084051840528405384054840558405684057840588405984060840618406284063840648406584066840678406884069840708407184072840738407484075840768407784078840798408084081840828408384084840858408684087840888408984090840918409284093840948409584096840978409884099841008410184102841038410484105841068410784108841098411084111841128411384114841158411684117841188411984120841218412284123841248412584126841278412884129841308413184132841338413484135841368413784138841398414084141841428414384144841458414684147841488414984150841518415284153841548415584156841578415884159841608416184162841638416484165841668416784168841698417084171841728417384174841758417684177841788417984180841818418284183841848418584186841878418884189841908419184192841938419484195841968419784198841998420084201842028420384204842058420684207842088420984210842118421284213842148421584216842178421884219842208422184222842238422484225842268422784228842298423084231842328423384234842358423684237842388423984240842418424284243842448424584246842478424884249842508425184252842538425484255842568425784258842598426084261842628426384264842658426684267842688426984270842718427284273842748427584276842778427884279842808428184282842838428484285842868428784288842898429084291842928429384294842958429684297842988429984300843018430284303843048430584306843078430884309843108431184312843138431484315843168431784318843198432084321843228432384324843258432684327843288432984330843318433284333843348433584336843378433884339843408434184342843438434484345843468434784348843498435084351843528435384354843558435684357843588435984360843618436284363843648436584366843678436884369843708437184372843738437484375843768437784378843798438084381843828438384384843858438684387843888438984390843918439284393843948439584396843978439884399844008440184402844038440484405844068440784408844098441084411844128441384414844158441684417844188441984420844218442284423844248442584426844278442884429844308443184432844338443484435844368443784438844398444084441844428444384444844458444684447844488444984450844518445284453844548445584456844578445884459844608446184462844638446484465844668446784468844698447084471844728447384474844758447684477844788447984480844818448284483844848448584486844878448884489844908449184492844938449484495844968449784498844998450084501845028450384504845058450684507845088450984510845118451284513845148451584516845178451884519845208452184522845238452484525845268452784528845298453084531845328453384534845358453684537845388453984540845418454284543845448454584546845478454884549845508455184552845538455484555845568455784558845598456084561845628456384564845658456684567845688456984570845718457284573845748457584576845778457884579845808458184582845838458484585845868458784588845898459084591845928459384594845958459684597845988459984600846018460284603846048460584606846078460884609846108461184612846138461484615846168461784618846198462084621846228462384624846258462684627846288462984630846318463284633846348463584636846378463884639846408464184642846438464484645846468464784648846498465084651846528465384654846558465684657846588465984660846618466284663846648466584666846678466884669846708467184672846738467484675846768467784678846798468084681846828468384684846858468684687846888468984690846918469284693846948469584696846978469884699847008470184702847038470484705847068470784708847098471084711847128471384714847158471684717847188471984720847218472284723847248472584726847278472884729847308473184732847338473484735847368473784738847398474084741847428474384744847458474684747847488474984750847518475284753847548475584756847578475884759847608476184762847638476484765847668476784768847698477084771847728477384774847758477684777847788477984780847818478284783847848478584786847878478884789847908479184792847938479484795847968479784798847998480084801848028480384804848058480684807848088480984810848118481284813848148481584816848178481884819848208482184822848238482484825848268482784828848298483084831848328483384834848358483684837848388483984840848418484284843848448484584846848478484884849848508485184852848538485484855848568485784858848598486084861848628486384864848658486684867848688486984870848718487284873848748487584876848778487884879848808488184882848838488484885848868488784888848898489084891848928489384894848958489684897848988489984900849018490284903849048490584906849078490884909849108491184912849138491484915849168491784918849198492084921849228492384924849258492684927849288492984930849318493284933849348493584936849378493884939849408494184942849438494484945849468494784948849498495084951849528495384954849558495684957849588495984960849618496284963849648496584966849678496884969849708497184972849738497484975849768497784978849798498084981849828498384984849858498684987849888498984990849918499284993849948499584996849978499884999850008500185002850038500485005850068500785008850098501085011850128501385014850158501685017850188501985020850218502285023850248502585026850278502885029850308503185032850338503485035850368503785038850398504085041850428504385044850458504685047850488504985050850518505285053850548505585056850578505885059850608506185062850638506485065850668506785068850698507085071850728507385074850758507685077850788507985080850818508285083850848508585086850878508885089850908509185092850938509485095850968509785098850998510085101851028510385104851058510685107851088510985110851118511285113851148511585116851178511885119851208512185122851238512485125851268512785128851298513085131851328513385134851358513685137851388513985140851418514285143851448514585146851478514885149851508515185152851538515485155851568515785158851598516085161851628516385164851658516685167851688516985170851718517285173851748517585176851778517885179851808518185182851838518485185851868518785188851898519085191851928519385194851958519685197851988519985200852018520285203852048520585206852078520885209852108521185212852138521485215852168521785218852198522085221852228522385224852258522685227852288522985230852318523285233852348523585236852378523885239852408524185242852438524485245852468524785248852498525085251852528525385254852558525685257852588525985260852618526285263852648526585266852678526885269852708527185272852738527485275852768527785278852798528085281852828528385284852858528685287852888528985290852918529285293852948529585296852978529885299853008530185302853038530485305853068530785308853098531085311853128531385314853158531685317853188531985320853218532285323853248532585326853278532885329853308533185332853338533485335853368533785338853398534085341853428534385344853458534685347853488534985350853518535285353853548535585356853578535885359853608536185362853638536485365853668536785368853698537085371853728537385374853758537685377853788537985380853818538285383853848538585386853878538885389853908539185392853938539485395853968539785398853998540085401854028540385404854058540685407854088540985410854118541285413854148541585416854178541885419854208542185422854238542485425854268542785428854298543085431854328543385434854358543685437854388543985440854418544285443854448544585446854478544885449854508545185452854538545485455854568545785458854598546085461854628546385464854658546685467854688546985470854718547285473854748547585476854778547885479854808548185482854838548485485854868548785488854898549085491854928549385494854958549685497854988549985500855018550285503855048550585506855078550885509855108551185512855138551485515855168551785518855198552085521855228552385524855258552685527855288552985530855318553285533855348553585536855378553885539855408554185542855438554485545855468554785548855498555085551855528555385554855558555685557855588555985560855618556285563855648556585566855678556885569855708557185572855738557485575855768557785578855798558085581855828558385584855858558685587855888558985590855918559285593855948559585596855978559885599856008560185602856038560485605856068560785608856098561085611856128561385614856158561685617856188561985620856218562285623856248562585626856278562885629856308563185632856338563485635856368563785638856398564085641856428564385644856458564685647856488564985650856518565285653856548565585656856578565885659856608566185662856638566485665856668566785668856698567085671856728567385674856758567685677856788567985680856818568285683856848568585686856878568885689856908569185692856938569485695856968569785698856998570085701857028570385704857058570685707857088570985710857118571285713857148571585716857178571885719857208572185722857238572485725857268572785728857298573085731857328573385734857358573685737857388573985740857418574285743857448574585746857478574885749857508575185752857538575485755857568575785758857598576085761857628576385764857658576685767857688576985770857718577285773857748577585776857778577885779857808578185782857838578485785857868578785788857898579085791857928579385794857958579685797857988579985800858018580285803858048580585806858078580885809858108581185812858138581485815858168581785818858198582085821858228582385824858258582685827858288582985830858318583285833858348583585836858378583885839858408584185842858438584485845858468584785848858498585085851858528585385854858558585685857858588585985860858618586285863858648586585866858678586885869858708587185872858738587485875858768587785878858798588085881858828588385884858858588685887858888588985890858918589285893858948589585896858978589885899859008590185902859038590485905859068590785908859098591085911859128591385914859158591685917859188591985920859218592285923859248592585926859278592885929859308593185932859338593485935859368593785938859398594085941859428594385944859458594685947859488594985950859518595285953859548595585956859578595885959859608596185962859638596485965859668596785968859698597085971859728597385974859758597685977859788597985980859818598285983859848598585986859878598885989859908599185992859938599485995859968599785998859998600086001860028600386004860058600686007860088600986010860118601286013860148601586016860178601886019860208602186022860238602486025860268602786028860298603086031860328603386034860358603686037860388603986040860418604286043860448604586046860478604886049860508605186052860538605486055860568605786058860598606086061860628606386064860658606686067860688606986070860718607286073860748607586076860778607886079860808608186082860838608486085860868608786088860898609086091860928609386094860958609686097860988609986100861018610286103861048610586106861078610886109861108611186112861138611486115861168611786118861198612086121861228612386124861258612686127861288612986130861318613286133861348613586136861378613886139861408614186142861438614486145861468614786148861498615086151861528615386154861558615686157861588615986160861618616286163861648616586166861678616886169861708617186172861738617486175861768617786178861798618086181861828618386184861858618686187861888618986190861918619286193861948619586196861978619886199862008620186202862038620486205862068620786208862098621086211862128621386214862158621686217862188621986220862218622286223862248622586226862278622886229862308623186232862338623486235862368623786238862398624086241862428624386244862458624686247862488624986250862518625286253862548625586256862578625886259862608626186262862638626486265862668626786268862698627086271862728627386274862758627686277862788627986280862818628286283862848628586286862878628886289862908629186292862938629486295862968629786298862998630086301863028630386304863058630686307863088630986310863118631286313863148631586316863178631886319863208632186322863238632486325863268632786328863298633086331863328633386334863358633686337863388633986340863418634286343863448634586346863478634886349863508635186352863538635486355863568635786358863598636086361863628636386364863658636686367863688636986370863718637286373863748637586376863778637886379863808638186382863838638486385863868638786388863898639086391863928639386394863958639686397863988639986400864018640286403864048640586406864078640886409864108641186412864138641486415864168641786418864198642086421864228642386424864258642686427864288642986430864318643286433864348643586436864378643886439864408644186442864438644486445864468644786448864498645086451864528645386454864558645686457864588645986460864618646286463864648646586466864678646886469864708647186472864738647486475864768647786478864798648086481864828648386484864858648686487864888648986490864918649286493864948649586496864978649886499865008650186502865038650486505865068650786508865098651086511865128651386514865158651686517865188651986520865218652286523865248652586526865278652886529865308653186532865338653486535865368653786538865398654086541865428654386544865458654686547865488654986550865518655286553865548655586556865578655886559865608656186562865638656486565865668656786568865698657086571865728657386574865758657686577865788657986580865818658286583865848658586586865878658886589865908659186592865938659486595865968659786598865998660086601866028660386604866058660686607866088660986610866118661286613866148661586616866178661886619866208662186622866238662486625866268662786628866298663086631866328663386634866358663686637866388663986640866418664286643866448664586646866478664886649866508665186652866538665486655866568665786658866598666086661866628666386664866658666686667866688666986670866718667286673866748667586676866778667886679866808668186682866838668486685866868668786688866898669086691866928669386694866958669686697866988669986700867018670286703867048670586706867078670886709867108671186712867138671486715867168671786718867198672086721867228672386724867258672686727867288672986730867318673286733867348673586736867378673886739867408674186742867438674486745867468674786748867498675086751867528675386754867558675686757867588675986760867618676286763867648676586766867678676886769867708677186772867738677486775867768677786778867798678086781867828678386784867858678686787867888678986790867918679286793867948679586796867978679886799868008680186802868038680486805868068680786808868098681086811868128681386814868158681686817868188681986820868218682286823868248682586826868278682886829868308683186832868338683486835868368683786838868398684086841868428684386844868458684686847868488684986850868518685286853868548685586856868578685886859868608686186862868638686486865868668686786868868698687086871868728687386874868758687686877868788687986880868818688286883868848688586886868878688886889868908689186892868938689486895868968689786898868998690086901869028690386904869058690686907869088690986910869118691286913869148691586916869178691886919869208692186922869238692486925869268692786928869298693086931869328693386934869358693686937869388693986940869418694286943869448694586946869478694886949869508695186952869538695486955869568695786958869598696086961869628696386964869658696686967869688696986970869718697286973869748697586976869778697886979869808698186982869838698486985869868698786988869898699086991869928699386994869958699686997869988699987000870018700287003870048700587006870078700887009870108701187012870138701487015870168701787018870198702087021870228702387024870258702687027870288702987030870318703287033870348703587036870378703887039870408704187042870438704487045870468704787048870498705087051870528705387054870558705687057870588705987060870618706287063870648706587066870678706887069870708707187072870738707487075870768707787078870798708087081870828708387084870858708687087870888708987090870918709287093870948709587096870978709887099871008710187102871038710487105871068710787108871098711087111871128711387114871158711687117871188711987120871218712287123871248712587126871278712887129871308713187132871338713487135871368713787138871398714087141871428714387144871458714687147871488714987150871518715287153871548715587156871578715887159871608716187162871638716487165871668716787168871698717087171871728717387174871758717687177871788717987180871818718287183871848718587186871878718887189871908719187192871938719487195871968719787198871998720087201872028720387204872058720687207872088720987210872118721287213872148721587216872178721887219872208722187222872238722487225872268722787228872298723087231872328723387234872358723687237872388723987240872418724287243872448724587246872478724887249872508725187252872538725487255872568725787258872598726087261872628726387264872658726687267872688726987270872718727287273872748727587276872778727887279872808728187282872838728487285872868728787288872898729087291872928729387294872958729687297872988729987300873018730287303873048730587306873078730887309873108731187312873138731487315873168731787318873198732087321873228732387324873258732687327873288732987330873318733287333873348733587336873378733887339873408734187342873438734487345873468734787348873498735087351873528735387354873558735687357873588735987360873618736287363873648736587366873678736887369873708737187372873738737487375873768737787378873798738087381873828738387384873858738687387873888738987390873918739287393873948739587396873978739887399874008740187402874038740487405874068740787408874098741087411874128741387414874158741687417874188741987420874218742287423874248742587426874278742887429874308743187432874338743487435874368743787438874398744087441874428744387444874458744687447874488744987450874518745287453874548745587456874578745887459874608746187462874638746487465874668746787468874698747087471874728747387474874758747687477874788747987480874818748287483874848748587486874878748887489874908749187492874938749487495874968749787498874998750087501875028750387504875058750687507875088750987510875118751287513875148751587516875178751887519875208752187522875238752487525875268752787528875298753087531875328753387534875358753687537875388753987540875418754287543875448754587546875478754887549875508755187552875538755487555875568755787558875598756087561875628756387564875658756687567875688756987570875718757287573875748757587576875778757887579875808758187582875838758487585875868758787588875898759087591875928759387594875958759687597875988759987600876018760287603876048760587606876078760887609876108761187612876138761487615876168761787618876198762087621876228762387624876258762687627876288762987630876318763287633876348763587636876378763887639876408764187642876438764487645876468764787648876498765087651876528765387654876558765687657876588765987660876618766287663876648766587666876678766887669876708767187672876738767487675876768767787678876798768087681876828768387684876858768687687876888768987690876918769287693876948769587696876978769887699877008770187702877038770487705877068770787708877098771087711877128771387714877158771687717877188771987720877218772287723877248772587726877278772887729877308773187732877338773487735877368773787738877398774087741877428774387744877458774687747877488774987750877518775287753877548775587756877578775887759877608776187762877638776487765877668776787768877698777087771877728777387774877758777687777877788777987780877818778287783877848778587786877878778887789877908779187792877938779487795877968779787798877998780087801878028780387804878058780687807878088780987810878118781287813878148781587816878178781887819878208782187822878238782487825878268782787828878298783087831878328783387834878358783687837878388783987840878418784287843878448784587846878478784887849878508785187852878538785487855878568785787858878598786087861878628786387864878658786687867878688786987870878718787287873878748787587876878778787887879878808788187882878838788487885878868788787888878898789087891878928789387894878958789687897878988789987900879018790287903879048790587906879078790887909879108791187912879138791487915879168791787918879198792087921879228792387924879258792687927879288792987930879318793287933879348793587936879378793887939879408794187942879438794487945879468794787948879498795087951879528795387954879558795687957879588795987960879618796287963879648796587966879678796887969879708797187972879738797487975879768797787978879798798087981879828798387984879858798687987879888798987990879918799287993879948799587996879978799887999880008800188002880038800488005880068800788008880098801088011880128801388014880158801688017880188801988020880218802288023880248802588026880278802888029880308803188032880338803488035880368803788038880398804088041880428804388044880458804688047880488804988050880518805288053880548805588056880578805888059880608806188062880638806488065880668806788068880698807088071880728807388074880758807688077880788807988080880818808288083880848808588086880878808888089880908809188092880938809488095880968809788098880998810088101881028810388104881058810688107881088810988110881118811288113881148811588116881178811888119881208812188122881238812488125881268812788128881298813088131881328813388134881358813688137881388813988140881418814288143881448814588146881478814888149881508815188152881538815488155881568815788158881598816088161881628816388164881658816688167881688816988170881718817288173881748817588176881778817888179881808818188182881838818488185881868818788188881898819088191881928819388194881958819688197881988819988200882018820288203882048820588206882078820888209882108821188212882138821488215882168821788218882198822088221882228822388224882258822688227882288822988230882318823288233882348823588236882378823888239882408824188242882438824488245882468824788248882498825088251882528825388254882558825688257882588825988260882618826288263882648826588266882678826888269882708827188272882738827488275882768827788278882798828088281882828828388284882858828688287882888828988290882918829288293882948829588296882978829888299883008830188302883038830488305883068830788308883098831088311883128831388314883158831688317883188831988320883218832288323883248832588326883278832888329883308833188332883338833488335883368833788338883398834088341883428834388344883458834688347883488834988350883518835288353883548835588356883578835888359883608836188362883638836488365883668836788368883698837088371883728837388374883758837688377883788837988380883818838288383883848838588386883878838888389883908839188392883938839488395883968839788398883998840088401884028840388404884058840688407884088840988410884118841288413884148841588416884178841888419884208842188422884238842488425884268842788428884298843088431884328843388434884358843688437884388843988440884418844288443884448844588446884478844888449884508845188452884538845488455884568845788458884598846088461884628846388464884658846688467884688846988470884718847288473884748847588476884778847888479884808848188482884838848488485884868848788488884898849088491884928849388494884958849688497884988849988500885018850288503885048850588506885078850888509885108851188512885138851488515885168851788518885198852088521885228852388524885258852688527885288852988530885318853288533885348853588536885378853888539885408854188542885438854488545885468854788548885498855088551885528855388554885558855688557885588855988560885618856288563885648856588566885678856888569885708857188572885738857488575885768857788578885798858088581885828858388584885858858688587885888858988590885918859288593885948859588596885978859888599886008860188602886038860488605886068860788608886098861088611886128861388614886158861688617886188861988620886218862288623886248862588626886278862888629886308863188632886338863488635886368863788638886398864088641886428864388644886458864688647886488864988650886518865288653886548865588656886578865888659886608866188662886638866488665886668866788668886698867088671886728867388674886758867688677886788867988680886818868288683886848868588686886878868888689886908869188692886938869488695886968869788698886998870088701887028870388704887058870688707887088870988710887118871288713887148871588716887178871888719887208872188722887238872488725887268872788728887298873088731887328873388734887358873688737887388873988740887418874288743887448874588746887478874888749887508875188752887538875488755887568875788758887598876088761887628876388764887658876688767887688876988770887718877288773887748877588776887778877888779887808878188782887838878488785887868878788788887898879088791887928879388794887958879688797887988879988800888018880288803888048880588806888078880888809888108881188812888138881488815888168881788818888198882088821888228882388824888258882688827888288882988830888318883288833888348883588836888378883888839888408884188842888438884488845888468884788848888498885088851888528885388854888558885688857888588885988860888618886288863888648886588866888678886888869888708887188872888738887488875888768887788878888798888088881888828888388884888858888688887888888888988890888918889288893888948889588896888978889888899889008890188902889038890488905889068890788908889098891088911889128891388914889158891688917889188891988920889218892288923889248892588926889278892888929889308893188932889338893488935889368893788938889398894088941889428894388944889458894688947889488894988950889518895288953889548895588956889578895888959889608896188962889638896488965889668896788968889698897088971889728897388974889758897688977889788897988980889818898288983889848898588986889878898888989889908899188992889938899488995889968899788998889998900089001890028900389004890058900689007890088900989010890118901289013890148901589016890178901889019890208902189022890238902489025890268902789028890298903089031890328903389034890358903689037890388903989040890418904289043890448904589046890478904889049890508905189052890538905489055890568905789058890598906089061890628906389064890658906689067890688906989070890718907289073890748907589076890778907889079890808908189082890838908489085890868908789088890898909089091890928909389094890958909689097890988909989100891018910289103891048910589106891078910889109891108911189112891138911489115891168911789118891198912089121891228912389124891258912689127891288912989130891318913289133891348913589136891378913889139891408914189142891438914489145891468914789148891498915089151891528915389154891558915689157891588915989160891618916289163891648916589166891678916889169891708917189172891738917489175891768917789178891798918089181891828918389184891858918689187891888918989190891918919289193891948919589196891978919889199892008920189202892038920489205892068920789208892098921089211892128921389214892158921689217892188921989220892218922289223892248922589226892278922889229892308923189232892338923489235892368923789238892398924089241892428924389244892458924689247892488924989250892518925289253892548925589256892578925889259892608926189262892638926489265892668926789268892698927089271892728927389274892758927689277892788927989280892818928289283892848928589286892878928889289892908929189292892938929489295892968929789298892998930089301893028930389304893058930689307893088930989310893118931289313893148931589316893178931889319893208932189322893238932489325893268932789328893298933089331893328933389334893358933689337893388933989340893418934289343893448934589346893478934889349893508935189352893538935489355893568935789358893598936089361893628936389364893658936689367893688936989370893718937289373893748937589376893778937889379893808938189382893838938489385893868938789388893898939089391893928939389394893958939689397893988939989400894018940289403894048940589406894078940889409894108941189412894138941489415894168941789418894198942089421894228942389424894258942689427894288942989430894318943289433894348943589436894378943889439894408944189442894438944489445894468944789448894498945089451894528945389454894558945689457894588945989460894618946289463894648946589466894678946889469894708947189472894738947489475894768947789478894798948089481894828948389484894858948689487894888948989490894918949289493894948949589496894978949889499895008950189502895038950489505895068950789508895098951089511895128951389514895158951689517895188951989520895218952289523895248952589526895278952889529895308953189532895338953489535895368953789538895398954089541895428954389544895458954689547895488954989550895518955289553895548955589556895578955889559895608956189562895638956489565895668956789568895698957089571895728957389574895758957689577895788957989580895818958289583895848958589586895878958889589895908959189592895938959489595895968959789598895998960089601896028960389604896058960689607896088960989610896118961289613896148961589616896178961889619896208962189622896238962489625896268962789628896298963089631896328963389634896358963689637896388963989640896418964289643896448964589646896478964889649896508965189652896538965489655896568965789658896598966089661896628966389664896658966689667896688966989670896718967289673896748967589676896778967889679896808968189682896838968489685896868968789688896898969089691896928969389694896958969689697896988969989700897018970289703897048970589706897078970889709897108971189712897138971489715897168971789718897198972089721897228972389724897258972689727897288972989730897318973289733897348973589736897378973889739897408974189742897438974489745897468974789748897498975089751897528975389754897558975689757897588975989760897618976289763897648976589766897678976889769897708977189772897738977489775897768977789778897798978089781897828978389784897858978689787897888978989790897918979289793897948979589796897978979889799898008980189802898038980489805898068980789808898098981089811898128981389814898158981689817898188981989820898218982289823898248982589826898278982889829898308983189832898338983489835898368983789838898398984089841898428984389844898458984689847898488984989850898518985289853898548985589856898578985889859898608986189862898638986489865898668986789868898698987089871898728987389874898758987689877898788987989880898818988289883898848988589886898878988889889898908989189892898938989489895898968989789898898998990089901899028990389904899058990689907899088990989910899118991289913899148991589916899178991889919899208992189922899238992489925899268992789928899298993089931899328993389934899358993689937899388993989940899418994289943899448994589946899478994889949899508995189952899538995489955899568995789958899598996089961899628996389964899658996689967899688996989970899718997289973899748997589976899778997889979899808998189982899838998489985899868998789988899898999089991899928999389994899958999689997899988999990000900019000290003900049000590006900079000890009900109001190012900139001490015900169001790018900199002090021900229002390024900259002690027900289002990030900319003290033900349003590036900379003890039900409004190042900439004490045900469004790048900499005090051900529005390054900559005690057900589005990060900619006290063900649006590066900679006890069900709007190072900739007490075900769007790078900799008090081900829008390084900859008690087900889008990090900919009290093900949009590096900979009890099901009010190102901039010490105901069010790108901099011090111901129011390114901159011690117901189011990120901219012290123901249012590126901279012890129901309013190132901339013490135901369013790138901399014090141901429014390144901459014690147901489014990150901519015290153901549015590156901579015890159901609016190162901639016490165901669016790168901699017090171901729017390174901759017690177901789017990180901819018290183901849018590186901879018890189901909019190192901939019490195901969019790198901999020090201902029020390204902059020690207902089020990210902119021290213902149021590216902179021890219902209022190222902239022490225902269022790228902299023090231902329023390234902359023690237902389023990240902419024290243902449024590246902479024890249902509025190252902539025490255902569025790258902599026090261902629026390264902659026690267902689026990270902719027290273902749027590276902779027890279902809028190282902839028490285902869028790288902899029090291902929029390294902959029690297902989029990300903019030290303903049030590306903079030890309903109031190312903139031490315903169031790318903199032090321903229032390324903259032690327903289032990330903319033290333903349033590336903379033890339903409034190342903439034490345903469034790348903499035090351903529035390354903559035690357903589035990360903619036290363903649036590366903679036890369903709037190372903739037490375903769037790378903799038090381903829038390384903859038690387903889038990390903919039290393903949039590396903979039890399904009040190402904039040490405904069040790408904099041090411904129041390414904159041690417904189041990420904219042290423904249042590426904279042890429904309043190432904339043490435904369043790438904399044090441904429044390444904459044690447904489044990450904519045290453904549045590456904579045890459904609046190462904639046490465904669046790468904699047090471904729047390474904759047690477904789047990480904819048290483904849048590486904879048890489904909049190492904939049490495904969049790498904999050090501905029050390504905059050690507905089050990510905119051290513905149051590516905179051890519905209052190522905239052490525905269052790528905299053090531905329053390534905359053690537905389053990540905419054290543905449054590546905479054890549905509055190552905539055490555905569055790558905599056090561905629056390564905659056690567905689056990570905719057290573905749057590576905779057890579905809058190582905839058490585905869058790588905899059090591905929059390594905959059690597905989059990600906019060290603906049060590606906079060890609906109061190612906139061490615906169061790618906199062090621906229062390624906259062690627906289062990630906319063290633906349063590636906379063890639906409064190642906439064490645906469064790648906499065090651906529065390654906559065690657906589065990660906619066290663906649066590666906679066890669906709067190672906739067490675906769067790678906799068090681906829068390684906859068690687906889068990690906919069290693906949069590696906979069890699907009070190702907039070490705907069070790708907099071090711907129071390714907159071690717907189071990720907219072290723907249072590726907279072890729907309073190732907339073490735907369073790738907399074090741907429074390744907459074690747907489074990750907519075290753907549075590756907579075890759907609076190762907639076490765907669076790768907699077090771907729077390774907759077690777907789077990780907819078290783907849078590786907879078890789907909079190792907939079490795907969079790798907999080090801908029080390804908059080690807908089080990810908119081290813908149081590816908179081890819908209082190822908239082490825908269082790828908299083090831908329083390834908359083690837908389083990840908419084290843908449084590846908479084890849908509085190852908539085490855908569085790858908599086090861908629086390864908659086690867908689086990870908719087290873908749087590876908779087890879908809088190882908839088490885908869088790888908899089090891908929089390894908959089690897908989089990900909019090290903909049090590906909079090890909909109091190912909139091490915909169091790918909199092090921909229092390924909259092690927909289092990930909319093290933909349093590936909379093890939909409094190942909439094490945909469094790948909499095090951909529095390954909559095690957909589095990960909619096290963909649096590966909679096890969909709097190972909739097490975909769097790978909799098090981909829098390984909859098690987909889098990990909919099290993909949099590996909979099890999910009100191002910039100491005910069100791008910099101091011910129101391014910159101691017910189101991020910219102291023910249102591026910279102891029910309103191032910339103491035910369103791038910399104091041910429104391044910459104691047910489104991050910519105291053910549105591056910579105891059910609106191062910639106491065910669106791068910699107091071910729107391074910759107691077910789107991080910819108291083910849108591086910879108891089910909109191092910939109491095910969109791098910999110091101911029110391104911059110691107911089110991110911119111291113911149111591116911179111891119911209112191122911239112491125911269112791128911299113091131911329113391134911359113691137911389113991140911419114291143911449114591146911479114891149911509115191152911539115491155911569115791158911599116091161911629116391164911659116691167911689116991170911719117291173911749117591176911779117891179911809118191182911839118491185911869118791188911899119091191911929119391194911959119691197911989119991200912019120291203912049120591206912079120891209912109121191212912139121491215912169121791218912199122091221912229122391224912259122691227912289122991230912319123291233912349123591236912379123891239912409124191242912439124491245912469124791248912499125091251912529125391254912559125691257912589125991260912619126291263912649126591266912679126891269912709127191272912739127491275912769127791278912799128091281912829128391284912859128691287912889128991290912919129291293912949129591296912979129891299913009130191302913039130491305913069130791308913099131091311913129131391314913159131691317913189131991320913219132291323913249132591326913279132891329913309133191332913339133491335913369133791338913399134091341913429134391344913459134691347913489134991350913519135291353913549135591356913579135891359913609136191362913639136491365913669136791368913699137091371913729137391374913759137691377913789137991380913819138291383913849138591386913879138891389913909139191392913939139491395913969139791398913999140091401914029140391404914059140691407914089140991410914119141291413914149141591416914179141891419914209142191422914239142491425914269142791428914299143091431914329143391434914359143691437914389143991440914419144291443914449144591446914479144891449914509145191452914539145491455914569145791458914599146091461914629146391464914659146691467914689146991470914719147291473914749147591476914779147891479914809148191482914839148491485914869148791488914899149091491914929149391494914959149691497914989149991500915019150291503915049150591506915079150891509915109151191512915139151491515915169151791518915199152091521915229152391524915259152691527915289152991530915319153291533915349153591536915379153891539915409154191542915439154491545915469154791548915499155091551915529155391554915559155691557915589155991560915619156291563915649156591566915679156891569915709157191572915739157491575915769157791578915799158091581915829158391584915859158691587915889158991590915919159291593915949159591596915979159891599916009160191602916039160491605916069160791608916099161091611916129161391614916159161691617916189161991620916219162291623916249162591626916279162891629916309163191632916339163491635916369163791638916399164091641916429164391644916459164691647916489164991650916519165291653916549165591656916579165891659916609166191662916639166491665916669166791668916699167091671916729167391674916759167691677916789167991680916819168291683916849168591686916879168891689916909169191692916939169491695916969169791698916999170091701917029170391704917059170691707917089170991710917119171291713917149171591716917179171891719917209172191722917239172491725917269172791728917299173091731917329173391734917359173691737917389173991740917419174291743917449174591746917479174891749917509175191752917539175491755917569175791758917599176091761917629176391764917659176691767917689176991770917719177291773917749177591776917779177891779917809178191782917839178491785917869178791788917899179091791917929179391794917959179691797917989179991800918019180291803918049180591806918079180891809918109181191812918139181491815918169181791818918199182091821918229182391824918259182691827918289182991830918319183291833918349183591836918379183891839918409184191842918439184491845918469184791848918499185091851918529185391854918559185691857918589185991860918619186291863918649186591866918679186891869918709187191872918739187491875918769187791878918799188091881918829188391884918859188691887918889188991890918919189291893918949189591896918979189891899919009190191902919039190491905919069190791908919099191091911919129191391914919159191691917919189191991920919219192291923919249192591926919279192891929919309193191932919339193491935919369193791938919399194091941919429194391944919459194691947919489194991950919519195291953919549195591956919579195891959919609196191962919639196491965919669196791968919699197091971919729197391974919759197691977919789197991980919819198291983919849198591986919879198891989919909199191992919939199491995919969199791998919999200092001920029200392004920059200692007920089200992010920119201292013920149201592016920179201892019920209202192022920239202492025920269202792028920299203092031920329203392034920359203692037920389203992040920419204292043920449204592046920479204892049920509205192052920539205492055920569205792058920599206092061920629206392064920659206692067920689206992070920719207292073920749207592076920779207892079920809208192082920839208492085920869208792088920899209092091920929209392094920959209692097920989209992100921019210292103921049210592106921079210892109921109211192112921139211492115921169211792118921199212092121921229212392124921259212692127921289212992130921319213292133921349213592136921379213892139921409214192142921439214492145921469214792148921499215092151921529215392154921559215692157921589215992160921619216292163921649216592166921679216892169921709217192172921739217492175921769217792178921799218092181921829218392184921859218692187921889218992190921919219292193921949219592196921979219892199922009220192202922039220492205922069220792208922099221092211922129221392214922159221692217922189221992220922219222292223922249222592226922279222892229922309223192232922339223492235922369223792238922399224092241922429224392244922459224692247922489224992250922519225292253922549225592256922579225892259922609226192262922639226492265922669226792268922699227092271922729227392274922759227692277922789227992280922819228292283922849228592286922879228892289922909229192292922939229492295922969229792298922999230092301923029230392304923059230692307923089230992310923119231292313923149231592316923179231892319923209232192322923239232492325923269232792328923299233092331923329233392334923359233692337923389233992340923419234292343923449234592346923479234892349923509235192352923539235492355923569235792358923599236092361923629236392364923659236692367923689236992370923719237292373923749237592376923779237892379923809238192382923839238492385923869238792388923899239092391923929239392394923959239692397923989239992400924019240292403924049240592406924079240892409924109241192412924139241492415924169241792418924199242092421924229242392424924259242692427924289242992430924319243292433924349243592436924379243892439924409244192442924439244492445924469244792448924499245092451924529245392454924559245692457924589245992460924619246292463924649246592466924679246892469924709247192472924739247492475924769247792478924799248092481924829248392484924859248692487924889248992490924919249292493924949249592496924979249892499925009250192502925039250492505925069250792508925099251092511925129251392514925159251692517925189251992520925219252292523925249252592526925279252892529925309253192532925339253492535925369253792538925399254092541925429254392544925459254692547925489254992550925519255292553925549255592556925579255892559925609256192562925639256492565925669256792568925699257092571925729257392574925759257692577925789257992580925819258292583925849258592586925879258892589925909259192592925939259492595925969259792598925999260092601926029260392604926059260692607926089260992610926119261292613926149261592616926179261892619926209262192622926239262492625926269262792628926299263092631926329263392634926359263692637926389263992640926419264292643926449264592646926479264892649926509265192652926539265492655926569265792658926599266092661926629266392664926659266692667926689266992670926719267292673926749267592676926779267892679926809268192682926839268492685926869268792688926899269092691926929269392694926959269692697926989269992700927019270292703927049270592706927079270892709927109271192712927139271492715927169271792718927199272092721927229272392724927259272692727927289272992730927319273292733927349273592736927379273892739927409274192742927439274492745927469274792748927499275092751927529275392754927559275692757927589275992760927619276292763927649276592766927679276892769927709277192772927739277492775927769277792778927799278092781927829278392784927859278692787927889278992790927919279292793927949279592796927979279892799928009280192802928039280492805928069280792808928099281092811928129281392814928159281692817928189281992820928219282292823928249282592826928279282892829928309283192832928339283492835928369283792838928399284092841928429284392844928459284692847928489284992850928519285292853928549285592856928579285892859928609286192862928639286492865928669286792868928699287092871928729287392874928759287692877928789287992880928819288292883928849288592886928879288892889928909289192892928939289492895928969289792898928999290092901929029290392904929059290692907929089290992910929119291292913929149291592916929179291892919929209292192922929239292492925929269292792928929299293092931929329293392934929359293692937929389293992940929419294292943929449294592946929479294892949929509295192952929539295492955929569295792958929599296092961929629296392964929659296692967929689296992970929719297292973929749297592976929779297892979929809298192982929839298492985929869298792988929899299092991929929299392994929959299692997929989299993000930019300293003930049300593006930079300893009930109301193012930139301493015930169301793018930199302093021930229302393024930259302693027930289302993030930319303293033930349303593036930379303893039930409304193042930439304493045930469304793048930499305093051930529305393054930559305693057930589305993060930619306293063930649306593066930679306893069930709307193072930739307493075930769307793078930799308093081930829308393084930859308693087930889308993090930919309293093930949309593096930979309893099931009310193102931039310493105931069310793108931099311093111931129311393114931159311693117931189311993120931219312293123931249312593126931279312893129931309313193132931339313493135931369313793138931399314093141931429314393144931459314693147931489314993150931519315293153931549315593156931579315893159931609316193162931639316493165931669316793168931699317093171931729317393174931759317693177931789317993180931819318293183931849318593186931879318893189931909319193192931939319493195931969319793198931999320093201932029320393204932059320693207932089320993210932119321293213932149321593216932179321893219932209322193222932239322493225932269322793228932299323093231932329323393234932359323693237932389323993240932419324293243932449324593246932479324893249932509325193252932539325493255932569325793258932599326093261932629326393264932659326693267932689326993270932719327293273932749327593276932779327893279932809328193282932839328493285932869328793288932899329093291932929329393294932959329693297932989329993300933019330293303933049330593306933079330893309933109331193312933139331493315933169331793318933199332093321933229332393324933259332693327933289332993330933319333293333933349333593336933379333893339933409334193342933439334493345933469334793348933499335093351933529335393354933559335693357933589335993360933619336293363933649336593366933679336893369933709337193372933739337493375933769337793378933799338093381933829338393384933859338693387933889338993390933919339293393933949339593396933979339893399934009340193402934039340493405934069340793408934099341093411934129341393414934159341693417934189341993420934219342293423934249342593426934279342893429934309343193432934339343493435934369343793438934399344093441934429344393444934459344693447934489344993450934519345293453934549345593456934579345893459934609346193462934639346493465934669346793468934699347093471934729347393474934759347693477934789347993480934819348293483934849348593486934879348893489934909349193492934939349493495934969349793498934999350093501935029350393504935059350693507935089350993510935119351293513935149351593516935179351893519935209352193522935239352493525935269352793528935299353093531935329353393534935359353693537935389353993540935419354293543935449354593546935479354893549935509355193552935539355493555935569355793558935599356093561935629356393564935659356693567935689356993570935719357293573935749357593576935779357893579935809358193582935839358493585935869358793588935899359093591935929359393594935959359693597935989359993600936019360293603936049360593606936079360893609936109361193612936139361493615936169361793618936199362093621936229362393624936259362693627936289362993630936319363293633936349363593636936379363893639936409364193642936439364493645936469364793648936499365093651936529365393654936559365693657936589365993660936619366293663936649366593666936679366893669936709367193672936739367493675936769367793678936799368093681936829368393684936859368693687936889368993690936919369293693936949369593696936979369893699937009370193702937039370493705937069370793708937099371093711937129371393714937159371693717937189371993720937219372293723937249372593726937279372893729937309373193732937339373493735937369373793738937399374093741937429374393744937459374693747937489374993750937519375293753937549375593756937579375893759937609376193762937639376493765937669376793768937699377093771937729377393774937759377693777937789377993780937819378293783937849378593786937879378893789937909379193792937939379493795937969379793798937999380093801938029380393804938059380693807938089380993810938119381293813938149381593816938179381893819938209382193822938239382493825938269382793828938299383093831938329383393834938359383693837938389383993840938419384293843938449384593846938479384893849938509385193852938539385493855938569385793858938599386093861938629386393864938659386693867938689386993870938719387293873938749387593876938779387893879938809388193882938839388493885938869388793888938899389093891938929389393894938959389693897938989389993900939019390293903939049390593906939079390893909939109391193912939139391493915939169391793918939199392093921939229392393924939259392693927939289392993930939319393293933939349393593936939379393893939939409394193942939439394493945939469394793948939499395093951939529395393954939559395693957939589395993960939619396293963939649396593966939679396893969939709397193972939739397493975939769397793978939799398093981939829398393984939859398693987939889398993990939919399293993939949399593996939979399893999940009400194002940039400494005940069400794008940099401094011940129401394014940159401694017940189401994020940219402294023940249402594026940279402894029940309403194032940339403494035940369403794038940399404094041940429404394044940459404694047940489404994050940519405294053940549405594056940579405894059940609406194062940639406494065940669406794068940699407094071940729407394074940759407694077940789407994080940819408294083940849408594086940879408894089940909409194092940939409494095940969409794098940999410094101941029410394104941059410694107941089410994110941119411294113941149411594116941179411894119941209412194122941239412494125941269412794128941299413094131941329413394134941359413694137941389413994140941419414294143941449414594146941479414894149941509415194152941539415494155941569415794158941599416094161941629416394164941659416694167941689416994170941719417294173941749417594176941779417894179941809418194182941839418494185941869418794188941899419094191941929419394194941959419694197941989419994200942019420294203942049420594206942079420894209942109421194212942139421494215942169421794218942199422094221942229422394224942259422694227942289422994230942319423294233942349423594236942379423894239942409424194242942439424494245942469424794248942499425094251942529425394254942559425694257942589425994260942619426294263942649426594266942679426894269942709427194272942739427494275942769427794278942799428094281942829428394284942859428694287942889428994290942919429294293942949429594296942979429894299943009430194302943039430494305943069430794308943099431094311943129431394314943159431694317943189431994320943219432294323943249432594326943279432894329943309433194332943339433494335943369433794338943399434094341943429434394344943459434694347943489434994350943519435294353943549435594356943579435894359943609436194362943639436494365943669436794368943699437094371943729437394374943759437694377943789437994380943819438294383943849438594386943879438894389943909439194392943939439494395943969439794398943999440094401944029440394404944059440694407944089440994410944119441294413944149441594416944179441894419944209442194422944239442494425944269442794428944299443094431944329443394434944359443694437944389443994440944419444294443944449444594446944479444894449944509445194452944539445494455944569445794458944599446094461944629446394464944659446694467944689446994470944719447294473944749447594476944779447894479944809448194482944839448494485944869448794488944899449094491944929449394494944959449694497944989449994500945019450294503945049450594506945079450894509945109451194512945139451494515945169451794518945199452094521945229452394524945259452694527945289452994530945319453294533945349453594536945379453894539945409454194542945439454494545945469454794548945499455094551945529455394554945559455694557945589455994560945619456294563945649456594566945679456894569945709457194572945739457494575945769457794578945799458094581945829458394584945859458694587945889458994590945919459294593945949459594596945979459894599946009460194602946039460494605946069460794608946099461094611946129461394614946159461694617946189461994620946219462294623946249462594626946279462894629946309463194632946339463494635946369463794638946399464094641946429464394644946459464694647946489464994650946519465294653946549465594656946579465894659946609466194662946639466494665946669466794668946699467094671946729467394674946759467694677946789467994680946819468294683946849468594686946879468894689946909469194692946939469494695946969469794698946999470094701947029470394704947059470694707947089470994710947119471294713947149471594716947179471894719947209472194722947239472494725947269472794728947299473094731947329473394734947359473694737947389473994740947419474294743947449474594746947479474894749947509475194752947539475494755947569475794758947599476094761947629476394764947659476694767947689476994770947719477294773947749477594776947779477894779947809478194782947839478494785947869478794788947899479094791947929479394794947959479694797947989479994800948019480294803948049480594806948079480894809948109481194812948139481494815948169481794818948199482094821948229482394824948259482694827948289482994830948319483294833948349483594836948379483894839948409484194842948439484494845948469484794848948499485094851948529485394854948559485694857948589485994860948619486294863948649486594866948679486894869948709487194872948739487494875948769487794878948799488094881948829488394884948859488694887948889488994890948919489294893948949489594896948979489894899949009490194902949039490494905949069490794908949099491094911949129491394914949159491694917949189491994920949219492294923949249492594926949279492894929949309493194932949339493494935949369493794938949399494094941949429494394944949459494694947949489494994950949519495294953949549495594956949579495894959949609496194962949639496494965949669496794968949699497094971949729497394974949759497694977949789497994980949819498294983949849498594986949879498894989949909499194992949939499494995949969499794998949999500095001950029500395004950059500695007950089500995010950119501295013950149501595016950179501895019950209502195022950239502495025950269502795028950299503095031950329503395034950359503695037950389503995040950419504295043950449504595046950479504895049950509505195052950539505495055950569505795058950599506095061950629506395064950659506695067950689506995070950719507295073950749507595076950779507895079950809508195082950839508495085950869508795088950899509095091950929509395094950959509695097950989509995100951019510295103951049510595106951079510895109951109511195112951139511495115951169511795118951199512095121951229512395124951259512695127951289512995130951319513295133951349513595136951379513895139951409514195142951439514495145951469514795148951499515095151951529515395154951559515695157951589515995160951619516295163951649516595166951679516895169951709517195172951739517495175951769517795178951799518095181951829518395184951859518695187951889518995190951919519295193951949519595196951979519895199952009520195202952039520495205952069520795208952099521095211952129521395214952159521695217952189521995220952219522295223952249522595226952279522895229952309523195232952339523495235952369523795238952399524095241952429524395244952459524695247952489524995250952519525295253952549525595256952579525895259952609526195262952639526495265952669526795268952699527095271952729527395274952759527695277952789527995280952819528295283952849528595286952879528895289952909529195292952939529495295952969529795298952999530095301953029530395304953059530695307953089530995310953119531295313953149531595316953179531895319953209532195322953239532495325953269532795328953299533095331953329533395334953359533695337953389533995340953419534295343953449534595346953479534895349953509535195352953539535495355953569535795358953599536095361953629536395364953659536695367953689536995370953719537295373953749537595376953779537895379953809538195382953839538495385953869538795388953899539095391953929539395394953959539695397953989539995400954019540295403954049540595406954079540895409954109541195412954139541495415954169541795418954199542095421954229542395424954259542695427954289542995430954319543295433954349543595436954379543895439954409544195442954439544495445954469544795448954499545095451954529545395454954559545695457954589545995460954619546295463954649546595466954679546895469954709547195472954739547495475954769547795478954799548095481954829548395484954859548695487954889548995490954919549295493954949549595496954979549895499955009550195502955039550495505955069550795508955099551095511955129551395514955159551695517955189551995520955219552295523955249552595526955279552895529955309553195532955339553495535955369553795538955399554095541955429554395544955459554695547955489554995550955519555295553955549555595556955579555895559955609556195562955639556495565955669556795568955699557095571955729557395574955759557695577955789557995580955819558295583955849558595586955879558895589955909559195592955939559495595955969559795598955999560095601956029560395604956059560695607956089560995610956119561295613956149561595616956179561895619956209562195622956239562495625956269562795628956299563095631956329563395634956359563695637956389563995640956419564295643956449564595646956479564895649956509565195652956539565495655956569565795658956599566095661956629566395664956659566695667956689566995670956719567295673956749567595676956779567895679956809568195682956839568495685956869568795688956899569095691956929569395694956959569695697956989569995700957019570295703957049570595706957079570895709957109571195712957139571495715957169571795718957199572095721957229572395724957259572695727957289572995730957319573295733957349573595736957379573895739957409574195742957439574495745957469574795748957499575095751957529575395754957559575695757957589575995760957619576295763957649576595766957679576895769957709577195772957739577495775957769577795778957799578095781957829578395784957859578695787957889578995790957919579295793957949579595796957979579895799958009580195802958039580495805958069580795808958099581095811958129581395814958159581695817958189581995820958219582295823958249582595826958279582895829958309583195832958339583495835958369583795838958399584095841958429584395844958459584695847958489584995850958519585295853958549585595856958579585895859958609586195862958639586495865958669586795868958699587095871958729587395874958759587695877958789587995880958819588295883958849588595886958879588895889958909589195892958939589495895958969589795898958999590095901959029590395904959059590695907959089590995910959119591295913959149591595916959179591895919959209592195922959239592495925959269592795928959299593095931959329593395934959359593695937959389593995940959419594295943959449594595946959479594895949959509595195952959539595495955959569595795958959599596095961959629596395964959659596695967959689596995970959719597295973959749597595976959779597895979959809598195982959839598495985959869598795988959899599095991959929599395994959959599695997959989599996000960019600296003960049600596006960079600896009960109601196012960139601496015960169601796018960199602096021960229602396024960259602696027960289602996030960319603296033960349603596036960379603896039960409604196042960439604496045960469604796048960499605096051960529605396054960559605696057960589605996060960619606296063960649606596066960679606896069960709607196072960739607496075960769607796078960799608096081960829608396084960859608696087960889608996090960919609296093960949609596096960979609896099961009610196102961039610496105961069610796108961099611096111961129611396114961159611696117961189611996120961219612296123961249612596126961279612896129961309613196132961339613496135961369613796138961399614096141961429614396144961459614696147961489614996150961519615296153961549615596156961579615896159961609616196162961639616496165961669616796168961699617096171961729617396174961759617696177961789617996180961819618296183961849618596186961879618896189961909619196192961939619496195961969619796198961999620096201962029620396204962059620696207962089620996210962119621296213962149621596216962179621896219962209622196222962239622496225962269622796228962299623096231962329623396234962359623696237962389623996240962419624296243962449624596246962479624896249962509625196252962539625496255962569625796258962599626096261962629626396264962659626696267962689626996270962719627296273962749627596276962779627896279962809628196282962839628496285962869628796288962899629096291962929629396294962959629696297962989629996300963019630296303963049630596306963079630896309963109631196312963139631496315963169631796318963199632096321963229632396324963259632696327963289632996330963319633296333963349633596336963379633896339963409634196342963439634496345963469634796348963499635096351963529635396354963559635696357963589635996360963619636296363963649636596366963679636896369963709637196372963739637496375963769637796378963799638096381963829638396384963859638696387963889638996390963919639296393963949639596396963979639896399964009640196402964039640496405964069640796408964099641096411964129641396414964159641696417964189641996420964219642296423964249642596426964279642896429964309643196432964339643496435964369643796438964399644096441964429644396444964459644696447964489644996450964519645296453964549645596456964579645896459964609646196462964639646496465964669646796468964699647096471964729647396474964759647696477964789647996480964819648296483964849648596486964879648896489964909649196492964939649496495964969649796498964999650096501965029650396504965059650696507965089650996510965119651296513965149651596516965179651896519965209652196522965239652496525965269652796528965299653096531965329653396534965359653696537965389653996540965419654296543965449654596546965479654896549965509655196552965539655496555965569655796558965599656096561965629656396564965659656696567965689656996570965719657296573965749657596576965779657896579965809658196582965839658496585965869658796588965899659096591965929659396594965959659696597965989659996600966019660296603966049660596606966079660896609966109661196612966139661496615966169661796618966199662096621966229662396624966259662696627966289662996630966319663296633966349663596636966379663896639966409664196642966439664496645966469664796648966499665096651966529665396654966559665696657966589665996660966619666296663966649666596666966679666896669966709667196672966739667496675966769667796678966799668096681966829668396684966859668696687966889668996690966919669296693966949669596696966979669896699967009670196702967039670496705967069670796708967099671096711967129671396714967159671696717967189671996720967219672296723967249672596726967279672896729967309673196732967339673496735967369673796738967399674096741967429674396744967459674696747967489674996750967519675296753967549675596756967579675896759967609676196762967639676496765967669676796768967699677096771967729677396774967759677696777967789677996780967819678296783967849678596786967879678896789967909679196792967939679496795967969679796798967999680096801968029680396804968059680696807968089680996810968119681296813968149681596816968179681896819968209682196822968239682496825968269682796828968299683096831968329683396834968359683696837968389683996840968419684296843968449684596846968479684896849968509685196852968539685496855968569685796858968599686096861968629686396864968659686696867968689686996870968719687296873968749687596876968779687896879968809688196882968839688496885968869688796888968899689096891968929689396894968959689696897968989689996900969019690296903969049690596906969079690896909969109691196912969139691496915969169691796918969199692096921969229692396924969259692696927969289692996930969319693296933969349693596936969379693896939969409694196942969439694496945969469694796948969499695096951969529695396954969559695696957969589695996960969619696296963969649696596966969679696896969969709697196972969739697496975969769697796978969799698096981969829698396984969859698696987969889698996990969919699296993969949699596996969979699896999970009700197002970039700497005970069700797008970099701097011970129701397014970159701697017970189701997020970219702297023970249702597026970279702897029970309703197032970339703497035970369703797038970399704097041970429704397044970459704697047970489704997050970519705297053970549705597056970579705897059970609706197062970639706497065970669706797068970699707097071970729707397074970759707697077970789707997080970819708297083970849708597086970879708897089970909709197092970939709497095970969709797098970999710097101971029710397104971059710697107971089710997110971119711297113971149711597116971179711897119971209712197122971239712497125971269712797128971299713097131971329713397134971359713697137971389713997140971419714297143971449714597146971479714897149971509715197152971539715497155971569715797158971599716097161971629716397164971659716697167971689716997170971719717297173971749717597176971779717897179971809718197182971839718497185971869718797188971899719097191971929719397194971959719697197971989719997200972019720297203972049720597206972079720897209972109721197212972139721497215972169721797218972199722097221972229722397224972259722697227972289722997230972319723297233972349723597236972379723897239972409724197242972439724497245972469724797248972499725097251972529725397254972559725697257972589725997260972619726297263972649726597266972679726897269972709727197272972739727497275972769727797278972799728097281972829728397284972859728697287972889728997290972919729297293972949729597296972979729897299973009730197302973039730497305973069730797308973099731097311973129731397314973159731697317973189731997320973219732297323973249732597326973279732897329973309733197332973339733497335973369733797338973399734097341973429734397344973459734697347973489734997350973519735297353973549735597356973579735897359973609736197362973639736497365973669736797368973699737097371973729737397374973759737697377973789737997380973819738297383973849738597386973879738897389973909739197392973939739497395973969739797398973999740097401974029740397404974059740697407974089740997410974119741297413974149741597416974179741897419974209742197422974239742497425974269742797428974299743097431974329743397434974359743697437974389743997440974419744297443974449744597446974479744897449974509745197452974539745497455974569745797458974599746097461974629746397464974659746697467974689746997470974719747297473974749747597476974779747897479974809748197482974839748497485974869748797488974899749097491974929749397494974959749697497974989749997500975019750297503975049750597506975079750897509975109751197512975139751497515975169751797518975199752097521975229752397524975259752697527975289752997530975319753297533975349753597536975379753897539975409754197542975439754497545975469754797548975499755097551975529755397554975559755697557975589755997560975619756297563975649756597566975679756897569975709757197572975739757497575975769757797578975799758097581975829758397584975859758697587975889758997590975919759297593975949759597596975979759897599976009760197602976039760497605976069760797608976099761097611976129761397614976159761697617976189761997620976219762297623976249762597626976279762897629976309763197632976339763497635976369763797638976399764097641976429764397644976459764697647976489764997650976519765297653976549765597656976579765897659976609766197662976639766497665976669766797668976699767097671976729767397674976759767697677976789767997680976819768297683976849768597686976879768897689976909769197692976939769497695976969769797698976999770097701977029770397704977059770697707977089770997710977119771297713977149771597716977179771897719977209772197722977239772497725977269772797728977299773097731977329773397734977359773697737977389773997740977419774297743977449774597746977479774897749977509775197752977539775497755977569775797758977599776097761977629776397764977659776697767977689776997770977719777297773977749777597776977779777897779977809778197782977839778497785977869778797788977899779097791977929779397794977959779697797977989779997800978019780297803978049780597806978079780897809978109781197812978139781497815978169781797818978199782097821978229782397824978259782697827978289782997830978319783297833978349783597836978379783897839978409784197842978439784497845978469784797848978499785097851978529785397854978559785697857978589785997860978619786297863978649786597866978679786897869978709787197872978739787497875978769787797878978799788097881978829788397884978859788697887978889788997890978919789297893978949789597896978979789897899979009790197902979039790497905979069790797908979099791097911979129791397914979159791697917979189791997920979219792297923979249792597926979279792897929979309793197932979339793497935979369793797938979399794097941979429794397944979459794697947979489794997950979519795297953979549795597956979579795897959979609796197962979639796497965979669796797968979699797097971979729797397974979759797697977979789797997980979819798297983979849798597986979879798897989979909799197992979939799497995979969799797998979999800098001980029800398004980059800698007980089800998010980119801298013980149801598016980179801898019980209802198022980239802498025980269802798028980299803098031980329803398034980359803698037980389803998040980419804298043980449804598046980479804898049980509805198052980539805498055980569805798058980599806098061980629806398064980659806698067980689806998070980719807298073980749807598076980779807898079980809808198082980839808498085980869808798088980899809098091980929809398094980959809698097980989809998100981019810298103981049810598106981079810898109981109811198112981139811498115981169811798118981199812098121981229812398124981259812698127981289812998130981319813298133981349813598136981379813898139981409814198142981439814498145981469814798148981499815098151981529815398154981559815698157981589815998160981619816298163981649816598166981679816898169981709817198172981739817498175981769817798178981799818098181981829818398184981859818698187981889818998190981919819298193981949819598196981979819898199982009820198202982039820498205982069820798208982099821098211982129821398214982159821698217982189821998220982219822298223982249822598226982279822898229982309823198232982339823498235982369823798238982399824098241982429824398244982459824698247982489824998250982519825298253982549825598256982579825898259982609826198262982639826498265982669826798268982699827098271982729827398274982759827698277982789827998280982819828298283982849828598286982879828898289982909829198292982939829498295982969829798298982999830098301983029830398304983059830698307983089830998310983119831298313983149831598316983179831898319983209832198322983239832498325983269832798328983299833098331983329833398334983359833698337983389833998340983419834298343983449834598346983479834898349983509835198352983539835498355983569835798358983599836098361983629836398364983659836698367983689836998370983719837298373983749837598376983779837898379983809838198382983839838498385983869838798388983899839098391983929839398394983959839698397983989839998400984019840298403984049840598406984079840898409984109841198412984139841498415984169841798418984199842098421984229842398424984259842698427984289842998430984319843298433984349843598436984379843898439984409844198442984439844498445984469844798448984499845098451984529845398454984559845698457984589845998460984619846298463984649846598466984679846898469984709847198472984739847498475984769847798478984799848098481984829848398484984859848698487984889848998490984919849298493984949849598496984979849898499985009850198502985039850498505985069850798508985099851098511985129851398514985159851698517985189851998520985219852298523985249852598526985279852898529985309853198532985339853498535985369853798538985399854098541985429854398544985459854698547985489854998550985519855298553985549855598556985579855898559985609856198562985639856498565985669856798568985699857098571985729857398574985759857698577985789857998580985819858298583985849858598586985879858898589985909859198592985939859498595985969859798598985999860098601986029860398604986059860698607986089860998610986119861298613986149861598616986179861898619986209862198622986239862498625986269862798628986299863098631986329863398634986359863698637986389863998640986419864298643986449864598646986479864898649986509865198652986539865498655986569865798658986599866098661986629866398664986659866698667986689866998670986719867298673986749867598676986779867898679986809868198682986839868498685986869868798688986899869098691986929869398694986959869698697986989869998700987019870298703987049870598706987079870898709987109871198712987139871498715987169871798718987199872098721987229872398724987259872698727987289872998730987319873298733987349873598736987379873898739987409874198742987439874498745987469874798748987499875098751987529875398754987559875698757987589875998760987619876298763987649876598766987679876898769987709877198772987739877498775987769877798778987799878098781987829878398784987859878698787987889878998790987919879298793987949879598796987979879898799988009880198802988039880498805988069880798808988099881098811988129881398814988159881698817988189881998820988219882298823988249882598826988279882898829988309883198832988339883498835988369883798838988399884098841988429884398844988459884698847988489884998850988519885298853988549885598856988579885898859988609886198862988639886498865988669886798868988699887098871988729887398874988759887698877988789887998880988819888298883988849888598886988879888898889988909889198892988939889498895988969889798898988999890098901989029890398904989059890698907989089890998910989119891298913989149891598916989179891898919989209892198922989239892498925989269892798928989299893098931989329893398934989359893698937989389893998940989419894298943989449894598946989479894898949989509895198952989539895498955989569895798958989599896098961989629896398964989659896698967989689896998970989719897298973989749897598976989779897898979989809898198982989839898498985989869898798988989899899098991989929899398994989959899698997989989899999000990019900299003990049900599006990079900899009990109901199012990139901499015990169901799018990199902099021990229902399024990259902699027990289902999030990319903299033990349903599036990379903899039990409904199042990439904499045990469904799048990499905099051990529905399054990559905699057990589905999060990619906299063990649906599066990679906899069990709907199072990739907499075990769907799078990799908099081990829908399084990859908699087990889908999090990919909299093990949909599096990979909899099991009910199102991039910499105991069910799108991099911099111991129911399114991159911699117991189911999120991219912299123991249912599126991279912899129991309913199132991339913499135991369913799138991399914099141991429914399144991459914699147991489914999150991519915299153991549915599156991579915899159991609916199162991639916499165991669916799168991699917099171991729917399174991759917699177991789917999180991819918299183991849918599186991879918899189991909919199192991939919499195991969919799198991999920099201992029920399204992059920699207992089920999210992119921299213992149921599216992179921899219992209922199222992239922499225992269922799228992299923099231992329923399234992359923699237992389923999240992419924299243992449924599246992479924899249992509925199252992539925499255992569925799258992599926099261992629926399264992659926699267992689926999270992719927299273992749927599276992779927899279992809928199282992839928499285992869928799288992899929099291992929929399294992959929699297992989929999300993019930299303993049930599306993079930899309993109931199312993139931499315993169931799318993199932099321993229932399324993259932699327993289932999330993319933299333993349933599336993379933899339993409934199342993439934499345993469934799348993499935099351993529935399354993559935699357993589935999360993619936299363993649936599366993679936899369993709937199372993739937499375993769937799378993799938099381993829938399384993859938699387993889938999390993919939299393993949939599396993979939899399994009940199402994039940499405994069940799408994099941099411994129941399414994159941699417994189941999420994219942299423994249942599426994279942899429994309943199432994339943499435994369943799438994399944099441994429944399444994459944699447994489944999450994519945299453994549945599456994579945899459994609946199462994639946499465994669946799468994699947099471994729947399474994759947699477994789947999480994819948299483994849948599486994879948899489994909949199492994939949499495994969949799498994999950099501995029950399504995059950699507995089950999510995119951299513995149951599516995179951899519995209952199522995239952499525995269952799528995299953099531995329953399534995359953699537995389953999540995419954299543995449954599546995479954899549995509955199552995539955499555995569955799558995599956099561995629956399564995659956699567995689956999570995719957299573995749957599576995779957899579995809958199582995839958499585995869958799588995899959099591995929959399594995959959699597995989959999600996019960299603996049960599606996079960899609996109961199612996139961499615996169961799618996199962099621996229962399624996259962699627996289962999630996319963299633996349963599636996379963899639996409964199642996439964499645996469964799648996499965099651996529965399654996559965699657996589965999660996619966299663996649966599666996679966899669996709967199672996739967499675996769967799678996799968099681996829968399684996859968699687996889968999690996919969299693996949969599696996979969899699997009970199702997039970499705997069970799708997099971099711997129971399714997159971699717997189971999720997219972299723997249972599726997279972899729997309973199732997339973499735997369973799738997399974099741997429974399744997459974699747997489974999750997519975299753997549975599756997579975899759997609976199762997639976499765997669976799768997699977099771997729977399774997759977699777997789977999780997819978299783997849978599786997879978899789997909979199792997939979499795997969979799798997999980099801998029980399804998059980699807998089980999810998119981299813998149981599816998179981899819998209982199822998239982499825998269982799828998299983099831998329983399834998359983699837998389983999840998419984299843998449984599846998479984899849998509985199852998539985499855998569985799858998599986099861998629986399864998659986699867998689986999870998719987299873998749987599876998779987899879998809988199882998839988499885998869988799888998899989099891998929989399894998959989699897998989989999900999019990299903999049990599906999079990899909999109991199912999139991499915999169991799918999199992099921999229992399924999259992699927999289992999930999319993299933999349993599936999379993899939999409994199942999439994499945999469994799948999499995099951999529995399954999559995699957999589995999960999619996299963999649996599966999679996899969999709997199972999739997499975999769997799978999799998099981999829998399984999859998699987999889998999990999919999299993999949999599996999979999899999100000100001100002100003100004100005100006100007100008100009100010100011100012100013100014100015100016100017100018100019100020100021100022100023100024100025100026100027100028100029100030100031100032100033100034100035100036100037100038100039100040100041100042100043100044100045100046100047100048100049100050100051100052100053100054100055100056100057100058100059100060100061100062100063100064100065100066100067100068100069100070100071100072100073100074100075100076100077100078100079100080100081100082100083100084100085100086100087100088100089100090100091100092100093100094100095100096100097100098100099100100100101100102100103100104100105100106100107100108100109100110100111100112100113100114100115100116100117100118100119100120100121100122100123100124100125100126100127100128100129100130100131100132100133100134100135100136100137100138100139100140100141100142100143100144100145100146100147100148100149100150100151100152100153100154100155100156100157100158100159100160100161100162100163100164100165100166100167100168100169100170100171100172100173100174100175100176100177100178100179100180100181100182100183100184100185100186100187100188100189100190100191100192100193100194100195100196100197100198100199100200100201100202100203100204100205100206100207100208100209100210100211100212100213100214100215100216100217100218100219100220100221100222100223100224100225100226100227100228100229100230100231100232100233100234100235100236100237100238100239100240100241100242100243100244100245100246100247100248100249100250100251100252100253100254100255100256100257100258100259100260100261100262100263100264100265100266100267100268100269100270100271100272100273100274100275100276100277100278100279100280100281100282100283100284100285100286100287100288100289100290100291100292100293100294100295100296100297100298100299100300100301100302100303100304100305100306100307100308100309100310100311100312100313100314100315100316100317100318100319100320100321100322100323100324100325100326100327100328100329100330100331100332100333100334100335100336100337100338100339100340100341100342100343100344100345100346100347100348100349100350100351100352100353100354100355100356100357100358100359100360100361100362100363100364100365100366100367100368100369100370100371100372100373100374100375100376100377100378100379100380100381100382100383100384100385100386100387100388100389100390100391100392100393100394100395100396100397100398100399100400100401100402100403100404100405100406100407100408100409100410100411100412100413100414100415100416100417100418100419100420100421100422100423100424100425100426100427100428100429100430100431100432100433100434100435100436100437100438100439100440100441100442100443100444100445100446100447100448100449100450100451100452100453100454100455100456100457100458100459100460100461100462100463100464100465100466100467100468100469100470100471100472100473100474100475100476100477100478100479100480100481100482100483100484100485100486100487100488100489100490100491100492100493100494100495100496100497100498100499100500100501100502100503100504100505100506100507100508100509100510100511100512100513100514100515100516100517100518100519100520100521100522100523100524100525100526100527100528100529100530100531100532100533100534100535100536100537100538100539100540100541100542100543100544100545100546100547100548100549100550100551100552100553100554100555100556100557100558100559100560100561100562100563100564100565100566100567100568100569100570100571100572100573100574100575100576100577100578100579100580100581100582100583100584100585100586100587100588100589100590100591100592
  1. diff -Nur linux-3.12.11.orig/arch/arm/configs/bcmrpi_cutdown_defconfig linux-3.12.11/arch/arm/configs/bcmrpi_cutdown_defconfig
  2. --- linux-3.12.11.orig/arch/arm/configs/bcmrpi_cutdown_defconfig 1970-01-01 01:00:00.000000000 +0100
  3. +++ linux-3.12.11/arch/arm/configs/bcmrpi_cutdown_defconfig 2014-02-18 11:52:14.000000000 +0100
  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.12.11.orig/arch/arm/configs/bcmrpi_defconfig linux-3.12.11/arch/arm/configs/bcmrpi_defconfig
  509. --- linux-3.12.11.orig/arch/arm/configs/bcmrpi_defconfig 1970-01-01 01:00:00.000000000 +0100
  510. +++ linux-3.12.11/arch/arm/configs/bcmrpi_defconfig 2014-02-18 11:52:14.000000000 +0100
  511. @@ -0,0 +1,1092 @@
  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_BLK_CGROUP=y
  533. +CONFIG_NAMESPACES=y
  534. +CONFIG_SCHED_AUTOGROUP=y
  535. +CONFIG_RELAY=y
  536. +CONFIG_BLK_DEV_INITRD=y
  537. +CONFIG_EMBEDDED=y
  538. +# CONFIG_COMPAT_BRK is not set
  539. +CONFIG_PROFILING=y
  540. +CONFIG_OPROFILE=m
  541. +CONFIG_KPROBES=y
  542. +CONFIG_JUMP_LABEL=y
  543. +CONFIG_MODULES=y
  544. +CONFIG_MODULE_UNLOAD=y
  545. +CONFIG_MODVERSIONS=y
  546. +CONFIG_MODULE_SRCVERSION_ALL=y
  547. +CONFIG_BLK_DEV_THROTTLING=y
  548. +CONFIG_PARTITION_ADVANCED=y
  549. +CONFIG_MAC_PARTITION=y
  550. +CONFIG_CFQ_GROUP_IOSCHED=y
  551. +CONFIG_ARCH_BCM2708=y
  552. +CONFIG_PREEMPT=y
  553. +CONFIG_AEABI=y
  554. +CONFIG_CLEANCACHE=y
  555. +CONFIG_FRONTSWAP=y
  556. +CONFIG_UACCESS_WITH_MEMCPY=y
  557. +CONFIG_SECCOMP=y
  558. +CONFIG_CC_STACKPROTECTOR=y
  559. +CONFIG_ZBOOT_ROM_TEXT=0x0
  560. +CONFIG_ZBOOT_ROM_BSS=0x0
  561. +CONFIG_CMDLINE="console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  562. +CONFIG_KEXEC=y
  563. +CONFIG_CPU_FREQ=y
  564. +CONFIG_CPU_FREQ_STAT=m
  565. +CONFIG_CPU_FREQ_STAT_DETAILS=y
  566. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  567. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  568. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  569. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  570. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  571. +CONFIG_CPU_IDLE=y
  572. +CONFIG_VFP=y
  573. +CONFIG_BINFMT_MISC=m
  574. +CONFIG_NET=y
  575. +CONFIG_PACKET=y
  576. +CONFIG_UNIX=y
  577. +CONFIG_XFRM_USER=y
  578. +CONFIG_NET_KEY=m
  579. +CONFIG_INET=y
  580. +CONFIG_IP_MULTICAST=y
  581. +CONFIG_IP_ADVANCED_ROUTER=y
  582. +CONFIG_IP_MULTIPLE_TABLES=y
  583. +CONFIG_IP_ROUTE_MULTIPATH=y
  584. +CONFIG_IP_ROUTE_VERBOSE=y
  585. +CONFIG_IP_PNP=y
  586. +CONFIG_IP_PNP_DHCP=y
  587. +CONFIG_IP_PNP_RARP=y
  588. +CONFIG_NET_IPIP=m
  589. +CONFIG_NET_IPGRE_DEMUX=m
  590. +CONFIG_NET_IPGRE=m
  591. +CONFIG_IP_MROUTE=y
  592. +CONFIG_IP_MROUTE_MULTIPLE_TABLES=y
  593. +CONFIG_IP_PIMSM_V1=y
  594. +CONFIG_IP_PIMSM_V2=y
  595. +CONFIG_SYN_COOKIES=y
  596. +CONFIG_INET_AH=m
  597. +CONFIG_INET_ESP=m
  598. +CONFIG_INET_IPCOMP=m
  599. +CONFIG_INET_XFRM_MODE_TRANSPORT=m
  600. +CONFIG_INET_XFRM_MODE_TUNNEL=m
  601. +CONFIG_INET_XFRM_MODE_BEET=m
  602. +CONFIG_INET_LRO=m
  603. +CONFIG_INET_DIAG=m
  604. +CONFIG_IPV6_PRIVACY=y
  605. +CONFIG_INET6_AH=m
  606. +CONFIG_INET6_ESP=m
  607. +CONFIG_INET6_IPCOMP=m
  608. +CONFIG_IPV6_MULTIPLE_TABLES=y
  609. +CONFIG_IPV6_MROUTE=y
  610. +CONFIG_IPV6_MROUTE_MULTIPLE_TABLES=y
  611. +CONFIG_IPV6_PIMSM_V2=y
  612. +CONFIG_NETFILTER=y
  613. +CONFIG_NF_CONNTRACK=m
  614. +CONFIG_NF_CONNTRACK_ZONES=y
  615. +CONFIG_NF_CONNTRACK_EVENTS=y
  616. +CONFIG_NF_CONNTRACK_TIMESTAMP=y
  617. +CONFIG_NF_CT_PROTO_DCCP=m
  618. +CONFIG_NF_CT_PROTO_UDPLITE=m
  619. +CONFIG_NF_CONNTRACK_AMANDA=m
  620. +CONFIG_NF_CONNTRACK_FTP=m
  621. +CONFIG_NF_CONNTRACK_H323=m
  622. +CONFIG_NF_CONNTRACK_IRC=m
  623. +CONFIG_NF_CONNTRACK_NETBIOS_NS=m
  624. +CONFIG_NF_CONNTRACK_SNMP=m
  625. +CONFIG_NF_CONNTRACK_PPTP=m
  626. +CONFIG_NF_CONNTRACK_SANE=m
  627. +CONFIG_NF_CONNTRACK_SIP=m
  628. +CONFIG_NF_CONNTRACK_TFTP=m
  629. +CONFIG_NF_CT_NETLINK=m
  630. +CONFIG_NETFILTER_TPROXY=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_BRIDGE=m
  782. +CONFIG_VLAN_8021Q=m
  783. +CONFIG_VLAN_8021Q_GVRP=y
  784. +CONFIG_ATALK=m
  785. +CONFIG_NET_SCHED=y
  786. +CONFIG_NET_SCH_CBQ=m
  787. +CONFIG_NET_SCH_HTB=m
  788. +CONFIG_NET_SCH_HFSC=m
  789. +CONFIG_NET_SCH_PRIO=m
  790. +CONFIG_NET_SCH_MULTIQ=m
  791. +CONFIG_NET_SCH_RED=m
  792. +CONFIG_NET_SCH_SFB=m
  793. +CONFIG_NET_SCH_SFQ=m
  794. +CONFIG_NET_SCH_TEQL=m
  795. +CONFIG_NET_SCH_TBF=m
  796. +CONFIG_NET_SCH_GRED=m
  797. +CONFIG_NET_SCH_DSMARK=m
  798. +CONFIG_NET_SCH_NETEM=m
  799. +CONFIG_NET_SCH_DRR=m
  800. +CONFIG_NET_SCH_MQPRIO=m
  801. +CONFIG_NET_SCH_CHOKE=m
  802. +CONFIG_NET_SCH_QFQ=m
  803. +CONFIG_NET_SCH_CODEL=m
  804. +CONFIG_NET_SCH_FQ_CODEL=m
  805. +CONFIG_NET_SCH_INGRESS=m
  806. +CONFIG_NET_SCH_PLUG=m
  807. +CONFIG_NET_CLS_BASIC=m
  808. +CONFIG_NET_CLS_TCINDEX=m
  809. +CONFIG_NET_CLS_ROUTE4=m
  810. +CONFIG_NET_CLS_FW=m
  811. +CONFIG_NET_CLS_U32=m
  812. +CONFIG_CLS_U32_MARK=y
  813. +CONFIG_NET_CLS_RSVP=m
  814. +CONFIG_NET_CLS_RSVP6=m
  815. +CONFIG_NET_CLS_FLOW=m
  816. +CONFIG_NET_CLS_CGROUP=m
  817. +CONFIG_NET_EMATCH=y
  818. +CONFIG_NET_EMATCH_CMP=m
  819. +CONFIG_NET_EMATCH_NBYTE=m
  820. +CONFIG_NET_EMATCH_U32=m
  821. +CONFIG_NET_EMATCH_META=m
  822. +CONFIG_NET_EMATCH_TEXT=m
  823. +CONFIG_NET_EMATCH_IPSET=m
  824. +CONFIG_NET_CLS_ACT=y
  825. +CONFIG_NET_ACT_POLICE=m
  826. +CONFIG_NET_ACT_GACT=m
  827. +CONFIG_GACT_PROB=y
  828. +CONFIG_NET_ACT_MIRRED=m
  829. +CONFIG_NET_ACT_IPT=m
  830. +CONFIG_NET_ACT_NAT=m
  831. +CONFIG_NET_ACT_PEDIT=m
  832. +CONFIG_NET_ACT_SIMP=m
  833. +CONFIG_NET_ACT_SKBEDIT=m
  834. +CONFIG_NET_ACT_CSUM=m
  835. +CONFIG_BATMAN_ADV=m
  836. +CONFIG_OPENVSWITCH=m
  837. +CONFIG_NET_PKTGEN=m
  838. +CONFIG_HAMRADIO=y
  839. +CONFIG_AX25=m
  840. +CONFIG_NETROM=m
  841. +CONFIG_ROSE=m
  842. +CONFIG_MKISS=m
  843. +CONFIG_6PACK=m
  844. +CONFIG_BPQETHER=m
  845. +CONFIG_BAYCOM_SER_FDX=m
  846. +CONFIG_BAYCOM_SER_HDX=m
  847. +CONFIG_YAM=m
  848. +CONFIG_IRDA=m
  849. +CONFIG_IRLAN=m
  850. +CONFIG_IRNET=m
  851. +CONFIG_IRCOMM=m
  852. +CONFIG_IRDA_ULTRA=y
  853. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  854. +CONFIG_IRDA_FAST_RR=y
  855. +CONFIG_IRTTY_SIR=m
  856. +CONFIG_KINGSUN_DONGLE=m
  857. +CONFIG_KSDAZZLE_DONGLE=m
  858. +CONFIG_KS959_DONGLE=m
  859. +CONFIG_USB_IRDA=m
  860. +CONFIG_SIGMATEL_FIR=m
  861. +CONFIG_MCS_FIR=m
  862. +CONFIG_BT=m
  863. +CONFIG_BT_RFCOMM=m
  864. +CONFIG_BT_RFCOMM_TTY=y
  865. +CONFIG_BT_BNEP=m
  866. +CONFIG_BT_BNEP_MC_FILTER=y
  867. +CONFIG_BT_BNEP_PROTO_FILTER=y
  868. +CONFIG_BT_HIDP=m
  869. +CONFIG_BT_HCIBTUSB=m
  870. +CONFIG_BT_HCIBCM203X=m
  871. +CONFIG_BT_HCIBPA10X=m
  872. +CONFIG_BT_HCIBFUSB=m
  873. +CONFIG_BT_HCIVHCI=m
  874. +CONFIG_BT_MRVL=m
  875. +CONFIG_BT_MRVL_SDIO=m
  876. +CONFIG_BT_ATH3K=m
  877. +CONFIG_BT_WILINK=m
  878. +CONFIG_CFG80211=m
  879. +CONFIG_CFG80211_WEXT=y
  880. +CONFIG_MAC80211=m
  881. +CONFIG_MAC80211_RC_PID=y
  882. +CONFIG_MAC80211_MESH=y
  883. +CONFIG_WIMAX=m
  884. +CONFIG_RFKILL=m
  885. +CONFIG_RFKILL_INPUT=y
  886. +CONFIG_NET_9P=m
  887. +CONFIG_NFC=m
  888. +CONFIG_NFC_PN533=m
  889. +CONFIG_DEVTMPFS=y
  890. +CONFIG_DEVTMPFS_MOUNT=y
  891. +CONFIG_CMA=y
  892. +CONFIG_BLK_DEV_LOOP=y
  893. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  894. +CONFIG_BLK_DEV_DRBD=m
  895. +CONFIG_BLK_DEV_NBD=m
  896. +CONFIG_BLK_DEV_RAM=y
  897. +CONFIG_CDROM_PKTCDVD=m
  898. +CONFIG_SCSI=y
  899. +# CONFIG_SCSI_PROC_FS is not set
  900. +CONFIG_BLK_DEV_SD=y
  901. +CONFIG_CHR_DEV_ST=m
  902. +CONFIG_CHR_DEV_OSST=m
  903. +CONFIG_BLK_DEV_SR=m
  904. +CONFIG_SCSI_MULTI_LUN=y
  905. +CONFIG_SCSI_ISCSI_ATTRS=y
  906. +CONFIG_ISCSI_TCP=m
  907. +CONFIG_ISCSI_BOOT_SYSFS=m
  908. +CONFIG_MD=y
  909. +CONFIG_MD_LINEAR=m
  910. +CONFIG_MD_RAID0=m
  911. +CONFIG_BLK_DEV_DM=m
  912. +CONFIG_DM_CRYPT=m
  913. +CONFIG_DM_SNAPSHOT=m
  914. +CONFIG_DM_MIRROR=m
  915. +CONFIG_DM_RAID=m
  916. +CONFIG_DM_LOG_USERSPACE=m
  917. +CONFIG_DM_ZERO=m
  918. +CONFIG_DM_DELAY=m
  919. +CONFIG_NETDEVICES=y
  920. +CONFIG_BONDING=m
  921. +CONFIG_DUMMY=m
  922. +CONFIG_IFB=m
  923. +CONFIG_MACVLAN=m
  924. +CONFIG_NETCONSOLE=m
  925. +CONFIG_TUN=m
  926. +CONFIG_MDIO_BITBANG=m
  927. +CONFIG_PPP=m
  928. +CONFIG_PPP_BSDCOMP=m
  929. +CONFIG_PPP_DEFLATE=m
  930. +CONFIG_PPP_FILTER=y
  931. +CONFIG_PPP_MPPE=m
  932. +CONFIG_PPP_MULTILINK=y
  933. +CONFIG_PPPOE=m
  934. +CONFIG_PPPOL2TP=m
  935. +CONFIG_PPP_ASYNC=m
  936. +CONFIG_PPP_SYNC_TTY=m
  937. +CONFIG_SLIP=m
  938. +CONFIG_SLIP_COMPRESSED=y
  939. +CONFIG_SLIP_SMART=y
  940. +CONFIG_USB_CATC=m
  941. +CONFIG_USB_KAWETH=m
  942. +CONFIG_USB_PEGASUS=m
  943. +CONFIG_USB_RTL8150=m
  944. +CONFIG_USB_RTL8152=m
  945. +CONFIG_USB_USBNET=y
  946. +CONFIG_USB_NET_AX8817X=m
  947. +CONFIG_USB_NET_CDCETHER=m
  948. +CONFIG_USB_NET_CDC_EEM=m
  949. +CONFIG_USB_NET_CDC_NCM=m
  950. +CONFIG_USB_NET_CDC_MBIM=m
  951. +CONFIG_USB_NET_DM9601=m
  952. +CONFIG_USB_NET_SMSC75XX=m
  953. +CONFIG_USB_NET_SMSC95XX=y
  954. +CONFIG_USB_NET_GL620A=m
  955. +CONFIG_USB_NET_NET1080=m
  956. +CONFIG_USB_NET_PLUSB=m
  957. +CONFIG_USB_NET_MCS7830=m
  958. +CONFIG_USB_NET_CDC_SUBSET=m
  959. +CONFIG_USB_ALI_M5632=y
  960. +CONFIG_USB_AN2720=y
  961. +CONFIG_USB_EPSON2888=y
  962. +CONFIG_USB_KC2190=y
  963. +CONFIG_USB_NET_ZAURUS=m
  964. +CONFIG_USB_NET_CX82310_ETH=m
  965. +CONFIG_USB_NET_KALMIA=m
  966. +CONFIG_USB_NET_QMI_WWAN=m
  967. +CONFIG_USB_NET_INT51X1=m
  968. +CONFIG_USB_IPHETH=m
  969. +CONFIG_USB_SIERRA_NET=m
  970. +CONFIG_USB_VL600=m
  971. +CONFIG_LIBERTAS_THINFIRM=m
  972. +CONFIG_LIBERTAS_THINFIRM_USB=m
  973. +CONFIG_AT76C50X_USB=m
  974. +CONFIG_USB_ZD1201=m
  975. +CONFIG_USB_NET_RNDIS_WLAN=m
  976. +CONFIG_RTL8187=m
  977. +CONFIG_MAC80211_HWSIM=m
  978. +CONFIG_ATH_CARDS=m
  979. +CONFIG_ATH9K=m
  980. +CONFIG_ATH9K_HTC=m
  981. +CONFIG_CARL9170=m
  982. +CONFIG_ATH6KL=m
  983. +CONFIG_ATH6KL_USB=m
  984. +CONFIG_AR5523=m
  985. +CONFIG_B43=m
  986. +# CONFIG_B43_PHY_N is not set
  987. +CONFIG_B43LEGACY=m
  988. +CONFIG_HOSTAP=m
  989. +CONFIG_LIBERTAS=m
  990. +CONFIG_LIBERTAS_USB=m
  991. +CONFIG_LIBERTAS_SDIO=m
  992. +CONFIG_P54_COMMON=m
  993. +CONFIG_P54_USB=m
  994. +CONFIG_RT2X00=m
  995. +CONFIG_RT2500USB=m
  996. +CONFIG_RT73USB=m
  997. +CONFIG_RT2800USB=m
  998. +CONFIG_RT2800USB_RT53XX=y
  999. +CONFIG_RT2800USB_UNKNOWN=y
  1000. +CONFIG_RTL8192CU=m
  1001. +CONFIG_ZD1211RW=m
  1002. +CONFIG_MWIFIEX=m
  1003. +CONFIG_MWIFIEX_SDIO=m
  1004. +CONFIG_WIMAX_I2400M_USB=m
  1005. +CONFIG_INPUT_POLLDEV=m
  1006. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  1007. +CONFIG_INPUT_JOYDEV=m
  1008. +CONFIG_INPUT_EVDEV=m
  1009. +# CONFIG_INPUT_KEYBOARD is not set
  1010. +# CONFIG_INPUT_MOUSE is not set
  1011. +CONFIG_INPUT_JOYSTICK=y
  1012. +CONFIG_JOYSTICK_IFORCE=m
  1013. +CONFIG_JOYSTICK_IFORCE_USB=y
  1014. +CONFIG_JOYSTICK_XPAD=y
  1015. +CONFIG_JOYSTICK_XPAD_FF=y
  1016. +CONFIG_INPUT_MISC=y
  1017. +CONFIG_INPUT_AD714X=m
  1018. +CONFIG_INPUT_ATI_REMOTE2=m
  1019. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  1020. +CONFIG_INPUT_POWERMATE=m
  1021. +CONFIG_INPUT_YEALINK=m
  1022. +CONFIG_INPUT_CM109=m
  1023. +CONFIG_INPUT_UINPUT=m
  1024. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  1025. +CONFIG_INPUT_ADXL34X=m
  1026. +CONFIG_INPUT_CMA3000=m
  1027. +CONFIG_SERIO=m
  1028. +CONFIG_SERIO_RAW=m
  1029. +CONFIG_GAMEPORT=m
  1030. +CONFIG_GAMEPORT_NS558=m
  1031. +CONFIG_GAMEPORT_L4=m
  1032. +CONFIG_VT_HW_CONSOLE_BINDING=y
  1033. +# CONFIG_LEGACY_PTYS is not set
  1034. +# CONFIG_DEVKMEM is not set
  1035. +CONFIG_SERIAL_AMBA_PL011=y
  1036. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  1037. +CONFIG_TTY_PRINTK=y
  1038. +CONFIG_HW_RANDOM=y
  1039. +CONFIG_HW_RANDOM_BCM2708=m
  1040. +CONFIG_RAW_DRIVER=y
  1041. +CONFIG_BRCM_CHAR_DRIVERS=y
  1042. +CONFIG_BCM_VC_CMA=y
  1043. +CONFIG_I2C=y
  1044. +CONFIG_I2C_CHARDEV=m
  1045. +CONFIG_I2C_BCM2708=m
  1046. +CONFIG_SPI=y
  1047. +CONFIG_SPI_BCM2708=m
  1048. +CONFIG_SPI_SPIDEV=y
  1049. +CONFIG_GPIO_SYSFS=y
  1050. +CONFIG_W1=m
  1051. +CONFIG_W1_MASTER_DS2490=m
  1052. +CONFIG_W1_MASTER_DS2482=m
  1053. +CONFIG_W1_MASTER_DS1WM=m
  1054. +CONFIG_W1_MASTER_GPIO=m
  1055. +CONFIG_W1_SLAVE_THERM=m
  1056. +CONFIG_W1_SLAVE_SMEM=m
  1057. +CONFIG_W1_SLAVE_DS2408=m
  1058. +CONFIG_W1_SLAVE_DS2413=m
  1059. +CONFIG_W1_SLAVE_DS2423=m
  1060. +CONFIG_W1_SLAVE_DS2431=m
  1061. +CONFIG_W1_SLAVE_DS2433=m
  1062. +CONFIG_W1_SLAVE_DS2760=m
  1063. +CONFIG_W1_SLAVE_DS2780=m
  1064. +CONFIG_W1_SLAVE_DS2781=m
  1065. +CONFIG_W1_SLAVE_DS28E04=m
  1066. +CONFIG_W1_SLAVE_BQ27000=m
  1067. +CONFIG_BATTERY_DS2760=m
  1068. +# CONFIG_HWMON is not set
  1069. +CONFIG_THERMAL=y
  1070. +CONFIG_THERMAL_BCM2835=y
  1071. +CONFIG_WATCHDOG=y
  1072. +CONFIG_BCM2708_WDT=m
  1073. +CONFIG_MEDIA_SUPPORT=m
  1074. +CONFIG_MEDIA_CAMERA_SUPPORT=y
  1075. +CONFIG_MEDIA_ANALOG_TV_SUPPORT=y
  1076. +CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y
  1077. +CONFIG_MEDIA_RADIO_SUPPORT=y
  1078. +CONFIG_MEDIA_RC_SUPPORT=y
  1079. +CONFIG_MEDIA_CONTROLLER=y
  1080. +CONFIG_LIRC=m
  1081. +CONFIG_RC_DEVICES=y
  1082. +CONFIG_RC_ATI_REMOTE=m
  1083. +CONFIG_IR_IMON=m
  1084. +CONFIG_IR_MCEUSB=m
  1085. +CONFIG_IR_REDRAT3=m
  1086. +CONFIG_IR_STREAMZAP=m
  1087. +CONFIG_IR_IGUANA=m
  1088. +CONFIG_IR_TTUSBIR=m
  1089. +CONFIG_RC_LOOPBACK=m
  1090. +CONFIG_IR_GPIO_CIR=m
  1091. +CONFIG_MEDIA_USB_SUPPORT=y
  1092. +CONFIG_USB_VIDEO_CLASS=m
  1093. +CONFIG_USB_M5602=m
  1094. +CONFIG_USB_STV06XX=m
  1095. +CONFIG_USB_GL860=m
  1096. +CONFIG_USB_GSPCA_BENQ=m
  1097. +CONFIG_USB_GSPCA_CONEX=m
  1098. +CONFIG_USB_GSPCA_CPIA1=m
  1099. +CONFIG_USB_GSPCA_ETOMS=m
  1100. +CONFIG_USB_GSPCA_FINEPIX=m
  1101. +CONFIG_USB_GSPCA_JEILINJ=m
  1102. +CONFIG_USB_GSPCA_JL2005BCD=m
  1103. +CONFIG_USB_GSPCA_KINECT=m
  1104. +CONFIG_USB_GSPCA_KONICA=m
  1105. +CONFIG_USB_GSPCA_MARS=m
  1106. +CONFIG_USB_GSPCA_MR97310A=m
  1107. +CONFIG_USB_GSPCA_NW80X=m
  1108. +CONFIG_USB_GSPCA_OV519=m
  1109. +CONFIG_USB_GSPCA_OV534=m
  1110. +CONFIG_USB_GSPCA_OV534_9=m
  1111. +CONFIG_USB_GSPCA_PAC207=m
  1112. +CONFIG_USB_GSPCA_PAC7302=m
  1113. +CONFIG_USB_GSPCA_PAC7311=m
  1114. +CONFIG_USB_GSPCA_SE401=m
  1115. +CONFIG_USB_GSPCA_SN9C2028=m
  1116. +CONFIG_USB_GSPCA_SN9C20X=m
  1117. +CONFIG_USB_GSPCA_SONIXB=m
  1118. +CONFIG_USB_GSPCA_SONIXJ=m
  1119. +CONFIG_USB_GSPCA_SPCA500=m
  1120. +CONFIG_USB_GSPCA_SPCA501=m
  1121. +CONFIG_USB_GSPCA_SPCA505=m
  1122. +CONFIG_USB_GSPCA_SPCA506=m
  1123. +CONFIG_USB_GSPCA_SPCA508=m
  1124. +CONFIG_USB_GSPCA_SPCA561=m
  1125. +CONFIG_USB_GSPCA_SPCA1528=m
  1126. +CONFIG_USB_GSPCA_SQ905=m
  1127. +CONFIG_USB_GSPCA_SQ905C=m
  1128. +CONFIG_USB_GSPCA_SQ930X=m
  1129. +CONFIG_USB_GSPCA_STK014=m
  1130. +CONFIG_USB_GSPCA_STV0680=m
  1131. +CONFIG_USB_GSPCA_SUNPLUS=m
  1132. +CONFIG_USB_GSPCA_T613=m
  1133. +CONFIG_USB_GSPCA_TOPRO=m
  1134. +CONFIG_USB_GSPCA_TV8532=m
  1135. +CONFIG_USB_GSPCA_VC032X=m
  1136. +CONFIG_USB_GSPCA_VICAM=m
  1137. +CONFIG_USB_GSPCA_XIRLINK_CIT=m
  1138. +CONFIG_USB_GSPCA_ZC3XX=m
  1139. +CONFIG_USB_PWC=m
  1140. +CONFIG_VIDEO_CPIA2=m
  1141. +CONFIG_USB_ZR364XX=m
  1142. +CONFIG_USB_STKWEBCAM=m
  1143. +CONFIG_USB_S2255=m
  1144. +CONFIG_USB_SN9C102=m
  1145. +CONFIG_VIDEO_PVRUSB2=m
  1146. +CONFIG_VIDEO_HDPVR=m
  1147. +CONFIG_VIDEO_TLG2300=m
  1148. +CONFIG_VIDEO_USBVISION=m
  1149. +CONFIG_VIDEO_STK1160=m
  1150. +CONFIG_VIDEO_STK1160_AC97=y
  1151. +CONFIG_VIDEO_AU0828=m
  1152. +CONFIG_VIDEO_CX231XX=m
  1153. +CONFIG_VIDEO_CX231XX_ALSA=m
  1154. +CONFIG_VIDEO_CX231XX_DVB=m
  1155. +CONFIG_VIDEO_TM6000=m
  1156. +CONFIG_VIDEO_TM6000_ALSA=m
  1157. +CONFIG_VIDEO_TM6000_DVB=m
  1158. +CONFIG_DVB_USB=m
  1159. +CONFIG_DVB_USB_A800=m
  1160. +CONFIG_DVB_USB_DIBUSB_MB=m
  1161. +CONFIG_DVB_USB_DIBUSB_MB_FAULTY=y
  1162. +CONFIG_DVB_USB_DIBUSB_MC=m
  1163. +CONFIG_DVB_USB_DIB0700=m
  1164. +CONFIG_DVB_USB_UMT_010=m
  1165. +CONFIG_DVB_USB_CXUSB=m
  1166. +CONFIG_DVB_USB_M920X=m
  1167. +CONFIG_DVB_USB_DIGITV=m
  1168. +CONFIG_DVB_USB_VP7045=m
  1169. +CONFIG_DVB_USB_VP702X=m
  1170. +CONFIG_DVB_USB_GP8PSK=m
  1171. +CONFIG_DVB_USB_NOVA_T_USB2=m
  1172. +CONFIG_DVB_USB_TTUSB2=m
  1173. +CONFIG_DVB_USB_DTT200U=m
  1174. +CONFIG_DVB_USB_OPERA1=m
  1175. +CONFIG_DVB_USB_AF9005=m
  1176. +CONFIG_DVB_USB_AF9005_REMOTE=m
  1177. +CONFIG_DVB_USB_PCTV452E=m
  1178. +CONFIG_DVB_USB_DW2102=m
  1179. +CONFIG_DVB_USB_CINERGY_T2=m
  1180. +CONFIG_DVB_USB_DTV5100=m
  1181. +CONFIG_DVB_USB_FRIIO=m
  1182. +CONFIG_DVB_USB_AZ6027=m
  1183. +CONFIG_DVB_USB_TECHNISAT_USB2=m
  1184. +CONFIG_DVB_USB_V2=m
  1185. +CONFIG_DVB_USB_AF9015=m
  1186. +CONFIG_DVB_USB_AF9035=m
  1187. +CONFIG_DVB_USB_ANYSEE=m
  1188. +CONFIG_DVB_USB_AU6610=m
  1189. +CONFIG_DVB_USB_AZ6007=m
  1190. +CONFIG_DVB_USB_CE6230=m
  1191. +CONFIG_DVB_USB_EC168=m
  1192. +CONFIG_DVB_USB_GL861=m
  1193. +CONFIG_DVB_USB_IT913X=m
  1194. +CONFIG_DVB_USB_LME2510=m
  1195. +CONFIG_DVB_USB_MXL111SF=m
  1196. +CONFIG_DVB_USB_RTL28XXU=m
  1197. +CONFIG_SMS_USB_DRV=m
  1198. +CONFIG_DVB_B2C2_FLEXCOP_USB=m
  1199. +CONFIG_VIDEO_EM28XX=m
  1200. +CONFIG_VIDEO_EM28XX_ALSA=m
  1201. +CONFIG_VIDEO_EM28XX_DVB=m
  1202. +CONFIG_V4L_PLATFORM_DRIVERS=y
  1203. +CONFIG_VIDEO_BCM2835=y
  1204. +CONFIG_VIDEO_BCM2835_MMAL=m
  1205. +CONFIG_RADIO_SI470X=y
  1206. +CONFIG_USB_SI470X=m
  1207. +CONFIG_I2C_SI470X=m
  1208. +CONFIG_USB_MR800=m
  1209. +CONFIG_USB_DSBR=m
  1210. +CONFIG_RADIO_SHARK=m
  1211. +CONFIG_RADIO_SHARK2=m
  1212. +CONFIG_RADIO_SI4713=m
  1213. +CONFIG_USB_KEENE=m
  1214. +CONFIG_USB_MA901=m
  1215. +CONFIG_RADIO_TEA5764=m
  1216. +CONFIG_RADIO_SAA7706H=m
  1217. +CONFIG_RADIO_TEF6862=m
  1218. +CONFIG_RADIO_WL1273=m
  1219. +CONFIG_RADIO_WL128X=m
  1220. +CONFIG_FB=y
  1221. +CONFIG_FB_BCM2708=y
  1222. +# CONFIG_BACKLIGHT_GENERIC is not set
  1223. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1224. +CONFIG_LOGO=y
  1225. +# CONFIG_LOGO_LINUX_MONO is not set
  1226. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1227. +CONFIG_SOUND=y
  1228. +CONFIG_SND=m
  1229. +CONFIG_SND_SEQUENCER=m
  1230. +CONFIG_SND_SEQ_DUMMY=m
  1231. +CONFIG_SND_MIXER_OSS=m
  1232. +CONFIG_SND_PCM_OSS=m
  1233. +CONFIG_SND_SEQUENCER_OSS=y
  1234. +CONFIG_SND_HRTIMER=m
  1235. +CONFIG_SND_DUMMY=m
  1236. +CONFIG_SND_ALOOP=m
  1237. +CONFIG_SND_VIRMIDI=m
  1238. +CONFIG_SND_MTPAV=m
  1239. +CONFIG_SND_SERIAL_U16550=m
  1240. +CONFIG_SND_MPU401=m
  1241. +CONFIG_SND_BCM2835=m
  1242. +CONFIG_SND_USB_AUDIO=m
  1243. +CONFIG_SND_USB_UA101=m
  1244. +CONFIG_SND_USB_CAIAQ=m
  1245. +CONFIG_SND_USB_CAIAQ_INPUT=y
  1246. +CONFIG_SND_USB_6FIRE=m
  1247. +CONFIG_SND_SOC=m
  1248. +CONFIG_SND_SOC_DMAENGINE_PCM=y
  1249. +CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM=y
  1250. +CONFIG_SND_BCM2708_SOC_I2S=m
  1251. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
  1252. +CONFIG_SND_BCM2708_SOC_RPI_DAC=m
  1253. +CONFIG_SND_SOC_I2C_AND_SPI=m
  1254. +CONFIG_SND_SOC_PCM5102A=m
  1255. +CONFIG_SND_SOC_PCM1794A=m
  1256. +CONFIG_SOUND_PRIME=m
  1257. +CONFIG_HIDRAW=y
  1258. +CONFIG_HID_A4TECH=m
  1259. +CONFIG_HID_ACRUX=m
  1260. +CONFIG_HID_APPLE=m
  1261. +CONFIG_HID_BELKIN=m
  1262. +CONFIG_HID_CHERRY=m
  1263. +CONFIG_HID_CHICONY=m
  1264. +CONFIG_HID_CYPRESS=m
  1265. +CONFIG_HID_DRAGONRISE=m
  1266. +CONFIG_HID_EMS_FF=m
  1267. +CONFIG_HID_ELECOM=m
  1268. +CONFIG_HID_EZKEY=m
  1269. +CONFIG_HID_HOLTEK=m
  1270. +CONFIG_HID_KEYTOUCH=m
  1271. +CONFIG_HID_KYE=m
  1272. +CONFIG_HID_UCLOGIC=m
  1273. +CONFIG_HID_WALTOP=m
  1274. +CONFIG_HID_GYRATION=m
  1275. +CONFIG_HID_TWINHAN=m
  1276. +CONFIG_HID_KENSINGTON=m
  1277. +CONFIG_HID_LCPOWER=m
  1278. +CONFIG_HID_LOGITECH=m
  1279. +CONFIG_HID_MAGICMOUSE=m
  1280. +CONFIG_HID_MICROSOFT=m
  1281. +CONFIG_HID_MONTEREY=m
  1282. +CONFIG_HID_MULTITOUCH=m
  1283. +CONFIG_HID_NTRIG=m
  1284. +CONFIG_HID_ORTEK=m
  1285. +CONFIG_HID_PANTHERLORD=m
  1286. +CONFIG_HID_PETALYNX=m
  1287. +CONFIG_HID_PICOLCD=m
  1288. +CONFIG_HID_ROCCAT=m
  1289. +CONFIG_HID_SAMSUNG=m
  1290. +CONFIG_HID_SONY=m
  1291. +CONFIG_HID_SPEEDLINK=m
  1292. +CONFIG_HID_SUNPLUS=m
  1293. +CONFIG_HID_GREENASIA=m
  1294. +CONFIG_HID_SMARTJOYPLUS=m
  1295. +CONFIG_HID_TOPSEED=m
  1296. +CONFIG_HID_THINGM=m
  1297. +CONFIG_HID_THRUSTMASTER=m
  1298. +CONFIG_HID_WACOM=m
  1299. +CONFIG_HID_WIIMOTE=m
  1300. +CONFIG_HID_ZEROPLUS=m
  1301. +CONFIG_HID_ZYDACRON=m
  1302. +CONFIG_HID_PID=y
  1303. +CONFIG_USB_HIDDEV=y
  1304. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  1305. +CONFIG_USB_MON=m
  1306. +CONFIG_USB_DWCOTG=y
  1307. +CONFIG_USB_PRINTER=m
  1308. +CONFIG_USB_STORAGE=y
  1309. +CONFIG_USB_STORAGE_REALTEK=m
  1310. +CONFIG_USB_STORAGE_DATAFAB=m
  1311. +CONFIG_USB_STORAGE_FREECOM=m
  1312. +CONFIG_USB_STORAGE_ISD200=m
  1313. +CONFIG_USB_STORAGE_USBAT=m
  1314. +CONFIG_USB_STORAGE_SDDR09=m
  1315. +CONFIG_USB_STORAGE_SDDR55=m
  1316. +CONFIG_USB_STORAGE_JUMPSHOT=m
  1317. +CONFIG_USB_STORAGE_ALAUDA=m
  1318. +CONFIG_USB_STORAGE_ONETOUCH=m
  1319. +CONFIG_USB_STORAGE_KARMA=m
  1320. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  1321. +CONFIG_USB_STORAGE_ENE_UB6250=m
  1322. +CONFIG_USB_MDC800=m
  1323. +CONFIG_USB_MICROTEK=m
  1324. +CONFIG_USB_SERIAL=m
  1325. +CONFIG_USB_SERIAL_GENERIC=y
  1326. +CONFIG_USB_SERIAL_AIRCABLE=m
  1327. +CONFIG_USB_SERIAL_ARK3116=m
  1328. +CONFIG_USB_SERIAL_BELKIN=m
  1329. +CONFIG_USB_SERIAL_CH341=m
  1330. +CONFIG_USB_SERIAL_WHITEHEAT=m
  1331. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  1332. +CONFIG_USB_SERIAL_CP210X=m
  1333. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  1334. +CONFIG_USB_SERIAL_EMPEG=m
  1335. +CONFIG_USB_SERIAL_FTDI_SIO=m
  1336. +CONFIG_USB_SERIAL_FUNSOFT=m
  1337. +CONFIG_USB_SERIAL_VISOR=m
  1338. +CONFIG_USB_SERIAL_IPAQ=m
  1339. +CONFIG_USB_SERIAL_IR=m
  1340. +CONFIG_USB_SERIAL_EDGEPORT=m
  1341. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  1342. +CONFIG_USB_SERIAL_F81232=m
  1343. +CONFIG_USB_SERIAL_GARMIN=m
  1344. +CONFIG_USB_SERIAL_IPW=m
  1345. +CONFIG_USB_SERIAL_IUU=m
  1346. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  1347. +CONFIG_USB_SERIAL_KEYSPAN=m
  1348. +CONFIG_USB_SERIAL_KLSI=m
  1349. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  1350. +CONFIG_USB_SERIAL_MCT_U232=m
  1351. +CONFIG_USB_SERIAL_METRO=m
  1352. +CONFIG_USB_SERIAL_MOS7720=m
  1353. +CONFIG_USB_SERIAL_MOS7840=m
  1354. +CONFIG_USB_SERIAL_MOTOROLA=m
  1355. +CONFIG_USB_SERIAL_NAVMAN=m
  1356. +CONFIG_USB_SERIAL_PL2303=m
  1357. +CONFIG_USB_SERIAL_OTI6858=m
  1358. +CONFIG_USB_SERIAL_QCAUX=m
  1359. +CONFIG_USB_SERIAL_QUALCOMM=m
  1360. +CONFIG_USB_SERIAL_SPCP8X5=m
  1361. +CONFIG_USB_SERIAL_HP4X=m
  1362. +CONFIG_USB_SERIAL_SAFE=m
  1363. +CONFIG_USB_SERIAL_SIEMENS_MPI=m
  1364. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  1365. +CONFIG_USB_SERIAL_SYMBOL=m
  1366. +CONFIG_USB_SERIAL_TI=m
  1367. +CONFIG_USB_SERIAL_CYBERJACK=m
  1368. +CONFIG_USB_SERIAL_XIRCOM=m
  1369. +CONFIG_USB_SERIAL_OPTION=m
  1370. +CONFIG_USB_SERIAL_OMNINET=m
  1371. +CONFIG_USB_SERIAL_OPTICON=m
  1372. +CONFIG_USB_SERIAL_VIVOPAY_SERIAL=m
  1373. +CONFIG_USB_SERIAL_XSENS_MT=m
  1374. +CONFIG_USB_SERIAL_ZIO=m
  1375. +CONFIG_USB_SERIAL_WISHBONE=m
  1376. +CONFIG_USB_SERIAL_ZTE=m
  1377. +CONFIG_USB_SERIAL_SSU100=m
  1378. +CONFIG_USB_SERIAL_QT2=m
  1379. +CONFIG_USB_SERIAL_DEBUG=m
  1380. +CONFIG_USB_EMI62=m
  1381. +CONFIG_USB_EMI26=m
  1382. +CONFIG_USB_ADUTUX=m
  1383. +CONFIG_USB_SEVSEG=m
  1384. +CONFIG_USB_RIO500=m
  1385. +CONFIG_USB_LEGOTOWER=m
  1386. +CONFIG_USB_LCD=m
  1387. +CONFIG_USB_LED=m
  1388. +CONFIG_USB_CYPRESS_CY7C63=m
  1389. +CONFIG_USB_CYTHERM=m
  1390. +CONFIG_USB_IDMOUSE=m
  1391. +CONFIG_USB_FTDI_ELAN=m
  1392. +CONFIG_USB_APPLEDISPLAY=m
  1393. +CONFIG_USB_LD=m
  1394. +CONFIG_USB_TRANCEVIBRATOR=m
  1395. +CONFIG_USB_IOWARRIOR=m
  1396. +CONFIG_USB_TEST=m
  1397. +CONFIG_USB_ISIGHTFW=m
  1398. +CONFIG_USB_YUREX=m
  1399. +CONFIG_MMC=y
  1400. +CONFIG_MMC_BLOCK_MINORS=32
  1401. +CONFIG_MMC_SDHCI=y
  1402. +CONFIG_MMC_SDHCI_PLTFM=y
  1403. +CONFIG_MMC_SDHCI_BCM2708=y
  1404. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  1405. +CONFIG_MMC_SPI=m
  1406. +CONFIG_LEDS_GPIO=m
  1407. +CONFIG_LEDS_TRIGGER_TIMER=y
  1408. +CONFIG_LEDS_TRIGGER_ONESHOT=y
  1409. +CONFIG_LEDS_TRIGGER_HEARTBEAT=y
  1410. +CONFIG_LEDS_TRIGGER_BACKLIGHT=y
  1411. +CONFIG_LEDS_TRIGGER_CPU=y
  1412. +CONFIG_LEDS_TRIGGER_GPIO=y
  1413. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
  1414. +CONFIG_LEDS_TRIGGER_TRANSIENT=m
  1415. +CONFIG_LEDS_TRIGGER_CAMERA=m
  1416. +CONFIG_RTC_CLASS=y
  1417. +CONFIG_RTC_DRV_DS1307=m
  1418. +CONFIG_RTC_DRV_DS1374=m
  1419. +CONFIG_RTC_DRV_DS1672=m
  1420. +CONFIG_RTC_DRV_DS3232=m
  1421. +CONFIG_RTC_DRV_MAX6900=m
  1422. +CONFIG_RTC_DRV_RS5C372=m
  1423. +CONFIG_RTC_DRV_ISL1208=m
  1424. +CONFIG_RTC_DRV_ISL12022=m
  1425. +CONFIG_RTC_DRV_X1205=m
  1426. +CONFIG_RTC_DRV_PCF8523=m
  1427. +CONFIG_RTC_DRV_PCF8563=m
  1428. +CONFIG_RTC_DRV_PCF8583=m
  1429. +CONFIG_RTC_DRV_M41T80=m
  1430. +CONFIG_RTC_DRV_BQ32K=m
  1431. +CONFIG_RTC_DRV_S35390A=m
  1432. +CONFIG_RTC_DRV_FM3130=m
  1433. +CONFIG_RTC_DRV_RX8581=m
  1434. +CONFIG_RTC_DRV_RX8025=m
  1435. +CONFIG_RTC_DRV_EM3027=m
  1436. +CONFIG_RTC_DRV_RV3029C2=m
  1437. +CONFIG_RTC_DRV_M41T93=m
  1438. +CONFIG_RTC_DRV_M41T94=m
  1439. +CONFIG_RTC_DRV_DS1305=m
  1440. +CONFIG_RTC_DRV_DS1390=m
  1441. +CONFIG_RTC_DRV_MAX6902=m
  1442. +CONFIG_RTC_DRV_R9701=m
  1443. +CONFIG_RTC_DRV_RS5C348=m
  1444. +CONFIG_RTC_DRV_DS3234=m
  1445. +CONFIG_RTC_DRV_PCF2123=m
  1446. +CONFIG_RTC_DRV_RX4581=m
  1447. +CONFIG_DMADEVICES=y
  1448. +CONFIG_DMA_BCM2708=m
  1449. +CONFIG_DMA_ENGINE=y
  1450. +CONFIG_DMA_VIRTUAL_CHANNELS=m
  1451. +CONFIG_UIO=m
  1452. +CONFIG_UIO_PDRV=m
  1453. +CONFIG_UIO_PDRV_GENIRQ=m
  1454. +CONFIG_STAGING=y
  1455. +CONFIG_W35UND=m
  1456. +CONFIG_PRISM2_USB=m
  1457. +CONFIG_R8712U=m
  1458. +CONFIG_VT6656=m
  1459. +CONFIG_SPEAKUP=m
  1460. +CONFIG_SPEAKUP_SYNTH_SOFT=m
  1461. +CONFIG_STAGING_MEDIA=y
  1462. +CONFIG_DVB_AS102=m
  1463. +CONFIG_LIRC_STAGING=y
  1464. +CONFIG_LIRC_IGORPLUGUSB=m
  1465. +CONFIG_LIRC_IMON=m
  1466. +CONFIG_LIRC_RPI=m
  1467. +CONFIG_LIRC_SASEM=m
  1468. +CONFIG_LIRC_SERIAL=m
  1469. +# CONFIG_IOMMU_SUPPORT is not set
  1470. +CONFIG_EXT4_FS=y
  1471. +CONFIG_EXT4_FS_POSIX_ACL=y
  1472. +CONFIG_EXT4_FS_SECURITY=y
  1473. +CONFIG_REISERFS_FS=m
  1474. +CONFIG_REISERFS_FS_XATTR=y
  1475. +CONFIG_REISERFS_FS_POSIX_ACL=y
  1476. +CONFIG_REISERFS_FS_SECURITY=y
  1477. +CONFIG_JFS_FS=m
  1478. +CONFIG_JFS_POSIX_ACL=y
  1479. +CONFIG_JFS_SECURITY=y
  1480. +CONFIG_JFS_STATISTICS=y
  1481. +CONFIG_XFS_FS=m
  1482. +CONFIG_XFS_QUOTA=y
  1483. +CONFIG_XFS_POSIX_ACL=y
  1484. +CONFIG_XFS_RT=y
  1485. +CONFIG_GFS2_FS=m
  1486. +CONFIG_OCFS2_FS=m
  1487. +CONFIG_BTRFS_FS=m
  1488. +CONFIG_BTRFS_FS_POSIX_ACL=y
  1489. +CONFIG_NILFS2_FS=m
  1490. +CONFIG_FANOTIFY=y
  1491. +CONFIG_QFMT_V1=m
  1492. +CONFIG_QFMT_V2=m
  1493. +CONFIG_AUTOFS4_FS=y
  1494. +CONFIG_FUSE_FS=m
  1495. +CONFIG_CUSE=m
  1496. +CONFIG_FSCACHE=y
  1497. +CONFIG_FSCACHE_STATS=y
  1498. +CONFIG_FSCACHE_HISTOGRAM=y
  1499. +CONFIG_CACHEFILES=y
  1500. +CONFIG_ISO9660_FS=m
  1501. +CONFIG_JOLIET=y
  1502. +CONFIG_ZISOFS=y
  1503. +CONFIG_UDF_FS=m
  1504. +CONFIG_MSDOS_FS=y
  1505. +CONFIG_VFAT_FS=y
  1506. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  1507. +CONFIG_NTFS_FS=m
  1508. +CONFIG_NTFS_RW=y
  1509. +CONFIG_TMPFS=y
  1510. +CONFIG_TMPFS_POSIX_ACL=y
  1511. +CONFIG_CONFIGFS_FS=y
  1512. +CONFIG_ECRYPT_FS=m
  1513. +CONFIG_HFS_FS=m
  1514. +CONFIG_HFSPLUS_FS=m
  1515. +CONFIG_SQUASHFS=m
  1516. +CONFIG_SQUASHFS_XATTR=y
  1517. +CONFIG_SQUASHFS_LZO=y
  1518. +CONFIG_SQUASHFS_XZ=y
  1519. +CONFIG_F2FS_FS=y
  1520. +CONFIG_NFS_FS=y
  1521. +CONFIG_NFS_V3_ACL=y
  1522. +CONFIG_NFS_V4=y
  1523. +CONFIG_ROOT_NFS=y
  1524. +CONFIG_NFS_FSCACHE=y
  1525. +CONFIG_NFSD=m
  1526. +CONFIG_NFSD_V3_ACL=y
  1527. +CONFIG_NFSD_V4=y
  1528. +CONFIG_CIFS=m
  1529. +CONFIG_CIFS_WEAK_PW_HASH=y
  1530. +CONFIG_CIFS_XATTR=y
  1531. +CONFIG_CIFS_POSIX=y
  1532. +CONFIG_9P_FS=m
  1533. +CONFIG_9P_FS_POSIX_ACL=y
  1534. +CONFIG_NLS_DEFAULT="utf8"
  1535. +CONFIG_NLS_CODEPAGE_437=y
  1536. +CONFIG_NLS_CODEPAGE_737=m
  1537. +CONFIG_NLS_CODEPAGE_775=m
  1538. +CONFIG_NLS_CODEPAGE_850=m
  1539. +CONFIG_NLS_CODEPAGE_852=m
  1540. +CONFIG_NLS_CODEPAGE_855=m
  1541. +CONFIG_NLS_CODEPAGE_857=m
  1542. +CONFIG_NLS_CODEPAGE_860=m
  1543. +CONFIG_NLS_CODEPAGE_861=m
  1544. +CONFIG_NLS_CODEPAGE_862=m
  1545. +CONFIG_NLS_CODEPAGE_863=m
  1546. +CONFIG_NLS_CODEPAGE_864=m
  1547. +CONFIG_NLS_CODEPAGE_865=m
  1548. +CONFIG_NLS_CODEPAGE_866=m
  1549. +CONFIG_NLS_CODEPAGE_869=m
  1550. +CONFIG_NLS_CODEPAGE_936=m
  1551. +CONFIG_NLS_CODEPAGE_950=m
  1552. +CONFIG_NLS_CODEPAGE_932=m
  1553. +CONFIG_NLS_CODEPAGE_949=m
  1554. +CONFIG_NLS_CODEPAGE_874=m
  1555. +CONFIG_NLS_ISO8859_8=m
  1556. +CONFIG_NLS_CODEPAGE_1250=m
  1557. +CONFIG_NLS_CODEPAGE_1251=m
  1558. +CONFIG_NLS_ASCII=y
  1559. +CONFIG_NLS_ISO8859_1=m
  1560. +CONFIG_NLS_ISO8859_2=m
  1561. +CONFIG_NLS_ISO8859_3=m
  1562. +CONFIG_NLS_ISO8859_4=m
  1563. +CONFIG_NLS_ISO8859_5=m
  1564. +CONFIG_NLS_ISO8859_6=m
  1565. +CONFIG_NLS_ISO8859_7=m
  1566. +CONFIG_NLS_ISO8859_9=m
  1567. +CONFIG_NLS_ISO8859_13=m
  1568. +CONFIG_NLS_ISO8859_14=m
  1569. +CONFIG_NLS_ISO8859_15=m
  1570. +CONFIG_NLS_KOI8_R=m
  1571. +CONFIG_NLS_KOI8_U=m
  1572. +CONFIG_DLM=m
  1573. +CONFIG_PRINTK_TIME=y
  1574. +CONFIG_BOOT_PRINTK_DELAY=y
  1575. +CONFIG_DEBUG_FS=y
  1576. +CONFIG_DEBUG_MEMORY_INIT=y
  1577. +CONFIG_DETECT_HUNG_TASK=y
  1578. +CONFIG_TIMER_STATS=y
  1579. +# CONFIG_DEBUG_PREEMPT is not set
  1580. +CONFIG_LATENCYTOP=y
  1581. +# CONFIG_KPROBE_EVENT is not set
  1582. +CONFIG_KGDB=y
  1583. +CONFIG_KGDB_KDB=y
  1584. +CONFIG_KDB_KEYBOARD=y
  1585. +CONFIG_STRICT_DEVMEM=y
  1586. +CONFIG_CRYPTO_USER=m
  1587. +CONFIG_CRYPTO_NULL=m
  1588. +CONFIG_CRYPTO_CRYPTD=m
  1589. +CONFIG_CRYPTO_SEQIV=m
  1590. +CONFIG_CRYPTO_CBC=y
  1591. +CONFIG_CRYPTO_XTS=m
  1592. +CONFIG_CRYPTO_XCBC=m
  1593. +CONFIG_CRYPTO_SHA1_ARM=m
  1594. +CONFIG_CRYPTO_SHA512=m
  1595. +CONFIG_CRYPTO_TGR192=m
  1596. +CONFIG_CRYPTO_WP512=m
  1597. +CONFIG_CRYPTO_AES_ARM=m
  1598. +CONFIG_CRYPTO_CAST5=m
  1599. +CONFIG_CRYPTO_DES=y
  1600. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  1601. +# CONFIG_CRYPTO_HW is not set
  1602. +CONFIG_CRC_ITU_T=y
  1603. +CONFIG_LIBCRC32C=y
  1604. diff -Nur linux-3.12.11.orig/arch/arm/configs/bcmrpi_emergency_defconfig linux-3.12.11/arch/arm/configs/bcmrpi_emergency_defconfig
  1605. --- linux-3.12.11.orig/arch/arm/configs/bcmrpi_emergency_defconfig 1970-01-01 01:00:00.000000000 +0100
  1606. +++ linux-3.12.11/arch/arm/configs/bcmrpi_emergency_defconfig 2014-02-18 11:52:14.000000000 +0100
  1607. @@ -0,0 +1,532 @@
  1608. +CONFIG_EXPERIMENTAL=y
  1609. +# CONFIG_LOCALVERSION_AUTO is not set
  1610. +CONFIG_SYSVIPC=y
  1611. +CONFIG_POSIX_MQUEUE=y
  1612. +CONFIG_BSD_PROCESS_ACCT=y
  1613. +CONFIG_BSD_PROCESS_ACCT_V3=y
  1614. +CONFIG_FHANDLE=y
  1615. +CONFIG_AUDIT=y
  1616. +CONFIG_IKCONFIG=y
  1617. +CONFIG_IKCONFIG_PROC=y
  1618. +CONFIG_BLK_DEV_INITRD=y
  1619. +CONFIG_INITRAMFS_SOURCE="../target_fs"
  1620. +CONFIG_CGROUP_FREEZER=y
  1621. +CONFIG_CGROUP_DEVICE=y
  1622. +CONFIG_CGROUP_CPUACCT=y
  1623. +CONFIG_RESOURCE_COUNTERS=y
  1624. +CONFIG_BLK_CGROUP=y
  1625. +CONFIG_NAMESPACES=y
  1626. +CONFIG_SCHED_AUTOGROUP=y
  1627. +CONFIG_EMBEDDED=y
  1628. +# CONFIG_COMPAT_BRK is not set
  1629. +CONFIG_SLAB=y
  1630. +CONFIG_PROFILING=y
  1631. +CONFIG_OPROFILE=m
  1632. +CONFIG_KPROBES=y
  1633. +CONFIG_MODULES=y
  1634. +CONFIG_MODULE_UNLOAD=y
  1635. +CONFIG_MODVERSIONS=y
  1636. +CONFIG_MODULE_SRCVERSION_ALL=y
  1637. +# CONFIG_BLK_DEV_BSG is not set
  1638. +CONFIG_BLK_DEV_THROTTLING=y
  1639. +CONFIG_CFQ_GROUP_IOSCHED=y
  1640. +CONFIG_ARCH_BCM2708=y
  1641. +CONFIG_NO_HZ=y
  1642. +CONFIG_HIGH_RES_TIMERS=y
  1643. +CONFIG_AEABI=y
  1644. +CONFIG_SECCOMP=y
  1645. +CONFIG_CC_STACKPROTECTOR=y
  1646. +CONFIG_ZBOOT_ROM_TEXT=0x0
  1647. +CONFIG_ZBOOT_ROM_BSS=0x0
  1648. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
  1649. +CONFIG_KEXEC=y
  1650. +CONFIG_CPU_IDLE=y
  1651. +CONFIG_VFP=y
  1652. +CONFIG_BINFMT_MISC=m
  1653. +CONFIG_NET=y
  1654. +CONFIG_PACKET=y
  1655. +CONFIG_UNIX=y
  1656. +CONFIG_XFRM_USER=y
  1657. +CONFIG_NET_KEY=m
  1658. +CONFIG_INET=y
  1659. +CONFIG_IP_MULTICAST=y
  1660. +CONFIG_IP_PNP=y
  1661. +CONFIG_IP_PNP_DHCP=y
  1662. +CONFIG_IP_PNP_RARP=y
  1663. +CONFIG_SYN_COOKIES=y
  1664. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  1665. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  1666. +# CONFIG_INET_XFRM_MODE_BEET is not set
  1667. +# CONFIG_INET_LRO is not set
  1668. +# CONFIG_INET_DIAG is not set
  1669. +# CONFIG_IPV6 is not set
  1670. +CONFIG_NET_PKTGEN=m
  1671. +CONFIG_IRDA=m
  1672. +CONFIG_IRLAN=m
  1673. +CONFIG_IRCOMM=m
  1674. +CONFIG_IRDA_ULTRA=y
  1675. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  1676. +CONFIG_IRDA_FAST_RR=y
  1677. +CONFIG_IRTTY_SIR=m
  1678. +CONFIG_KINGSUN_DONGLE=m
  1679. +CONFIG_KSDAZZLE_DONGLE=m
  1680. +CONFIG_KS959_DONGLE=m
  1681. +CONFIG_USB_IRDA=m
  1682. +CONFIG_SIGMATEL_FIR=m
  1683. +CONFIG_MCS_FIR=m
  1684. +CONFIG_BT=m
  1685. +CONFIG_BT_L2CAP=y
  1686. +CONFIG_BT_SCO=y
  1687. +CONFIG_BT_RFCOMM=m
  1688. +CONFIG_BT_RFCOMM_TTY=y
  1689. +CONFIG_BT_BNEP=m
  1690. +CONFIG_BT_BNEP_MC_FILTER=y
  1691. +CONFIG_BT_BNEP_PROTO_FILTER=y
  1692. +CONFIG_BT_HIDP=m
  1693. +CONFIG_BT_HCIBTUSB=m
  1694. +CONFIG_BT_HCIBCM203X=m
  1695. +CONFIG_BT_HCIBPA10X=m
  1696. +CONFIG_BT_HCIBFUSB=m
  1697. +CONFIG_BT_HCIVHCI=m
  1698. +CONFIG_BT_MRVL=m
  1699. +CONFIG_BT_MRVL_SDIO=m
  1700. +CONFIG_BT_ATH3K=m
  1701. +CONFIG_CFG80211=m
  1702. +CONFIG_MAC80211=m
  1703. +CONFIG_MAC80211_RC_PID=y
  1704. +CONFIG_MAC80211_MESH=y
  1705. +CONFIG_WIMAX=m
  1706. +CONFIG_NET_9P=m
  1707. +CONFIG_NFC=m
  1708. +CONFIG_NFC_PN533=m
  1709. +CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
  1710. +CONFIG_BLK_DEV_LOOP=y
  1711. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  1712. +CONFIG_BLK_DEV_NBD=m
  1713. +CONFIG_BLK_DEV_RAM=y
  1714. +CONFIG_CDROM_PKTCDVD=m
  1715. +CONFIG_MISC_DEVICES=y
  1716. +CONFIG_SCSI=y
  1717. +# CONFIG_SCSI_PROC_FS is not set
  1718. +CONFIG_BLK_DEV_SD=y
  1719. +CONFIG_BLK_DEV_SR=m
  1720. +CONFIG_SCSI_MULTI_LUN=y
  1721. +# CONFIG_SCSI_LOWLEVEL is not set
  1722. +CONFIG_MD=y
  1723. +CONFIG_NETDEVICES=y
  1724. +CONFIG_TUN=m
  1725. +CONFIG_PHYLIB=m
  1726. +CONFIG_MDIO_BITBANG=m
  1727. +CONFIG_NET_ETHERNET=y
  1728. +# CONFIG_NETDEV_1000 is not set
  1729. +# CONFIG_NETDEV_10000 is not set
  1730. +CONFIG_LIBERTAS_THINFIRM=m
  1731. +CONFIG_LIBERTAS_THINFIRM_USB=m
  1732. +CONFIG_AT76C50X_USB=m
  1733. +CONFIG_USB_ZD1201=m
  1734. +CONFIG_USB_NET_RNDIS_WLAN=m
  1735. +CONFIG_RTL8187=m
  1736. +CONFIG_MAC80211_HWSIM=m
  1737. +CONFIG_ATH_COMMON=m
  1738. +CONFIG_ATH9K=m
  1739. +CONFIG_ATH9K_HTC=m
  1740. +CONFIG_CARL9170=m
  1741. +CONFIG_B43=m
  1742. +CONFIG_B43LEGACY=m
  1743. +CONFIG_HOSTAP=m
  1744. +CONFIG_IWM=m
  1745. +CONFIG_LIBERTAS=m
  1746. +CONFIG_LIBERTAS_USB=m
  1747. +CONFIG_LIBERTAS_SDIO=m
  1748. +CONFIG_P54_COMMON=m
  1749. +CONFIG_P54_USB=m
  1750. +CONFIG_RT2X00=m
  1751. +CONFIG_RT2500USB=m
  1752. +CONFIG_RT73USB=m
  1753. +CONFIG_RT2800USB=m
  1754. +CONFIG_RT2800USB_RT53XX=y
  1755. +CONFIG_RTL8192CU=m
  1756. +CONFIG_WL1251=m
  1757. +CONFIG_WL12XX_MENU=m
  1758. +CONFIG_ZD1211RW=m
  1759. +CONFIG_MWIFIEX=m
  1760. +CONFIG_MWIFIEX_SDIO=m
  1761. +CONFIG_WIMAX_I2400M_USB=m
  1762. +CONFIG_USB_CATC=m
  1763. +CONFIG_USB_KAWETH=m
  1764. +CONFIG_USB_PEGASUS=m
  1765. +CONFIG_USB_RTL8150=m
  1766. +CONFIG_USB_USBNET=y
  1767. +CONFIG_USB_NET_AX8817X=m
  1768. +CONFIG_USB_NET_CDCETHER=m
  1769. +CONFIG_USB_NET_CDC_EEM=m
  1770. +CONFIG_USB_NET_DM9601=m
  1771. +CONFIG_USB_NET_SMSC75XX=m
  1772. +CONFIG_USB_NET_SMSC95XX=y
  1773. +CONFIG_USB_NET_GL620A=m
  1774. +CONFIG_USB_NET_NET1080=m
  1775. +CONFIG_USB_NET_PLUSB=m
  1776. +CONFIG_USB_NET_MCS7830=m
  1777. +CONFIG_USB_NET_CDC_SUBSET=m
  1778. +CONFIG_USB_ALI_M5632=y
  1779. +CONFIG_USB_AN2720=y
  1780. +CONFIG_USB_KC2190=y
  1781. +# CONFIG_USB_NET_ZAURUS is not set
  1782. +CONFIG_USB_NET_CX82310_ETH=m
  1783. +CONFIG_USB_NET_KALMIA=m
  1784. +CONFIG_USB_NET_INT51X1=m
  1785. +CONFIG_USB_IPHETH=m
  1786. +CONFIG_USB_SIERRA_NET=m
  1787. +CONFIG_USB_VL600=m
  1788. +CONFIG_PPP=m
  1789. +CONFIG_PPP_ASYNC=m
  1790. +CONFIG_PPP_SYNC_TTY=m
  1791. +CONFIG_PPP_DEFLATE=m
  1792. +CONFIG_PPP_BSDCOMP=m
  1793. +CONFIG_SLIP=m
  1794. +CONFIG_SLIP_COMPRESSED=y
  1795. +CONFIG_NETCONSOLE=m
  1796. +CONFIG_INPUT_POLLDEV=m
  1797. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  1798. +CONFIG_INPUT_JOYDEV=m
  1799. +CONFIG_INPUT_EVDEV=m
  1800. +# CONFIG_INPUT_KEYBOARD is not set
  1801. +# CONFIG_INPUT_MOUSE is not set
  1802. +CONFIG_INPUT_MISC=y
  1803. +CONFIG_INPUT_AD714X=m
  1804. +CONFIG_INPUT_ATI_REMOTE=m
  1805. +CONFIG_INPUT_ATI_REMOTE2=m
  1806. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  1807. +CONFIG_INPUT_POWERMATE=m
  1808. +CONFIG_INPUT_YEALINK=m
  1809. +CONFIG_INPUT_CM109=m
  1810. +CONFIG_INPUT_UINPUT=m
  1811. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  1812. +CONFIG_INPUT_ADXL34X=m
  1813. +CONFIG_INPUT_CMA3000=m
  1814. +CONFIG_SERIO=m
  1815. +CONFIG_SERIO_RAW=m
  1816. +CONFIG_GAMEPORT=m
  1817. +CONFIG_GAMEPORT_NS558=m
  1818. +CONFIG_GAMEPORT_L4=m
  1819. +CONFIG_VT_HW_CONSOLE_BINDING=y
  1820. +# CONFIG_LEGACY_PTYS is not set
  1821. +# CONFIG_DEVKMEM is not set
  1822. +CONFIG_SERIAL_AMBA_PL011=y
  1823. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  1824. +# CONFIG_HW_RANDOM is not set
  1825. +CONFIG_RAW_DRIVER=y
  1826. +CONFIG_GPIO_SYSFS=y
  1827. +# CONFIG_HWMON is not set
  1828. +CONFIG_WATCHDOG=y
  1829. +CONFIG_BCM2708_WDT=m
  1830. +# CONFIG_MFD_SUPPORT is not set
  1831. +CONFIG_FB=y
  1832. +CONFIG_FB_BCM2708=y
  1833. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1834. +CONFIG_LOGO=y
  1835. +# CONFIG_LOGO_LINUX_MONO is not set
  1836. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1837. +CONFIG_SOUND=y
  1838. +CONFIG_SND=m
  1839. +CONFIG_SND_SEQUENCER=m
  1840. +CONFIG_SND_SEQ_DUMMY=m
  1841. +CONFIG_SND_MIXER_OSS=m
  1842. +CONFIG_SND_PCM_OSS=m
  1843. +CONFIG_SND_SEQUENCER_OSS=y
  1844. +CONFIG_SND_HRTIMER=m
  1845. +CONFIG_SND_DUMMY=m
  1846. +CONFIG_SND_ALOOP=m
  1847. +CONFIG_SND_VIRMIDI=m
  1848. +CONFIG_SND_MTPAV=m
  1849. +CONFIG_SND_SERIAL_U16550=m
  1850. +CONFIG_SND_MPU401=m
  1851. +CONFIG_SND_BCM2835=m
  1852. +CONFIG_SND_USB_AUDIO=m
  1853. +CONFIG_SND_USB_UA101=m
  1854. +CONFIG_SND_USB_CAIAQ=m
  1855. +CONFIG_SND_USB_6FIRE=m
  1856. +CONFIG_SOUND_PRIME=m
  1857. +CONFIG_HID_PID=y
  1858. +CONFIG_USB_HIDDEV=y
  1859. +CONFIG_HID_A4TECH=m
  1860. +CONFIG_HID_ACRUX=m
  1861. +CONFIG_HID_APPLE=m
  1862. +CONFIG_HID_BELKIN=m
  1863. +CONFIG_HID_CHERRY=m
  1864. +CONFIG_HID_CHICONY=m
  1865. +CONFIG_HID_CYPRESS=m
  1866. +CONFIG_HID_DRAGONRISE=m
  1867. +CONFIG_HID_EMS_FF=m
  1868. +CONFIG_HID_ELECOM=m
  1869. +CONFIG_HID_EZKEY=m
  1870. +CONFIG_HID_HOLTEK=m
  1871. +CONFIG_HID_KEYTOUCH=m
  1872. +CONFIG_HID_KYE=m
  1873. +CONFIG_HID_UCLOGIC=m
  1874. +CONFIG_HID_WALTOP=m
  1875. +CONFIG_HID_GYRATION=m
  1876. +CONFIG_HID_TWINHAN=m
  1877. +CONFIG_HID_KENSINGTON=m
  1878. +CONFIG_HID_LCPOWER=m
  1879. +CONFIG_HID_LOGITECH=m
  1880. +CONFIG_HID_MAGICMOUSE=m
  1881. +CONFIG_HID_MICROSOFT=m
  1882. +CONFIG_HID_MONTEREY=m
  1883. +CONFIG_HID_MULTITOUCH=m
  1884. +CONFIG_HID_NTRIG=m
  1885. +CONFIG_HID_ORTEK=m
  1886. +CONFIG_HID_PANTHERLORD=m
  1887. +CONFIG_HID_PETALYNX=m
  1888. +CONFIG_HID_PICOLCD=m
  1889. +CONFIG_HID_QUANTA=m
  1890. +CONFIG_HID_ROCCAT=m
  1891. +CONFIG_HID_SAMSUNG=m
  1892. +CONFIG_HID_SONY=m
  1893. +CONFIG_HID_SPEEDLINK=m
  1894. +CONFIG_HID_SUNPLUS=m
  1895. +CONFIG_HID_GREENASIA=m
  1896. +CONFIG_HID_SMARTJOYPLUS=m
  1897. +CONFIG_HID_TOPSEED=m
  1898. +CONFIG_HID_THRUSTMASTER=m
  1899. +CONFIG_HID_WACOM=m
  1900. +CONFIG_HID_WIIMOTE=m
  1901. +CONFIG_HID_ZEROPLUS=m
  1902. +CONFIG_HID_ZYDACRON=m
  1903. +CONFIG_USB=y
  1904. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  1905. +CONFIG_USB_MON=m
  1906. +CONFIG_USB_DWCOTG=y
  1907. +CONFIG_USB_STORAGE=y
  1908. +CONFIG_USB_STORAGE_REALTEK=m
  1909. +CONFIG_USB_STORAGE_DATAFAB=m
  1910. +CONFIG_USB_STORAGE_FREECOM=m
  1911. +CONFIG_USB_STORAGE_ISD200=m
  1912. +CONFIG_USB_STORAGE_USBAT=m
  1913. +CONFIG_USB_STORAGE_SDDR09=m
  1914. +CONFIG_USB_STORAGE_SDDR55=m
  1915. +CONFIG_USB_STORAGE_JUMPSHOT=m
  1916. +CONFIG_USB_STORAGE_ALAUDA=m
  1917. +CONFIG_USB_STORAGE_ONETOUCH=m
  1918. +CONFIG_USB_STORAGE_KARMA=m
  1919. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  1920. +CONFIG_USB_STORAGE_ENE_UB6250=m
  1921. +CONFIG_USB_UAS=y
  1922. +CONFIG_USB_LIBUSUAL=y
  1923. +CONFIG_USB_MDC800=m
  1924. +CONFIG_USB_MICROTEK=m
  1925. +CONFIG_USB_SERIAL=m
  1926. +CONFIG_USB_SERIAL_GENERIC=y
  1927. +CONFIG_USB_SERIAL_AIRCABLE=m
  1928. +CONFIG_USB_SERIAL_ARK3116=m
  1929. +CONFIG_USB_SERIAL_BELKIN=m
  1930. +CONFIG_USB_SERIAL_CH341=m
  1931. +CONFIG_USB_SERIAL_WHITEHEAT=m
  1932. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  1933. +CONFIG_USB_SERIAL_CP210X=m
  1934. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  1935. +CONFIG_USB_SERIAL_EMPEG=m
  1936. +CONFIG_USB_SERIAL_FTDI_SIO=m
  1937. +CONFIG_USB_SERIAL_FUNSOFT=m
  1938. +CONFIG_USB_SERIAL_VISOR=m
  1939. +CONFIG_USB_SERIAL_IPAQ=m
  1940. +CONFIG_USB_SERIAL_IR=m
  1941. +CONFIG_USB_SERIAL_EDGEPORT=m
  1942. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  1943. +CONFIG_USB_SERIAL_GARMIN=m
  1944. +CONFIG_USB_SERIAL_IPW=m
  1945. +CONFIG_USB_SERIAL_IUU=m
  1946. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  1947. +CONFIG_USB_SERIAL_KEYSPAN=m
  1948. +CONFIG_USB_SERIAL_KLSI=m
  1949. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  1950. +CONFIG_USB_SERIAL_MCT_U232=m
  1951. +CONFIG_USB_SERIAL_MOS7720=m
  1952. +CONFIG_USB_SERIAL_MOS7840=m
  1953. +CONFIG_USB_SERIAL_MOTOROLA=m
  1954. +CONFIG_USB_SERIAL_NAVMAN=m
  1955. +CONFIG_USB_SERIAL_PL2303=m
  1956. +CONFIG_USB_SERIAL_OTI6858=m
  1957. +CONFIG_USB_SERIAL_QCAUX=m
  1958. +CONFIG_USB_SERIAL_QUALCOMM=m
  1959. +CONFIG_USB_SERIAL_SPCP8X5=m
  1960. +CONFIG_USB_SERIAL_HP4X=m
  1961. +CONFIG_USB_SERIAL_SAFE=m
  1962. +CONFIG_USB_SERIAL_SIEMENS_MPI=m
  1963. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  1964. +CONFIG_USB_SERIAL_SYMBOL=m
  1965. +CONFIG_USB_SERIAL_TI=m
  1966. +CONFIG_USB_SERIAL_CYBERJACK=m
  1967. +CONFIG_USB_SERIAL_XIRCOM=m
  1968. +CONFIG_USB_SERIAL_OPTION=m
  1969. +CONFIG_USB_SERIAL_OMNINET=m
  1970. +CONFIG_USB_SERIAL_OPTICON=m
  1971. +CONFIG_USB_SERIAL_VIVOPAY_SERIAL=m
  1972. +CONFIG_USB_SERIAL_ZIO=m
  1973. +CONFIG_USB_SERIAL_SSU100=m
  1974. +CONFIG_USB_SERIAL_DEBUG=m
  1975. +CONFIG_USB_EMI62=m
  1976. +CONFIG_USB_EMI26=m
  1977. +CONFIG_USB_ADUTUX=m
  1978. +CONFIG_USB_SEVSEG=m
  1979. +CONFIG_USB_RIO500=m
  1980. +CONFIG_USB_LEGOTOWER=m
  1981. +CONFIG_USB_LCD=m
  1982. +CONFIG_USB_LED=m
  1983. +CONFIG_USB_CYPRESS_CY7C63=m
  1984. +CONFIG_USB_CYTHERM=m
  1985. +CONFIG_USB_IDMOUSE=m
  1986. +CONFIG_USB_FTDI_ELAN=m
  1987. +CONFIG_USB_APPLEDISPLAY=m
  1988. +CONFIG_USB_LD=m
  1989. +CONFIG_USB_TRANCEVIBRATOR=m
  1990. +CONFIG_USB_IOWARRIOR=m
  1991. +CONFIG_USB_TEST=m
  1992. +CONFIG_USB_ISIGHTFW=m
  1993. +CONFIG_USB_YUREX=m
  1994. +CONFIG_MMC=y
  1995. +CONFIG_MMC_SDHCI=y
  1996. +CONFIG_MMC_SDHCI_PLTFM=y
  1997. +CONFIG_MMC_SDHCI_BCM2708=y
  1998. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  1999. +CONFIG_LEDS_GPIO=y
  2000. +CONFIG_LEDS_TRIGGER_TIMER=m
  2001. +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
  2002. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=m
  2003. +CONFIG_UIO=m
  2004. +CONFIG_UIO_PDRV=m
  2005. +CONFIG_UIO_PDRV_GENIRQ=m
  2006. +# CONFIG_IOMMU_SUPPORT is not set
  2007. +CONFIG_EXT4_FS=y
  2008. +CONFIG_EXT4_FS_POSIX_ACL=y
  2009. +CONFIG_EXT4_FS_SECURITY=y
  2010. +CONFIG_REISERFS_FS=m
  2011. +CONFIG_REISERFS_FS_XATTR=y
  2012. +CONFIG_REISERFS_FS_POSIX_ACL=y
  2013. +CONFIG_REISERFS_FS_SECURITY=y
  2014. +CONFIG_JFS_FS=m
  2015. +CONFIG_JFS_POSIX_ACL=y
  2016. +CONFIG_JFS_SECURITY=y
  2017. +CONFIG_JFS_STATISTICS=y
  2018. +CONFIG_XFS_FS=m
  2019. +CONFIG_XFS_QUOTA=y
  2020. +CONFIG_XFS_POSIX_ACL=y
  2021. +CONFIG_XFS_RT=y
  2022. +CONFIG_GFS2_FS=m
  2023. +CONFIG_OCFS2_FS=m
  2024. +CONFIG_BTRFS_FS=m
  2025. +CONFIG_BTRFS_FS_POSIX_ACL=y
  2026. +CONFIG_NILFS2_FS=m
  2027. +CONFIG_FANOTIFY=y
  2028. +CONFIG_AUTOFS4_FS=y
  2029. +CONFIG_FUSE_FS=m
  2030. +CONFIG_CUSE=m
  2031. +CONFIG_FSCACHE=y
  2032. +CONFIG_FSCACHE_STATS=y
  2033. +CONFIG_FSCACHE_HISTOGRAM=y
  2034. +CONFIG_CACHEFILES=y
  2035. +CONFIG_ISO9660_FS=m
  2036. +CONFIG_JOLIET=y
  2037. +CONFIG_ZISOFS=y
  2038. +CONFIG_UDF_FS=m
  2039. +CONFIG_MSDOS_FS=y
  2040. +CONFIG_VFAT_FS=y
  2041. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2042. +CONFIG_NTFS_FS=m
  2043. +CONFIG_TMPFS=y
  2044. +CONFIG_TMPFS_POSIX_ACL=y
  2045. +CONFIG_CONFIGFS_FS=y
  2046. +CONFIG_SQUASHFS=m
  2047. +CONFIG_SQUASHFS_XATTR=y
  2048. +CONFIG_SQUASHFS_LZO=y
  2049. +CONFIG_SQUASHFS_XZ=y
  2050. +CONFIG_NFS_FS=y
  2051. +CONFIG_NFS_V3=y
  2052. +CONFIG_NFS_V3_ACL=y
  2053. +CONFIG_NFS_V4=y
  2054. +CONFIG_ROOT_NFS=y
  2055. +CONFIG_NFS_FSCACHE=y
  2056. +CONFIG_CIFS=m
  2057. +CONFIG_CIFS_WEAK_PW_HASH=y
  2058. +CONFIG_CIFS_XATTR=y
  2059. +CONFIG_CIFS_POSIX=y
  2060. +CONFIG_9P_FS=m
  2061. +CONFIG_9P_FS_POSIX_ACL=y
  2062. +CONFIG_PARTITION_ADVANCED=y
  2063. +CONFIG_MAC_PARTITION=y
  2064. +CONFIG_EFI_PARTITION=y
  2065. +CONFIG_NLS_DEFAULT="utf8"
  2066. +CONFIG_NLS_CODEPAGE_437=y
  2067. +CONFIG_NLS_CODEPAGE_737=m
  2068. +CONFIG_NLS_CODEPAGE_775=m
  2069. +CONFIG_NLS_CODEPAGE_850=m
  2070. +CONFIG_NLS_CODEPAGE_852=m
  2071. +CONFIG_NLS_CODEPAGE_855=m
  2072. +CONFIG_NLS_CODEPAGE_857=m
  2073. +CONFIG_NLS_CODEPAGE_860=m
  2074. +CONFIG_NLS_CODEPAGE_861=m
  2075. +CONFIG_NLS_CODEPAGE_862=m
  2076. +CONFIG_NLS_CODEPAGE_863=m
  2077. +CONFIG_NLS_CODEPAGE_864=m
  2078. +CONFIG_NLS_CODEPAGE_865=m
  2079. +CONFIG_NLS_CODEPAGE_866=m
  2080. +CONFIG_NLS_CODEPAGE_869=m
  2081. +CONFIG_NLS_CODEPAGE_936=m
  2082. +CONFIG_NLS_CODEPAGE_950=m
  2083. +CONFIG_NLS_CODEPAGE_932=m
  2084. +CONFIG_NLS_CODEPAGE_949=m
  2085. +CONFIG_NLS_CODEPAGE_874=m
  2086. +CONFIG_NLS_ISO8859_8=m
  2087. +CONFIG_NLS_CODEPAGE_1250=m
  2088. +CONFIG_NLS_CODEPAGE_1251=m
  2089. +CONFIG_NLS_ASCII=y
  2090. +CONFIG_NLS_ISO8859_1=m
  2091. +CONFIG_NLS_ISO8859_2=m
  2092. +CONFIG_NLS_ISO8859_3=m
  2093. +CONFIG_NLS_ISO8859_4=m
  2094. +CONFIG_NLS_ISO8859_5=m
  2095. +CONFIG_NLS_ISO8859_6=m
  2096. +CONFIG_NLS_ISO8859_7=m
  2097. +CONFIG_NLS_ISO8859_9=m
  2098. +CONFIG_NLS_ISO8859_13=m
  2099. +CONFIG_NLS_ISO8859_14=m
  2100. +CONFIG_NLS_ISO8859_15=m
  2101. +CONFIG_NLS_KOI8_R=m
  2102. +CONFIG_NLS_KOI8_U=m
  2103. +CONFIG_NLS_UTF8=m
  2104. +CONFIG_PRINTK_TIME=y
  2105. +CONFIG_DETECT_HUNG_TASK=y
  2106. +CONFIG_TIMER_STATS=y
  2107. +CONFIG_DEBUG_STACK_USAGE=y
  2108. +CONFIG_DEBUG_INFO=y
  2109. +CONFIG_DEBUG_MEMORY_INIT=y
  2110. +CONFIG_BOOT_PRINTK_DELAY=y
  2111. +CONFIG_LATENCYTOP=y
  2112. +CONFIG_SYSCTL_SYSCALL_CHECK=y
  2113. +CONFIG_IRQSOFF_TRACER=y
  2114. +CONFIG_SCHED_TRACER=y
  2115. +CONFIG_STACK_TRACER=y
  2116. +CONFIG_BLK_DEV_IO_TRACE=y
  2117. +CONFIG_FUNCTION_PROFILER=y
  2118. +CONFIG_KGDB=y
  2119. +CONFIG_KGDB_KDB=y
  2120. +CONFIG_KDB_KEYBOARD=y
  2121. +CONFIG_STRICT_DEVMEM=y
  2122. +CONFIG_CRYPTO_AUTHENC=m
  2123. +CONFIG_CRYPTO_SEQIV=m
  2124. +CONFIG_CRYPTO_CBC=y
  2125. +CONFIG_CRYPTO_HMAC=y
  2126. +CONFIG_CRYPTO_XCBC=m
  2127. +CONFIG_CRYPTO_MD5=y
  2128. +CONFIG_CRYPTO_SHA1=y
  2129. +CONFIG_CRYPTO_SHA256=m
  2130. +CONFIG_CRYPTO_SHA512=m
  2131. +CONFIG_CRYPTO_TGR192=m
  2132. +CONFIG_CRYPTO_WP512=m
  2133. +CONFIG_CRYPTO_CAST5=m
  2134. +CONFIG_CRYPTO_DES=y
  2135. +CONFIG_CRYPTO_DEFLATE=m
  2136. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2137. +# CONFIG_CRYPTO_HW is not set
  2138. +CONFIG_CRC_ITU_T=y
  2139. +CONFIG_LIBCRC32C=y
  2140. diff -Nur linux-3.12.11.orig/arch/arm/configs/bcmrpi_quick_defconfig linux-3.12.11/arch/arm/configs/bcmrpi_quick_defconfig
  2141. --- linux-3.12.11.orig/arch/arm/configs/bcmrpi_quick_defconfig 1970-01-01 01:00:00.000000000 +0100
  2142. +++ linux-3.12.11/arch/arm/configs/bcmrpi_quick_defconfig 2014-02-18 11:52:14.000000000 +0100
  2143. @@ -0,0 +1,197 @@
  2144. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  2145. +CONFIG_LOCALVERSION="-quick"
  2146. +# CONFIG_LOCALVERSION_AUTO is not set
  2147. +# CONFIG_SWAP is not set
  2148. +CONFIG_SYSVIPC=y
  2149. +CONFIG_POSIX_MQUEUE=y
  2150. +CONFIG_NO_HZ=y
  2151. +CONFIG_HIGH_RES_TIMERS=y
  2152. +CONFIG_IKCONFIG=y
  2153. +CONFIG_IKCONFIG_PROC=y
  2154. +CONFIG_KALLSYMS_ALL=y
  2155. +CONFIG_EMBEDDED=y
  2156. +CONFIG_PERF_EVENTS=y
  2157. +# CONFIG_COMPAT_BRK is not set
  2158. +CONFIG_SLAB=y
  2159. +CONFIG_MODULES=y
  2160. +CONFIG_MODULE_UNLOAD=y
  2161. +CONFIG_MODVERSIONS=y
  2162. +CONFIG_MODULE_SRCVERSION_ALL=y
  2163. +# CONFIG_BLK_DEV_BSG is not set
  2164. +CONFIG_ARCH_BCM2708=y
  2165. +CONFIG_PREEMPT=y
  2166. +CONFIG_AEABI=y
  2167. +CONFIG_UACCESS_WITH_MEMCPY=y
  2168. +CONFIG_ZBOOT_ROM_TEXT=0x0
  2169. +CONFIG_ZBOOT_ROM_BSS=0x0
  2170. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  2171. +CONFIG_CPU_FREQ=y
  2172. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  2173. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  2174. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  2175. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  2176. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  2177. +CONFIG_CPU_IDLE=y
  2178. +CONFIG_VFP=y
  2179. +CONFIG_BINFMT_MISC=y
  2180. +CONFIG_NET=y
  2181. +CONFIG_PACKET=y
  2182. +CONFIG_UNIX=y
  2183. +CONFIG_INET=y
  2184. +CONFIG_IP_MULTICAST=y
  2185. +CONFIG_IP_PNP=y
  2186. +CONFIG_IP_PNP_DHCP=y
  2187. +CONFIG_IP_PNP_RARP=y
  2188. +CONFIG_SYN_COOKIES=y
  2189. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  2190. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  2191. +# CONFIG_INET_XFRM_MODE_BEET is not set
  2192. +# CONFIG_INET_LRO is not set
  2193. +# CONFIG_INET_DIAG is not set
  2194. +# CONFIG_IPV6 is not set
  2195. +# CONFIG_WIRELESS is not set
  2196. +CONFIG_DEVTMPFS=y
  2197. +CONFIG_DEVTMPFS_MOUNT=y
  2198. +CONFIG_BLK_DEV_LOOP=y
  2199. +CONFIG_BLK_DEV_RAM=y
  2200. +CONFIG_SCSI=y
  2201. +# CONFIG_SCSI_PROC_FS is not set
  2202. +# CONFIG_SCSI_LOWLEVEL is not set
  2203. +CONFIG_NETDEVICES=y
  2204. +# CONFIG_NET_VENDOR_BROADCOM is not set
  2205. +# CONFIG_NET_VENDOR_CIRRUS is not set
  2206. +# CONFIG_NET_VENDOR_FARADAY is not set
  2207. +# CONFIG_NET_VENDOR_INTEL is not set
  2208. +# CONFIG_NET_VENDOR_MARVELL is not set
  2209. +# CONFIG_NET_VENDOR_MICREL is not set
  2210. +# CONFIG_NET_VENDOR_NATSEMI is not set
  2211. +# CONFIG_NET_VENDOR_SEEQ is not set
  2212. +# CONFIG_NET_VENDOR_STMICRO is not set
  2213. +# CONFIG_NET_VENDOR_WIZNET is not set
  2214. +CONFIG_USB_USBNET=y
  2215. +# CONFIG_USB_NET_AX8817X is not set
  2216. +# CONFIG_USB_NET_CDCETHER is not set
  2217. +# CONFIG_USB_NET_CDC_NCM is not set
  2218. +CONFIG_USB_NET_SMSC95XX=y
  2219. +# CONFIG_USB_NET_NET1080 is not set
  2220. +# CONFIG_USB_NET_CDC_SUBSET is not set
  2221. +# CONFIG_USB_NET_ZAURUS is not set
  2222. +# CONFIG_WLAN is not set
  2223. +# CONFIG_INPUT_MOUSEDEV is not set
  2224. +CONFIG_INPUT_EVDEV=y
  2225. +# CONFIG_INPUT_KEYBOARD is not set
  2226. +# CONFIG_INPUT_MOUSE is not set
  2227. +# CONFIG_SERIO is not set
  2228. +CONFIG_VT_HW_CONSOLE_BINDING=y
  2229. +# CONFIG_LEGACY_PTYS is not set
  2230. +# CONFIG_DEVKMEM is not set
  2231. +CONFIG_SERIAL_AMBA_PL011=y
  2232. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  2233. +CONFIG_TTY_PRINTK=y
  2234. +CONFIG_HW_RANDOM=y
  2235. +CONFIG_HW_RANDOM_BCM2708=y
  2236. +CONFIG_RAW_DRIVER=y
  2237. +CONFIG_THERMAL=y
  2238. +CONFIG_THERMAL_BCM2835=y
  2239. +CONFIG_WATCHDOG=y
  2240. +CONFIG_BCM2708_WDT=y
  2241. +CONFIG_REGULATOR=y
  2242. +CONFIG_REGULATOR_DEBUG=y
  2243. +CONFIG_REGULATOR_FIXED_VOLTAGE=y
  2244. +CONFIG_REGULATOR_VIRTUAL_CONSUMER=y
  2245. +CONFIG_REGULATOR_USERSPACE_CONSUMER=y
  2246. +CONFIG_FB=y
  2247. +CONFIG_FB_BCM2708=y
  2248. +CONFIG_FRAMEBUFFER_CONSOLE=y
  2249. +CONFIG_LOGO=y
  2250. +# CONFIG_LOGO_LINUX_MONO is not set
  2251. +# CONFIG_LOGO_LINUX_VGA16 is not set
  2252. +CONFIG_SOUND=y
  2253. +CONFIG_SND=y
  2254. +CONFIG_SND_BCM2835=y
  2255. +# CONFIG_SND_USB is not set
  2256. +CONFIG_USB=y
  2257. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  2258. +CONFIG_USB_DWCOTG=y
  2259. +CONFIG_MMC=y
  2260. +CONFIG_MMC_SDHCI=y
  2261. +CONFIG_MMC_SDHCI_PLTFM=y
  2262. +CONFIG_MMC_SDHCI_BCM2708=y
  2263. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  2264. +CONFIG_NEW_LEDS=y
  2265. +CONFIG_LEDS_CLASS=y
  2266. +CONFIG_LEDS_TRIGGERS=y
  2267. +# CONFIG_IOMMU_SUPPORT is not set
  2268. +CONFIG_EXT4_FS=y
  2269. +CONFIG_EXT4_FS_POSIX_ACL=y
  2270. +CONFIG_EXT4_FS_SECURITY=y
  2271. +CONFIG_AUTOFS4_FS=y
  2272. +CONFIG_FSCACHE=y
  2273. +CONFIG_CACHEFILES=y
  2274. +CONFIG_MSDOS_FS=y
  2275. +CONFIG_VFAT_FS=y
  2276. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2277. +CONFIG_TMPFS=y
  2278. +CONFIG_TMPFS_POSIX_ACL=y
  2279. +CONFIG_CONFIGFS_FS=y
  2280. +# CONFIG_MISC_FILESYSTEMS is not set
  2281. +CONFIG_NFS_FS=y
  2282. +CONFIG_NFS_V3_ACL=y
  2283. +CONFIG_NFS_V4=y
  2284. +CONFIG_ROOT_NFS=y
  2285. +CONFIG_NFS_FSCACHE=y
  2286. +CONFIG_NLS_DEFAULT="utf8"
  2287. +CONFIG_NLS_CODEPAGE_437=y
  2288. +CONFIG_NLS_CODEPAGE_737=y
  2289. +CONFIG_NLS_CODEPAGE_775=y
  2290. +CONFIG_NLS_CODEPAGE_850=y
  2291. +CONFIG_NLS_CODEPAGE_852=y
  2292. +CONFIG_NLS_CODEPAGE_855=y
  2293. +CONFIG_NLS_CODEPAGE_857=y
  2294. +CONFIG_NLS_CODEPAGE_860=y
  2295. +CONFIG_NLS_CODEPAGE_861=y
  2296. +CONFIG_NLS_CODEPAGE_862=y
  2297. +CONFIG_NLS_CODEPAGE_863=y
  2298. +CONFIG_NLS_CODEPAGE_864=y
  2299. +CONFIG_NLS_CODEPAGE_865=y
  2300. +CONFIG_NLS_CODEPAGE_866=y
  2301. +CONFIG_NLS_CODEPAGE_869=y
  2302. +CONFIG_NLS_CODEPAGE_936=y
  2303. +CONFIG_NLS_CODEPAGE_950=y
  2304. +CONFIG_NLS_CODEPAGE_932=y
  2305. +CONFIG_NLS_CODEPAGE_949=y
  2306. +CONFIG_NLS_CODEPAGE_874=y
  2307. +CONFIG_NLS_ISO8859_8=y
  2308. +CONFIG_NLS_CODEPAGE_1250=y
  2309. +CONFIG_NLS_CODEPAGE_1251=y
  2310. +CONFIG_NLS_ASCII=y
  2311. +CONFIG_NLS_ISO8859_1=y
  2312. +CONFIG_NLS_ISO8859_2=y
  2313. +CONFIG_NLS_ISO8859_3=y
  2314. +CONFIG_NLS_ISO8859_4=y
  2315. +CONFIG_NLS_ISO8859_5=y
  2316. +CONFIG_NLS_ISO8859_6=y
  2317. +CONFIG_NLS_ISO8859_7=y
  2318. +CONFIG_NLS_ISO8859_9=y
  2319. +CONFIG_NLS_ISO8859_13=y
  2320. +CONFIG_NLS_ISO8859_14=y
  2321. +CONFIG_NLS_ISO8859_15=y
  2322. +CONFIG_NLS_UTF8=y
  2323. +CONFIG_PRINTK_TIME=y
  2324. +CONFIG_DEBUG_FS=y
  2325. +CONFIG_DETECT_HUNG_TASK=y
  2326. +# CONFIG_DEBUG_PREEMPT is not set
  2327. +# CONFIG_DEBUG_BUGVERBOSE is not set
  2328. +# CONFIG_FTRACE is not set
  2329. +CONFIG_KGDB=y
  2330. +CONFIG_KGDB_KDB=y
  2331. +# CONFIG_ARM_UNWIND is not set
  2332. +CONFIG_CRYPTO_CBC=y
  2333. +CONFIG_CRYPTO_HMAC=y
  2334. +CONFIG_CRYPTO_MD5=y
  2335. +CONFIG_CRYPTO_SHA1=y
  2336. +CONFIG_CRYPTO_DES=y
  2337. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2338. +# CONFIG_CRYPTO_HW is not set
  2339. +CONFIG_CRC_ITU_T=y
  2340. +CONFIG_LIBCRC32C=y
  2341. diff -Nur linux-3.12.11.orig/arch/arm/include/asm/fiq.h linux-3.12.11/arch/arm/include/asm/fiq.h
  2342. --- linux-3.12.11.orig/arch/arm/include/asm/fiq.h 2014-02-13 22:51:06.000000000 +0100
  2343. +++ linux-3.12.11/arch/arm/include/asm/fiq.h 2014-02-18 11:52:14.000000000 +0100
  2344. @@ -42,6 +42,7 @@
  2345. /* helpers defined in fiqasm.S: */
  2346. extern void __set_fiq_regs(unsigned long const *regs);
  2347. extern void __get_fiq_regs(unsigned long *regs);
  2348. +extern void __FIQ_Branch(unsigned long *regs);
  2349. static inline void set_fiq_regs(struct pt_regs const *regs)
  2350. {
  2351. diff -Nur linux-3.12.11.orig/arch/arm/Kconfig linux-3.12.11/arch/arm/Kconfig
  2352. --- linux-3.12.11.orig/arch/arm/Kconfig 2014-02-13 22:51:06.000000000 +0100
  2353. +++ linux-3.12.11/arch/arm/Kconfig 2014-02-18 11:52:14.000000000 +0100
  2354. @@ -368,6 +368,24 @@
  2355. This enables support for systems based on Atmel
  2356. AT91RM9200 and AT91SAM9* processors.
  2357. +config ARCH_BCM2708
  2358. + bool "Broadcom BCM2708 family"
  2359. + select CPU_V6
  2360. + select ARM_AMBA
  2361. + select HAVE_CLK
  2362. + select HAVE_SCHED_CLOCK
  2363. + select NEED_MACH_GPIO_H
  2364. + select NEED_MACH_MEMORY_H
  2365. + select CLKDEV_LOOKUP
  2366. + select ARCH_HAS_CPUFREQ
  2367. + select GENERIC_CLOCKEVENTS
  2368. + select ARM_ERRATA_411920
  2369. + select MACH_BCM2708
  2370. + select VC4
  2371. + select FIQ
  2372. + help
  2373. + This enables support for Broadcom BCM2708 boards.
  2374. +
  2375. config ARCH_CLPS711X
  2376. bool "Cirrus Logic CLPS711x/EP721x/EP731x-based"
  2377. select ARCH_REQUIRE_GPIOLIB
  2378. @@ -1043,6 +1061,7 @@
  2379. source "arch/arm/mach-vt8500/Kconfig"
  2380. source "arch/arm/mach-w90x900/Kconfig"
  2381. +source "arch/arm/mach-bcm2708/Kconfig"
  2382. source "arch/arm/mach-zynq/Kconfig"
  2383. diff -Nur linux-3.12.11.orig/arch/arm/Kconfig.debug linux-3.12.11/arch/arm/Kconfig.debug
  2384. --- linux-3.12.11.orig/arch/arm/Kconfig.debug 2014-02-13 22:51:06.000000000 +0100
  2385. +++ linux-3.12.11/arch/arm/Kconfig.debug 2014-02-18 11:52:14.000000000 +0100
  2386. @@ -847,6 +847,14 @@
  2387. options; the platform specific options are deprecated
  2388. and will be soon removed.
  2389. + config DEBUG_BCM2708_UART0
  2390. + bool "Broadcom BCM2708 UART0 (PL011)"
  2391. + depends on MACH_BCM2708
  2392. + help
  2393. + Say Y here if you want the debug print routines to direct
  2394. + their output to UART 0. The port must have been initialised
  2395. + by the boot-loader before use.
  2396. +
  2397. endchoice
  2398. config DEBUG_EXYNOS_UART
  2399. diff -Nur linux-3.12.11.orig/arch/arm/kernel/fiqasm.S linux-3.12.11/arch/arm/kernel/fiqasm.S
  2400. --- linux-3.12.11.orig/arch/arm/kernel/fiqasm.S 2014-02-13 22:51:06.000000000 +0100
  2401. +++ linux-3.12.11/arch/arm/kernel/fiqasm.S 2014-02-18 11:52:14.000000000 +0100
  2402. @@ -25,6 +25,9 @@
  2403. ENTRY(__set_fiq_regs)
  2404. mov r2, #PSR_I_BIT | PSR_F_BIT | FIQ_MODE
  2405. mrs r1, cpsr
  2406. +@@@@@@@@@@@@@@@ hack: enable the fiq here to keep usb driver happy
  2407. + and r1, #~PSR_F_BIT
  2408. +@@@@@@@@@@@@@@@ endhack: (need to find better place for this to happen)
  2409. msr cpsr_c, r2 @ select FIQ mode
  2410. mov r0, r0 @ avoid hazard prior to ARMv4
  2411. ldmia r0!, {r8 - r12}
  2412. @@ -47,3 +50,7 @@
  2413. mov r0, r0 @ avoid hazard prior to ARMv4
  2414. mov pc, lr
  2415. ENDPROC(__get_fiq_regs)
  2416. +
  2417. +ENTRY(__FIQ_Branch)
  2418. + mov pc, r8
  2419. +ENDPROC(__FIQ_Branch)
  2420. diff -Nur linux-3.12.11.orig/arch/arm/kernel/fiq.c linux-3.12.11/arch/arm/kernel/fiq.c
  2421. --- linux-3.12.11.orig/arch/arm/kernel/fiq.c 2014-02-13 22:51:06.000000000 +0100
  2422. +++ linux-3.12.11/arch/arm/kernel/fiq.c 2014-02-18 11:52:14.000000000 +0100
  2423. @@ -142,6 +142,7 @@
  2424. EXPORT_SYMBOL(set_fiq_handler);
  2425. EXPORT_SYMBOL(__set_fiq_regs); /* defined in fiqasm.S */
  2426. EXPORT_SYMBOL(__get_fiq_regs); /* defined in fiqasm.S */
  2427. +EXPORT_SYMBOL(__FIQ_Branch); /* defined in fiqasm.S */
  2428. EXPORT_SYMBOL(claim_fiq);
  2429. EXPORT_SYMBOL(release_fiq);
  2430. EXPORT_SYMBOL(enable_fiq);
  2431. diff -Nur linux-3.12.11.orig/arch/arm/kernel/process.c linux-3.12.11/arch/arm/kernel/process.c
  2432. --- linux-3.12.11.orig/arch/arm/kernel/process.c 2014-02-13 22:51:06.000000000 +0100
  2433. +++ linux-3.12.11/arch/arm/kernel/process.c 2014-02-18 11:52:14.000000000 +0100
  2434. @@ -176,6 +176,16 @@
  2435. default_idle();
  2436. }
  2437. +char bcm2708_reboot_mode = 'h';
  2438. +
  2439. +int __init reboot_setup(char *str)
  2440. +{
  2441. + bcm2708_reboot_mode = str[0];
  2442. + return 1;
  2443. +}
  2444. +
  2445. +__setup("reboot=", reboot_setup);
  2446. +
  2447. /*
  2448. * Called by kexec, immediately prior to machine_kexec().
  2449. *
  2450. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/armctrl.c linux-3.12.11/arch/arm/mach-bcm2708/armctrl.c
  2451. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/armctrl.c 1970-01-01 01:00:00.000000000 +0100
  2452. +++ linux-3.12.11/arch/arm/mach-bcm2708/armctrl.c 2014-02-18 11:52:14.000000000 +0100
  2453. @@ -0,0 +1,219 @@
  2454. +/*
  2455. + * linux/arch/arm/mach-bcm2708/armctrl.c
  2456. + *
  2457. + * Copyright (C) 2010 Broadcom
  2458. + *
  2459. + * This program is free software; you can redistribute it and/or modify
  2460. + * it under the terms of the GNU General Public License as published by
  2461. + * the Free Software Foundation; either version 2 of the License, or
  2462. + * (at your option) any later version.
  2463. + *
  2464. + * This program is distributed in the hope that it will be useful,
  2465. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2466. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2467. + * GNU General Public License for more details.
  2468. + *
  2469. + * You should have received a copy of the GNU General Public License
  2470. + * along with this program; if not, write to the Free Software
  2471. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2472. + */
  2473. +#include <linux/init.h>
  2474. +#include <linux/list.h>
  2475. +#include <linux/io.h>
  2476. +#include <linux/version.h>
  2477. +#include <linux/syscore_ops.h>
  2478. +#include <linux/interrupt.h>
  2479. +
  2480. +#include <asm/mach/irq.h>
  2481. +#include <mach/hardware.h>
  2482. +#include "armctrl.h"
  2483. +
  2484. +/* For support of kernels >= 3.0 assume only one VIC for now*/
  2485. +static unsigned int remap_irqs[(INTERRUPT_ARASANSDIO + 1) - INTERRUPT_JPEG] = {
  2486. + INTERRUPT_VC_JPEG,
  2487. + INTERRUPT_VC_USB,
  2488. + INTERRUPT_VC_3D,
  2489. + INTERRUPT_VC_DMA2,
  2490. + INTERRUPT_VC_DMA3,
  2491. + INTERRUPT_VC_I2C,
  2492. + INTERRUPT_VC_SPI,
  2493. + INTERRUPT_VC_I2SPCM,
  2494. + INTERRUPT_VC_SDIO,
  2495. + INTERRUPT_VC_UART,
  2496. + INTERRUPT_VC_ARASANSDIO
  2497. +};
  2498. +
  2499. +static void armctrl_mask_irq(struct irq_data *d)
  2500. +{
  2501. + static const unsigned int disables[4] = {
  2502. + ARM_IRQ_DIBL1,
  2503. + ARM_IRQ_DIBL2,
  2504. + ARM_IRQ_DIBL3,
  2505. + 0
  2506. + };
  2507. +
  2508. + if (d->irq >= FIQ_START) {
  2509. + writel(0, __io_address(ARM_IRQ_FAST));
  2510. + } else {
  2511. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  2512. + writel(1 << (data & 0x1f), __io_address(disables[(data >> 5) & 0x3]));
  2513. + }
  2514. +}
  2515. +
  2516. +static void armctrl_unmask_irq(struct irq_data *d)
  2517. +{
  2518. + static const unsigned int enables[4] = {
  2519. + ARM_IRQ_ENBL1,
  2520. + ARM_IRQ_ENBL2,
  2521. + ARM_IRQ_ENBL3,
  2522. + 0
  2523. + };
  2524. +
  2525. + if (d->irq >= FIQ_START) {
  2526. + unsigned int data =
  2527. + (unsigned int)irq_get_chip_data(d->irq) - FIQ_START;
  2528. + writel(0x80 | data, __io_address(ARM_IRQ_FAST));
  2529. + } else {
  2530. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  2531. + writel(1 << (data & 0x1f), __io_address(enables[(data >> 5) & 0x3]));
  2532. + }
  2533. +}
  2534. +
  2535. +#if defined(CONFIG_PM)
  2536. +
  2537. +/* for kernels 3.xx use the new syscore_ops apis but for older kernels use the sys dev class */
  2538. +
  2539. +/* Static defines
  2540. + * struct armctrl_device - VIC PM device (< 3.xx)
  2541. + * @sysdev: The system device which is registered. (< 3.xx)
  2542. + * @irq: The IRQ number for the base of the VIC.
  2543. + * @base: The register base for the VIC.
  2544. + * @resume_sources: A bitmask of interrupts for resume.
  2545. + * @resume_irqs: The IRQs enabled for resume.
  2546. + * @int_select: Save for VIC_INT_SELECT.
  2547. + * @int_enable: Save for VIC_INT_ENABLE.
  2548. + * @soft_int: Save for VIC_INT_SOFT.
  2549. + * @protect: Save for VIC_PROTECT.
  2550. + */
  2551. +struct armctrl_info {
  2552. + void __iomem *base;
  2553. + int irq;
  2554. + u32 resume_sources;
  2555. + u32 resume_irqs;
  2556. + u32 int_select;
  2557. + u32 int_enable;
  2558. + u32 soft_int;
  2559. + u32 protect;
  2560. +} armctrl;
  2561. +
  2562. +static int armctrl_suspend(void)
  2563. +{
  2564. + return 0;
  2565. +}
  2566. +
  2567. +static void armctrl_resume(void)
  2568. +{
  2569. + return;
  2570. +}
  2571. +
  2572. +/**
  2573. + * armctrl_pm_register - Register a VIC for later power management control
  2574. + * @base: The base address of the VIC.
  2575. + * @irq: The base IRQ for the VIC.
  2576. + * @resume_sources: bitmask of interrupts allowed for resume sources.
  2577. + *
  2578. + * For older kernels (< 3.xx) do -
  2579. + * Register the VIC with the system device tree so that it can be notified
  2580. + * of suspend and resume requests and ensure that the correct actions are
  2581. + * taken to re-instate the settings on resume.
  2582. + */
  2583. +static void __init armctrl_pm_register(void __iomem * base, unsigned int irq,
  2584. + u32 resume_sources)
  2585. +{
  2586. + armctrl.base = base;
  2587. + armctrl.resume_sources = resume_sources;
  2588. + armctrl.irq = irq;
  2589. +}
  2590. +
  2591. +static int armctrl_set_wake(struct irq_data *d, unsigned int on)
  2592. +{
  2593. + unsigned int off = d->irq & 31;
  2594. + u32 bit = 1 << off;
  2595. +
  2596. + if (!(bit & armctrl.resume_sources))
  2597. + return -EINVAL;
  2598. +
  2599. + if (on)
  2600. + armctrl.resume_irqs |= bit;
  2601. + else
  2602. + armctrl.resume_irqs &= ~bit;
  2603. +
  2604. + return 0;
  2605. +}
  2606. +
  2607. +#else
  2608. +static inline void armctrl_pm_register(void __iomem * base, unsigned int irq,
  2609. + u32 arg1)
  2610. +{
  2611. +}
  2612. +
  2613. +#define armctrl_suspend NULL
  2614. +#define armctrl_resume NULL
  2615. +#define armctrl_set_wake NULL
  2616. +#endif /* CONFIG_PM */
  2617. +
  2618. +static struct syscore_ops armctrl_syscore_ops = {
  2619. + .suspend = armctrl_suspend,
  2620. + .resume = armctrl_resume,
  2621. +};
  2622. +
  2623. +/**
  2624. + * armctrl_syscore_init - initicall to register VIC pm functions
  2625. + *
  2626. + * This is called via late_initcall() to register
  2627. + * the resources for the VICs due to the early
  2628. + * nature of the VIC's registration.
  2629. +*/
  2630. +static int __init armctrl_syscore_init(void)
  2631. +{
  2632. + register_syscore_ops(&armctrl_syscore_ops);
  2633. + return 0;
  2634. +}
  2635. +
  2636. +late_initcall(armctrl_syscore_init);
  2637. +
  2638. +static struct irq_chip armctrl_chip = {
  2639. + .name = "ARMCTRL",
  2640. + .irq_ack = armctrl_mask_irq,
  2641. + .irq_mask = armctrl_mask_irq,
  2642. + .irq_unmask = armctrl_unmask_irq,
  2643. + .irq_set_wake = armctrl_set_wake,
  2644. +};
  2645. +
  2646. +/**
  2647. + * armctrl_init - initialise a vectored interrupt controller
  2648. + * @base: iomem base address
  2649. + * @irq_start: starting interrupt number, must be muliple of 32
  2650. + * @armctrl_sources: bitmask of interrupt sources to allow
  2651. + * @resume_sources: bitmask of interrupt sources to allow for resume
  2652. + */
  2653. +int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  2654. + u32 armctrl_sources, u32 resume_sources)
  2655. +{
  2656. + unsigned int irq;
  2657. +
  2658. + for (irq = 0; irq < NR_IRQS; irq++) {
  2659. + unsigned int data = irq;
  2660. + if (irq >= INTERRUPT_JPEG && irq <= INTERRUPT_ARASANSDIO)
  2661. + data = remap_irqs[irq - INTERRUPT_JPEG];
  2662. +
  2663. + irq_set_chip(irq, &armctrl_chip);
  2664. + irq_set_chip_data(irq, (void *)data);
  2665. + irq_set_handler(irq, handle_level_irq);
  2666. + set_irq_flags(irq, IRQF_VALID | IRQF_PROBE | IRQF_DISABLED);
  2667. + }
  2668. +
  2669. + armctrl_pm_register(base, irq_start, resume_sources);
  2670. + init_FIQ(FIQ_START);
  2671. + return 0;
  2672. +}
  2673. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/armctrl.h linux-3.12.11/arch/arm/mach-bcm2708/armctrl.h
  2674. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/armctrl.h 1970-01-01 01:00:00.000000000 +0100
  2675. +++ linux-3.12.11/arch/arm/mach-bcm2708/armctrl.h 2014-02-18 11:52:14.000000000 +0100
  2676. @@ -0,0 +1,27 @@
  2677. +/*
  2678. + * linux/arch/arm/mach-bcm2708/armctrl.h
  2679. + *
  2680. + * Copyright (C) 2010 Broadcom
  2681. + *
  2682. + * This program is free software; you can redistribute it and/or modify
  2683. + * it under the terms of the GNU General Public License as published by
  2684. + * the Free Software Foundation; either version 2 of the License, or
  2685. + * (at your option) any later version.
  2686. + *
  2687. + * This program is distributed in the hope that it will be useful,
  2688. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2689. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2690. + * GNU General Public License for more details.
  2691. + *
  2692. + * You should have received a copy of the GNU General Public License
  2693. + * along with this program; if not, write to the Free Software
  2694. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2695. + */
  2696. +
  2697. +#ifndef __BCM2708_ARMCTRL_H
  2698. +#define __BCM2708_ARMCTRL_H
  2699. +
  2700. +extern int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  2701. + u32 armctrl_sources, u32 resume_sources);
  2702. +
  2703. +#endif
  2704. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/bcm2708.c linux-3.12.11/arch/arm/mach-bcm2708/bcm2708.c
  2705. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  2706. +++ linux-3.12.11/arch/arm/mach-bcm2708/bcm2708.c 2014-02-18 11:52:14.000000000 +0100
  2707. @@ -0,0 +1,985 @@
  2708. +/*
  2709. + * linux/arch/arm/mach-bcm2708/bcm2708.c
  2710. + *
  2711. + * Copyright (C) 2010 Broadcom
  2712. + *
  2713. + * This program is free software; you can redistribute it and/or modify
  2714. + * it under the terms of the GNU General Public License as published by
  2715. + * the Free Software Foundation; either version 2 of the License, or
  2716. + * (at your option) any later version.
  2717. + *
  2718. + * This program is distributed in the hope that it will be useful,
  2719. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2720. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2721. + * GNU General Public License for more details.
  2722. + *
  2723. + * You should have received a copy of the GNU General Public License
  2724. + * along with this program; if not, write to the Free Software
  2725. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2726. + */
  2727. +
  2728. +#include <linux/init.h>
  2729. +#include <linux/device.h>
  2730. +#include <linux/dma-mapping.h>
  2731. +#include <linux/serial_8250.h>
  2732. +#include <linux/platform_device.h>
  2733. +#include <linux/syscore_ops.h>
  2734. +#include <linux/interrupt.h>
  2735. +#include <linux/amba/bus.h>
  2736. +#include <linux/amba/clcd.h>
  2737. +#include <linux/clockchips.h>
  2738. +#include <linux/cnt32_to_63.h>
  2739. +#include <linux/io.h>
  2740. +#include <linux/module.h>
  2741. +#include <linux/spi/spi.h>
  2742. +#include <linux/w1-gpio.h>
  2743. +
  2744. +#include <linux/version.h>
  2745. +#include <linux/clkdev.h>
  2746. +#include <asm/system.h>
  2747. +#include <mach/hardware.h>
  2748. +#include <asm/irq.h>
  2749. +#include <linux/leds.h>
  2750. +#include <asm/mach-types.h>
  2751. +#include <asm/sched_clock.h>
  2752. +
  2753. +#include <asm/mach/arch.h>
  2754. +#include <asm/mach/flash.h>
  2755. +#include <asm/mach/irq.h>
  2756. +#include <asm/mach/time.h>
  2757. +#include <asm/mach/map.h>
  2758. +
  2759. +#include <mach/timex.h>
  2760. +#include <mach/dma.h>
  2761. +#include <mach/vcio.h>
  2762. +#include <mach/system.h>
  2763. +
  2764. +#include <linux/delay.h>
  2765. +
  2766. +#include "bcm2708.h"
  2767. +#include "armctrl.h"
  2768. +#include "clock.h"
  2769. +
  2770. +#ifdef CONFIG_BCM_VC_CMA
  2771. +#include <linux/broadcom/vc_cma.h>
  2772. +#endif
  2773. +
  2774. +
  2775. +/* Effectively we have an IOMMU (ARM<->VideoCore map) that is set up to
  2776. + * give us IO access only to 64Mbytes of physical memory (26 bits). We could
  2777. + * represent this window by setting our dmamasks to 26 bits but, in fact
  2778. + * we're not going to use addresses outside this range (they're not in real
  2779. + * memory) so we don't bother.
  2780. + *
  2781. + * In the future we might include code to use this IOMMU to remap other
  2782. + * physical addresses onto VideoCore memory then the use of 32-bits would be
  2783. + * more legitimate.
  2784. + */
  2785. +#define DMA_MASK_BITS_COMMON 32
  2786. +
  2787. +// use GPIO 4 for the one-wire GPIO pin, if enabled
  2788. +#define W1_GPIO 4
  2789. +
  2790. +/* command line parameters */
  2791. +static unsigned boardrev, serial;
  2792. +static unsigned uart_clock;
  2793. +static unsigned reboot_part = 0;
  2794. +
  2795. +static void __init bcm2708_init_led(void);
  2796. +
  2797. +void __init bcm2708_init_irq(void)
  2798. +{
  2799. + armctrl_init(__io_address(ARMCTRL_IC_BASE), 0, 0, 0);
  2800. +}
  2801. +
  2802. +static struct map_desc bcm2708_io_desc[] __initdata = {
  2803. + {
  2804. + .virtual = IO_ADDRESS(ARMCTRL_BASE),
  2805. + .pfn = __phys_to_pfn(ARMCTRL_BASE),
  2806. + .length = SZ_4K,
  2807. + .type = MT_DEVICE},
  2808. + {
  2809. + .virtual = IO_ADDRESS(UART0_BASE),
  2810. + .pfn = __phys_to_pfn(UART0_BASE),
  2811. + .length = SZ_4K,
  2812. + .type = MT_DEVICE},
  2813. + {
  2814. + .virtual = IO_ADDRESS(UART1_BASE),
  2815. + .pfn = __phys_to_pfn(UART1_BASE),
  2816. + .length = SZ_4K,
  2817. + .type = MT_DEVICE},
  2818. + {
  2819. + .virtual = IO_ADDRESS(DMA_BASE),
  2820. + .pfn = __phys_to_pfn(DMA_BASE),
  2821. + .length = SZ_4K,
  2822. + .type = MT_DEVICE},
  2823. + {
  2824. + .virtual = IO_ADDRESS(MCORE_BASE),
  2825. + .pfn = __phys_to_pfn(MCORE_BASE),
  2826. + .length = SZ_4K,
  2827. + .type = MT_DEVICE},
  2828. + {
  2829. + .virtual = IO_ADDRESS(ST_BASE),
  2830. + .pfn = __phys_to_pfn(ST_BASE),
  2831. + .length = SZ_4K,
  2832. + .type = MT_DEVICE},
  2833. + {
  2834. + .virtual = IO_ADDRESS(USB_BASE),
  2835. + .pfn = __phys_to_pfn(USB_BASE),
  2836. + .length = SZ_128K,
  2837. + .type = MT_DEVICE},
  2838. + {
  2839. + .virtual = IO_ADDRESS(PM_BASE),
  2840. + .pfn = __phys_to_pfn(PM_BASE),
  2841. + .length = SZ_4K,
  2842. + .type = MT_DEVICE},
  2843. + {
  2844. + .virtual = IO_ADDRESS(GPIO_BASE),
  2845. + .pfn = __phys_to_pfn(GPIO_BASE),
  2846. + .length = SZ_4K,
  2847. + .type = MT_DEVICE}
  2848. +};
  2849. +
  2850. +void __init bcm2708_map_io(void)
  2851. +{
  2852. + iotable_init(bcm2708_io_desc, ARRAY_SIZE(bcm2708_io_desc));
  2853. +}
  2854. +
  2855. +/* The STC is a free running counter that increments at the rate of 1MHz */
  2856. +#define STC_FREQ_HZ 1000000
  2857. +
  2858. +static inline uint32_t timer_read(void)
  2859. +{
  2860. + /* STC: a free running counter that increments at the rate of 1MHz */
  2861. + return readl(__io_address(ST_BASE + 0x04));
  2862. +}
  2863. +
  2864. +static unsigned long bcm2708_read_current_timer(void)
  2865. +{
  2866. + return timer_read();
  2867. +}
  2868. +
  2869. +static u32 notrace bcm2708_read_sched_clock(void)
  2870. +{
  2871. + return timer_read();
  2872. +}
  2873. +
  2874. +static cycle_t clksrc_read(struct clocksource *cs)
  2875. +{
  2876. + return timer_read();
  2877. +}
  2878. +
  2879. +static struct clocksource clocksource_stc = {
  2880. + .name = "stc",
  2881. + .rating = 300,
  2882. + .read = clksrc_read,
  2883. + .mask = CLOCKSOURCE_MASK(32),
  2884. + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  2885. +};
  2886. +
  2887. +unsigned long frc_clock_ticks32(void)
  2888. +{
  2889. + return timer_read();
  2890. +}
  2891. +
  2892. +static void __init bcm2708_clocksource_init(void)
  2893. +{
  2894. + if (clocksource_register_hz(&clocksource_stc, STC_FREQ_HZ)) {
  2895. + printk(KERN_ERR "timer: failed to initialize clock "
  2896. + "source %s\n", clocksource_stc.name);
  2897. + }
  2898. +}
  2899. +
  2900. +
  2901. +/*
  2902. + * These are fixed clocks.
  2903. + */
  2904. +static struct clk ref24_clk = {
  2905. + .rate = UART0_CLOCK, /* The UART is clocked at 3MHz via APB_CLK */
  2906. +};
  2907. +
  2908. +static struct clk osc_clk = {
  2909. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  2910. + .rate = 27000000,
  2911. +#else
  2912. + .rate = 500000000, /* ARM clock is set from the VideoCore booter */
  2913. +#endif
  2914. +};
  2915. +
  2916. +/* warning - the USB needs a clock > 34MHz */
  2917. +
  2918. +static struct clk sdhost_clk = {
  2919. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  2920. + .rate = 4000000, /* 4MHz */
  2921. +#else
  2922. + .rate = 250000000, /* 250MHz */
  2923. +#endif
  2924. +};
  2925. +
  2926. +static struct clk_lookup lookups[] = {
  2927. + { /* UART0 */
  2928. + .dev_id = "dev:f1",
  2929. + .clk = &ref24_clk,
  2930. + },
  2931. + { /* USB */
  2932. + .dev_id = "bcm2708_usb",
  2933. + .clk = &osc_clk,
  2934. + }, { /* SPI */
  2935. + .dev_id = "bcm2708_spi.0",
  2936. + .clk = &sdhost_clk,
  2937. + }, { /* BSC0 */
  2938. + .dev_id = "bcm2708_i2c.0",
  2939. + .clk = &sdhost_clk,
  2940. + }, { /* BSC1 */
  2941. + .dev_id = "bcm2708_i2c.1",
  2942. + .clk = &sdhost_clk,
  2943. + }
  2944. +};
  2945. +
  2946. +#define UART0_IRQ { IRQ_UART, 0 /*NO_IRQ*/ }
  2947. +#define UART0_DMA { 15, 14 }
  2948. +
  2949. +AMBA_DEVICE(uart0, "dev:f1", UART0, NULL);
  2950. +
  2951. +static struct amba_device *amba_devs[] __initdata = {
  2952. + &uart0_device,
  2953. +};
  2954. +
  2955. +static struct resource bcm2708_dmaman_resources[] = {
  2956. + {
  2957. + .start = DMA_BASE,
  2958. + .end = DMA_BASE + SZ_4K - 1,
  2959. + .flags = IORESOURCE_MEM,
  2960. + }
  2961. +};
  2962. +
  2963. +static struct platform_device bcm2708_dmaman_device = {
  2964. + .name = BCM_DMAMAN_DRIVER_NAME,
  2965. + .id = 0, /* first bcm2708_dma */
  2966. + .resource = bcm2708_dmaman_resources,
  2967. + .num_resources = ARRAY_SIZE(bcm2708_dmaman_resources),
  2968. +};
  2969. +
  2970. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  2971. +static struct w1_gpio_platform_data w1_gpio_pdata = {
  2972. + .pin = W1_GPIO,
  2973. + .is_open_drain = 0,
  2974. +};
  2975. +
  2976. +static struct platform_device w1_device = {
  2977. + .name = "w1-gpio",
  2978. + .id = -1,
  2979. + .dev.platform_data = &w1_gpio_pdata,
  2980. +};
  2981. +#endif
  2982. +
  2983. +static u64 fb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  2984. +
  2985. +static struct platform_device bcm2708_fb_device = {
  2986. + .name = "bcm2708_fb",
  2987. + .id = -1, /* only one bcm2708_fb */
  2988. + .resource = NULL,
  2989. + .num_resources = 0,
  2990. + .dev = {
  2991. + .dma_mask = &fb_dmamask,
  2992. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  2993. + },
  2994. +};
  2995. +
  2996. +static struct plat_serial8250_port bcm2708_uart1_platform_data[] = {
  2997. + {
  2998. + .mapbase = UART1_BASE + 0x40,
  2999. + .irq = IRQ_AUX,
  3000. + .uartclk = 125000000,
  3001. + .regshift = 2,
  3002. + .iotype = UPIO_MEM,
  3003. + .flags = UPF_FIXED_TYPE | UPF_IOREMAP | UPF_SKIP_TEST,
  3004. + .type = PORT_8250,
  3005. + },
  3006. + {},
  3007. +};
  3008. +
  3009. +static struct platform_device bcm2708_uart1_device = {
  3010. + .name = "serial8250",
  3011. + .id = PLAT8250_DEV_PLATFORM,
  3012. + .dev = {
  3013. + .platform_data = bcm2708_uart1_platform_data,
  3014. + },
  3015. +};
  3016. +
  3017. +static struct resource bcm2708_usb_resources[] = {
  3018. + [0] = {
  3019. + .start = USB_BASE,
  3020. + .end = USB_BASE + SZ_128K - 1,
  3021. + .flags = IORESOURCE_MEM,
  3022. + },
  3023. + [1] = {
  3024. + .start = MPHI_BASE,
  3025. + .end = MPHI_BASE + SZ_4K - 1,
  3026. + .flags = IORESOURCE_MEM,
  3027. + },
  3028. + [2] = {
  3029. + .start = IRQ_HOSTPORT,
  3030. + .end = IRQ_HOSTPORT,
  3031. + .flags = IORESOURCE_IRQ,
  3032. + },
  3033. +};
  3034. +
  3035. +bool fiq_fix_enable = true;
  3036. +
  3037. +static struct resource bcm2708_usb_resources_no_fiq_fix[] = {
  3038. + [0] = {
  3039. + .start = USB_BASE,
  3040. + .end = USB_BASE + SZ_128K - 1,
  3041. + .flags = IORESOURCE_MEM,
  3042. + },
  3043. + [1] = {
  3044. + .start = IRQ_USB,
  3045. + .end = IRQ_USB,
  3046. + .flags = IORESOURCE_IRQ,
  3047. + },
  3048. +};
  3049. +
  3050. +static u64 usb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3051. +
  3052. +static struct platform_device bcm2708_usb_device = {
  3053. + .name = "bcm2708_usb",
  3054. + .id = -1, /* only one bcm2708_usb */
  3055. + .resource = bcm2708_usb_resources,
  3056. + .num_resources = ARRAY_SIZE(bcm2708_usb_resources),
  3057. + .dev = {
  3058. + .dma_mask = &usb_dmamask,
  3059. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3060. + },
  3061. +};
  3062. +
  3063. +static struct resource bcm2708_vcio_resources[] = {
  3064. + [0] = { /* mailbox/semaphore/doorbell access */
  3065. + .start = MCORE_BASE,
  3066. + .end = MCORE_BASE + SZ_4K - 1,
  3067. + .flags = IORESOURCE_MEM,
  3068. + },
  3069. +};
  3070. +
  3071. +static u64 vcio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3072. +
  3073. +static struct platform_device bcm2708_vcio_device = {
  3074. + .name = BCM_VCIO_DRIVER_NAME,
  3075. + .id = -1, /* only one VideoCore I/O area */
  3076. + .resource = bcm2708_vcio_resources,
  3077. + .num_resources = ARRAY_SIZE(bcm2708_vcio_resources),
  3078. + .dev = {
  3079. + .dma_mask = &vcio_dmamask,
  3080. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3081. + },
  3082. +};
  3083. +
  3084. +#ifdef CONFIG_BCM2708_GPIO
  3085. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  3086. +
  3087. +static struct resource bcm2708_gpio_resources[] = {
  3088. + [0] = { /* general purpose I/O */
  3089. + .start = GPIO_BASE,
  3090. + .end = GPIO_BASE + SZ_4K - 1,
  3091. + .flags = IORESOURCE_MEM,
  3092. + },
  3093. +};
  3094. +
  3095. +static u64 gpio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3096. +
  3097. +static struct platform_device bcm2708_gpio_device = {
  3098. + .name = BCM_GPIO_DRIVER_NAME,
  3099. + .id = -1, /* only one VideoCore I/O area */
  3100. + .resource = bcm2708_gpio_resources,
  3101. + .num_resources = ARRAY_SIZE(bcm2708_gpio_resources),
  3102. + .dev = {
  3103. + .dma_mask = &gpio_dmamask,
  3104. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3105. + },
  3106. +};
  3107. +#endif
  3108. +
  3109. +static struct resource bcm2708_systemtimer_resources[] = {
  3110. + [0] = { /* system timer access */
  3111. + .start = ST_BASE,
  3112. + .end = ST_BASE + SZ_4K - 1,
  3113. + .flags = IORESOURCE_MEM,
  3114. + },
  3115. + {
  3116. + .start = IRQ_TIMER3,
  3117. + .end = IRQ_TIMER3,
  3118. + .flags = IORESOURCE_IRQ,
  3119. + }
  3120. +
  3121. +};
  3122. +
  3123. +static u64 systemtimer_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3124. +
  3125. +static struct platform_device bcm2708_systemtimer_device = {
  3126. + .name = "bcm2708_systemtimer",
  3127. + .id = -1, /* only one VideoCore I/O area */
  3128. + .resource = bcm2708_systemtimer_resources,
  3129. + .num_resources = ARRAY_SIZE(bcm2708_systemtimer_resources),
  3130. + .dev = {
  3131. + .dma_mask = &systemtimer_dmamask,
  3132. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3133. + },
  3134. +};
  3135. +
  3136. +#ifdef CONFIG_MMC_SDHCI_BCM2708 /* Arasan emmc SD */
  3137. +static struct resource bcm2708_emmc_resources[] = {
  3138. + [0] = {
  3139. + .start = EMMC_BASE,
  3140. + .end = EMMC_BASE + SZ_256 - 1, /* we only need this area */
  3141. + /* the memory map actually makes SZ_4K available */
  3142. + .flags = IORESOURCE_MEM,
  3143. + },
  3144. + [1] = {
  3145. + .start = IRQ_ARASANSDIO,
  3146. + .end = IRQ_ARASANSDIO,
  3147. + .flags = IORESOURCE_IRQ,
  3148. + },
  3149. +};
  3150. +
  3151. +static u64 bcm2708_emmc_dmamask = 0xffffffffUL;
  3152. +
  3153. +struct platform_device bcm2708_emmc_device = {
  3154. + .name = "bcm2708_sdhci",
  3155. + .id = 0,
  3156. + .num_resources = ARRAY_SIZE(bcm2708_emmc_resources),
  3157. + .resource = bcm2708_emmc_resources,
  3158. + .dev = {
  3159. + .dma_mask = &bcm2708_emmc_dmamask,
  3160. + .coherent_dma_mask = 0xffffffffUL},
  3161. +};
  3162. +#endif /* CONFIG_MMC_SDHCI_BCM2708 */
  3163. +
  3164. +static struct resource bcm2708_powerman_resources[] = {
  3165. + [0] = {
  3166. + .start = PM_BASE,
  3167. + .end = PM_BASE + SZ_256 - 1,
  3168. + .flags = IORESOURCE_MEM,
  3169. + },
  3170. +};
  3171. +
  3172. +static u64 powerman_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3173. +
  3174. +struct platform_device bcm2708_powerman_device = {
  3175. + .name = "bcm2708_powerman",
  3176. + .id = 0,
  3177. + .num_resources = ARRAY_SIZE(bcm2708_powerman_resources),
  3178. + .resource = bcm2708_powerman_resources,
  3179. + .dev = {
  3180. + .dma_mask = &powerman_dmamask,
  3181. + .coherent_dma_mask = 0xffffffffUL},
  3182. +};
  3183. +
  3184. +
  3185. +static struct platform_device bcm2708_alsa_devices[] = {
  3186. + [0] = {
  3187. + .name = "bcm2835_AUD0",
  3188. + .id = 0, /* first audio device */
  3189. + .resource = 0,
  3190. + .num_resources = 0,
  3191. + },
  3192. + [1] = {
  3193. + .name = "bcm2835_AUD1",
  3194. + .id = 1, /* second audio device */
  3195. + .resource = 0,
  3196. + .num_resources = 0,
  3197. + },
  3198. + [2] = {
  3199. + .name = "bcm2835_AUD2",
  3200. + .id = 2, /* third audio device */
  3201. + .resource = 0,
  3202. + .num_resources = 0,
  3203. + },
  3204. + [3] = {
  3205. + .name = "bcm2835_AUD3",
  3206. + .id = 3, /* forth audio device */
  3207. + .resource = 0,
  3208. + .num_resources = 0,
  3209. + },
  3210. + [4] = {
  3211. + .name = "bcm2835_AUD4",
  3212. + .id = 4, /* fifth audio device */
  3213. + .resource = 0,
  3214. + .num_resources = 0,
  3215. + },
  3216. + [5] = {
  3217. + .name = "bcm2835_AUD5",
  3218. + .id = 5, /* sixth audio device */
  3219. + .resource = 0,
  3220. + .num_resources = 0,
  3221. + },
  3222. + [6] = {
  3223. + .name = "bcm2835_AUD6",
  3224. + .id = 6, /* seventh audio device */
  3225. + .resource = 0,
  3226. + .num_resources = 0,
  3227. + },
  3228. + [7] = {
  3229. + .name = "bcm2835_AUD7",
  3230. + .id = 7, /* eighth audio device */
  3231. + .resource = 0,
  3232. + .num_resources = 0,
  3233. + },
  3234. +};
  3235. +
  3236. +static struct resource bcm2708_spi_resources[] = {
  3237. + {
  3238. + .start = SPI0_BASE,
  3239. + .end = SPI0_BASE + SZ_256 - 1,
  3240. + .flags = IORESOURCE_MEM,
  3241. + }, {
  3242. + .start = IRQ_SPI,
  3243. + .end = IRQ_SPI,
  3244. + .flags = IORESOURCE_IRQ,
  3245. + }
  3246. +};
  3247. +
  3248. +
  3249. +static u64 bcm2708_spi_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3250. +static struct platform_device bcm2708_spi_device = {
  3251. + .name = "bcm2708_spi",
  3252. + .id = 0,
  3253. + .num_resources = ARRAY_SIZE(bcm2708_spi_resources),
  3254. + .resource = bcm2708_spi_resources,
  3255. + .dev = {
  3256. + .dma_mask = &bcm2708_spi_dmamask,
  3257. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON)},
  3258. +};
  3259. +
  3260. +#ifdef CONFIG_BCM2708_SPIDEV
  3261. +static struct spi_board_info bcm2708_spi_devices[] = {
  3262. +#ifdef CONFIG_SPI_SPIDEV
  3263. + {
  3264. + .modalias = "spidev",
  3265. + .max_speed_hz = 500000,
  3266. + .bus_num = 0,
  3267. + .chip_select = 0,
  3268. + .mode = SPI_MODE_0,
  3269. + }, {
  3270. + .modalias = "spidev",
  3271. + .max_speed_hz = 500000,
  3272. + .bus_num = 0,
  3273. + .chip_select = 1,
  3274. + .mode = SPI_MODE_0,
  3275. + }
  3276. +#endif
  3277. +};
  3278. +#endif
  3279. +
  3280. +static struct resource bcm2708_bsc0_resources[] = {
  3281. + {
  3282. + .start = BSC0_BASE,
  3283. + .end = BSC0_BASE + SZ_256 - 1,
  3284. + .flags = IORESOURCE_MEM,
  3285. + }, {
  3286. + .start = INTERRUPT_I2C,
  3287. + .end = INTERRUPT_I2C,
  3288. + .flags = IORESOURCE_IRQ,
  3289. + }
  3290. +};
  3291. +
  3292. +static struct platform_device bcm2708_bsc0_device = {
  3293. + .name = "bcm2708_i2c",
  3294. + .id = 0,
  3295. + .num_resources = ARRAY_SIZE(bcm2708_bsc0_resources),
  3296. + .resource = bcm2708_bsc0_resources,
  3297. +};
  3298. +
  3299. +
  3300. +static struct resource bcm2708_bsc1_resources[] = {
  3301. + {
  3302. + .start = BSC1_BASE,
  3303. + .end = BSC1_BASE + SZ_256 - 1,
  3304. + .flags = IORESOURCE_MEM,
  3305. + }, {
  3306. + .start = INTERRUPT_I2C,
  3307. + .end = INTERRUPT_I2C,
  3308. + .flags = IORESOURCE_IRQ,
  3309. + }
  3310. +};
  3311. +
  3312. +static struct platform_device bcm2708_bsc1_device = {
  3313. + .name = "bcm2708_i2c",
  3314. + .id = 1,
  3315. + .num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
  3316. + .resource = bcm2708_bsc1_resources,
  3317. +};
  3318. +
  3319. +static struct platform_device bcm2835_hwmon_device = {
  3320. + .name = "bcm2835_hwmon",
  3321. +};
  3322. +
  3323. +static struct platform_device bcm2835_thermal_device = {
  3324. + .name = "bcm2835_thermal",
  3325. +};
  3326. +
  3327. +#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
  3328. +static struct resource bcm2708_i2s_resources[] = {
  3329. + {
  3330. + .start = I2S_BASE,
  3331. + .end = I2S_BASE + 0x20,
  3332. + .flags = IORESOURCE_MEM,
  3333. + },
  3334. + {
  3335. + .start = PCM_CLOCK_BASE,
  3336. + .end = PCM_CLOCK_BASE + 0x02,
  3337. + .flags = IORESOURCE_MEM,
  3338. + }
  3339. +};
  3340. +
  3341. +static struct platform_device bcm2708_i2s_device = {
  3342. + .name = "bcm2708-i2s",
  3343. + .id = 0,
  3344. + .num_resources = ARRAY_SIZE(bcm2708_i2s_resources),
  3345. + .resource = bcm2708_i2s_resources,
  3346. +};
  3347. +#endif
  3348. +
  3349. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  3350. +static struct platform_device snd_hifiberry_dac_device = {
  3351. + .name = "snd-hifiberry-dac",
  3352. + .id = 0,
  3353. + .num_resources = 0,
  3354. +};
  3355. +
  3356. +static struct platform_device snd_pcm5102a_codec_device = {
  3357. + .name = "pcm5102a-codec",
  3358. + .id = -1,
  3359. + .num_resources = 0,
  3360. +};
  3361. +#endif
  3362. +
  3363. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  3364. +static struct platform_device snd_rpi_dac_device = {
  3365. + .name = "snd-rpi-dac",
  3366. + .id = 0,
  3367. + .num_resources = 0,
  3368. +};
  3369. +
  3370. +static struct platform_device snd_pcm1794a_codec_device = {
  3371. + .name = "pcm1794a-codec",
  3372. + .id = -1,
  3373. + .num_resources = 0,
  3374. +};
  3375. +#endif
  3376. +
  3377. +int __init bcm_register_device(struct platform_device *pdev)
  3378. +{
  3379. + int ret;
  3380. +
  3381. + ret = platform_device_register(pdev);
  3382. + if (ret)
  3383. + pr_debug("Unable to register platform device '%s': %d\n",
  3384. + pdev->name, ret);
  3385. +
  3386. + return ret;
  3387. +}
  3388. +
  3389. +int calc_rsts(int partition)
  3390. +{
  3391. + return PM_PASSWORD |
  3392. + ((partition & (1 << 0)) << 0) |
  3393. + ((partition & (1 << 1)) << 1) |
  3394. + ((partition & (1 << 2)) << 2) |
  3395. + ((partition & (1 << 3)) << 3) |
  3396. + ((partition & (1 << 4)) << 4) |
  3397. + ((partition & (1 << 5)) << 5);
  3398. +}
  3399. +
  3400. +static void bcm2708_restart(enum reboot_mode mode, const char *cmd)
  3401. +{
  3402. + extern char bcm2708_reboot_mode;
  3403. + uint32_t pm_rstc, pm_wdog;
  3404. + uint32_t timeout = 10;
  3405. + uint32_t pm_rsts = 0;
  3406. +
  3407. + if(bcm2708_reboot_mode == 'q')
  3408. + {
  3409. + // NOOBS < 1.3 booting with reboot=q
  3410. + pm_rsts = readl(__io_address(PM_RSTS));
  3411. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRQ_SET;
  3412. + }
  3413. + else if(bcm2708_reboot_mode == 'p')
  3414. + {
  3415. + // NOOBS < 1.3 halting
  3416. + pm_rsts = readl(__io_address(PM_RSTS));
  3417. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRH_SET;
  3418. + }
  3419. + else
  3420. + {
  3421. + pm_rsts = calc_rsts(reboot_part);
  3422. + }
  3423. +
  3424. + writel(pm_rsts, __io_address(PM_RSTS));
  3425. +
  3426. + /* Setup watchdog for reset */
  3427. + pm_rstc = readl(__io_address(PM_RSTC));
  3428. +
  3429. + pm_wdog = PM_PASSWORD | (timeout & PM_WDOG_TIME_SET); // watchdog timer = timer clock / 16; need password (31:16) + value (11:0)
  3430. + pm_rstc = PM_PASSWORD | (pm_rstc & PM_RSTC_WRCFG_CLR) | PM_RSTC_WRCFG_FULL_RESET;
  3431. +
  3432. + writel(pm_wdog, __io_address(PM_WDOG));
  3433. + writel(pm_rstc, __io_address(PM_RSTC));
  3434. +}
  3435. +
  3436. +/* 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 */
  3437. +static void bcm2708_power_off(void)
  3438. +{
  3439. + extern char bcm2708_reboot_mode;
  3440. + if(bcm2708_reboot_mode == 'q')
  3441. + {
  3442. + // NOOBS < v1.3
  3443. + bcm2708_restart('p', "");
  3444. + }
  3445. + else
  3446. + {
  3447. + /* partition 63 is special code for HALT the bootloader knows not to boot*/
  3448. + reboot_part = 63;
  3449. + /* continue with normal reset mechanism */
  3450. + bcm2708_restart(0, "");
  3451. + }
  3452. +}
  3453. +
  3454. +void __init bcm2708_init(void)
  3455. +{
  3456. + int i;
  3457. +
  3458. +#if defined(CONFIG_BCM_VC_CMA)
  3459. + vc_cma_early_init();
  3460. +#endif
  3461. + printk("bcm2708.uart_clock = %d\n", uart_clock);
  3462. + pm_power_off = bcm2708_power_off;
  3463. +
  3464. + if (uart_clock)
  3465. + lookups[0].clk->rate = uart_clock;
  3466. +
  3467. + for (i = 0; i < ARRAY_SIZE(lookups); i++)
  3468. + clkdev_add(&lookups[i]);
  3469. +
  3470. + bcm_register_device(&bcm2708_dmaman_device);
  3471. + bcm_register_device(&bcm2708_vcio_device);
  3472. +#ifdef CONFIG_BCM2708_GPIO
  3473. + bcm_register_device(&bcm2708_gpio_device);
  3474. +#endif
  3475. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  3476. + platform_device_register(&w1_device);
  3477. +#endif
  3478. + bcm_register_device(&bcm2708_systemtimer_device);
  3479. + bcm_register_device(&bcm2708_fb_device);
  3480. + if (!fiq_fix_enable)
  3481. + {
  3482. + bcm2708_usb_device.resource = bcm2708_usb_resources_no_fiq_fix;
  3483. + bcm2708_usb_device.num_resources = ARRAY_SIZE(bcm2708_usb_resources_no_fiq_fix);
  3484. + }
  3485. + bcm_register_device(&bcm2708_usb_device);
  3486. + bcm_register_device(&bcm2708_uart1_device);
  3487. + bcm_register_device(&bcm2708_powerman_device);
  3488. +
  3489. +#ifdef CONFIG_MMC_SDHCI_BCM2708
  3490. + bcm_register_device(&bcm2708_emmc_device);
  3491. +#endif
  3492. + bcm2708_init_led();
  3493. + for (i = 0; i < ARRAY_SIZE(bcm2708_alsa_devices); i++)
  3494. + bcm_register_device(&bcm2708_alsa_devices[i]);
  3495. +
  3496. + bcm_register_device(&bcm2708_spi_device);
  3497. + bcm_register_device(&bcm2708_bsc0_device);
  3498. + bcm_register_device(&bcm2708_bsc1_device);
  3499. +
  3500. + bcm_register_device(&bcm2835_hwmon_device);
  3501. + bcm_register_device(&bcm2835_thermal_device);
  3502. +
  3503. +#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
  3504. + bcm_register_device(&bcm2708_i2s_device);
  3505. +#endif
  3506. +
  3507. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  3508. + bcm_register_device(&snd_hifiberry_dac_device);
  3509. + bcm_register_device(&snd_pcm5102a_codec_device);
  3510. +#endif
  3511. +
  3512. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  3513. + bcm_register_device(&snd_rpi_dac_device);
  3514. + bcm_register_device(&snd_pcm1794a_codec_device);
  3515. +#endif
  3516. +
  3517. + for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  3518. + struct amba_device *d = amba_devs[i];
  3519. + amba_device_register(d, &iomem_resource);
  3520. + }
  3521. + system_rev = boardrev;
  3522. + system_serial_low = serial;
  3523. +
  3524. +#ifdef CONFIG_BCM2708_SPIDEV
  3525. + spi_register_board_info(bcm2708_spi_devices,
  3526. + ARRAY_SIZE(bcm2708_spi_devices));
  3527. +#endif
  3528. +}
  3529. +
  3530. +static void timer_set_mode(enum clock_event_mode mode,
  3531. + struct clock_event_device *clk)
  3532. +{
  3533. + switch (mode) {
  3534. + case CLOCK_EVT_MODE_ONESHOT: /* Leave the timer disabled, .set_next_event will enable it */
  3535. + case CLOCK_EVT_MODE_SHUTDOWN:
  3536. + break;
  3537. + case CLOCK_EVT_MODE_PERIODIC:
  3538. +
  3539. + case CLOCK_EVT_MODE_UNUSED:
  3540. + case CLOCK_EVT_MODE_RESUME:
  3541. +
  3542. + default:
  3543. + printk(KERN_ERR "timer_set_mode: unhandled mode:%d\n",
  3544. + (int)mode);
  3545. + break;
  3546. + }
  3547. +
  3548. +}
  3549. +
  3550. +static int timer_set_next_event(unsigned long cycles,
  3551. + struct clock_event_device *unused)
  3552. +{
  3553. + unsigned long stc;
  3554. +
  3555. + stc = readl(__io_address(ST_BASE + 0x04));
  3556. + writel(stc + cycles, __io_address(ST_BASE + 0x18)); /* stc3 */
  3557. + return 0;
  3558. +}
  3559. +
  3560. +static struct clock_event_device timer0_clockevent = {
  3561. + .name = "timer0",
  3562. + .shift = 32,
  3563. + .features = CLOCK_EVT_FEAT_ONESHOT,
  3564. + .set_mode = timer_set_mode,
  3565. + .set_next_event = timer_set_next_event,
  3566. +};
  3567. +
  3568. +/*
  3569. + * IRQ handler for the timer
  3570. + */
  3571. +static irqreturn_t bcm2708_timer_interrupt(int irq, void *dev_id)
  3572. +{
  3573. + struct clock_event_device *evt = &timer0_clockevent;
  3574. +
  3575. + writel(1 << 3, __io_address(ST_BASE + 0x00)); /* stcs clear timer int */
  3576. +
  3577. + evt->event_handler(evt);
  3578. +
  3579. + return IRQ_HANDLED;
  3580. +}
  3581. +
  3582. +static struct irqaction bcm2708_timer_irq = {
  3583. + .name = "BCM2708 Timer Tick",
  3584. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  3585. + .handler = bcm2708_timer_interrupt,
  3586. +};
  3587. +
  3588. +/*
  3589. + * Set up timer interrupt, and return the current time in seconds.
  3590. + */
  3591. +
  3592. +static struct delay_timer bcm2708_delay_timer = {
  3593. + .read_current_timer = bcm2708_read_current_timer,
  3594. + .freq = STC_FREQ_HZ,
  3595. +};
  3596. +
  3597. +static void __init bcm2708_timer_init(void)
  3598. +{
  3599. + /* init high res timer */
  3600. + bcm2708_clocksource_init();
  3601. +
  3602. + /*
  3603. + * Initialise to a known state (all timers off)
  3604. + */
  3605. + writel(0, __io_address(ARM_T_CONTROL));
  3606. + /*
  3607. + * Make irqs happen for the system timer
  3608. + */
  3609. + setup_irq(IRQ_TIMER3, &bcm2708_timer_irq);
  3610. +
  3611. + setup_sched_clock(bcm2708_read_sched_clock, 32, STC_FREQ_HZ);
  3612. +
  3613. + timer0_clockevent.mult =
  3614. + div_sc(STC_FREQ_HZ, NSEC_PER_SEC, timer0_clockevent.shift);
  3615. + timer0_clockevent.max_delta_ns =
  3616. + clockevent_delta2ns(0xffffffff, &timer0_clockevent);
  3617. + timer0_clockevent.min_delta_ns =
  3618. + clockevent_delta2ns(0xf, &timer0_clockevent);
  3619. +
  3620. + timer0_clockevent.cpumask = cpumask_of(0);
  3621. + clockevents_register_device(&timer0_clockevent);
  3622. +
  3623. + register_current_timer_delay(&bcm2708_delay_timer);
  3624. +}
  3625. +
  3626. +#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  3627. +#include <linux/leds.h>
  3628. +
  3629. +static struct gpio_led bcm2708_leds[] = {
  3630. + [0] = {
  3631. + .gpio = 16,
  3632. + .name = "led0",
  3633. + .default_trigger = "mmc0",
  3634. + .active_low = 1,
  3635. + },
  3636. +};
  3637. +
  3638. +static struct gpio_led_platform_data bcm2708_led_pdata = {
  3639. + .num_leds = ARRAY_SIZE(bcm2708_leds),
  3640. + .leds = bcm2708_leds,
  3641. +};
  3642. +
  3643. +static struct platform_device bcm2708_led_device = {
  3644. + .name = "leds-gpio",
  3645. + .id = -1,
  3646. + .dev = {
  3647. + .platform_data = &bcm2708_led_pdata,
  3648. + },
  3649. +};
  3650. +
  3651. +static void __init bcm2708_init_led(void)
  3652. +{
  3653. + platform_device_register(&bcm2708_led_device);
  3654. +}
  3655. +#else
  3656. +static inline void bcm2708_init_led(void)
  3657. +{
  3658. +}
  3659. +#endif
  3660. +
  3661. +void __init bcm2708_init_early(void)
  3662. +{
  3663. + /*
  3664. + * Some devices allocate their coherent buffers from atomic
  3665. + * context. Increase size of atomic coherent pool to make sure such
  3666. + * the allocations won't fail.
  3667. + */
  3668. + init_dma_coherent_pool_size(SZ_4M);
  3669. +}
  3670. +
  3671. +static void __init board_reserve(void)
  3672. +{
  3673. +#if defined(CONFIG_BCM_VC_CMA)
  3674. + vc_cma_reserve();
  3675. +#endif
  3676. +}
  3677. +
  3678. +MACHINE_START(BCM2708, "BCM2708")
  3679. + /* Maintainer: Broadcom Europe Ltd. */
  3680. + .map_io = bcm2708_map_io,
  3681. + .init_irq = bcm2708_init_irq,
  3682. + .init_time = bcm2708_timer_init,
  3683. + .init_machine = bcm2708_init,
  3684. + .init_early = bcm2708_init_early,
  3685. + .reserve = board_reserve,
  3686. + .restart = bcm2708_restart,
  3687. +MACHINE_END
  3688. +
  3689. +module_param(boardrev, uint, 0644);
  3690. +module_param(serial, uint, 0644);
  3691. +module_param(uart_clock, uint, 0644);
  3692. +module_param(reboot_part, uint, 0644);
  3693. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/bcm2708_gpio.c linux-3.12.11/arch/arm/mach-bcm2708/bcm2708_gpio.c
  3694. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/bcm2708_gpio.c 1970-01-01 01:00:00.000000000 +0100
  3695. +++ linux-3.12.11/arch/arm/mach-bcm2708/bcm2708_gpio.c 2014-02-18 11:52:14.000000000 +0100
  3696. @@ -0,0 +1,339 @@
  3697. +/*
  3698. + * linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
  3699. + *
  3700. + * Copyright (C) 2010 Broadcom
  3701. + *
  3702. + * This program is free software; you can redistribute it and/or modify
  3703. + * it under the terms of the GNU General Public License version 2 as
  3704. + * published by the Free Software Foundation.
  3705. + *
  3706. + */
  3707. +
  3708. +#include <linux/spinlock.h>
  3709. +#include <linux/module.h>
  3710. +#include <linux/list.h>
  3711. +#include <linux/io.h>
  3712. +#include <linux/irq.h>
  3713. +#include <linux/interrupt.h>
  3714. +#include <linux/slab.h>
  3715. +#include <mach/gpio.h>
  3716. +#include <linux/gpio.h>
  3717. +#include <linux/platform_device.h>
  3718. +#include <mach/platform.h>
  3719. +
  3720. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  3721. +#define DRIVER_NAME BCM_GPIO_DRIVER_NAME
  3722. +#define BCM_GPIO_USE_IRQ 1
  3723. +
  3724. +#define GPIOFSEL(x) (0x00+(x)*4)
  3725. +#define GPIOSET(x) (0x1c+(x)*4)
  3726. +#define GPIOCLR(x) (0x28+(x)*4)
  3727. +#define GPIOLEV(x) (0x34+(x)*4)
  3728. +#define GPIOEDS(x) (0x40+(x)*4)
  3729. +#define GPIOREN(x) (0x4c+(x)*4)
  3730. +#define GPIOFEN(x) (0x58+(x)*4)
  3731. +#define GPIOHEN(x) (0x64+(x)*4)
  3732. +#define GPIOLEN(x) (0x70+(x)*4)
  3733. +#define GPIOAREN(x) (0x7c+(x)*4)
  3734. +#define GPIOAFEN(x) (0x88+(x)*4)
  3735. +#define GPIOUD(x) (0x94+(x)*4)
  3736. +#define GPIOUDCLK(x) (0x98+(x)*4)
  3737. +
  3738. +enum { GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
  3739. + GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
  3740. + GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
  3741. + GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
  3742. +};
  3743. +
  3744. + /* Each of the two spinlocks protects a different set of hardware
  3745. + * regiters and data structurs. This decouples the code of the IRQ from
  3746. + * the GPIO code. This also makes the case of a GPIO routine call from
  3747. + * the IRQ code simpler.
  3748. + */
  3749. +static DEFINE_SPINLOCK(lock); /* GPIO registers */
  3750. +
  3751. +struct bcm2708_gpio {
  3752. + struct list_head list;
  3753. + void __iomem *base;
  3754. + struct gpio_chip gc;
  3755. + unsigned long rising;
  3756. + unsigned long falling;
  3757. +};
  3758. +
  3759. +static int bcm2708_set_function(struct gpio_chip *gc, unsigned offset,
  3760. + int function)
  3761. +{
  3762. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3763. + unsigned long flags;
  3764. + unsigned gpiodir;
  3765. + unsigned gpio_bank = offset / 10;
  3766. + unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
  3767. +
  3768. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set_function %p (%d,%d)\n", gc, offset, function);
  3769. + if (offset >= ARCH_NR_GPIOS)
  3770. + return -EINVAL;
  3771. +
  3772. + spin_lock_irqsave(&lock, flags);
  3773. +
  3774. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  3775. + gpiodir &= ~(7 << gpio_field_offset);
  3776. + gpiodir |= function << gpio_field_offset;
  3777. + writel(gpiodir, gpio->base + GPIOFSEL(gpio_bank));
  3778. + spin_unlock_irqrestore(&lock, flags);
  3779. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  3780. +
  3781. + return 0;
  3782. +}
  3783. +
  3784. +static int bcm2708_gpio_dir_in(struct gpio_chip *gc, unsigned offset)
  3785. +{
  3786. + return bcm2708_set_function(gc, offset, GPIO_FSEL_INPUT);
  3787. +}
  3788. +
  3789. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
  3790. +static int bcm2708_gpio_dir_out(struct gpio_chip *gc, unsigned offset,
  3791. + int value)
  3792. +{
  3793. + int ret;
  3794. + ret = bcm2708_set_function(gc, offset, GPIO_FSEL_OUTPUT);
  3795. + if (ret >= 0)
  3796. + bcm2708_gpio_set(gc, offset, value);
  3797. + return ret;
  3798. +}
  3799. +
  3800. +static int bcm2708_gpio_get(struct gpio_chip *gc, unsigned offset)
  3801. +{
  3802. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3803. + unsigned gpio_bank = offset / 32;
  3804. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  3805. + unsigned lev;
  3806. +
  3807. + if (offset >= ARCH_NR_GPIOS)
  3808. + return 0;
  3809. + lev = readl(gpio->base + GPIOLEV(gpio_bank));
  3810. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_get %p (%d)=%d\n", gc, offset, 0x1 & (lev>>gpio_field_offset));
  3811. + return 0x1 & (lev >> gpio_field_offset);
  3812. +}
  3813. +
  3814. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
  3815. +{
  3816. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3817. + unsigned gpio_bank = offset / 32;
  3818. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  3819. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set %p (%d=%d)\n", gc, offset, value);
  3820. + if (offset >= ARCH_NR_GPIOS)
  3821. + return;
  3822. + if (value)
  3823. + writel(1 << gpio_field_offset, gpio->base + GPIOSET(gpio_bank));
  3824. + else
  3825. + writel(1 << gpio_field_offset, gpio->base + GPIOCLR(gpio_bank));
  3826. +}
  3827. +
  3828. +/*************************************************************************************************************************
  3829. + * bcm2708 GPIO IRQ
  3830. + */
  3831. +
  3832. +#if BCM_GPIO_USE_IRQ
  3833. +
  3834. +static int bcm2708_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
  3835. +{
  3836. + return gpio_to_irq(gpio);
  3837. +}
  3838. +
  3839. +static int bcm2708_gpio_irq_set_type(struct irq_data *d, unsigned type)
  3840. +{
  3841. + unsigned irq = d->irq;
  3842. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3843. +
  3844. + if (type & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
  3845. + return -EINVAL;
  3846. +
  3847. + if (type & IRQ_TYPE_EDGE_RISING) {
  3848. + gpio->rising |= (1 << irq_to_gpio(irq));
  3849. + } else {
  3850. + gpio->rising &= ~(1 << irq_to_gpio(irq));
  3851. + }
  3852. +
  3853. + if (type & IRQ_TYPE_EDGE_FALLING) {
  3854. + gpio->falling |= (1 << irq_to_gpio(irq));
  3855. + } else {
  3856. + gpio->falling &= ~(1 << irq_to_gpio(irq));
  3857. + }
  3858. + return 0;
  3859. +}
  3860. +
  3861. +static void bcm2708_gpio_irq_mask(struct irq_data *d)
  3862. +{
  3863. + unsigned irq = d->irq;
  3864. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3865. + unsigned gn = irq_to_gpio(irq);
  3866. + unsigned gb = gn / 32;
  3867. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  3868. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  3869. +
  3870. + gn = gn % 32;
  3871. +
  3872. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  3873. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  3874. +}
  3875. +
  3876. +static void bcm2708_gpio_irq_unmask(struct irq_data *d)
  3877. +{
  3878. + unsigned irq = d->irq;
  3879. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3880. + unsigned gn = irq_to_gpio(irq);
  3881. + unsigned gb = gn / 32;
  3882. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  3883. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  3884. +
  3885. + gn = gn % 32;
  3886. +
  3887. + writel(1 << gn, gpio->base + GPIOEDS(gb));
  3888. +
  3889. + if (gpio->rising & (1 << gn)) {
  3890. + writel(rising | (1 << gn), gpio->base + GPIOREN(gb));
  3891. + } else {
  3892. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  3893. + }
  3894. +
  3895. + if (gpio->falling & (1 << gn)) {
  3896. + writel(falling | (1 << gn), gpio->base + GPIOFEN(gb));
  3897. + } else {
  3898. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  3899. + }
  3900. +}
  3901. +
  3902. +static struct irq_chip bcm2708_irqchip = {
  3903. + .name = "GPIO",
  3904. + .irq_enable = bcm2708_gpio_irq_unmask,
  3905. + .irq_disable = bcm2708_gpio_irq_mask,
  3906. + .irq_unmask = bcm2708_gpio_irq_unmask,
  3907. + .irq_mask = bcm2708_gpio_irq_mask,
  3908. + .irq_set_type = bcm2708_gpio_irq_set_type,
  3909. +};
  3910. +
  3911. +static irqreturn_t bcm2708_gpio_interrupt(int irq, void *dev_id)
  3912. +{
  3913. + unsigned long edsr;
  3914. + unsigned bank;
  3915. + int i;
  3916. + unsigned gpio;
  3917. + for (bank = 0; bank <= 1; bank++) {
  3918. + edsr = readl(__io_address(GPIO_BASE) + GPIOEDS(bank));
  3919. + for_each_set_bit(i, &edsr, 32) {
  3920. + gpio = i + bank * 32;
  3921. + generic_handle_irq(gpio_to_irq(gpio));
  3922. + }
  3923. + writel(0xffffffff, __io_address(GPIO_BASE) + GPIOEDS(bank));
  3924. + }
  3925. + return IRQ_HANDLED;
  3926. +}
  3927. +
  3928. +static struct irqaction bcm2708_gpio_irq = {
  3929. + .name = "BCM2708 GPIO catchall handler",
  3930. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  3931. + .handler = bcm2708_gpio_interrupt,
  3932. +};
  3933. +
  3934. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  3935. +{
  3936. + unsigned irq;
  3937. +
  3938. + ucb->gc.to_irq = bcm2708_gpio_to_irq;
  3939. +
  3940. + for (irq = GPIO_IRQ_START; irq < (GPIO_IRQ_START + GPIO_IRQS); irq++) {
  3941. + irq_set_chip_data(irq, ucb);
  3942. + irq_set_chip(irq, &bcm2708_irqchip);
  3943. + set_irq_flags(irq, IRQF_VALID);
  3944. + }
  3945. + setup_irq(IRQ_GPIO3, &bcm2708_gpio_irq);
  3946. +}
  3947. +
  3948. +#else
  3949. +
  3950. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  3951. +{
  3952. +}
  3953. +
  3954. +#endif /* #if BCM_GPIO_USE_IRQ ***************************************************************************************************************** */
  3955. +
  3956. +static int bcm2708_gpio_probe(struct platform_device *dev)
  3957. +{
  3958. + struct bcm2708_gpio *ucb;
  3959. + struct resource *res;
  3960. + int err = 0;
  3961. +
  3962. + printk(KERN_INFO DRIVER_NAME ": bcm2708_gpio_probe %p\n", dev);
  3963. +
  3964. + ucb = kzalloc(sizeof(*ucb), GFP_KERNEL);
  3965. + if (NULL == ucb) {
  3966. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  3967. + "mailbox memory\n");
  3968. + err = -ENOMEM;
  3969. + goto err;
  3970. + }
  3971. +
  3972. + res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  3973. +
  3974. + platform_set_drvdata(dev, ucb);
  3975. + ucb->base = __io_address(GPIO_BASE);
  3976. +
  3977. + ucb->gc.label = "bcm2708_gpio";
  3978. + ucb->gc.base = 0;
  3979. + ucb->gc.ngpio = ARCH_NR_GPIOS;
  3980. + ucb->gc.owner = THIS_MODULE;
  3981. +
  3982. + ucb->gc.direction_input = bcm2708_gpio_dir_in;
  3983. + ucb->gc.direction_output = bcm2708_gpio_dir_out;
  3984. + ucb->gc.get = bcm2708_gpio_get;
  3985. + ucb->gc.set = bcm2708_gpio_set;
  3986. + ucb->gc.can_sleep = 0;
  3987. +
  3988. + bcm2708_gpio_irq_init(ucb);
  3989. +
  3990. + err = gpiochip_add(&ucb->gc);
  3991. + if (err)
  3992. + goto err;
  3993. +
  3994. +err:
  3995. + return err;
  3996. +
  3997. +}
  3998. +
  3999. +static int bcm2708_gpio_remove(struct platform_device *dev)
  4000. +{
  4001. + int err = 0;
  4002. + struct bcm2708_gpio *ucb = platform_get_drvdata(dev);
  4003. +
  4004. + printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_remove %p\n", dev);
  4005. +
  4006. + err = gpiochip_remove(&ucb->gc);
  4007. +
  4008. + platform_set_drvdata(dev, NULL);
  4009. + kfree(ucb);
  4010. +
  4011. + return err;
  4012. +}
  4013. +
  4014. +static struct platform_driver bcm2708_gpio_driver = {
  4015. + .probe = bcm2708_gpio_probe,
  4016. + .remove = bcm2708_gpio_remove,
  4017. + .driver = {
  4018. + .name = "bcm2708_gpio"},
  4019. +};
  4020. +
  4021. +static int __init bcm2708_gpio_init(void)
  4022. +{
  4023. + return platform_driver_register(&bcm2708_gpio_driver);
  4024. +}
  4025. +
  4026. +static void __exit bcm2708_gpio_exit(void)
  4027. +{
  4028. + platform_driver_unregister(&bcm2708_gpio_driver);
  4029. +}
  4030. +
  4031. +module_init(bcm2708_gpio_init);
  4032. +module_exit(bcm2708_gpio_exit);
  4033. +
  4034. +MODULE_DESCRIPTION("Broadcom BCM2708 GPIO driver");
  4035. +MODULE_LICENSE("GPL");
  4036. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/bcm2708.h linux-3.12.11/arch/arm/mach-bcm2708/bcm2708.h
  4037. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/bcm2708.h 1970-01-01 01:00:00.000000000 +0100
  4038. +++ linux-3.12.11/arch/arm/mach-bcm2708/bcm2708.h 2014-02-18 11:52:14.000000000 +0100
  4039. @@ -0,0 +1,51 @@
  4040. +/*
  4041. + * linux/arch/arm/mach-bcm2708/bcm2708.h
  4042. + *
  4043. + * BCM2708 machine support header
  4044. + *
  4045. + * Copyright (C) 2010 Broadcom
  4046. + *
  4047. + * This program is free software; you can redistribute it and/or modify
  4048. + * it under the terms of the GNU General Public License as published by
  4049. + * the Free Software Foundation; either version 2 of the License, or
  4050. + * (at your option) any later version.
  4051. + *
  4052. + * This program is distributed in the hope that it will be useful,
  4053. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4054. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4055. + * GNU General Public License for more details.
  4056. + *
  4057. + * You should have received a copy of the GNU General Public License
  4058. + * along with this program; if not, write to the Free Software
  4059. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4060. + */
  4061. +
  4062. +#ifndef __BCM2708_BCM2708_H
  4063. +#define __BCM2708_BCM2708_H
  4064. +
  4065. +#include <linux/amba/bus.h>
  4066. +
  4067. +extern void __init bcm2708_init(void);
  4068. +extern void __init bcm2708_init_irq(void);
  4069. +extern void __init bcm2708_map_io(void);
  4070. +extern struct sys_timer bcm2708_timer;
  4071. +extern unsigned int mmc_status(struct device *dev);
  4072. +
  4073. +#define AMBA_DEVICE(name, busid, base, plat) \
  4074. +static struct amba_device name##_device = { \
  4075. + .dev = { \
  4076. + .coherent_dma_mask = ~0, \
  4077. + .init_name = busid, \
  4078. + .platform_data = plat, \
  4079. + }, \
  4080. + .res = { \
  4081. + .start = base##_BASE, \
  4082. + .end = (base##_BASE) + SZ_4K - 1,\
  4083. + .flags = IORESOURCE_MEM, \
  4084. + }, \
  4085. + .dma_mask = ~0, \
  4086. + .irq = base##_IRQ, \
  4087. + /* .dma = base##_DMA,*/ \
  4088. +}
  4089. +
  4090. +#endif
  4091. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/clock.c linux-3.12.11/arch/arm/mach-bcm2708/clock.c
  4092. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/clock.c 1970-01-01 01:00:00.000000000 +0100
  4093. +++ linux-3.12.11/arch/arm/mach-bcm2708/clock.c 2014-02-18 11:52:14.000000000 +0100
  4094. @@ -0,0 +1,61 @@
  4095. +/*
  4096. + * linux/arch/arm/mach-bcm2708/clock.c
  4097. + *
  4098. + * Copyright (C) 2010 Broadcom
  4099. + *
  4100. + * This program is free software; you can redistribute it and/or modify
  4101. + * it under the terms of the GNU General Public License as published by
  4102. + * the Free Software Foundation; either version 2 of the License, or
  4103. + * (at your option) any later version.
  4104. + *
  4105. + * This program is distributed in the hope that it will be useful,
  4106. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4107. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4108. + * GNU General Public License for more details.
  4109. + *
  4110. + * You should have received a copy of the GNU General Public License
  4111. + * along with this program; if not, write to the Free Software
  4112. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4113. + */
  4114. +#include <linux/module.h>
  4115. +#include <linux/kernel.h>
  4116. +#include <linux/device.h>
  4117. +#include <linux/list.h>
  4118. +#include <linux/errno.h>
  4119. +#include <linux/err.h>
  4120. +#include <linux/string.h>
  4121. +#include <linux/clk.h>
  4122. +#include <linux/mutex.h>
  4123. +
  4124. +#include <asm/clkdev.h>
  4125. +
  4126. +#include "clock.h"
  4127. +
  4128. +int clk_enable(struct clk *clk)
  4129. +{
  4130. + return 0;
  4131. +}
  4132. +EXPORT_SYMBOL(clk_enable);
  4133. +
  4134. +void clk_disable(struct clk *clk)
  4135. +{
  4136. +}
  4137. +EXPORT_SYMBOL(clk_disable);
  4138. +
  4139. +unsigned long clk_get_rate(struct clk *clk)
  4140. +{
  4141. + return clk->rate;
  4142. +}
  4143. +EXPORT_SYMBOL(clk_get_rate);
  4144. +
  4145. +long clk_round_rate(struct clk *clk, unsigned long rate)
  4146. +{
  4147. + return clk->rate;
  4148. +}
  4149. +EXPORT_SYMBOL(clk_round_rate);
  4150. +
  4151. +int clk_set_rate(struct clk *clk, unsigned long rate)
  4152. +{
  4153. + return -EIO;
  4154. +}
  4155. +EXPORT_SYMBOL(clk_set_rate);
  4156. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/clock.h linux-3.12.11/arch/arm/mach-bcm2708/clock.h
  4157. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/clock.h 1970-01-01 01:00:00.000000000 +0100
  4158. +++ linux-3.12.11/arch/arm/mach-bcm2708/clock.h 2014-02-18 11:52:14.000000000 +0100
  4159. @@ -0,0 +1,24 @@
  4160. +/*
  4161. + * linux/arch/arm/mach-bcm2708/clock.h
  4162. + *
  4163. + * Copyright (C) 2010 Broadcom
  4164. + *
  4165. + * This program is free software; you can redistribute it and/or modify
  4166. + * it under the terms of the GNU General Public License as published by
  4167. + * the Free Software Foundation; either version 2 of the License, or
  4168. + * (at your option) any later version.
  4169. + *
  4170. + * This program is distributed in the hope that it will be useful,
  4171. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4172. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4173. + * GNU General Public License for more details.
  4174. + *
  4175. + * You should have received a copy of the GNU General Public License
  4176. + * along with this program; if not, write to the Free Software
  4177. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4178. + */
  4179. +struct module;
  4180. +
  4181. +struct clk {
  4182. + unsigned long rate;
  4183. +};
  4184. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/dma.c linux-3.12.11/arch/arm/mach-bcm2708/dma.c
  4185. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/dma.c 1970-01-01 01:00:00.000000000 +0100
  4186. +++ linux-3.12.11/arch/arm/mach-bcm2708/dma.c 2014-02-18 11:52:14.000000000 +0100
  4187. @@ -0,0 +1,399 @@
  4188. +/*
  4189. + * linux/arch/arm/mach-bcm2708/dma.c
  4190. + *
  4191. + * Copyright (C) 2010 Broadcom
  4192. + *
  4193. + * This program is free software; you can redistribute it and/or modify
  4194. + * it under the terms of the GNU General Public License version 2 as
  4195. + * published by the Free Software Foundation.
  4196. + */
  4197. +
  4198. +#include <linux/slab.h>
  4199. +#include <linux/device.h>
  4200. +#include <linux/platform_device.h>
  4201. +#include <linux/module.h>
  4202. +#include <linux/scatterlist.h>
  4203. +
  4204. +#include <mach/dma.h>
  4205. +#include <mach/irqs.h>
  4206. +
  4207. +/*****************************************************************************\
  4208. + * *
  4209. + * Configuration *
  4210. + * *
  4211. +\*****************************************************************************/
  4212. +
  4213. +#define CACHE_LINE_MASK 31
  4214. +#define DRIVER_NAME BCM_DMAMAN_DRIVER_NAME
  4215. +#define DEFAULT_DMACHAN_BITMAP 0x10 /* channel 4 only */
  4216. +
  4217. +/* valid only for channels 0 - 14, 15 has its own base address */
  4218. +#define BCM2708_DMA_CHAN(n) ((n)<<8) /* base address */
  4219. +#define BCM2708_DMA_CHANIO(dma_base, n) \
  4220. + ((void __iomem *)((char *)(dma_base)+BCM2708_DMA_CHAN(n)))
  4221. +
  4222. +
  4223. +/*****************************************************************************\
  4224. + * *
  4225. + * DMA Auxilliary Functions *
  4226. + * *
  4227. +\*****************************************************************************/
  4228. +
  4229. +/* A DMA buffer on an arbitrary boundary may separate a cache line into a
  4230. + section inside the DMA buffer and another section outside it.
  4231. + Even if we flush DMA buffers from the cache there is always the chance that
  4232. + during a DMA someone will access the part of a cache line that is outside
  4233. + the DMA buffer - which will then bring in unwelcome data.
  4234. + Without being able to dictate our own buffer pools we must insist that
  4235. + DMA buffers consist of a whole number of cache lines.
  4236. +*/
  4237. +
  4238. +extern int
  4239. +bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len)
  4240. +{
  4241. + int i;
  4242. +
  4243. + for (i = 0; i < sg_len; i++) {
  4244. + if (sg_ptr[i].offset & CACHE_LINE_MASK ||
  4245. + sg_ptr[i].length & CACHE_LINE_MASK)
  4246. + return 0;
  4247. + }
  4248. +
  4249. + return 1;
  4250. +}
  4251. +EXPORT_SYMBOL_GPL(bcm_sg_suitable_for_dma);
  4252. +
  4253. +extern void
  4254. +bcm_dma_start(void __iomem *dma_chan_base, dma_addr_t control_block)
  4255. +{
  4256. + dsb(); /* ARM data synchronization (push) operation */
  4257. +
  4258. + writel(control_block, dma_chan_base + BCM2708_DMA_ADDR);
  4259. + writel(BCM2708_DMA_ACTIVE, dma_chan_base + BCM2708_DMA_CS);
  4260. +}
  4261. +
  4262. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base)
  4263. +{
  4264. + dsb();
  4265. +
  4266. + /* ugly busy wait only option for now */
  4267. + while (readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE)
  4268. + cpu_relax();
  4269. +}
  4270. +
  4271. +EXPORT_SYMBOL_GPL(bcm_dma_start);
  4272. +
  4273. +/* Complete an ongoing DMA (assuming its results are to be ignored)
  4274. + Does nothing if there is no DMA in progress.
  4275. + This routine waits for the current AXI transfer to complete before
  4276. + terminating the current DMA. If the current transfer is hung on a DREQ used
  4277. + by an uncooperative peripheral the AXI transfer may never complete. In this
  4278. + case the routine times out and return a non-zero error code.
  4279. + Use of this routine doesn't guarantee that the ongoing or aborted DMA
  4280. + does not produce an interrupt.
  4281. +*/
  4282. +extern int
  4283. +bcm_dma_abort(void __iomem *dma_chan_base)
  4284. +{
  4285. + unsigned long int cs;
  4286. + int rc = 0;
  4287. +
  4288. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  4289. +
  4290. + if (BCM2708_DMA_ACTIVE & cs) {
  4291. + long int timeout = 10000;
  4292. +
  4293. + /* write 0 to the active bit - pause the DMA */
  4294. + writel(0, dma_chan_base + BCM2708_DMA_CS);
  4295. +
  4296. + /* wait for any current AXI transfer to complete */
  4297. + while (0 != (cs & BCM2708_DMA_ISPAUSED) && --timeout >= 0)
  4298. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  4299. +
  4300. + if (0 != (cs & BCM2708_DMA_ISPAUSED)) {
  4301. + /* we'll un-pause when we set of our next DMA */
  4302. + rc = -ETIMEDOUT;
  4303. +
  4304. + } else if (BCM2708_DMA_ACTIVE & cs) {
  4305. + /* terminate the control block chain */
  4306. + writel(0, dma_chan_base + BCM2708_DMA_NEXTCB);
  4307. +
  4308. + /* abort the whole DMA */
  4309. + writel(BCM2708_DMA_ABORT | BCM2708_DMA_ACTIVE,
  4310. + dma_chan_base + BCM2708_DMA_CS);
  4311. + }
  4312. + }
  4313. +
  4314. + return rc;
  4315. +}
  4316. +EXPORT_SYMBOL_GPL(bcm_dma_abort);
  4317. +
  4318. +
  4319. +/***************************************************************************** \
  4320. + * *
  4321. + * DMA Manager Device Methods *
  4322. + * *
  4323. +\*****************************************************************************/
  4324. +
  4325. +struct vc_dmaman {
  4326. + void __iomem *dma_base;
  4327. + u32 chan_available; /* bitmap of available channels */
  4328. + u32 has_feature[BCM_DMA_FEATURE_COUNT]; /* bitmap of feature presence */
  4329. +};
  4330. +
  4331. +static void vc_dmaman_init(struct vc_dmaman *dmaman, void __iomem *dma_base,
  4332. + u32 chans_available)
  4333. +{
  4334. + dmaman->dma_base = dma_base;
  4335. + dmaman->chan_available = chans_available;
  4336. + dmaman->has_feature[BCM_DMA_FEATURE_FAST_ORD] = 0x0c; /* chans 2 & 3 */
  4337. + dmaman->has_feature[BCM_DMA_FEATURE_BULK_ORD] = 0x01; /* chan 0 */
  4338. +}
  4339. +
  4340. +static int vc_dmaman_chan_alloc(struct vc_dmaman *dmaman,
  4341. + unsigned preferred_feature_set)
  4342. +{
  4343. + u32 chans;
  4344. + int feature;
  4345. +
  4346. + chans = dmaman->chan_available;
  4347. + for (feature = 0; feature < BCM_DMA_FEATURE_COUNT; feature++)
  4348. + /* select the subset of available channels with the desired
  4349. + feature so long as some of the candidate channels have that
  4350. + feature */
  4351. + if ((preferred_feature_set & (1 << feature)) &&
  4352. + (chans & dmaman->has_feature[feature]))
  4353. + chans &= dmaman->has_feature[feature];
  4354. +
  4355. + if (chans) {
  4356. + int chan = 0;
  4357. + /* return the ordinal of the first channel in the bitmap */
  4358. + while (chans != 0 && (chans & 1) == 0) {
  4359. + chans >>= 1;
  4360. + chan++;
  4361. + }
  4362. + /* claim the channel */
  4363. + dmaman->chan_available &= ~(1 << chan);
  4364. + return chan;
  4365. + } else
  4366. + return -ENOMEM;
  4367. +}
  4368. +
  4369. +static int vc_dmaman_chan_free(struct vc_dmaman *dmaman, int chan)
  4370. +{
  4371. + if (chan < 0)
  4372. + return -EINVAL;
  4373. + else if ((1 << chan) & dmaman->chan_available)
  4374. + return -EIDRM;
  4375. + else {
  4376. + dmaman->chan_available |= (1 << chan);
  4377. + return 0;
  4378. + }
  4379. +}
  4380. +
  4381. +/*****************************************************************************\
  4382. + * *
  4383. + * DMA IRQs *
  4384. + * *
  4385. +\*****************************************************************************/
  4386. +
  4387. +static unsigned char bcm_dma_irqs[] = {
  4388. + IRQ_DMA0,
  4389. + IRQ_DMA1,
  4390. + IRQ_DMA2,
  4391. + IRQ_DMA3,
  4392. + IRQ_DMA4,
  4393. + IRQ_DMA5,
  4394. + IRQ_DMA6,
  4395. + IRQ_DMA7,
  4396. + IRQ_DMA8,
  4397. + IRQ_DMA9,
  4398. + IRQ_DMA10,
  4399. + IRQ_DMA11,
  4400. + IRQ_DMA12
  4401. +};
  4402. +
  4403. +
  4404. +/***************************************************************************** \
  4405. + * *
  4406. + * DMA Manager Monitor *
  4407. + * *
  4408. +\*****************************************************************************/
  4409. +
  4410. +static struct device *dmaman_dev; /* we assume there's only one! */
  4411. +
  4412. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  4413. + void __iomem **out_dma_base, int *out_dma_irq)
  4414. +{
  4415. + if (!dmaman_dev)
  4416. + return -ENODEV;
  4417. + else {
  4418. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  4419. + int rc;
  4420. +
  4421. + device_lock(dmaman_dev);
  4422. + rc = vc_dmaman_chan_alloc(dmaman, preferred_feature_set);
  4423. + if (rc >= 0) {
  4424. + *out_dma_base = BCM2708_DMA_CHANIO(dmaman->dma_base,
  4425. + rc);
  4426. + *out_dma_irq = bcm_dma_irqs[rc];
  4427. + }
  4428. + device_unlock(dmaman_dev);
  4429. +
  4430. + return rc;
  4431. + }
  4432. +}
  4433. +EXPORT_SYMBOL_GPL(bcm_dma_chan_alloc);
  4434. +
  4435. +extern int bcm_dma_chan_free(int channel)
  4436. +{
  4437. + if (dmaman_dev) {
  4438. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  4439. + int rc;
  4440. +
  4441. + device_lock(dmaman_dev);
  4442. + rc = vc_dmaman_chan_free(dmaman, channel);
  4443. + device_unlock(dmaman_dev);
  4444. +
  4445. + return rc;
  4446. + } else
  4447. + return -ENODEV;
  4448. +}
  4449. +EXPORT_SYMBOL_GPL(bcm_dma_chan_free);
  4450. +
  4451. +static int dev_dmaman_register(const char *dev_name, struct device *dev)
  4452. +{
  4453. + int rc = dmaman_dev ? -EINVAL : 0;
  4454. + dmaman_dev = dev;
  4455. + return rc;
  4456. +}
  4457. +
  4458. +static void dev_dmaman_deregister(const char *dev_name, struct device *dev)
  4459. +{
  4460. + dmaman_dev = NULL;
  4461. +}
  4462. +
  4463. +/*****************************************************************************\
  4464. + * *
  4465. + * DMA Device *
  4466. + * *
  4467. +\*****************************************************************************/
  4468. +
  4469. +static int dmachans = -1; /* module parameter */
  4470. +
  4471. +static int bcm_dmaman_probe(struct platform_device *pdev)
  4472. +{
  4473. + int ret = 0;
  4474. + struct vc_dmaman *dmaman;
  4475. + struct resource *dma_res = NULL;
  4476. + void __iomem *dma_base = NULL;
  4477. + int have_dma_region = 0;
  4478. +
  4479. + dmaman = kzalloc(sizeof(*dmaman), GFP_KERNEL);
  4480. + if (NULL == dmaman) {
  4481. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  4482. + "DMA management memory\n");
  4483. + ret = -ENOMEM;
  4484. + } else {
  4485. +
  4486. + dma_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  4487. + if (dma_res == NULL) {
  4488. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  4489. + "resource\n");
  4490. + ret = -ENODEV;
  4491. + } else if (!request_mem_region(dma_res->start,
  4492. + resource_size(dma_res),
  4493. + DRIVER_NAME)) {
  4494. + dev_err(&pdev->dev, "cannot obtain DMA region\n");
  4495. + ret = -EBUSY;
  4496. + } else {
  4497. + have_dma_region = 1;
  4498. + dma_base = ioremap(dma_res->start,
  4499. + resource_size(dma_res));
  4500. + if (!dma_base) {
  4501. + dev_err(&pdev->dev, "cannot map DMA region\n");
  4502. + ret = -ENOMEM;
  4503. + } else {
  4504. + /* use module parameter if one was provided */
  4505. + if (dmachans > 0)
  4506. + vc_dmaman_init(dmaman, dma_base,
  4507. + dmachans);
  4508. + else
  4509. + vc_dmaman_init(dmaman, dma_base,
  4510. + DEFAULT_DMACHAN_BITMAP);
  4511. +
  4512. + platform_set_drvdata(pdev, dmaman);
  4513. + dev_dmaman_register(DRIVER_NAME, &pdev->dev);
  4514. +
  4515. + printk(KERN_INFO DRIVER_NAME ": DMA manager "
  4516. + "at %p\n", dma_base);
  4517. + }
  4518. + }
  4519. + }
  4520. + if (ret != 0) {
  4521. + if (dma_base)
  4522. + iounmap(dma_base);
  4523. + if (dma_res && have_dma_region)
  4524. + release_mem_region(dma_res->start,
  4525. + resource_size(dma_res));
  4526. + if (dmaman)
  4527. + kfree(dmaman);
  4528. + }
  4529. + return ret;
  4530. +}
  4531. +
  4532. +static int bcm_dmaman_remove(struct platform_device *pdev)
  4533. +{
  4534. + struct vc_dmaman *dmaman = platform_get_drvdata(pdev);
  4535. +
  4536. + platform_set_drvdata(pdev, NULL);
  4537. + dev_dmaman_deregister(DRIVER_NAME, &pdev->dev);
  4538. + kfree(dmaman);
  4539. +
  4540. + return 0;
  4541. +}
  4542. +
  4543. +static struct platform_driver bcm_dmaman_driver = {
  4544. + .probe = bcm_dmaman_probe,
  4545. + .remove = bcm_dmaman_remove,
  4546. +
  4547. + .driver = {
  4548. + .name = DRIVER_NAME,
  4549. + .owner = THIS_MODULE,
  4550. + },
  4551. +};
  4552. +
  4553. +/*****************************************************************************\
  4554. + * *
  4555. + * Driver init/exit *
  4556. + * *
  4557. +\*****************************************************************************/
  4558. +
  4559. +static int __init bcm_dmaman_drv_init(void)
  4560. +{
  4561. + int ret;
  4562. +
  4563. + ret = platform_driver_register(&bcm_dmaman_driver);
  4564. + if (ret != 0) {
  4565. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  4566. + "on platform\n");
  4567. + }
  4568. +
  4569. + return ret;
  4570. +}
  4571. +
  4572. +static void __exit bcm_dmaman_drv_exit(void)
  4573. +{
  4574. + platform_driver_unregister(&bcm_dmaman_driver);
  4575. +}
  4576. +
  4577. +module_init(bcm_dmaman_drv_init);
  4578. +module_exit(bcm_dmaman_drv_exit);
  4579. +
  4580. +module_param(dmachans, int, 0644);
  4581. +
  4582. +MODULE_AUTHOR("Gray Girling <grayg@broadcom.com>");
  4583. +MODULE_DESCRIPTION("DMA channel manager driver");
  4584. +MODULE_LICENSE("GPL");
  4585. +
  4586. +MODULE_PARM_DESC(dmachans, "Bitmap of DMA channels available to the ARM");
  4587. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/dmaer.c linux-3.12.11/arch/arm/mach-bcm2708/dmaer.c
  4588. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/dmaer.c 1970-01-01 01:00:00.000000000 +0100
  4589. +++ linux-3.12.11/arch/arm/mach-bcm2708/dmaer.c 2014-02-18 11:52:14.000000000 +0100
  4590. @@ -0,0 +1,886 @@
  4591. +#include <linux/init.h>
  4592. +#include <linux/sched.h>
  4593. +#include <linux/module.h>
  4594. +#include <linux/types.h>
  4595. +#include <linux/kdev_t.h>
  4596. +#include <linux/fs.h>
  4597. +#include <linux/cdev.h>
  4598. +#include <linux/mm.h>
  4599. +#include <linux/slab.h>
  4600. +#include <linux/pagemap.h>
  4601. +#include <linux/device.h>
  4602. +#include <linux/jiffies.h>
  4603. +#include <linux/timex.h>
  4604. +#include <linux/dma-mapping.h>
  4605. +
  4606. +#include <asm/uaccess.h>
  4607. +#include <asm/atomic.h>
  4608. +#include <asm/cacheflush.h>
  4609. +#include <asm/io.h>
  4610. +
  4611. +#include <mach/dma.h>
  4612. +#include <mach/vc_support.h>
  4613. +
  4614. +#ifdef ECLIPSE_IGNORE
  4615. +
  4616. +#define __user
  4617. +#define __init
  4618. +#define __exit
  4619. +#define __iomem
  4620. +#define KERN_DEBUG
  4621. +#define KERN_ERR
  4622. +#define KERN_WARNING
  4623. +#define KERN_INFO
  4624. +#define _IOWR(a, b, c) b
  4625. +#define _IOW(a, b, c) b
  4626. +#define _IO(a, b) b
  4627. +
  4628. +#endif
  4629. +
  4630. +//#define inline
  4631. +
  4632. +#define PRINTK(args...) printk(args)
  4633. +//#define PRINTK_VERBOSE(args...) printk(args)
  4634. +//#define PRINTK(args...)
  4635. +#define PRINTK_VERBOSE(args...)
  4636. +
  4637. +/***** TYPES ****/
  4638. +#define PAGES_PER_LIST 500
  4639. +struct PageList
  4640. +{
  4641. + struct page *m_pPages[PAGES_PER_LIST];
  4642. + unsigned int m_used;
  4643. + struct PageList *m_pNext;
  4644. +};
  4645. +
  4646. +struct VmaPageList
  4647. +{
  4648. + //each vma has a linked list of pages associated with it
  4649. + struct PageList *m_pPageHead;
  4650. + struct PageList *m_pPageTail;
  4651. + unsigned int m_refCount;
  4652. +};
  4653. +
  4654. +struct DmaControlBlock
  4655. +{
  4656. + unsigned int m_transferInfo;
  4657. + void __user *m_pSourceAddr;
  4658. + void __user *m_pDestAddr;
  4659. + unsigned int m_xferLen;
  4660. + unsigned int m_tdStride;
  4661. + struct DmaControlBlock *m_pNext;
  4662. + unsigned int m_blank1, m_blank2;
  4663. +};
  4664. +
  4665. +/***** DEFINES ******/
  4666. +//magic number defining the module
  4667. +#define DMA_MAGIC 0xdd
  4668. +
  4669. +//do user virtual to physical translation of the CB chain
  4670. +#define DMA_PREPARE _IOWR(DMA_MAGIC, 0, struct DmaControlBlock *)
  4671. +
  4672. +//kick the pre-prepared CB chain
  4673. +#define DMA_KICK _IOW(DMA_MAGIC, 1, struct DmaControlBlock *)
  4674. +
  4675. +//prepare it, kick it, wait for it
  4676. +#define DMA_PREPARE_KICK_WAIT _IOWR(DMA_MAGIC, 2, struct DmaControlBlock *)
  4677. +
  4678. +//prepare it, kick it, don't wait for it
  4679. +#define DMA_PREPARE_KICK _IOWR(DMA_MAGIC, 3, struct DmaControlBlock *)
  4680. +
  4681. +//not currently implemented
  4682. +#define DMA_WAIT_ONE _IO(DMA_MAGIC, 4, struct DmaControlBlock *)
  4683. +
  4684. +//wait on all kicked CB chains
  4685. +#define DMA_WAIT_ALL _IO(DMA_MAGIC, 5)
  4686. +
  4687. +//in order to discover the largest AXI burst that should be programmed into the transfer params
  4688. +#define DMA_MAX_BURST _IO(DMA_MAGIC, 6)
  4689. +
  4690. +//set the address range through which the user address is assumed to already by a physical address
  4691. +#define DMA_SET_MIN_PHYS _IOW(DMA_MAGIC, 7, unsigned long)
  4692. +#define DMA_SET_MAX_PHYS _IOW(DMA_MAGIC, 8, unsigned long)
  4693. +#define DMA_SET_PHYS_OFFSET _IOW(DMA_MAGIC, 9, unsigned long)
  4694. +
  4695. +//used to define the size for the CMA-based allocation *in pages*, can only be done once once the file is opened
  4696. +#define DMA_CMA_SET_SIZE _IOW(DMA_MAGIC, 10, unsigned long)
  4697. +
  4698. +//used to get the version of the module, to test for a capability
  4699. +#define DMA_GET_VERSION _IO(DMA_MAGIC, 99)
  4700. +
  4701. +#define VERSION_NUMBER 1
  4702. +
  4703. +#define VIRT_TO_BUS_CACHE_SIZE 8
  4704. +
  4705. +/***** FILE OPS *****/
  4706. +static int Open(struct inode *pInode, struct file *pFile);
  4707. +static int Release(struct inode *pInode, struct file *pFile);
  4708. +static long Ioctl(struct file *pFile, unsigned int cmd, unsigned long arg);
  4709. +static ssize_t Read(struct file *pFile, char __user *pUser, size_t count, loff_t *offp);
  4710. +static int Mmap(struct file *pFile, struct vm_area_struct *pVma);
  4711. +
  4712. +/***** VMA OPS ****/
  4713. +static void VmaOpen4k(struct vm_area_struct *pVma);
  4714. +static void VmaClose4k(struct vm_area_struct *pVma);
  4715. +static int VmaFault4k(struct vm_area_struct *pVma, struct vm_fault *pVmf);
  4716. +
  4717. +/**** DMA PROTOTYPES */
  4718. +static struct DmaControlBlock __user *DmaPrepare(struct DmaControlBlock __user *pUserCB, int *pError);
  4719. +static int DmaKick(struct DmaControlBlock __user *pUserCB);
  4720. +static void DmaWaitAll(void);
  4721. +
  4722. +/**** GENERIC ****/
  4723. +static int __init dmaer_init(void);
  4724. +static void __exit dmaer_exit(void);
  4725. +
  4726. +/*** OPS ***/
  4727. +static struct vm_operations_struct g_vmOps4k = {
  4728. + .open = VmaOpen4k,
  4729. + .close = VmaClose4k,
  4730. + .fault = VmaFault4k,
  4731. +};
  4732. +
  4733. +static struct file_operations g_fOps = {
  4734. + .owner = THIS_MODULE,
  4735. + .llseek = 0,
  4736. + .read = Read,
  4737. + .write = 0,
  4738. + .unlocked_ioctl = Ioctl,
  4739. + .open = Open,
  4740. + .release = Release,
  4741. + .mmap = Mmap,
  4742. +};
  4743. +
  4744. +/***** GLOBALS ******/
  4745. +static dev_t g_majorMinor;
  4746. +
  4747. +//tracking usage of the two files
  4748. +static atomic_t g_oneLock4k = ATOMIC_INIT(1);
  4749. +
  4750. +//device operations
  4751. +static struct cdev g_cDev;
  4752. +static int g_trackedPages = 0;
  4753. +
  4754. +//dma control
  4755. +static unsigned int *g_pDmaChanBase;
  4756. +static int g_dmaIrq;
  4757. +static int g_dmaChan;
  4758. +
  4759. +//cma allocation
  4760. +static int g_cmaHandle;
  4761. +
  4762. +//user virtual to bus address translation acceleration
  4763. +static unsigned long g_virtAddr[VIRT_TO_BUS_CACHE_SIZE];
  4764. +static unsigned long g_busAddr[VIRT_TO_BUS_CACHE_SIZE];
  4765. +static unsigned long g_cbVirtAddr;
  4766. +static unsigned long g_cbBusAddr;
  4767. +static int g_cacheInsertAt;
  4768. +static int g_cacheHit, g_cacheMiss;
  4769. +
  4770. +//off by default
  4771. +static void __user *g_pMinPhys;
  4772. +static void __user *g_pMaxPhys;
  4773. +static unsigned long g_physOffset;
  4774. +
  4775. +/****** CACHE OPERATIONS ********/
  4776. +static inline void FlushAddrCache(void)
  4777. +{
  4778. + int count = 0;
  4779. + for (count = 0; count < VIRT_TO_BUS_CACHE_SIZE; count++)
  4780. + g_virtAddr[count] = 0xffffffff; //never going to match as we always chop the bottom bits anyway
  4781. +
  4782. + g_cbVirtAddr = 0xffffffff;
  4783. +
  4784. + g_cacheInsertAt = 0;
  4785. +}
  4786. +
  4787. +//translate from a user virtual address to a bus address by mapping the page
  4788. +//NB this won't lock a page in memory, so to avoid potential paging issues using kernel logical addresses
  4789. +static inline void __iomem *UserVirtualToBus(void __user *pUser)
  4790. +{
  4791. + int mapped;
  4792. + struct page *pPage;
  4793. + void *phys;
  4794. +
  4795. + //map it (requiring that the pointer points to something that does not hang off the page boundary)
  4796. + mapped = get_user_pages(current, current->mm,
  4797. + (unsigned long)pUser, 1,
  4798. + 1, 0,
  4799. + &pPage,
  4800. + 0);
  4801. +
  4802. + if (mapped <= 0) //error
  4803. + return 0;
  4804. +
  4805. + PRINTK_VERBOSE(KERN_DEBUG "user virtual %p arm phys %p bus %p\n",
  4806. + pUser, page_address(pPage), (void __iomem *)__virt_to_bus(page_address(pPage)));
  4807. +
  4808. + //get the arm physical address
  4809. + phys = page_address(pPage) + offset_in_page(pUser);
  4810. + page_cache_release(pPage);
  4811. +
  4812. + //and now the bus address
  4813. + return (void __iomem *)__virt_to_bus(phys);
  4814. +}
  4815. +
  4816. +static inline void __iomem *UserVirtualToBusViaCbCache(void __user *pUser)
  4817. +{
  4818. + unsigned long virtual_page = (unsigned long)pUser & ~4095;
  4819. + unsigned long page_offset = (unsigned long)pUser & 4095;
  4820. + unsigned long bus_addr;
  4821. +
  4822. + if (g_cbVirtAddr == virtual_page)
  4823. + {
  4824. + bus_addr = g_cbBusAddr + page_offset;
  4825. + g_cacheHit++;
  4826. + return (void __iomem *)bus_addr;
  4827. + }
  4828. + else
  4829. + {
  4830. + bus_addr = (unsigned long)UserVirtualToBus(pUser);
  4831. +
  4832. + if (!bus_addr)
  4833. + return 0;
  4834. +
  4835. + g_cbVirtAddr = virtual_page;
  4836. + g_cbBusAddr = bus_addr & ~4095;
  4837. + g_cacheMiss++;
  4838. +
  4839. + return (void __iomem *)bus_addr;
  4840. + }
  4841. +}
  4842. +
  4843. +//do the same as above, by query our virt->bus cache
  4844. +static inline void __iomem *UserVirtualToBusViaCache(void __user *pUser)
  4845. +{
  4846. + int count;
  4847. + //get the page and its offset
  4848. + unsigned long virtual_page = (unsigned long)pUser & ~4095;
  4849. + unsigned long page_offset = (unsigned long)pUser & 4095;
  4850. + unsigned long bus_addr;
  4851. +
  4852. + if (pUser >= g_pMinPhys && pUser < g_pMaxPhys)
  4853. + {
  4854. + PRINTK_VERBOSE(KERN_DEBUG "user->phys passthrough on %p\n", pUser);
  4855. + return (void __iomem *)((unsigned long)pUser + g_physOffset);
  4856. + }
  4857. +
  4858. + //check the cache for our entry
  4859. + for (count = 0; count < VIRT_TO_BUS_CACHE_SIZE; count++)
  4860. + if (g_virtAddr[count] == virtual_page)
  4861. + {
  4862. + bus_addr = g_busAddr[count] + page_offset;
  4863. + g_cacheHit++;
  4864. + return (void __iomem *)bus_addr;
  4865. + }
  4866. +
  4867. + //not found, look up manually and then insert its page address
  4868. + bus_addr = (unsigned long)UserVirtualToBus(pUser);
  4869. +
  4870. + if (!bus_addr)
  4871. + return 0;
  4872. +
  4873. + g_virtAddr[g_cacheInsertAt] = virtual_page;
  4874. + g_busAddr[g_cacheInsertAt] = bus_addr & ~4095;
  4875. +
  4876. + //round robin
  4877. + g_cacheInsertAt++;
  4878. + if (g_cacheInsertAt == VIRT_TO_BUS_CACHE_SIZE)
  4879. + g_cacheInsertAt = 0;
  4880. +
  4881. + g_cacheMiss++;
  4882. +
  4883. + return (void __iomem *)bus_addr;
  4884. +}
  4885. +
  4886. +/***** FILE OPERATIONS ****/
  4887. +static int Open(struct inode *pInode, struct file *pFile)
  4888. +{
  4889. + PRINTK(KERN_DEBUG "file opening: %d/%d\n", imajor(pInode), iminor(pInode));
  4890. +
  4891. + //check which device we are
  4892. + if (iminor(pInode) == 0) //4k
  4893. + {
  4894. + //only one at a time
  4895. + if (!atomic_dec_and_test(&g_oneLock4k))
  4896. + {
  4897. + atomic_inc(&g_oneLock4k);
  4898. + return -EBUSY;
  4899. + }
  4900. + }
  4901. + else
  4902. + return -EINVAL;
  4903. +
  4904. + //todo there will be trouble if two different processes open the files
  4905. +
  4906. + //reset after any file is opened
  4907. + g_pMinPhys = (void __user *)-1;
  4908. + g_pMaxPhys = (void __user *)0;
  4909. + g_physOffset = 0;
  4910. + g_cmaHandle = 0;
  4911. +
  4912. + return 0;
  4913. +}
  4914. +
  4915. +static int Release(struct inode *pInode, struct file *pFile)
  4916. +{
  4917. + PRINTK(KERN_DEBUG "file closing, %d pages tracked\n", g_trackedPages);
  4918. + if (g_trackedPages)
  4919. + PRINTK(KERN_ERR "we\'re leaking memory!\n");
  4920. +
  4921. + //wait for any dmas to finish
  4922. + DmaWaitAll();
  4923. +
  4924. + //free this memory on the application closing the file or it crashing (implicitly closing the file)
  4925. + if (g_cmaHandle)
  4926. + {
  4927. + PRINTK(KERN_DEBUG "unlocking vc memory\n");
  4928. + if (UnlockVcMemory(g_cmaHandle))
  4929. + PRINTK(KERN_ERR "uh-oh, unable to unlock vc memory!\n");
  4930. + PRINTK(KERN_DEBUG "releasing vc memory\n");
  4931. + if (ReleaseVcMemory(g_cmaHandle))
  4932. + PRINTK(KERN_ERR "uh-oh, unable to release vc memory!\n");
  4933. + }
  4934. +
  4935. + if (iminor(pInode) == 0)
  4936. + atomic_inc(&g_oneLock4k);
  4937. + else
  4938. + return -EINVAL;
  4939. +
  4940. + return 0;
  4941. +}
  4942. +
  4943. +static struct DmaControlBlock __user *DmaPrepare(struct DmaControlBlock __user *pUserCB, int *pError)
  4944. +{
  4945. + struct DmaControlBlock kernCB;
  4946. + struct DmaControlBlock __user *pUNext;
  4947. + void __iomem *pSourceBus, __iomem *pDestBus;
  4948. +
  4949. + //get the control block into kernel memory so we can work on it
  4950. + if (copy_from_user(&kernCB, pUserCB, sizeof(struct DmaControlBlock)) != 0)
  4951. + {
  4952. + PRINTK(KERN_ERR "copy_from_user failed for user cb %p\n", pUserCB);
  4953. + *pError = 1;
  4954. + return 0;
  4955. + }
  4956. +
  4957. + if (kernCB.m_pSourceAddr == 0 || kernCB.m_pDestAddr == 0)
  4958. + {
  4959. + PRINTK(KERN_ERR "faulty source (%p) dest (%p) addresses for user cb %p\n",
  4960. + kernCB.m_pSourceAddr, kernCB.m_pDestAddr, pUserCB);
  4961. + *pError = 1;
  4962. + return 0;
  4963. + }
  4964. +
  4965. + pSourceBus = UserVirtualToBusViaCache(kernCB.m_pSourceAddr);
  4966. + pDestBus = UserVirtualToBusViaCache(kernCB.m_pDestAddr);
  4967. +
  4968. + if (!pSourceBus || !pDestBus)
  4969. + {
  4970. + PRINTK(KERN_ERR "virtual to bus translation failure for source/dest %p/%p->%p/%p\n",
  4971. + kernCB.m_pSourceAddr, kernCB.m_pDestAddr,
  4972. + pSourceBus, pDestBus);
  4973. + *pError = 1;
  4974. + return 0;
  4975. + }
  4976. +
  4977. + //update the user structure with the new bus addresses
  4978. + kernCB.m_pSourceAddr = pSourceBus;
  4979. + kernCB.m_pDestAddr = pDestBus;
  4980. +
  4981. + PRINTK_VERBOSE(KERN_DEBUG "final source %p dest %p\n", kernCB.m_pSourceAddr, kernCB.m_pDestAddr);
  4982. +
  4983. + //sort out the bus address for the next block
  4984. + pUNext = kernCB.m_pNext;
  4985. +
  4986. + if (kernCB.m_pNext)
  4987. + {
  4988. + void __iomem *pNextBus;
  4989. + pNextBus = UserVirtualToBusViaCbCache(kernCB.m_pNext);
  4990. +
  4991. + if (!pNextBus)
  4992. + {
  4993. + PRINTK(KERN_ERR "virtual to bus translation failure for m_pNext\n");
  4994. + *pError = 1;
  4995. + return 0;
  4996. + }
  4997. +
  4998. + //update the pointer with the bus address
  4999. + kernCB.m_pNext = pNextBus;
  5000. + }
  5001. +
  5002. + //write it back to user space
  5003. + if (copy_to_user(pUserCB, &kernCB, sizeof(struct DmaControlBlock)) != 0)
  5004. + {
  5005. + PRINTK(KERN_ERR "copy_to_user failed for cb %p\n", pUserCB);
  5006. + *pError = 1;
  5007. + return 0;
  5008. + }
  5009. +
  5010. + __cpuc_flush_dcache_area(pUserCB, 32);
  5011. +
  5012. + *pError = 0;
  5013. + return pUNext;
  5014. +}
  5015. +
  5016. +static int DmaKick(struct DmaControlBlock __user *pUserCB)
  5017. +{
  5018. + void __iomem *pBusCB;
  5019. +
  5020. + pBusCB = UserVirtualToBusViaCbCache(pUserCB);
  5021. + if (!pBusCB)
  5022. + {
  5023. + PRINTK(KERN_ERR "virtual to bus translation failure for cb\n");
  5024. + return 1;
  5025. + }
  5026. +
  5027. + //flush_cache_all();
  5028. +
  5029. + bcm_dma_start(g_pDmaChanBase, (dma_addr_t)pBusCB);
  5030. +
  5031. + return 0;
  5032. +}
  5033. +
  5034. +static void DmaWaitAll(void)
  5035. +{
  5036. + int counter = 0;
  5037. + volatile int inner_count;
  5038. + volatile unsigned int cs;
  5039. + unsigned long time_before, time_after;
  5040. +
  5041. + time_before = jiffies;
  5042. + //bcm_dma_wait_idle(g_pDmaChanBase);
  5043. + dsb();
  5044. +
  5045. + cs = readl(g_pDmaChanBase);
  5046. +
  5047. + while ((cs & 1) == 1)
  5048. + {
  5049. + cs = readl(g_pDmaChanBase);
  5050. + counter++;
  5051. +
  5052. + for (inner_count = 0; inner_count < 32; inner_count++);
  5053. +
  5054. + asm volatile ("MCR p15,0,r0,c7,c0,4 \n");
  5055. + //cpu_do_idle();
  5056. + if (counter >= 1000000)
  5057. + {
  5058. + PRINTK(KERN_WARNING "DMA failed to finish in a timely fashion\n");
  5059. + break;
  5060. + }
  5061. + }
  5062. + time_after = jiffies;
  5063. + PRINTK_VERBOSE(KERN_DEBUG "done, counter %d, cs %08x", counter, cs);
  5064. + PRINTK_VERBOSE(KERN_DEBUG "took %ld jiffies, %d HZ\n", time_after - time_before, HZ);
  5065. +}
  5066. +
  5067. +static long Ioctl(struct file *pFile, unsigned int cmd, unsigned long arg)
  5068. +{
  5069. + int error = 0;
  5070. + PRINTK_VERBOSE(KERN_DEBUG "ioctl cmd %x arg %lx\n", cmd, arg);
  5071. +
  5072. + switch (cmd)
  5073. + {
  5074. + case DMA_PREPARE:
  5075. + case DMA_PREPARE_KICK:
  5076. + case DMA_PREPARE_KICK_WAIT:
  5077. + {
  5078. + struct DmaControlBlock __user *pUCB = (struct DmaControlBlock *)arg;
  5079. + int steps = 0;
  5080. + unsigned long start_time = jiffies;
  5081. + (void)start_time;
  5082. +
  5083. + //flush our address cache
  5084. + FlushAddrCache();
  5085. +
  5086. + PRINTK_VERBOSE(KERN_DEBUG "dma prepare\n");
  5087. +
  5088. + //do virtual to bus translation for each entry
  5089. + do
  5090. + {
  5091. + pUCB = DmaPrepare(pUCB, &error);
  5092. + } while (error == 0 && ++steps && pUCB);
  5093. + PRINTK_VERBOSE(KERN_DEBUG "prepare done in %d steps, %ld\n", steps, jiffies - start_time);
  5094. +
  5095. + //carry straight on if we want to kick too
  5096. + if (cmd == DMA_PREPARE || error)
  5097. + {
  5098. + PRINTK_VERBOSE(KERN_DEBUG "falling out\n");
  5099. + return error ? -EINVAL : 0;
  5100. + }
  5101. + }
  5102. + case DMA_KICK:
  5103. + PRINTK_VERBOSE(KERN_DEBUG "dma begin\n");
  5104. +
  5105. + if (cmd == DMA_KICK)
  5106. + FlushAddrCache();
  5107. +
  5108. + DmaKick((struct DmaControlBlock __user *)arg);
  5109. +
  5110. + if (cmd != DMA_PREPARE_KICK_WAIT)
  5111. + break;
  5112. +/* case DMA_WAIT_ONE:
  5113. + //PRINTK(KERN_DEBUG "dma wait one\n");
  5114. + break;*/
  5115. + case DMA_WAIT_ALL:
  5116. + //PRINTK(KERN_DEBUG "dma wait all\n");
  5117. + DmaWaitAll();
  5118. + break;
  5119. + case DMA_MAX_BURST:
  5120. + if (g_dmaChan == 0)
  5121. + return 10;
  5122. + else
  5123. + return 5;
  5124. + case DMA_SET_MIN_PHYS:
  5125. + g_pMinPhys = (void __user *)arg;
  5126. + PRINTK(KERN_DEBUG "min/max user/phys bypass set to %p %p\n", g_pMinPhys, g_pMaxPhys);
  5127. + break;
  5128. + case DMA_SET_MAX_PHYS:
  5129. + g_pMaxPhys = (void __user *)arg;
  5130. + PRINTK(KERN_DEBUG "min/max user/phys bypass set to %p %p\n", g_pMinPhys, g_pMaxPhys);
  5131. + break;
  5132. + case DMA_SET_PHYS_OFFSET:
  5133. + g_physOffset = arg;
  5134. + PRINTK(KERN_DEBUG "user/phys bypass offset set to %ld\n", g_physOffset);
  5135. + break;
  5136. + case DMA_CMA_SET_SIZE:
  5137. + {
  5138. + unsigned int pBusAddr;
  5139. +
  5140. + if (g_cmaHandle)
  5141. + {
  5142. + PRINTK(KERN_ERR "memory has already been allocated (handle %d)\n", g_cmaHandle);
  5143. + return -EINVAL;
  5144. + }
  5145. +
  5146. + PRINTK(KERN_INFO "allocating %ld bytes of VC memory\n", arg * 4096);
  5147. +
  5148. + //get the memory
  5149. + if (AllocateVcMemory(&g_cmaHandle, arg * 4096, 4096, MEM_FLAG_L1_NONALLOCATING | MEM_FLAG_NO_INIT | MEM_FLAG_HINT_PERMALOCK))
  5150. + {
  5151. + PRINTK(KERN_ERR "failed to allocate %ld bytes of VC memory\n", arg * 4096);
  5152. + g_cmaHandle = 0;
  5153. + return -EINVAL;
  5154. + }
  5155. +
  5156. + //get an address for it
  5157. + PRINTK(KERN_INFO "trying to map VC memory\n");
  5158. +
  5159. + if (LockVcMemory(&pBusAddr, g_cmaHandle))
  5160. + {
  5161. + PRINTK(KERN_ERR "failed to map CMA handle %d, releasing memory\n", g_cmaHandle);
  5162. + ReleaseVcMemory(g_cmaHandle);
  5163. + g_cmaHandle = 0;
  5164. + }
  5165. +
  5166. + PRINTK(KERN_INFO "bus address for CMA memory is %x\n", pBusAddr);
  5167. + return pBusAddr;
  5168. + }
  5169. + case DMA_GET_VERSION:
  5170. + PRINTK(KERN_DEBUG "returning version number, %d\n", VERSION_NUMBER);
  5171. + return VERSION_NUMBER;
  5172. + default:
  5173. + PRINTK(KERN_DEBUG "unknown ioctl: %d\n", cmd);
  5174. + return -EINVAL;
  5175. + }
  5176. +
  5177. + return 0;
  5178. +}
  5179. +
  5180. +static ssize_t Read(struct file *pFile, char __user *pUser, size_t count, loff_t *offp)
  5181. +{
  5182. + return -EIO;
  5183. +}
  5184. +
  5185. +static int Mmap(struct file *pFile, struct vm_area_struct *pVma)
  5186. +{
  5187. + struct PageList *pPages;
  5188. + struct VmaPageList *pVmaList;
  5189. +
  5190. + PRINTK_VERBOSE(KERN_DEBUG "MMAP vma %p, length %ld (%s %d)\n",
  5191. + pVma, pVma->vm_end - pVma->vm_start,
  5192. + current->comm, current->pid);
  5193. + PRINTK_VERBOSE(KERN_DEBUG "MMAP %p %d (tracked %d)\n", pVma, current->pid, g_trackedPages);
  5194. +
  5195. + //make a new page list
  5196. + pPages = (struct PageList *)kmalloc(sizeof(struct PageList), GFP_KERNEL);
  5197. + if (!pPages)
  5198. + {
  5199. + PRINTK(KERN_ERR "couldn\'t allocate a new page list (%s %d)\n",
  5200. + current->comm, current->pid);
  5201. + return -ENOMEM;
  5202. + }
  5203. +
  5204. + //clear the page list
  5205. + pPages->m_used = 0;
  5206. + pPages->m_pNext = 0;
  5207. +
  5208. + //insert our vma and new page list somewhere
  5209. + if (!pVma->vm_private_data)
  5210. + {
  5211. + struct VmaPageList *pList;
  5212. +
  5213. + PRINTK_VERBOSE(KERN_DEBUG "new vma list, making new one (%s %d)\n",
  5214. + current->comm, current->pid);
  5215. +
  5216. + //make a new vma list
  5217. + pList = (struct VmaPageList *)kmalloc(sizeof(struct VmaPageList), GFP_KERNEL);
  5218. + if (!pList)
  5219. + {
  5220. + PRINTK(KERN_ERR "couldn\'t allocate vma page list (%s %d)\n",
  5221. + current->comm, current->pid);
  5222. + kfree(pPages);
  5223. + return -ENOMEM;
  5224. + }
  5225. +
  5226. + //clear this list
  5227. + pVma->vm_private_data = (void *)pList;
  5228. + pList->m_refCount = 0;
  5229. + }
  5230. +
  5231. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  5232. +
  5233. + //add it to the vma list
  5234. + pVmaList->m_pPageHead = pPages;
  5235. + pVmaList->m_pPageTail = pPages;
  5236. +
  5237. + pVma->vm_ops = &g_vmOps4k;
  5238. + pVma->vm_flags |= VM_IO;
  5239. +
  5240. + VmaOpen4k(pVma);
  5241. +
  5242. + return 0;
  5243. +}
  5244. +
  5245. +/****** VMA OPERATIONS ******/
  5246. +
  5247. +static void VmaOpen4k(struct vm_area_struct *pVma)
  5248. +{
  5249. + struct VmaPageList *pVmaList;
  5250. +
  5251. + PRINTK_VERBOSE(KERN_DEBUG "vma open %p private %p (%s %d), %d live pages\n", pVma, pVma->vm_private_data, current->comm, current->pid, g_trackedPages);
  5252. + PRINTK_VERBOSE(KERN_DEBUG "OPEN %p %d %ld pages (tracked pages %d)\n",
  5253. + pVma, current->pid, (pVma->vm_end - pVma->vm_start) >> 12,
  5254. + g_trackedPages);
  5255. +
  5256. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  5257. +
  5258. + if (pVmaList)
  5259. + {
  5260. + pVmaList->m_refCount++;
  5261. + PRINTK_VERBOSE(KERN_DEBUG "ref count is now %d\n", pVmaList->m_refCount);
  5262. + }
  5263. + else
  5264. + {
  5265. + PRINTK_VERBOSE(KERN_DEBUG "err, open but no vma page list\n");
  5266. + }
  5267. +}
  5268. +
  5269. +static void VmaClose4k(struct vm_area_struct *pVma)
  5270. +{
  5271. + struct VmaPageList *pVmaList;
  5272. + int freed = 0;
  5273. +
  5274. + PRINTK_VERBOSE(KERN_DEBUG "vma close %p private %p (%s %d)\n", pVma, pVma->vm_private_data, current->comm, current->pid);
  5275. +
  5276. + //wait for any dmas to finish
  5277. + DmaWaitAll();
  5278. +
  5279. + //find our vma in the list
  5280. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  5281. +
  5282. + //may be a fork
  5283. + if (pVmaList)
  5284. + {
  5285. + struct PageList *pPages;
  5286. +
  5287. + pVmaList->m_refCount--;
  5288. +
  5289. + if (pVmaList->m_refCount == 0)
  5290. + {
  5291. + PRINTK_VERBOSE(KERN_DEBUG "found vma, freeing pages (%s %d)\n",
  5292. + current->comm, current->pid);
  5293. +
  5294. + pPages = pVmaList->m_pPageHead;
  5295. +
  5296. + if (!pPages)
  5297. + {
  5298. + PRINTK(KERN_ERR "no page list (%s %d)!\n",
  5299. + current->comm, current->pid);
  5300. + return;
  5301. + }
  5302. +
  5303. + while (pPages)
  5304. + {
  5305. + struct PageList *next;
  5306. + int count;
  5307. +
  5308. + PRINTK_VERBOSE(KERN_DEBUG "page list (%s %d)\n",
  5309. + current->comm, current->pid);
  5310. +
  5311. + next = pPages->m_pNext;
  5312. + for (count = 0; count < pPages->m_used; count++)
  5313. + {
  5314. + PRINTK_VERBOSE(KERN_DEBUG "freeing page %p (%s %d)\n",
  5315. + pPages->m_pPages[count],
  5316. + current->comm, current->pid);
  5317. + __free_pages(pPages->m_pPages[count], 0);
  5318. + g_trackedPages--;
  5319. + freed++;
  5320. + }
  5321. +
  5322. + PRINTK_VERBOSE(KERN_DEBUG "freeing page list (%s %d)\n",
  5323. + current->comm, current->pid);
  5324. + kfree(pPages);
  5325. + pPages = next;
  5326. + }
  5327. +
  5328. + //remove our vma from the list
  5329. + kfree(pVmaList);
  5330. + pVma->vm_private_data = 0;
  5331. + }
  5332. + else
  5333. + {
  5334. + PRINTK_VERBOSE(KERN_DEBUG "ref count is %d, not closing\n", pVmaList->m_refCount);
  5335. + }
  5336. + }
  5337. + else
  5338. + {
  5339. + PRINTK_VERBOSE(KERN_ERR "uh-oh, vma %p not found (%s %d)!\n", pVma, current->comm, current->pid);
  5340. + PRINTK_VERBOSE(KERN_ERR "CLOSE ERR\n");
  5341. + }
  5342. +
  5343. + PRINTK_VERBOSE(KERN_DEBUG "CLOSE %p %d %d pages (tracked pages %d)",
  5344. + pVma, current->pid, freed, g_trackedPages);
  5345. +
  5346. + PRINTK_VERBOSE(KERN_DEBUG "%d pages open\n", g_trackedPages);
  5347. +}
  5348. +
  5349. +static int VmaFault4k(struct vm_area_struct *pVma, struct vm_fault *pVmf)
  5350. +{
  5351. + PRINTK_VERBOSE(KERN_DEBUG "vma fault for vma %p private %p at offset %ld (%s %d)\n", pVma, pVma->vm_private_data, pVmf->pgoff,
  5352. + current->comm, current->pid);
  5353. + PRINTK_VERBOSE(KERN_DEBUG "FAULT\n");
  5354. + pVmf->page = alloc_page(GFP_KERNEL);
  5355. +
  5356. + if (pVmf->page)
  5357. + {
  5358. + PRINTK_VERBOSE(KERN_DEBUG "alloc page virtual %p\n", page_address(pVmf->page));
  5359. + }
  5360. +
  5361. + if (!pVmf->page)
  5362. + {
  5363. + PRINTK(KERN_ERR "vma fault oom (%s %d)\n", current->comm, current->pid);
  5364. + return VM_FAULT_OOM;
  5365. + }
  5366. + else
  5367. + {
  5368. + struct VmaPageList *pVmaList;
  5369. +
  5370. + get_page(pVmf->page);
  5371. + g_trackedPages++;
  5372. +
  5373. + //find our vma in the list
  5374. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  5375. +
  5376. + if (pVmaList)
  5377. + {
  5378. + PRINTK_VERBOSE(KERN_DEBUG "vma found (%s %d)\n", current->comm, current->pid);
  5379. +
  5380. + if (pVmaList->m_pPageTail->m_used == PAGES_PER_LIST)
  5381. + {
  5382. + PRINTK_VERBOSE(KERN_DEBUG "making new page list (%s %d)\n", current->comm, current->pid);
  5383. + //making a new page list
  5384. + pVmaList->m_pPageTail->m_pNext = (struct PageList *)kmalloc(sizeof(struct PageList), GFP_KERNEL);
  5385. + if (!pVmaList->m_pPageTail->m_pNext)
  5386. + return -ENOMEM;
  5387. +
  5388. + //update the tail pointer
  5389. + pVmaList->m_pPageTail = pVmaList->m_pPageTail->m_pNext;
  5390. + pVmaList->m_pPageTail->m_used = 0;
  5391. + pVmaList->m_pPageTail->m_pNext = 0;
  5392. + }
  5393. +
  5394. + PRINTK_VERBOSE(KERN_DEBUG "adding page to list (%s %d)\n", current->comm, current->pid);
  5395. +
  5396. + pVmaList->m_pPageTail->m_pPages[pVmaList->m_pPageTail->m_used] = pVmf->page;
  5397. + pVmaList->m_pPageTail->m_used++;
  5398. + }
  5399. + else
  5400. + PRINTK(KERN_ERR "returned page for vma we don\'t know %p (%s %d)\n", pVma, current->comm, current->pid);
  5401. +
  5402. + return 0;
  5403. + }
  5404. +}
  5405. +
  5406. +/****** GENERIC FUNCTIONS ******/
  5407. +static int __init dmaer_init(void)
  5408. +{
  5409. + int result = alloc_chrdev_region(&g_majorMinor, 0, 1, "dmaer");
  5410. + if (result < 0)
  5411. + {
  5412. + PRINTK(KERN_ERR "unable to get major device number\n");
  5413. + return result;
  5414. + }
  5415. + else
  5416. + PRINTK(KERN_DEBUG "major device number %d\n", MAJOR(g_majorMinor));
  5417. +
  5418. + PRINTK(KERN_DEBUG "vma list size %d, page list size %d, page size %ld\n",
  5419. + sizeof(struct VmaPageList), sizeof(struct PageList), PAGE_SIZE);
  5420. +
  5421. + //get a dma channel to work with
  5422. + result = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST, (void **)&g_pDmaChanBase, &g_dmaIrq);
  5423. +
  5424. + //uncomment to force to channel 0
  5425. + //result = 0;
  5426. + //g_pDmaChanBase = 0xce808000;
  5427. +
  5428. + if (result < 0)
  5429. + {
  5430. + PRINTK(KERN_ERR "failed to allocate dma channel\n");
  5431. + cdev_del(&g_cDev);
  5432. + unregister_chrdev_region(g_majorMinor, 1);
  5433. + }
  5434. +
  5435. + //reset the channel
  5436. + PRINTK(KERN_DEBUG "allocated dma channel %d (%p), initial state %08x\n", result, g_pDmaChanBase, *g_pDmaChanBase);
  5437. + *g_pDmaChanBase = 1 << 31;
  5438. + PRINTK(KERN_DEBUG "post-reset %08x\n", *g_pDmaChanBase);
  5439. +
  5440. + g_dmaChan = result;
  5441. +
  5442. + //clear the cache stats
  5443. + g_cacheHit = 0;
  5444. + g_cacheMiss = 0;
  5445. +
  5446. + //register our device - after this we are go go go
  5447. + cdev_init(&g_cDev, &g_fOps);
  5448. + g_cDev.owner = THIS_MODULE;
  5449. + g_cDev.ops = &g_fOps;
  5450. +
  5451. + result = cdev_add(&g_cDev, g_majorMinor, 1);
  5452. + if (result < 0)
  5453. + {
  5454. + PRINTK(KERN_ERR "failed to add character device\n");
  5455. + unregister_chrdev_region(g_majorMinor, 1);
  5456. + bcm_dma_chan_free(g_dmaChan);
  5457. + return result;
  5458. + }
  5459. +
  5460. + return 0;
  5461. +}
  5462. +
  5463. +static void __exit dmaer_exit(void)
  5464. +{
  5465. + PRINTK(KERN_INFO "closing dmaer device, cache stats: %d hits %d misses\n", g_cacheHit, g_cacheMiss);
  5466. + //unregister the device
  5467. + cdev_del(&g_cDev);
  5468. + unregister_chrdev_region(g_majorMinor, 1);
  5469. + //free the dma channel
  5470. + bcm_dma_chan_free(g_dmaChan);
  5471. +}
  5472. +
  5473. +MODULE_LICENSE("Dual BSD/GPL");
  5474. +MODULE_AUTHOR("Simon Hall");
  5475. +module_init(dmaer_init);
  5476. +module_exit(dmaer_exit);
  5477. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/arm_control.h linux-3.12.11/arch/arm/mach-bcm2708/include/mach/arm_control.h
  5478. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/arm_control.h 1970-01-01 01:00:00.000000000 +0100
  5479. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/arm_control.h 2014-02-18 11:52:14.000000000 +0100
  5480. @@ -0,0 +1,419 @@
  5481. +/*
  5482. + * linux/arch/arm/mach-bcm2708/arm_control.h
  5483. + *
  5484. + * Copyright (C) 2010 Broadcom
  5485. + *
  5486. + * This program is free software; you can redistribute it and/or modify
  5487. + * it under the terms of the GNU General Public License as published by
  5488. + * the Free Software Foundation; either version 2 of the License, or
  5489. + * (at your option) any later version.
  5490. + *
  5491. + * This program is distributed in the hope that it will be useful,
  5492. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5493. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5494. + * GNU General Public License for more details.
  5495. + *
  5496. + * You should have received a copy of the GNU General Public License
  5497. + * along with this program; if not, write to the Free Software
  5498. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5499. + */
  5500. +
  5501. +#ifndef __BCM2708_ARM_CONTROL_H
  5502. +#define __BCM2708_ARM_CONTROL_H
  5503. +
  5504. +/*
  5505. + * Definitions and addresses for the ARM CONTROL logic
  5506. + * This file is manually generated.
  5507. + */
  5508. +
  5509. +#define ARM_BASE 0x7E00B000
  5510. +
  5511. +/* Basic configuration */
  5512. +#define ARM_CONTROL0 HW_REGISTER_RW(ARM_BASE+0x000)
  5513. +#define ARM_C0_SIZ128M 0x00000000
  5514. +#define ARM_C0_SIZ256M 0x00000001
  5515. +#define ARM_C0_SIZ512M 0x00000002
  5516. +#define ARM_C0_SIZ1G 0x00000003
  5517. +#define ARM_C0_BRESP0 0x00000000
  5518. +#define ARM_C0_BRESP1 0x00000004
  5519. +#define ARM_C0_BRESP2 0x00000008
  5520. +#define ARM_C0_BOOTHI 0x00000010
  5521. +#define ARM_C0_UNUSED05 0x00000020 /* free */
  5522. +#define ARM_C0_FULLPERI 0x00000040
  5523. +#define ARM_C0_UNUSED78 0x00000180 /* free */
  5524. +#define ARM_C0_JTAGMASK 0x00000E00
  5525. +#define ARM_C0_JTAGOFF 0x00000000
  5526. +#define ARM_C0_JTAGBASH 0x00000800 /* Debug on GPIO off */
  5527. +#define ARM_C0_JTAGGPIO 0x00000C00 /* Debug on GPIO on */
  5528. +#define ARM_C0_APROTMSK 0x0000F000
  5529. +#define ARM_C0_DBG0SYNC 0x00010000 /* VPU0 halt sync */
  5530. +#define ARM_C0_DBG1SYNC 0x00020000 /* VPU1 halt sync */
  5531. +#define ARM_C0_SWDBGREQ 0x00040000 /* HW debug request */
  5532. +#define ARM_C0_PASSHALT 0x00080000 /* ARM halt passed to debugger */
  5533. +#define ARM_C0_PRIO_PER 0x00F00000 /* per priority mask */
  5534. +#define ARM_C0_PRIO_L2 0x0F000000
  5535. +#define ARM_C0_PRIO_UC 0xF0000000
  5536. +
  5537. +#define ARM_C0_APROTPASS 0x0000A000 /* Translate 1:1 */
  5538. +#define ARM_C0_APROTUSER 0x00000000 /* Only user mode */
  5539. +#define ARM_C0_APROTSYST 0x0000F000 /* Only system mode */
  5540. +
  5541. +
  5542. +#define ARM_CONTROL1 HW_REGISTER_RW(ARM_BASE+0x440)
  5543. +#define ARM_C1_TIMER 0x00000001 /* re-route timer IRQ to VC */
  5544. +#define ARM_C1_MAIL 0x00000002 /* re-route Mail IRQ to VC */
  5545. +#define ARM_C1_BELL0 0x00000004 /* re-route Doorbell 0 to VC */
  5546. +#define ARM_C1_BELL1 0x00000008 /* re-route Doorbell 1 to VC */
  5547. +#define ARM_C1_PERSON 0x00000100 /* peripherals on */
  5548. +#define ARM_C1_REQSTOP 0x00000200 /* ASYNC bridge request stop */
  5549. +
  5550. +#define ARM_STATUS HW_REGISTER_RW(ARM_BASE+0x444)
  5551. +#define ARM_S_ACKSTOP 0x80000000 /* Bridge stopped */
  5552. +#define ARM_S_READPEND 0x000003FF /* pending reads counter */
  5553. +#define ARM_S_WRITPEND 0x000FFC00 /* pending writes counter */
  5554. +
  5555. +#define ARM_ERRHALT HW_REGISTER_RW(ARM_BASE+0x448)
  5556. +#define ARM_EH_PERIBURST 0x00000001 /* Burst write seen on peri bus */
  5557. +#define ARM_EH_ILLADDRS1 0x00000002 /* Address bits 25-27 error */
  5558. +#define ARM_EH_ILLADDRS2 0x00000004 /* Address bits 31-28 error */
  5559. +#define ARM_EH_VPU0HALT 0x00000008 /* VPU0 halted & in debug mode */
  5560. +#define ARM_EH_VPU1HALT 0x00000010 /* VPU1 halted & in debug mode */
  5561. +#define ARM_EH_ARMHALT 0x00000020 /* ARM in halted debug mode */
  5562. +
  5563. +#define ARM_ID_SECURE HW_REGISTER_RW(ARM_BASE+0x00C)
  5564. +#define ARM_ID HW_REGISTER_RW(ARM_BASE+0x44C)
  5565. +#define ARM_IDVAL 0x364D5241
  5566. +
  5567. +/* Translation memory */
  5568. +#define ARM_TRANSLATE HW_REGISTER_RW(ARM_BASE+0x100)
  5569. +/* 32 locations: 0x100.. 0x17F */
  5570. +/* 32 spare means we CAN go to 64 pages.... */
  5571. +
  5572. +
  5573. +/* Interrupts */
  5574. +#define ARM_IRQ_PEND0 HW_REGISTER_RW(ARM_BASE+0x200) /* Top IRQ bits */
  5575. +#define ARM_I0_TIMER 0x00000001 /* timer IRQ */
  5576. +#define ARM_I0_MAIL 0x00000002 /* Mail IRQ */
  5577. +#define ARM_I0_BELL0 0x00000004 /* Doorbell 0 */
  5578. +#define ARM_I0_BELL1 0x00000008 /* Doorbell 1 */
  5579. +#define ARM_I0_BANK1 0x00000100 /* Bank1 IRQ */
  5580. +#define ARM_I0_BANK2 0x00000200 /* Bank2 IRQ */
  5581. +
  5582. +#define ARM_IRQ_PEND1 HW_REGISTER_RW(ARM_BASE+0x204) /* All bank1 IRQ bits */
  5583. +/* todo: all I1_interrupt sources */
  5584. +#define ARM_IRQ_PEND2 HW_REGISTER_RW(ARM_BASE+0x208) /* All bank2 IRQ bits */
  5585. +/* todo: all I2_interrupt sources */
  5586. +
  5587. +#define ARM_IRQ_FAST HW_REGISTER_RW(ARM_BASE+0x20C) /* FIQ control */
  5588. +#define ARM_IF_INDEX 0x0000007F /* FIQ select */
  5589. +#define ARM_IF_ENABLE 0x00000080 /* FIQ enable */
  5590. +#define ARM_IF_VCMASK 0x0000003F /* FIQ = (index from VC source) */
  5591. +#define ARM_IF_TIMER 0x00000040 /* FIQ = ARM timer */
  5592. +#define ARM_IF_MAIL 0x00000041 /* FIQ = ARM Mail */
  5593. +#define ARM_IF_BELL0 0x00000042 /* FIQ = ARM Doorbell 0 */
  5594. +#define ARM_IF_BELL1 0x00000043 /* FIQ = ARM Doorbell 1 */
  5595. +#define ARM_IF_VP0HALT 0x00000044 /* FIQ = VPU0 Halt seen */
  5596. +#define ARM_IF_VP1HALT 0x00000045 /* FIQ = VPU1 Halt seen */
  5597. +#define ARM_IF_ILLEGAL 0x00000046 /* FIQ = Illegal access seen */
  5598. +
  5599. +#define ARM_IRQ_ENBL1 HW_REGISTER_RW(ARM_BASE+0x210) /* Bank1 enable bits */
  5600. +#define ARM_IRQ_ENBL2 HW_REGISTER_RW(ARM_BASE+0x214) /* Bank2 enable bits */
  5601. +#define ARM_IRQ_ENBL3 HW_REGISTER_RW(ARM_BASE+0x218) /* ARM irqs enable bits */
  5602. +#define ARM_IRQ_DIBL1 HW_REGISTER_RW(ARM_BASE+0x21C) /* Bank1 disable bits */
  5603. +#define ARM_IRQ_DIBL2 HW_REGISTER_RW(ARM_BASE+0x220) /* Bank2 disable bits */
  5604. +#define ARM_IRQ_DIBL3 HW_REGISTER_RW(ARM_BASE+0x224) /* ARM irqs disable bits */
  5605. +#define ARM_IE_TIMER 0x00000001 /* Timer IRQ */
  5606. +#define ARM_IE_MAIL 0x00000002 /* Mail IRQ */
  5607. +#define ARM_IE_BELL0 0x00000004 /* Doorbell 0 */
  5608. +#define ARM_IE_BELL1 0x00000008 /* Doorbell 1 */
  5609. +#define ARM_IE_VP0HALT 0x00000010 /* VPU0 Halt */
  5610. +#define ARM_IE_VP1HALT 0x00000020 /* VPU1 Halt */
  5611. +#define ARM_IE_ILLEGAL 0x00000040 /* Illegal access seen */
  5612. +
  5613. +/* Timer */
  5614. +/* For reg. fields see sp804 spec. */
  5615. +#define ARM_T_LOAD HW_REGISTER_RW(ARM_BASE+0x400)
  5616. +#define ARM_T_VALUE HW_REGISTER_RW(ARM_BASE+0x404)
  5617. +#define ARM_T_CONTROL HW_REGISTER_RW(ARM_BASE+0x408)
  5618. +#define ARM_T_IRQCNTL HW_REGISTER_RW(ARM_BASE+0x40C)
  5619. +#define ARM_T_RAWIRQ HW_REGISTER_RW(ARM_BASE+0x410)
  5620. +#define ARM_T_MSKIRQ HW_REGISTER_RW(ARM_BASE+0x414)
  5621. +#define ARM_T_RELOAD HW_REGISTER_RW(ARM_BASE+0x418)
  5622. +#define ARM_T_PREDIV HW_REGISTER_RW(ARM_BASE+0x41c)
  5623. +#define ARM_T_FREECNT HW_REGISTER_RW(ARM_BASE+0x420)
  5624. +
  5625. +#define TIMER_CTRL_ONESHOT (1 << 0)
  5626. +#define TIMER_CTRL_32BIT (1 << 1)
  5627. +#define TIMER_CTRL_DIV1 (0 << 2)
  5628. +#define TIMER_CTRL_DIV16 (1 << 2)
  5629. +#define TIMER_CTRL_DIV256 (2 << 2)
  5630. +#define TIMER_CTRL_IE (1 << 5)
  5631. +#define TIMER_CTRL_PERIODIC (1 << 6)
  5632. +#define TIMER_CTRL_ENABLE (1 << 7)
  5633. +#define TIMER_CTRL_DBGHALT (1 << 8)
  5634. +#define TIMER_CTRL_ENAFREE (1 << 9)
  5635. +#define TIMER_CTRL_FREEDIV_SHIFT 16)
  5636. +#define TIMER_CTRL_FREEDIV_MASK 0xff
  5637. +
  5638. +/* Semaphores, Doorbells, Mailboxes */
  5639. +#define ARM_SBM_OWN0 (ARM_BASE+0x800)
  5640. +#define ARM_SBM_OWN1 (ARM_BASE+0x900)
  5641. +#define ARM_SBM_OWN2 (ARM_BASE+0xA00)
  5642. +#define ARM_SBM_OWN3 (ARM_BASE+0xB00)
  5643. +
  5644. +/* MAILBOXES
  5645. + * Register flags are common across all
  5646. + * owner registers. See end of this section
  5647. + *
  5648. + * Semaphores, Doorbells, Mailboxes Owner 0
  5649. + *
  5650. + */
  5651. +
  5652. +#define ARM_0_SEMS HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  5653. +#define ARM_0_SEM0 HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  5654. +#define ARM_0_SEM1 HW_REGISTER_RW(ARM_SBM_OWN0+0x04)
  5655. +#define ARM_0_SEM2 HW_REGISTER_RW(ARM_SBM_OWN0+0x08)
  5656. +#define ARM_0_SEM3 HW_REGISTER_RW(ARM_SBM_OWN0+0x0C)
  5657. +#define ARM_0_SEM4 HW_REGISTER_RW(ARM_SBM_OWN0+0x10)
  5658. +#define ARM_0_SEM5 HW_REGISTER_RW(ARM_SBM_OWN0+0x14)
  5659. +#define ARM_0_SEM6 HW_REGISTER_RW(ARM_SBM_OWN0+0x18)
  5660. +#define ARM_0_SEM7 HW_REGISTER_RW(ARM_SBM_OWN0+0x1C)
  5661. +#define ARM_0_BELL0 HW_REGISTER_RW(ARM_SBM_OWN0+0x40)
  5662. +#define ARM_0_BELL1 HW_REGISTER_RW(ARM_SBM_OWN0+0x44)
  5663. +#define ARM_0_BELL2 HW_REGISTER_RW(ARM_SBM_OWN0+0x48)
  5664. +#define ARM_0_BELL3 HW_REGISTER_RW(ARM_SBM_OWN0+0x4C)
  5665. +/* MAILBOX 0 access in Owner 0 area */
  5666. +/* Some addresses should ONLY be used by owner 0 */
  5667. +#define ARM_0_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) */
  5668. +#define ARM_0_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) Normal read */
  5669. +#define ARM_0_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN0+0x90) /* none-pop read */
  5670. +#define ARM_0_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN0+0x94) /* Sender read (only LS 2 bits) */
  5671. +#define ARM_0_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN0+0x98) /* Status read */
  5672. +#define ARM_0_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0x9C) /* Config read/write */
  5673. +/* MAILBOX 1 access in Owner 0 area */
  5674. +/* Owner 0 should only WRITE to this mailbox */
  5675. +#define ARM_0_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) /* .. 0xAC (4 locations) */
  5676. +/*#define ARM_0_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) */ /* DO NOT USE THIS !!!!! */
  5677. +/*#define ARM_0_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN0+0xB0) */ /* DO NOT USE THIS !!!!! */
  5678. +/*#define ARM_0_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN0+0xB4) */ /* DO NOT USE THIS !!!!! */
  5679. +#define ARM_0_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN0+0xB8) /* Status read */
  5680. +/*#define ARM_0_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0xBC) */ /* DO NOT USE THIS !!!!! */
  5681. +/* General SEM, BELL, MAIL config/status */
  5682. +#define ARM_0_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE0) /* semaphore clear/debug register */
  5683. +#define ARM_0_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE4) /* Doorbells clear/debug register */
  5684. +#define ARM_0_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xF8) /* ALL interrupts */
  5685. +#define ARM_0_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xFC) /* IRQS pending for owner 0 */
  5686. +
  5687. +/* Semaphores, Doorbells, Mailboxes Owner 1 */
  5688. +#define ARM_1_SEMS HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  5689. +#define ARM_1_SEM0 HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  5690. +#define ARM_1_SEM1 HW_REGISTER_RW(ARM_SBM_OWN1+0x04)
  5691. +#define ARM_1_SEM2 HW_REGISTER_RW(ARM_SBM_OWN1+0x08)
  5692. +#define ARM_1_SEM3 HW_REGISTER_RW(ARM_SBM_OWN1+0x0C)
  5693. +#define ARM_1_SEM4 HW_REGISTER_RW(ARM_SBM_OWN1+0x10)
  5694. +#define ARM_1_SEM5 HW_REGISTER_RW(ARM_SBM_OWN1+0x14)
  5695. +#define ARM_1_SEM6 HW_REGISTER_RW(ARM_SBM_OWN1+0x18)
  5696. +#define ARM_1_SEM7 HW_REGISTER_RW(ARM_SBM_OWN1+0x1C)
  5697. +#define ARM_1_BELL0 HW_REGISTER_RW(ARM_SBM_OWN1+0x40)
  5698. +#define ARM_1_BELL1 HW_REGISTER_RW(ARM_SBM_OWN1+0x44)
  5699. +#define ARM_1_BELL2 HW_REGISTER_RW(ARM_SBM_OWN1+0x48)
  5700. +#define ARM_1_BELL3 HW_REGISTER_RW(ARM_SBM_OWN1+0x4C)
  5701. +/* MAILBOX 0 access in Owner 0 area */
  5702. +/* Owner 1 should only WRITE to this mailbox */
  5703. +#define ARM_1_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0x80) /* .. 0x8C (4 locations) */
  5704. +/*#define ARM_1_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN1+0x80) */ /* DO NOT USE THIS !!!!! */
  5705. +/*#define ARM_1_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN1+0x90) */ /* DO NOT USE THIS !!!!! */
  5706. +/*#define ARM_1_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN1+0x94) */ /* DO NOT USE THIS !!!!! */
  5707. +#define ARM_1_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN1+0x98) /* Status read */
  5708. +/*#define ARM_1_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0x9C) */ /* DO NOT USE THIS !!!!! */
  5709. +/* MAILBOX 1 access in Owner 0 area */
  5710. +#define ARM_1_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) */
  5711. +#define ARM_1_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) Normal read */
  5712. +#define ARM_1_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN1+0xB0) /* none-pop read */
  5713. +#define ARM_1_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN1+0xB4) /* Sender read (only LS 2 bits) */
  5714. +#define ARM_1_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN1+0xB8) /* Status read */
  5715. +#define ARM_1_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0xBC)
  5716. +/* General SEM, BELL, MAIL config/status */
  5717. +#define ARM_1_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE0) /* semaphore clear/debug register */
  5718. +#define ARM_1_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE4) /* Doorbells clear/debug register */
  5719. +#define ARM_1_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xFC) /* IRQS pending for owner 1 */
  5720. +#define ARM_1_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xF8) /* ALL interrupts */
  5721. +
  5722. +/* Semaphores, Doorbells, Mailboxes Owner 2 */
  5723. +#define ARM_2_SEMS HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  5724. +#define ARM_2_SEM0 HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  5725. +#define ARM_2_SEM1 HW_REGISTER_RW(ARM_SBM_OWN2+0x04)
  5726. +#define ARM_2_SEM2 HW_REGISTER_RW(ARM_SBM_OWN2+0x08)
  5727. +#define ARM_2_SEM3 HW_REGISTER_RW(ARM_SBM_OWN2+0x0C)
  5728. +#define ARM_2_SEM4 HW_REGISTER_RW(ARM_SBM_OWN2+0x10)
  5729. +#define ARM_2_SEM5 HW_REGISTER_RW(ARM_SBM_OWN2+0x14)
  5730. +#define ARM_2_SEM6 HW_REGISTER_RW(ARM_SBM_OWN2+0x18)
  5731. +#define ARM_2_SEM7 HW_REGISTER_RW(ARM_SBM_OWN2+0x1C)
  5732. +#define ARM_2_BELL0 HW_REGISTER_RW(ARM_SBM_OWN2+0x40)
  5733. +#define ARM_2_BELL1 HW_REGISTER_RW(ARM_SBM_OWN2+0x44)
  5734. +#define ARM_2_BELL2 HW_REGISTER_RW(ARM_SBM_OWN2+0x48)
  5735. +#define ARM_2_BELL3 HW_REGISTER_RW(ARM_SBM_OWN2+0x4C)
  5736. +/* MAILBOX 0 access in Owner 2 area */
  5737. +/* Owner 2 should only WRITE to this mailbox */
  5738. +#define ARM_2_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0x80) /* .. 0x8C (4 locations) */
  5739. +/*#define ARM_2_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN2+0x80) */ /* DO NOT USE THIS !!!!! */
  5740. +/*#define ARM_2_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN2+0x90) */ /* DO NOT USE THIS !!!!! */
  5741. +/*#define ARM_2_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN2+0x94) */ /* DO NOT USE THIS !!!!! */
  5742. +#define ARM_2_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN2+0x98) /* Status read */
  5743. +/*#define ARM_2_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0x9C) */ /* DO NOT USE THIS !!!!! */
  5744. +/* MAILBOX 1 access in Owner 2 area */
  5745. +/* Owner 2 should only WRITE to this mailbox */
  5746. +#define ARM_2_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) /* .. 0xAC (4 locations) */
  5747. +/*#define ARM_2_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) */ /* DO NOT USE THIS !!!!! */
  5748. +/*#define ARM_2_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN2+0xB0) */ /* DO NOT USE THIS !!!!! */
  5749. +/*#define ARM_2_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN2+0xB4) */ /* DO NOT USE THIS !!!!! */
  5750. +#define ARM_2_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN2+0xB8) /* Status read */
  5751. +/*#define ARM_2_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0xBC) */ /* DO NOT USE THIS !!!!! */
  5752. +/* General SEM, BELL, MAIL config/status */
  5753. +#define ARM_2_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE0) /* semaphore clear/debug register */
  5754. +#define ARM_2_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE4) /* Doorbells clear/debug register */
  5755. +#define ARM_2_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xFC) /* IRQS pending for owner 2 */
  5756. +#define ARM_2_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xF8) /* ALL interrupts */
  5757. +
  5758. +/* Semaphores, Doorbells, Mailboxes Owner 3 */
  5759. +#define ARM_3_SEMS HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  5760. +#define ARM_3_SEM0 HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  5761. +#define ARM_3_SEM1 HW_REGISTER_RW(ARM_SBM_OWN3+0x04)
  5762. +#define ARM_3_SEM2 HW_REGISTER_RW(ARM_SBM_OWN3+0x08)
  5763. +#define ARM_3_SEM3 HW_REGISTER_RW(ARM_SBM_OWN3+0x0C)
  5764. +#define ARM_3_SEM4 HW_REGISTER_RW(ARM_SBM_OWN3+0x10)
  5765. +#define ARM_3_SEM5 HW_REGISTER_RW(ARM_SBM_OWN3+0x14)
  5766. +#define ARM_3_SEM6 HW_REGISTER_RW(ARM_SBM_OWN3+0x18)
  5767. +#define ARM_3_SEM7 HW_REGISTER_RW(ARM_SBM_OWN3+0x1C)
  5768. +#define ARM_3_BELL0 HW_REGISTER_RW(ARM_SBM_OWN3+0x40)
  5769. +#define ARM_3_BELL1 HW_REGISTER_RW(ARM_SBM_OWN3+0x44)
  5770. +#define ARM_3_BELL2 HW_REGISTER_RW(ARM_SBM_OWN3+0x48)
  5771. +#define ARM_3_BELL3 HW_REGISTER_RW(ARM_SBM_OWN3+0x4C)
  5772. +/* MAILBOX 0 access in Owner 3 area */
  5773. +/* Owner 3 should only WRITE to this mailbox */
  5774. +#define ARM_3_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0x80) /* .. 0x8C (4 locations) */
  5775. +/*#define ARM_3_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN3+0x80) */ /* DO NOT USE THIS !!!!! */
  5776. +/*#define ARM_3_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN3+0x90) */ /* DO NOT USE THIS !!!!! */
  5777. +/*#define ARM_3_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN3+0x94) */ /* DO NOT USE THIS !!!!! */
  5778. +#define ARM_3_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN3+0x98) /* Status read */
  5779. +/*#define ARM_3_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0x9C) */ /* DO NOT USE THIS !!!!! */
  5780. +/* MAILBOX 1 access in Owner 3 area */
  5781. +/* Owner 3 should only WRITE to this mailbox */
  5782. +#define ARM_3_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) /* .. 0xAC (4 locations) */
  5783. +/*#define ARM_3_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) */ /* DO NOT USE THIS !!!!! */
  5784. +/*#define ARM_3_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN3+0xB0) */ /* DO NOT USE THIS !!!!! */
  5785. +/*#define ARM_3_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN3+0xB4) */ /* DO NOT USE THIS !!!!! */
  5786. +#define ARM_3_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN3+0xB8) /* Status read */
  5787. +/*#define ARM_3_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0xBC) */ /* DO NOT USE THIS !!!!! */
  5788. +/* General SEM, BELL, MAIL config/status */
  5789. +#define ARM_3_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE0) /* semaphore clear/debug register */
  5790. +#define ARM_3_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE4) /* Doorbells clear/debug register */
  5791. +#define ARM_3_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xFC) /* IRQS pending for owner 3 */
  5792. +#define ARM_3_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xF8) /* ALL interrupts */
  5793. +
  5794. +
  5795. +
  5796. +/* Mailbox flags. Valid for all owners */
  5797. +
  5798. +/* Mailbox status register (...0x98) */
  5799. +#define ARM_MS_FULL 0x80000000
  5800. +#define ARM_MS_EMPTY 0x40000000
  5801. +#define ARM_MS_LEVEL 0x400000FF /* Max. value depdnds on mailbox depth parameter */
  5802. +
  5803. +/* MAILBOX config/status register (...0x9C) */
  5804. +/* ANY write to this register clears the error bits! */
  5805. +#define ARM_MC_IHAVEDATAIRQEN 0x00000001 /* mailbox irq enable: has data */
  5806. +#define ARM_MC_IHAVESPACEIRQEN 0x00000002 /* mailbox irq enable: has space */
  5807. +#define ARM_MC_OPPISEMPTYIRQEN 0x00000004 /* mailbox irq enable: Opp. is empty */
  5808. +#define ARM_MC_MAIL_CLEAR 0x00000008 /* mailbox clear write 1, then 0 */
  5809. +#define ARM_MC_IHAVEDATAIRQPEND 0x00000010 /* mailbox irq pending: has space */
  5810. +#define ARM_MC_IHAVESPACEIRQPEND 0x00000020 /* mailbox irq pending: Opp. is empty */
  5811. +#define ARM_MC_OPPISEMPTYIRQPEND 0x00000040 /* mailbox irq pending */
  5812. +/* Bit 7 is unused */
  5813. +#define ARM_MC_ERRNOOWN 0x00000100 /* error : none owner read from mailbox */
  5814. +#define ARM_MC_ERROVERFLW 0x00000200 /* error : write to fill mailbox */
  5815. +#define ARM_MC_ERRUNDRFLW 0x00000400 /* error : read from empty mailbox */
  5816. +
  5817. +/* Semaphore clear/debug register (...0xE0) */
  5818. +#define ARM_SD_OWN0 0x00000003 /* Owner of sem 0 */
  5819. +#define ARM_SD_OWN1 0x0000000C /* Owner of sem 1 */
  5820. +#define ARM_SD_OWN2 0x00000030 /* Owner of sem 2 */
  5821. +#define ARM_SD_OWN3 0x000000C0 /* Owner of sem 3 */
  5822. +#define ARM_SD_OWN4 0x00000300 /* Owner of sem 4 */
  5823. +#define ARM_SD_OWN5 0x00000C00 /* Owner of sem 5 */
  5824. +#define ARM_SD_OWN6 0x00003000 /* Owner of sem 6 */
  5825. +#define ARM_SD_OWN7 0x0000C000 /* Owner of sem 7 */
  5826. +#define ARM_SD_SEM0 0x00010000 /* Status of sem 0 */
  5827. +#define ARM_SD_SEM1 0x00020000 /* Status of sem 1 */
  5828. +#define ARM_SD_SEM2 0x00040000 /* Status of sem 2 */
  5829. +#define ARM_SD_SEM3 0x00080000 /* Status of sem 3 */
  5830. +#define ARM_SD_SEM4 0x00100000 /* Status of sem 4 */
  5831. +#define ARM_SD_SEM5 0x00200000 /* Status of sem 5 */
  5832. +#define ARM_SD_SEM6 0x00400000 /* Status of sem 6 */
  5833. +#define ARM_SD_SEM7 0x00800000 /* Status of sem 7 */
  5834. +
  5835. +/* Doorbells clear/debug register (...0xE4) */
  5836. +#define ARM_BD_OWN0 0x00000003 /* Owner of doorbell 0 */
  5837. +#define ARM_BD_OWN1 0x0000000C /* Owner of doorbell 1 */
  5838. +#define ARM_BD_OWN2 0x00000030 /* Owner of doorbell 2 */
  5839. +#define ARM_BD_OWN3 0x000000C0 /* Owner of doorbell 3 */
  5840. +#define ARM_BD_BELL0 0x00000100 /* Status of doorbell 0 */
  5841. +#define ARM_BD_BELL1 0x00000200 /* Status of doorbell 1 */
  5842. +#define ARM_BD_BELL2 0x00000400 /* Status of doorbell 2 */
  5843. +#define ARM_BD_BELL3 0x00000800 /* Status of doorbell 3 */
  5844. +
  5845. +/* MY IRQS register (...0xF8) */
  5846. +#define ARM_MYIRQ_BELL 0x00000001 /* This owner has a doorbell IRQ */
  5847. +#define ARM_MYIRQ_MAIL 0x00000002 /* This owner has a mailbox IRQ */
  5848. +
  5849. +/* ALL IRQS register (...0xF8) */
  5850. +#define ARM_AIS_BELL0 0x00000001 /* Doorbell 0 IRQ pending */
  5851. +#define ARM_AIS_BELL1 0x00000002 /* Doorbell 1 IRQ pending */
  5852. +#define ARM_AIS_BELL2 0x00000004 /* Doorbell 2 IRQ pending */
  5853. +#define ARM_AIS_BELL3 0x00000008 /* Doorbell 3 IRQ pending */
  5854. +#define ARM_AIS0_HAVEDATA 0x00000010 /* MAIL 0 has data IRQ pending */
  5855. +#define ARM_AIS0_HAVESPAC 0x00000020 /* MAIL 0 has space IRQ pending */
  5856. +#define ARM_AIS0_OPPEMPTY 0x00000040 /* MAIL 0 opposite is empty IRQ */
  5857. +#define ARM_AIS1_HAVEDATA 0x00000080 /* MAIL 1 has data IRQ pending */
  5858. +#define ARM_AIS1_HAVESPAC 0x00000100 /* MAIL 1 has space IRQ pending */
  5859. +#define ARM_AIS1_OPPEMPTY 0x00000200 /* MAIL 1 opposite is empty IRQ */
  5860. +/* Note that bell-0, bell-1 and MAIL0 IRQ go only to the ARM */
  5861. +/* Whilst that bell-2, bell-3 and MAIL1 IRQ go only to the VC */
  5862. +/* */
  5863. +/* ARM JTAG BASH */
  5864. +/* */
  5865. +#define AJB_BASE 0x7e2000c0
  5866. +
  5867. +#define AJBCONF HW_REGISTER_RW(AJB_BASE+0x00)
  5868. +#define AJB_BITS0 0x000000
  5869. +#define AJB_BITS4 0x000004
  5870. +#define AJB_BITS8 0x000008
  5871. +#define AJB_BITS12 0x00000C
  5872. +#define AJB_BITS16 0x000010
  5873. +#define AJB_BITS20 0x000014
  5874. +#define AJB_BITS24 0x000018
  5875. +#define AJB_BITS28 0x00001C
  5876. +#define AJB_BITS32 0x000020
  5877. +#define AJB_BITS34 0x000022
  5878. +#define AJB_OUT_MS 0x000040
  5879. +#define AJB_OUT_LS 0x000000
  5880. +#define AJB_INV_CLK 0x000080
  5881. +#define AJB_D0_RISE 0x000100
  5882. +#define AJB_D0_FALL 0x000000
  5883. +#define AJB_D1_RISE 0x000200
  5884. +#define AJB_D1_FALL 0x000000
  5885. +#define AJB_IN_RISE 0x000400
  5886. +#define AJB_IN_FALL 0x000000
  5887. +#define AJB_ENABLE 0x000800
  5888. +#define AJB_HOLD0 0x000000
  5889. +#define AJB_HOLD1 0x001000
  5890. +#define AJB_HOLD2 0x002000
  5891. +#define AJB_HOLD3 0x003000
  5892. +#define AJB_RESETN 0x004000
  5893. +#define AJB_CLKSHFT 16
  5894. +#define AJB_BUSY 0x80000000
  5895. +#define AJBTMS HW_REGISTER_RW(AJB_BASE+0x04)
  5896. +#define AJBTDI HW_REGISTER_RW(AJB_BASE+0x08)
  5897. +#define AJBTDO HW_REGISTER_RW(AJB_BASE+0x0c)
  5898. +
  5899. +#endif
  5900. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/arm_power.h linux-3.12.11/arch/arm/mach-bcm2708/include/mach/arm_power.h
  5901. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/arm_power.h 1970-01-01 01:00:00.000000000 +0100
  5902. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/arm_power.h 2014-02-18 11:52:14.000000000 +0100
  5903. @@ -0,0 +1,60 @@
  5904. +/*
  5905. + * linux/arch/arm/mach-bcm2708/include/mach/arm_power.h
  5906. + *
  5907. + * Copyright (C) 2010 Broadcom
  5908. + *
  5909. + * This program is free software; you can redistribute it and/or modify
  5910. + * it under the terms of the GNU General Public License as published by
  5911. + * the Free Software Foundation; either version 2 of the License, or
  5912. + * (at your option) any later version.
  5913. + *
  5914. + * This program is distributed in the hope that it will be useful,
  5915. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5916. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5917. + * GNU General Public License for more details.
  5918. + *
  5919. + * You should have received a copy of the GNU General Public License
  5920. + * along with this program; if not, write to the Free Software
  5921. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5922. + */
  5923. +
  5924. +#ifndef _ARM_POWER_H
  5925. +#define _ARM_POWER_H
  5926. +
  5927. +/* Use meaningful names on each side */
  5928. +#ifdef __VIDEOCORE__
  5929. +#define PREFIX(x) ARM_##x
  5930. +#else
  5931. +#define PREFIX(x) BCM_##x
  5932. +#endif
  5933. +
  5934. +enum {
  5935. + PREFIX(POWER_SDCARD_BIT),
  5936. + PREFIX(POWER_UART_BIT),
  5937. + PREFIX(POWER_MINIUART_BIT),
  5938. + PREFIX(POWER_USB_BIT),
  5939. + PREFIX(POWER_I2C0_BIT),
  5940. + PREFIX(POWER_I2C1_BIT),
  5941. + PREFIX(POWER_I2C2_BIT),
  5942. + PREFIX(POWER_SPI_BIT),
  5943. + PREFIX(POWER_CCP2TX_BIT),
  5944. +
  5945. + PREFIX(POWER_MAX)
  5946. +};
  5947. +
  5948. +enum {
  5949. + PREFIX(POWER_SDCARD) = (1 << PREFIX(POWER_SDCARD_BIT)),
  5950. + PREFIX(POWER_UART) = (1 << PREFIX(POWER_UART_BIT)),
  5951. + PREFIX(POWER_MINIUART) = (1 << PREFIX(POWER_MINIUART_BIT)),
  5952. + PREFIX(POWER_USB) = (1 << PREFIX(POWER_USB_BIT)),
  5953. + PREFIX(POWER_I2C0) = (1 << PREFIX(POWER_I2C0_BIT)),
  5954. + PREFIX(POWER_I2C1_MASK) = (1 << PREFIX(POWER_I2C1_BIT)),
  5955. + PREFIX(POWER_I2C2_MASK) = (1 << PREFIX(POWER_I2C2_BIT)),
  5956. + PREFIX(POWER_SPI_MASK) = (1 << PREFIX(POWER_SPI_BIT)),
  5957. + PREFIX(POWER_CCP2TX_MASK) = (1 << PREFIX(POWER_CCP2TX_BIT)),
  5958. +
  5959. + PREFIX(POWER_MASK) = (1 << PREFIX(POWER_MAX)) - 1,
  5960. + PREFIX(POWER_NONE) = 0
  5961. +};
  5962. +
  5963. +#endif
  5964. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/clkdev.h linux-3.12.11/arch/arm/mach-bcm2708/include/mach/clkdev.h
  5965. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/clkdev.h 1970-01-01 01:00:00.000000000 +0100
  5966. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/clkdev.h 2014-02-18 11:52:14.000000000 +0100
  5967. @@ -0,0 +1,7 @@
  5968. +#ifndef __ASM_MACH_CLKDEV_H
  5969. +#define __ASM_MACH_CLKDEV_H
  5970. +
  5971. +#define __clk_get(clk) ({ 1; })
  5972. +#define __clk_put(clk) do { } while (0)
  5973. +
  5974. +#endif
  5975. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/debug-macro.S linux-3.12.11/arch/arm/mach-bcm2708/include/mach/debug-macro.S
  5976. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/debug-macro.S 1970-01-01 01:00:00.000000000 +0100
  5977. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/debug-macro.S 2014-02-18 11:52:14.000000000 +0100
  5978. @@ -0,0 +1,22 @@
  5979. +/* arch/arm/mach-bcm2708/include/mach/debug-macro.S
  5980. + *
  5981. + * Debugging macro include header
  5982. + *
  5983. + * Copyright (C) 2010 Broadcom
  5984. + * Copyright (C) 1994-1999 Russell King
  5985. + * Moved from linux/arch/arm/kernel/debug.S by Ben Dooks
  5986. + *
  5987. + * This program is free software; you can redistribute it and/or modify
  5988. + * it under the terms of the GNU General Public License version 2 as
  5989. + * published by the Free Software Foundation.
  5990. + *
  5991. +*/
  5992. +
  5993. +#include <mach/platform.h>
  5994. +
  5995. + .macro addruart, rp, rv, tmp
  5996. + ldr \rp, =UART0_BASE
  5997. + ldr \rv, =IO_ADDRESS(UART0_BASE)
  5998. + .endm
  5999. +
  6000. +#include <debug/pl01x.S>
  6001. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/dma.h linux-3.12.11/arch/arm/mach-bcm2708/include/mach/dma.h
  6002. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/dma.h 1970-01-01 01:00:00.000000000 +0100
  6003. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/dma.h 2014-02-18 11:52:14.000000000 +0100
  6004. @@ -0,0 +1,88 @@
  6005. +/*
  6006. + * linux/arch/arm/mach-bcm2708/include/mach/dma.h
  6007. + *
  6008. + * Copyright (C) 2010 Broadcom
  6009. + *
  6010. + * This program is free software; you can redistribute it and/or modify
  6011. + * it under the terms of the GNU General Public License version 2 as
  6012. + * published by the Free Software Foundation.
  6013. + */
  6014. +
  6015. +
  6016. +#ifndef _MACH_BCM2708_DMA_H
  6017. +#define _MACH_BCM2708_DMA_H
  6018. +
  6019. +#define BCM_DMAMAN_DRIVER_NAME "bcm2708_dma"
  6020. +
  6021. +/* DMA CS Control and Status bits */
  6022. +#define BCM2708_DMA_ACTIVE (1 << 0)
  6023. +#define BCM2708_DMA_INT (1 << 2)
  6024. +#define BCM2708_DMA_ISPAUSED (1 << 4) /* Pause requested or not active */
  6025. +#define BCM2708_DMA_ISHELD (1 << 5) /* Is held by DREQ flow control */
  6026. +#define BCM2708_DMA_ERR (1 << 8)
  6027. +#define BCM2708_DMA_ABORT (1 << 30) /* stop current CB, go to next, WO */
  6028. +#define BCM2708_DMA_RESET (1 << 31) /* WO, self clearing */
  6029. +
  6030. +/* DMA control block "info" field bits */
  6031. +#define BCM2708_DMA_INT_EN (1 << 0)
  6032. +#define BCM2708_DMA_TDMODE (1 << 1)
  6033. +#define BCM2708_DMA_WAIT_RESP (1 << 3)
  6034. +#define BCM2708_DMA_D_INC (1 << 4)
  6035. +#define BCM2708_DMA_D_WIDTH (1 << 5)
  6036. +#define BCM2708_DMA_D_DREQ (1 << 6)
  6037. +#define BCM2708_DMA_S_INC (1 << 8)
  6038. +#define BCM2708_DMA_S_WIDTH (1 << 9)
  6039. +#define BCM2708_DMA_S_DREQ (1 << 10)
  6040. +
  6041. +#define BCM2708_DMA_BURST(x) (((x)&0xf) << 12)
  6042. +#define BCM2708_DMA_PER_MAP(x) ((x) << 16)
  6043. +#define BCM2708_DMA_WAITS(x) (((x)&0x1f) << 21)
  6044. +
  6045. +#define BCM2708_DMA_DREQ_EMMC 11
  6046. +#define BCM2708_DMA_DREQ_SDHOST 13
  6047. +
  6048. +#define BCM2708_DMA_CS 0x00 /* Control and Status */
  6049. +#define BCM2708_DMA_ADDR 0x04
  6050. +/* the current control block appears in the following registers - read only */
  6051. +#define BCM2708_DMA_INFO 0x08
  6052. +#define BCM2708_DMA_SOURCE_AD 0x0c
  6053. +#define BCM2708_DMA_DEST_AD 0x10
  6054. +#define BCM2708_DMA_NEXTCB 0x1C
  6055. +#define BCM2708_DMA_DEBUG 0x20
  6056. +
  6057. +#define BCM2708_DMA4_CS (BCM2708_DMA_CHAN(4)+BCM2708_DMA_CS)
  6058. +#define BCM2708_DMA4_ADDR (BCM2708_DMA_CHAN(4)+BCM2708_DMA_ADDR)
  6059. +
  6060. +#define BCM2708_DMA_TDMODE_LEN(w, h) ((h) << 16 | (w))
  6061. +
  6062. +struct bcm2708_dma_cb {
  6063. + unsigned long info;
  6064. + unsigned long src;
  6065. + unsigned long dst;
  6066. + unsigned long length;
  6067. + unsigned long stride;
  6068. + unsigned long next;
  6069. + unsigned long pad[2];
  6070. +};
  6071. +
  6072. +extern int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len);
  6073. +extern void bcm_dma_start(void __iomem *dma_chan_base,
  6074. + dma_addr_t control_block);
  6075. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base);
  6076. +extern int /*rc*/ bcm_dma_abort(void __iomem *dma_chan_base);
  6077. +
  6078. +/* When listing features we can ask for when allocating DMA channels give
  6079. + those with higher priority smaller ordinal numbers */
  6080. +#define BCM_DMA_FEATURE_FAST_ORD 0
  6081. +#define BCM_DMA_FEATURE_BULK_ORD 1
  6082. +#define BCM_DMA_FEATURE_FAST (1<<BCM_DMA_FEATURE_FAST_ORD)
  6083. +#define BCM_DMA_FEATURE_BULK (1<<BCM_DMA_FEATURE_BULK_ORD)
  6084. +#define BCM_DMA_FEATURE_COUNT 2
  6085. +
  6086. +/* return channel no or -ve error */
  6087. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  6088. + void __iomem **out_dma_base, int *out_dma_irq);
  6089. +extern int bcm_dma_chan_free(int channel);
  6090. +
  6091. +
  6092. +#endif /* _MACH_BCM2708_DMA_H */
  6093. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/entry-macro.S linux-3.12.11/arch/arm/mach-bcm2708/include/mach/entry-macro.S
  6094. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/entry-macro.S 1970-01-01 01:00:00.000000000 +0100
  6095. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/entry-macro.S 2014-02-18 11:52:14.000000000 +0100
  6096. @@ -0,0 +1,69 @@
  6097. +/*
  6098. + * arch/arm/mach-bcm2708/include/mach/entry-macro.S
  6099. + *
  6100. + * Low-level IRQ helper macros for BCM2708 platforms
  6101. + *
  6102. + * Copyright (C) 2010 Broadcom
  6103. + *
  6104. + * This program is free software; you can redistribute it and/or modify
  6105. + * it under the terms of the GNU General Public License as published by
  6106. + * the Free Software Foundation; either version 2 of the License, or
  6107. + * (at your option) any later version.
  6108. + *
  6109. + * This program is distributed in the hope that it will be useful,
  6110. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6111. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6112. + * GNU General Public License for more details.
  6113. + *
  6114. + * You should have received a copy of the GNU General Public License
  6115. + * along with this program; if not, write to the Free Software
  6116. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6117. + */
  6118. +#include <mach/hardware.h>
  6119. +
  6120. + .macro disable_fiq
  6121. + .endm
  6122. +
  6123. + .macro get_irqnr_preamble, base, tmp
  6124. + ldr \base, =IO_ADDRESS(ARMCTRL_IC_BASE)
  6125. + .endm
  6126. +
  6127. + .macro arch_ret_to_user, tmp1, tmp2
  6128. + .endm
  6129. +
  6130. + .macro get_irqnr_and_base, irqnr, irqstat, base, tmp
  6131. + /* get masked status */
  6132. + ldr \irqstat, [\base, #(ARM_IRQ_PEND0 - ARMCTRL_IC_BASE)]
  6133. + mov \irqnr, #(ARM_IRQ0_BASE + 31)
  6134. + and \tmp, \irqstat, #0x300 @ save bits 8 and 9
  6135. + /* clear bits 8 and 9, and test */
  6136. + bics \irqstat, \irqstat, #0x300
  6137. + bne 1010f
  6138. +
  6139. + tst \tmp, #0x100
  6140. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND1 - ARMCTRL_IC_BASE)]
  6141. + movne \irqnr, #(ARM_IRQ1_BASE + 31)
  6142. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  6143. + bicne \irqstat, #((1<<7) | (1<<9) | (1<<10))
  6144. + bicne \irqstat, #((1<<18) | (1<<19))
  6145. + bne 1010f
  6146. +
  6147. + tst \tmp, #0x200
  6148. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND2 - ARMCTRL_IC_BASE)]
  6149. + movne \irqnr, #(ARM_IRQ2_BASE + 31)
  6150. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  6151. + bicne \irqstat, #((1<<21) | (1<<22) | (1<<23) | (1<<24) | (1<<25))
  6152. + bicne \irqstat, #((1<<30))
  6153. + beq 1020f
  6154. +
  6155. +1010:
  6156. + @ For non-zero x, LSB(x) = 31 - CLZ(x^(x-1))
  6157. + @ N.B. CLZ is an ARM5 instruction.
  6158. + sub \tmp, \irqstat, #1
  6159. + eor \irqstat, \irqstat, \tmp
  6160. + clz \tmp, \irqstat
  6161. + sub \irqnr, \tmp
  6162. +
  6163. +1020: @ EQ will be set if no irqs pending
  6164. +
  6165. + .endm
  6166. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/frc.h linux-3.12.11/arch/arm/mach-bcm2708/include/mach/frc.h
  6167. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/frc.h 1970-01-01 01:00:00.000000000 +0100
  6168. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/frc.h 2014-02-18 11:52:14.000000000 +0100
  6169. @@ -0,0 +1,38 @@
  6170. +/*
  6171. + * arch/arm/mach-bcm2708/include/mach/timex.h
  6172. + *
  6173. + * BCM2708 free running counter (timer)
  6174. + *
  6175. + * Copyright (C) 2010 Broadcom
  6176. + *
  6177. + * This program is free software; you can redistribute it and/or modify
  6178. + * it under the terms of the GNU General Public License as published by
  6179. + * the Free Software Foundation; either version 2 of the License, or
  6180. + * (at your option) any later version.
  6181. + *
  6182. + * This program is distributed in the hope that it will be useful,
  6183. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6184. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6185. + * GNU General Public License for more details.
  6186. + *
  6187. + * You should have received a copy of the GNU General Public License
  6188. + * along with this program; if not, write to the Free Software
  6189. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6190. + */
  6191. +
  6192. +#ifndef _MACH_FRC_H
  6193. +#define _MACH_FRC_H
  6194. +
  6195. +#define FRC_TICK_RATE (1000000)
  6196. +
  6197. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  6198. + (slightly faster than frc_clock_ticks63()
  6199. + */
  6200. +extern unsigned long frc_clock_ticks32(void);
  6201. +
  6202. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  6203. + * Note - top bit should be ignored (see cnt32_to_63)
  6204. + */
  6205. +extern unsigned long long frc_clock_ticks63(void);
  6206. +
  6207. +#endif
  6208. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/gpio.h linux-3.12.11/arch/arm/mach-bcm2708/include/mach/gpio.h
  6209. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/gpio.h 1970-01-01 01:00:00.000000000 +0100
  6210. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/gpio.h 2014-02-18 11:52:14.000000000 +0100
  6211. @@ -0,0 +1,17 @@
  6212. +/*
  6213. + * arch/arm/mach-bcm2708/include/mach/gpio.h
  6214. + *
  6215. + * This file is licensed under the terms of the GNU General Public
  6216. + * License version 2. This program is licensed "as is" without any
  6217. + * warranty of any kind, whether express or implied.
  6218. + */
  6219. +
  6220. +#ifndef __ASM_ARCH_GPIO_H
  6221. +#define __ASM_ARCH_GPIO_H
  6222. +
  6223. +#define ARCH_NR_GPIOS 54 // number of gpio lines
  6224. +
  6225. +#define gpio_to_irq(x) ((x) + GPIO_IRQ_START)
  6226. +#define irq_to_gpio(x) ((x) - GPIO_IRQ_START)
  6227. +
  6228. +#endif
  6229. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/hardware.h linux-3.12.11/arch/arm/mach-bcm2708/include/mach/hardware.h
  6230. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/hardware.h 1970-01-01 01:00:00.000000000 +0100
  6231. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/hardware.h 2014-02-18 11:52:14.000000000 +0100
  6232. @@ -0,0 +1,28 @@
  6233. +/*
  6234. + * arch/arm/mach-bcm2708/include/mach/hardware.h
  6235. + *
  6236. + * This file contains the hardware definitions of the BCM2708 devices.
  6237. + *
  6238. + * Copyright (C) 2010 Broadcom
  6239. + *
  6240. + * This program is free software; you can redistribute it and/or modify
  6241. + * it under the terms of the GNU General Public License as published by
  6242. + * the Free Software Foundation; either version 2 of the License, or
  6243. + * (at your option) any later version.
  6244. + *
  6245. + * This program is distributed in the hope that it will be useful,
  6246. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6247. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6248. + * GNU General Public License for more details.
  6249. + *
  6250. + * You should have received a copy of the GNU General Public License
  6251. + * along with this program; if not, write to the Free Software
  6252. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6253. + */
  6254. +#ifndef __ASM_ARCH_HARDWARE_H
  6255. +#define __ASM_ARCH_HARDWARE_H
  6256. +
  6257. +#include <asm/sizes.h>
  6258. +#include <mach/platform.h>
  6259. +
  6260. +#endif
  6261. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/io.h linux-3.12.11/arch/arm/mach-bcm2708/include/mach/io.h
  6262. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/io.h 1970-01-01 01:00:00.000000000 +0100
  6263. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/io.h 2014-02-18 11:52:14.000000000 +0100
  6264. @@ -0,0 +1,27 @@
  6265. +/*
  6266. + * arch/arm/mach-bcm2708/include/mach/io.h
  6267. + *
  6268. + * Copyright (C) 2003 ARM Limited
  6269. + *
  6270. + * This program is free software; you can redistribute it and/or modify
  6271. + * it under the terms of the GNU General Public License as published by
  6272. + * the Free Software Foundation; either version 2 of the License, or
  6273. + * (at your option) any later version.
  6274. + *
  6275. + * This program is distributed in the hope that it will be useful,
  6276. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6277. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6278. + * GNU General Public License for more details.
  6279. + *
  6280. + * You should have received a copy of the GNU General Public License
  6281. + * along with this program; if not, write to the Free Software
  6282. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6283. + */
  6284. +#ifndef __ASM_ARM_ARCH_IO_H
  6285. +#define __ASM_ARM_ARCH_IO_H
  6286. +
  6287. +#define IO_SPACE_LIMIT 0xffffffff
  6288. +
  6289. +#define __io(a) __typesafe_io(a)
  6290. +
  6291. +#endif
  6292. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/irqs.h linux-3.12.11/arch/arm/mach-bcm2708/include/mach/irqs.h
  6293. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/irqs.h 1970-01-01 01:00:00.000000000 +0100
  6294. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/irqs.h 2014-02-18 11:52:14.000000000 +0100
  6295. @@ -0,0 +1,199 @@
  6296. +/*
  6297. + * arch/arm/mach-bcm2708/include/mach/irqs.h
  6298. + *
  6299. + * Copyright (C) 2010 Broadcom
  6300. + * Copyright (C) 2003 ARM Limited
  6301. + * Copyright (C) 2000 Deep Blue Solutions Ltd.
  6302. + *
  6303. + * This program is free software; you can redistribute it and/or modify
  6304. + * it under the terms of the GNU General Public License as published by
  6305. + * the Free Software Foundation; either version 2 of the License, or
  6306. + * (at your option) any later version.
  6307. + *
  6308. + * This program is distributed in the hope that it will be useful,
  6309. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6310. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6311. + * GNU General Public License for more details.
  6312. + *
  6313. + * You should have received a copy of the GNU General Public License
  6314. + * along with this program; if not, write to the Free Software
  6315. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6316. + */
  6317. +
  6318. +#ifndef _BCM2708_IRQS_H_
  6319. +#define _BCM2708_IRQS_H_
  6320. +
  6321. +#include <mach/platform.h>
  6322. +
  6323. +/*
  6324. + * IRQ interrupts definitions are the same as the INT definitions
  6325. + * held within platform.h
  6326. + */
  6327. +#define IRQ_ARMCTRL_START 0
  6328. +#define IRQ_TIMER0 (IRQ_ARMCTRL_START + INTERRUPT_TIMER0)
  6329. +#define IRQ_TIMER1 (IRQ_ARMCTRL_START + INTERRUPT_TIMER1)
  6330. +#define IRQ_TIMER2 (IRQ_ARMCTRL_START + INTERRUPT_TIMER2)
  6331. +#define IRQ_TIMER3 (IRQ_ARMCTRL_START + INTERRUPT_TIMER3)
  6332. +#define IRQ_CODEC0 (IRQ_ARMCTRL_START + INTERRUPT_CODEC0)
  6333. +#define IRQ_CODEC1 (IRQ_ARMCTRL_START + INTERRUPT_CODEC1)
  6334. +#define IRQ_CODEC2 (IRQ_ARMCTRL_START + INTERRUPT_CODEC2)
  6335. +#define IRQ_JPEG (IRQ_ARMCTRL_START + INTERRUPT_JPEG)
  6336. +#define IRQ_ISP (IRQ_ARMCTRL_START + INTERRUPT_ISP)
  6337. +#define IRQ_USB (IRQ_ARMCTRL_START + INTERRUPT_USB)
  6338. +#define IRQ_3D (IRQ_ARMCTRL_START + INTERRUPT_3D)
  6339. +#define IRQ_TRANSPOSER (IRQ_ARMCTRL_START + INTERRUPT_TRANSPOSER)
  6340. +#define IRQ_MULTICORESYNC0 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC0)
  6341. +#define IRQ_MULTICORESYNC1 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC1)
  6342. +#define IRQ_MULTICORESYNC2 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC2)
  6343. +#define IRQ_MULTICORESYNC3 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC3)
  6344. +#define IRQ_DMA0 (IRQ_ARMCTRL_START + INTERRUPT_DMA0)
  6345. +#define IRQ_DMA1 (IRQ_ARMCTRL_START + INTERRUPT_DMA1)
  6346. +#define IRQ_DMA2 (IRQ_ARMCTRL_START + INTERRUPT_DMA2)
  6347. +#define IRQ_DMA3 (IRQ_ARMCTRL_START + INTERRUPT_DMA3)
  6348. +#define IRQ_DMA4 (IRQ_ARMCTRL_START + INTERRUPT_DMA4)
  6349. +#define IRQ_DMA5 (IRQ_ARMCTRL_START + INTERRUPT_DMA5)
  6350. +#define IRQ_DMA6 (IRQ_ARMCTRL_START + INTERRUPT_DMA6)
  6351. +#define IRQ_DMA7 (IRQ_ARMCTRL_START + INTERRUPT_DMA7)
  6352. +#define IRQ_DMA8 (IRQ_ARMCTRL_START + INTERRUPT_DMA8)
  6353. +#define IRQ_DMA9 (IRQ_ARMCTRL_START + INTERRUPT_DMA9)
  6354. +#define IRQ_DMA10 (IRQ_ARMCTRL_START + INTERRUPT_DMA10)
  6355. +#define IRQ_DMA11 (IRQ_ARMCTRL_START + INTERRUPT_DMA11)
  6356. +#define IRQ_DMA12 (IRQ_ARMCTRL_START + INTERRUPT_DMA12)
  6357. +#define IRQ_AUX (IRQ_ARMCTRL_START + INTERRUPT_AUX)
  6358. +#define IRQ_ARM (IRQ_ARMCTRL_START + INTERRUPT_ARM)
  6359. +#define IRQ_VPUDMA (IRQ_ARMCTRL_START + INTERRUPT_VPUDMA)
  6360. +#define IRQ_HOSTPORT (IRQ_ARMCTRL_START + INTERRUPT_HOSTPORT)
  6361. +#define IRQ_VIDEOSCALER (IRQ_ARMCTRL_START + INTERRUPT_VIDEOSCALER)
  6362. +#define IRQ_CCP2TX (IRQ_ARMCTRL_START + INTERRUPT_CCP2TX)
  6363. +#define IRQ_SDC (IRQ_ARMCTRL_START + INTERRUPT_SDC)
  6364. +#define IRQ_DSI0 (IRQ_ARMCTRL_START + INTERRUPT_DSI0)
  6365. +#define IRQ_AVE (IRQ_ARMCTRL_START + INTERRUPT_AVE)
  6366. +#define IRQ_CAM0 (IRQ_ARMCTRL_START + INTERRUPT_CAM0)
  6367. +#define IRQ_CAM1 (IRQ_ARMCTRL_START + INTERRUPT_CAM1)
  6368. +#define IRQ_HDMI0 (IRQ_ARMCTRL_START + INTERRUPT_HDMI0)
  6369. +#define IRQ_HDMI1 (IRQ_ARMCTRL_START + INTERRUPT_HDMI1)
  6370. +#define IRQ_PIXELVALVE1 (IRQ_ARMCTRL_START + INTERRUPT_PIXELVALVE1)
  6371. +#define IRQ_I2CSPISLV (IRQ_ARMCTRL_START + INTERRUPT_I2CSPISLV)
  6372. +#define IRQ_DSI1 (IRQ_ARMCTRL_START + INTERRUPT_DSI1)
  6373. +#define IRQ_PWA0 (IRQ_ARMCTRL_START + INTERRUPT_PWA0)
  6374. +#define IRQ_PWA1 (IRQ_ARMCTRL_START + INTERRUPT_PWA1)
  6375. +#define IRQ_CPR (IRQ_ARMCTRL_START + INTERRUPT_CPR)
  6376. +#define IRQ_SMI (IRQ_ARMCTRL_START + INTERRUPT_SMI)
  6377. +#define IRQ_GPIO0 (IRQ_ARMCTRL_START + INTERRUPT_GPIO0)
  6378. +#define IRQ_GPIO1 (IRQ_ARMCTRL_START + INTERRUPT_GPIO1)
  6379. +#define IRQ_GPIO2 (IRQ_ARMCTRL_START + INTERRUPT_GPIO2)
  6380. +#define IRQ_GPIO3 (IRQ_ARMCTRL_START + INTERRUPT_GPIO3)
  6381. +#define IRQ_I2C (IRQ_ARMCTRL_START + INTERRUPT_I2C)
  6382. +#define IRQ_SPI (IRQ_ARMCTRL_START + INTERRUPT_SPI)
  6383. +#define IRQ_I2SPCM (IRQ_ARMCTRL_START + INTERRUPT_I2SPCM)
  6384. +#define IRQ_SDIO (IRQ_ARMCTRL_START + INTERRUPT_SDIO)
  6385. +#define IRQ_UART (IRQ_ARMCTRL_START + INTERRUPT_UART)
  6386. +#define IRQ_SLIMBUS (IRQ_ARMCTRL_START + INTERRUPT_SLIMBUS)
  6387. +#define IRQ_VEC (IRQ_ARMCTRL_START + INTERRUPT_VEC)
  6388. +#define IRQ_CPG (IRQ_ARMCTRL_START + INTERRUPT_CPG)
  6389. +#define IRQ_RNG (IRQ_ARMCTRL_START + INTERRUPT_RNG)
  6390. +#define IRQ_ARASANSDIO (IRQ_ARMCTRL_START + INTERRUPT_ARASANSDIO)
  6391. +#define IRQ_AVSPMON (IRQ_ARMCTRL_START + INTERRUPT_AVSPMON)
  6392. +
  6393. +#define IRQ_ARM_TIMER (IRQ_ARMCTRL_START + INTERRUPT_ARM_TIMER)
  6394. +#define IRQ_ARM_MAILBOX (IRQ_ARMCTRL_START + INTERRUPT_ARM_MAILBOX)
  6395. +#define IRQ_ARM_DOORBELL_0 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_0)
  6396. +#define IRQ_ARM_DOORBELL_1 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_1)
  6397. +#define IRQ_VPU0_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU0_HALTED)
  6398. +#define IRQ_VPU1_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU1_HALTED)
  6399. +#define IRQ_ILLEGAL_TYPE0 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE0)
  6400. +#define IRQ_ILLEGAL_TYPE1 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE1)
  6401. +#define IRQ_PENDING1 (IRQ_ARMCTRL_START + INTERRUPT_PENDING1)
  6402. +#define IRQ_PENDING2 (IRQ_ARMCTRL_START + INTERRUPT_PENDING2)
  6403. +
  6404. +#define FIQ_START HARD_IRQS
  6405. +
  6406. +/*
  6407. + * FIQ interrupts definitions are the same as the INT definitions.
  6408. + */
  6409. +#define FIQ_TIMER0 (FIQ_START+INTERRUPT_TIMER0)
  6410. +#define FIQ_TIMER1 (FIQ_START+INTERRUPT_TIMER1)
  6411. +#define FIQ_TIMER2 (FIQ_START+INTERRUPT_TIMER2)
  6412. +#define FIQ_TIMER3 (FIQ_START+INTERRUPT_TIMER3)
  6413. +#define FIQ_CODEC0 (FIQ_START+INTERRUPT_CODEC0)
  6414. +#define FIQ_CODEC1 (FIQ_START+INTERRUPT_CODEC1)
  6415. +#define FIQ_CODEC2 (FIQ_START+INTERRUPT_CODEC2)
  6416. +#define FIQ_JPEG (FIQ_START+INTERRUPT_JPEG)
  6417. +#define FIQ_ISP (FIQ_START+INTERRUPT_ISP)
  6418. +#define FIQ_USB (FIQ_START+INTERRUPT_USB)
  6419. +#define FIQ_3D (FIQ_START+INTERRUPT_3D)
  6420. +#define FIQ_TRANSPOSER (FIQ_START+INTERRUPT_TRANSPOSER)
  6421. +#define FIQ_MULTICORESYNC0 (FIQ_START+INTERRUPT_MULTICORESYNC0)
  6422. +#define FIQ_MULTICORESYNC1 (FIQ_START+INTERRUPT_MULTICORESYNC1)
  6423. +#define FIQ_MULTICORESYNC2 (FIQ_START+INTERRUPT_MULTICORESYNC2)
  6424. +#define FIQ_MULTICORESYNC3 (FIQ_START+INTERRUPT_MULTICORESYNC3)
  6425. +#define FIQ_DMA0 (FIQ_START+INTERRUPT_DMA0)
  6426. +#define FIQ_DMA1 (FIQ_START+INTERRUPT_DMA1)
  6427. +#define FIQ_DMA2 (FIQ_START+INTERRUPT_DMA2)
  6428. +#define FIQ_DMA3 (FIQ_START+INTERRUPT_DMA3)
  6429. +#define FIQ_DMA4 (FIQ_START+INTERRUPT_DMA4)
  6430. +#define FIQ_DMA5 (FIQ_START+INTERRUPT_DMA5)
  6431. +#define FIQ_DMA6 (FIQ_START+INTERRUPT_DMA6)
  6432. +#define FIQ_DMA7 (FIQ_START+INTERRUPT_DMA7)
  6433. +#define FIQ_DMA8 (FIQ_START+INTERRUPT_DMA8)
  6434. +#define FIQ_DMA9 (FIQ_START+INTERRUPT_DMA9)
  6435. +#define FIQ_DMA10 (FIQ_START+INTERRUPT_DMA10)
  6436. +#define FIQ_DMA11 (FIQ_START+INTERRUPT_DMA11)
  6437. +#define FIQ_DMA12 (FIQ_START+INTERRUPT_DMA12)
  6438. +#define FIQ_AUX (FIQ_START+INTERRUPT_AUX)
  6439. +#define FIQ_ARM (FIQ_START+INTERRUPT_ARM)
  6440. +#define FIQ_VPUDMA (FIQ_START+INTERRUPT_VPUDMA)
  6441. +#define FIQ_HOSTPORT (FIQ_START+INTERRUPT_HOSTPORT)
  6442. +#define FIQ_VIDEOSCALER (FIQ_START+INTERRUPT_VIDEOSCALER)
  6443. +#define FIQ_CCP2TX (FIQ_START+INTERRUPT_CCP2TX)
  6444. +#define FIQ_SDC (FIQ_START+INTERRUPT_SDC)
  6445. +#define FIQ_DSI0 (FIQ_START+INTERRUPT_DSI0)
  6446. +#define FIQ_AVE (FIQ_START+INTERRUPT_AVE)
  6447. +#define FIQ_CAM0 (FIQ_START+INTERRUPT_CAM0)
  6448. +#define FIQ_CAM1 (FIQ_START+INTERRUPT_CAM1)
  6449. +#define FIQ_HDMI0 (FIQ_START+INTERRUPT_HDMI0)
  6450. +#define FIQ_HDMI1 (FIQ_START+INTERRUPT_HDMI1)
  6451. +#define FIQ_PIXELVALVE1 (FIQ_START+INTERRUPT_PIXELVALVE1)
  6452. +#define FIQ_I2CSPISLV (FIQ_START+INTERRUPT_I2CSPISLV)
  6453. +#define FIQ_DSI1 (FIQ_START+INTERRUPT_DSI1)
  6454. +#define FIQ_PWA0 (FIQ_START+INTERRUPT_PWA0)
  6455. +#define FIQ_PWA1 (FIQ_START+INTERRUPT_PWA1)
  6456. +#define FIQ_CPR (FIQ_START+INTERRUPT_CPR)
  6457. +#define FIQ_SMI (FIQ_START+INTERRUPT_SMI)
  6458. +#define FIQ_GPIO0 (FIQ_START+INTERRUPT_GPIO0)
  6459. +#define FIQ_GPIO1 (FIQ_START+INTERRUPT_GPIO1)
  6460. +#define FIQ_GPIO2 (FIQ_START+INTERRUPT_GPIO2)
  6461. +#define FIQ_GPIO3 (FIQ_START+INTERRUPT_GPIO3)
  6462. +#define FIQ_I2C (FIQ_START+INTERRUPT_I2C)
  6463. +#define FIQ_SPI (FIQ_START+INTERRUPT_SPI)
  6464. +#define FIQ_I2SPCM (FIQ_START+INTERRUPT_I2SPCM)
  6465. +#define FIQ_SDIO (FIQ_START+INTERRUPT_SDIO)
  6466. +#define FIQ_UART (FIQ_START+INTERRUPT_UART)
  6467. +#define FIQ_SLIMBUS (FIQ_START+INTERRUPT_SLIMBUS)
  6468. +#define FIQ_VEC (FIQ_START+INTERRUPT_VEC)
  6469. +#define FIQ_CPG (FIQ_START+INTERRUPT_CPG)
  6470. +#define FIQ_RNG (FIQ_START+INTERRUPT_RNG)
  6471. +#define FIQ_ARASANSDIO (FIQ_START+INTERRUPT_ARASANSDIO)
  6472. +#define FIQ_AVSPMON (FIQ_START+INTERRUPT_AVSPMON)
  6473. +
  6474. +#define FIQ_ARM_TIMER (FIQ_START+INTERRUPT_ARM_TIMER)
  6475. +#define FIQ_ARM_MAILBOX (FIQ_START+INTERRUPT_ARM_MAILBOX)
  6476. +#define FIQ_ARM_DOORBELL_0 (FIQ_START+INTERRUPT_ARM_DOORBELL_0)
  6477. +#define FIQ_ARM_DOORBELL_1 (FIQ_START+INTERRUPT_ARM_DOORBELL_1)
  6478. +#define FIQ_VPU0_HALTED (FIQ_START+INTERRUPT_VPU0_HALTED)
  6479. +#define FIQ_VPU1_HALTED (FIQ_START+INTERRUPT_VPU1_HALTED)
  6480. +#define FIQ_ILLEGAL_TYPE0 (FIQ_START+INTERRUPT_ILLEGAL_TYPE0)
  6481. +#define FIQ_ILLEGAL_TYPE1 (FIQ_START+INTERRUPT_ILLEGAL_TYPE1)
  6482. +#define FIQ_PENDING1 (FIQ_START+INTERRUPT_PENDING1)
  6483. +#define FIQ_PENDING2 (FIQ_START+INTERRUPT_PENDING2)
  6484. +
  6485. +#define GPIO_IRQ_START (HARD_IRQS + FIQ_IRQS)
  6486. +
  6487. +#define HARD_IRQS (64 + 21)
  6488. +#define FIQ_IRQS (64 + 21)
  6489. +#define GPIO_IRQS (32*5)
  6490. +
  6491. +#define NR_IRQS HARD_IRQS+FIQ_IRQS+GPIO_IRQS
  6492. +
  6493. +
  6494. +#endif /* _BCM2708_IRQS_H_ */
  6495. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/memory.h linux-3.12.11/arch/arm/mach-bcm2708/include/mach/memory.h
  6496. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/memory.h 1970-01-01 01:00:00.000000000 +0100
  6497. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/memory.h 2014-02-18 11:52:14.000000000 +0100
  6498. @@ -0,0 +1,57 @@
  6499. +/*
  6500. + * arch/arm/mach-bcm2708/include/mach/memory.h
  6501. + *
  6502. + * Copyright (C) 2010 Broadcom
  6503. + *
  6504. + * This program is free software; you can redistribute it and/or modify
  6505. + * it under the terms of the GNU General Public License as published by
  6506. + * the Free Software Foundation; either version 2 of the License, or
  6507. + * (at your option) any later version.
  6508. + *
  6509. + * This program is distributed in the hope that it will be useful,
  6510. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6511. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6512. + * GNU General Public License for more details.
  6513. + *
  6514. + * You should have received a copy of the GNU General Public License
  6515. + * along with this program; if not, write to the Free Software
  6516. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6517. + */
  6518. +#ifndef __ASM_ARCH_MEMORY_H
  6519. +#define __ASM_ARCH_MEMORY_H
  6520. +
  6521. +/* Memory overview:
  6522. +
  6523. + [ARMcore] <--virtual addr-->
  6524. + [ARMmmu] <--physical addr-->
  6525. + [GERTmap] <--bus add-->
  6526. + [VCperiph]
  6527. +
  6528. +*/
  6529. +
  6530. +/*
  6531. + * Physical DRAM offset.
  6532. + */
  6533. +#define PLAT_PHYS_OFFSET UL(0x00000000)
  6534. +#define VC_ARMMEM_OFFSET UL(0x00000000) /* offset in VC of ARM memory */
  6535. +
  6536. +#ifdef CONFIG_BCM2708_NOL2CACHE
  6537. + #define _REAL_BUS_OFFSET UL(0xC0000000) /* don't use L1 or L2 caches */
  6538. +#else
  6539. + #define _REAL_BUS_OFFSET UL(0x40000000) /* use L2 cache */
  6540. +#endif
  6541. +
  6542. +/* We're using the memory at 64M in the VideoCore for Linux - this adjustment
  6543. + * will provide the offset into this area as well as setting the bits that
  6544. + * stop the L1 and L2 cache from being used
  6545. + *
  6546. + * WARNING: this only works because the ARM is given memory at a fixed location
  6547. + * (ARMMEM_OFFSET)
  6548. + */
  6549. +#define BUS_OFFSET (VC_ARMMEM_OFFSET + _REAL_BUS_OFFSET)
  6550. +#define __virt_to_bus(x) ((x) + (BUS_OFFSET - PAGE_OFFSET))
  6551. +#define __bus_to_virt(x) ((x) - (BUS_OFFSET - PAGE_OFFSET))
  6552. +#define __pfn_to_bus(x) (__pfn_to_phys(x) + (BUS_OFFSET - PLAT_PHYS_OFFSET))
  6553. +#define __bus_to_pfn(x) __phys_to_pfn((x) - (BUS_OFFSET - PLAT_PHYS_OFFSET))
  6554. +
  6555. +#endif
  6556. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/platform.h linux-3.12.11/arch/arm/mach-bcm2708/include/mach/platform.h
  6557. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/platform.h 1970-01-01 01:00:00.000000000 +0100
  6558. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/platform.h 2014-02-18 11:52:14.000000000 +0100
  6559. @@ -0,0 +1,228 @@
  6560. +/*
  6561. + * arch/arm/mach-bcm2708/include/mach/platform.h
  6562. + *
  6563. + * Copyright (C) 2010 Broadcom
  6564. + *
  6565. + * This program is free software; you can redistribute it and/or modify
  6566. + * it under the terms of the GNU General Public License as published by
  6567. + * the Free Software Foundation; either version 2 of the License, or
  6568. + * (at your option) any later version.
  6569. + *
  6570. + * This program is distributed in the hope that it will be useful,
  6571. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6572. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6573. + * GNU General Public License for more details.
  6574. + *
  6575. + * You should have received a copy of the GNU General Public License
  6576. + * along with this program; if not, write to the Free Software
  6577. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6578. + */
  6579. +
  6580. +#ifndef _BCM2708_PLATFORM_H
  6581. +#define _BCM2708_PLATFORM_H
  6582. +
  6583. +
  6584. +/* macros to get at IO space when running virtually */
  6585. +#define IO_ADDRESS(x) (((x) & 0x0fffffff) + (((x) >> 4) & 0x0f000000) + 0xf0000000)
  6586. +
  6587. +#define __io_address(n) IOMEM(IO_ADDRESS(n))
  6588. +
  6589. +
  6590. +/*
  6591. + * SDRAM
  6592. + */
  6593. +#define BCM2708_SDRAM_BASE 0x00000000
  6594. +
  6595. +/*
  6596. + * Logic expansion modules
  6597. + *
  6598. + */
  6599. +
  6600. +
  6601. +/* ------------------------------------------------------------------------
  6602. + * BCM2708 ARMCTRL Registers
  6603. + * ------------------------------------------------------------------------
  6604. + */
  6605. +
  6606. +#define HW_REGISTER_RW(addr) (addr)
  6607. +#define HW_REGISTER_RO(addr) (addr)
  6608. +
  6609. +#include "arm_control.h"
  6610. +#undef ARM_BASE
  6611. +
  6612. +/*
  6613. + * Definitions and addresses for the ARM CONTROL logic
  6614. + * This file is manually generated.
  6615. + */
  6616. +
  6617. +#define BCM2708_PERI_BASE 0x20000000
  6618. +#define IC0_BASE (BCM2708_PERI_BASE + 0x2000)
  6619. +#define ST_BASE (BCM2708_PERI_BASE + 0x3000) /* System Timer */
  6620. +#define MPHI_BASE (BCM2708_PERI_BASE + 0x6000) /* Message -based Parallel Host Interface */
  6621. +#define DMA_BASE (BCM2708_PERI_BASE + 0x7000) /* DMA controller */
  6622. +#define ARM_BASE (BCM2708_PERI_BASE + 0xB000) /* BCM2708 ARM control block */
  6623. +#define PM_BASE (BCM2708_PERI_BASE + 0x100000) /* Power Management, Reset controller and Watchdog registers */
  6624. +#define PCM_CLOCK_BASE (BCM2708_PERI_BASE + 0x101098) /* PCM Clock */
  6625. +#define RNG_BASE (BCM2708_PERI_BASE + 0x104000) /* Hardware RNG */
  6626. +#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO */
  6627. +#define UART0_BASE (BCM2708_PERI_BASE + 0x201000) /* Uart 0 */
  6628. +#define MMCI0_BASE (BCM2708_PERI_BASE + 0x202000) /* MMC interface */
  6629. +#define I2S_BASE (BCM2708_PERI_BASE + 0x203000) /* I2S */
  6630. +#define SPI0_BASE (BCM2708_PERI_BASE + 0x204000) /* SPI0 */
  6631. +#define BSC0_BASE (BCM2708_PERI_BASE + 0x205000) /* BSC0 I2C/TWI */
  6632. +#define UART1_BASE (BCM2708_PERI_BASE + 0x215000) /* Uart 1 */
  6633. +#define EMMC_BASE (BCM2708_PERI_BASE + 0x300000) /* eMMC interface */
  6634. +#define SMI_BASE (BCM2708_PERI_BASE + 0x600000) /* SMI */
  6635. +#define BSC1_BASE (BCM2708_PERI_BASE + 0x804000) /* BSC1 I2C/TWI */
  6636. +#define USB_BASE (BCM2708_PERI_BASE + 0x980000) /* DTC_OTG USB controller */
  6637. +#define MCORE_BASE (BCM2708_PERI_BASE + 0x0000) /* Fake frame buffer device (actually the multicore sync block*/
  6638. +
  6639. +#define ARMCTRL_BASE (ARM_BASE + 0x000)
  6640. +#define ARMCTRL_IC_BASE (ARM_BASE + 0x200) /* ARM interrupt controller */
  6641. +#define ARMCTRL_TIMER0_1_BASE (ARM_BASE + 0x400) /* Timer 0 and 1 */
  6642. +#define ARMCTRL_0_SBM_BASE (ARM_BASE + 0x800) /* User 0 (ARM)'s Semaphores Doorbells and Mailboxes */
  6643. +
  6644. +
  6645. +/*
  6646. + * Interrupt assignments
  6647. + */
  6648. +
  6649. +#define ARM_IRQ1_BASE 0
  6650. +#define INTERRUPT_TIMER0 (ARM_IRQ1_BASE + 0)
  6651. +#define INTERRUPT_TIMER1 (ARM_IRQ1_BASE + 1)
  6652. +#define INTERRUPT_TIMER2 (ARM_IRQ1_BASE + 2)
  6653. +#define INTERRUPT_TIMER3 (ARM_IRQ1_BASE + 3)
  6654. +#define INTERRUPT_CODEC0 (ARM_IRQ1_BASE + 4)
  6655. +#define INTERRUPT_CODEC1 (ARM_IRQ1_BASE + 5)
  6656. +#define INTERRUPT_CODEC2 (ARM_IRQ1_BASE + 6)
  6657. +#define INTERRUPT_VC_JPEG (ARM_IRQ1_BASE + 7)
  6658. +#define INTERRUPT_ISP (ARM_IRQ1_BASE + 8)
  6659. +#define INTERRUPT_VC_USB (ARM_IRQ1_BASE + 9)
  6660. +#define INTERRUPT_VC_3D (ARM_IRQ1_BASE + 10)
  6661. +#define INTERRUPT_TRANSPOSER (ARM_IRQ1_BASE + 11)
  6662. +#define INTERRUPT_MULTICORESYNC0 (ARM_IRQ1_BASE + 12)
  6663. +#define INTERRUPT_MULTICORESYNC1 (ARM_IRQ1_BASE + 13)
  6664. +#define INTERRUPT_MULTICORESYNC2 (ARM_IRQ1_BASE + 14)
  6665. +#define INTERRUPT_MULTICORESYNC3 (ARM_IRQ1_BASE + 15)
  6666. +#define INTERRUPT_DMA0 (ARM_IRQ1_BASE + 16)
  6667. +#define INTERRUPT_DMA1 (ARM_IRQ1_BASE + 17)
  6668. +#define INTERRUPT_VC_DMA2 (ARM_IRQ1_BASE + 18)
  6669. +#define INTERRUPT_VC_DMA3 (ARM_IRQ1_BASE + 19)
  6670. +#define INTERRUPT_DMA4 (ARM_IRQ1_BASE + 20)
  6671. +#define INTERRUPT_DMA5 (ARM_IRQ1_BASE + 21)
  6672. +#define INTERRUPT_DMA6 (ARM_IRQ1_BASE + 22)
  6673. +#define INTERRUPT_DMA7 (ARM_IRQ1_BASE + 23)
  6674. +#define INTERRUPT_DMA8 (ARM_IRQ1_BASE + 24)
  6675. +#define INTERRUPT_DMA9 (ARM_IRQ1_BASE + 25)
  6676. +#define INTERRUPT_DMA10 (ARM_IRQ1_BASE + 26)
  6677. +#define INTERRUPT_DMA11 (ARM_IRQ1_BASE + 27)
  6678. +#define INTERRUPT_DMA12 (ARM_IRQ1_BASE + 28)
  6679. +#define INTERRUPT_AUX (ARM_IRQ1_BASE + 29)
  6680. +#define INTERRUPT_ARM (ARM_IRQ1_BASE + 30)
  6681. +#define INTERRUPT_VPUDMA (ARM_IRQ1_BASE + 31)
  6682. +
  6683. +#define ARM_IRQ2_BASE 32
  6684. +#define INTERRUPT_HOSTPORT (ARM_IRQ2_BASE + 0)
  6685. +#define INTERRUPT_VIDEOSCALER (ARM_IRQ2_BASE + 1)
  6686. +#define INTERRUPT_CCP2TX (ARM_IRQ2_BASE + 2)
  6687. +#define INTERRUPT_SDC (ARM_IRQ2_BASE + 3)
  6688. +#define INTERRUPT_DSI0 (ARM_IRQ2_BASE + 4)
  6689. +#define INTERRUPT_AVE (ARM_IRQ2_BASE + 5)
  6690. +#define INTERRUPT_CAM0 (ARM_IRQ2_BASE + 6)
  6691. +#define INTERRUPT_CAM1 (ARM_IRQ2_BASE + 7)
  6692. +#define INTERRUPT_HDMI0 (ARM_IRQ2_BASE + 8)
  6693. +#define INTERRUPT_HDMI1 (ARM_IRQ2_BASE + 9)
  6694. +#define INTERRUPT_PIXELVALVE1 (ARM_IRQ2_BASE + 10)
  6695. +#define INTERRUPT_I2CSPISLV (ARM_IRQ2_BASE + 11)
  6696. +#define INTERRUPT_DSI1 (ARM_IRQ2_BASE + 12)
  6697. +#define INTERRUPT_PWA0 (ARM_IRQ2_BASE + 13)
  6698. +#define INTERRUPT_PWA1 (ARM_IRQ2_BASE + 14)
  6699. +#define INTERRUPT_CPR (ARM_IRQ2_BASE + 15)
  6700. +#define INTERRUPT_SMI (ARM_IRQ2_BASE + 16)
  6701. +#define INTERRUPT_GPIO0 (ARM_IRQ2_BASE + 17)
  6702. +#define INTERRUPT_GPIO1 (ARM_IRQ2_BASE + 18)
  6703. +#define INTERRUPT_GPIO2 (ARM_IRQ2_BASE + 19)
  6704. +#define INTERRUPT_GPIO3 (ARM_IRQ2_BASE + 20)
  6705. +#define INTERRUPT_VC_I2C (ARM_IRQ2_BASE + 21)
  6706. +#define INTERRUPT_VC_SPI (ARM_IRQ2_BASE + 22)
  6707. +#define INTERRUPT_VC_I2SPCM (ARM_IRQ2_BASE + 23)
  6708. +#define INTERRUPT_VC_SDIO (ARM_IRQ2_BASE + 24)
  6709. +#define INTERRUPT_VC_UART (ARM_IRQ2_BASE + 25)
  6710. +#define INTERRUPT_SLIMBUS (ARM_IRQ2_BASE + 26)
  6711. +#define INTERRUPT_VEC (ARM_IRQ2_BASE + 27)
  6712. +#define INTERRUPT_CPG (ARM_IRQ2_BASE + 28)
  6713. +#define INTERRUPT_RNG (ARM_IRQ2_BASE + 29)
  6714. +#define INTERRUPT_VC_ARASANSDIO (ARM_IRQ2_BASE + 30)
  6715. +#define INTERRUPT_AVSPMON (ARM_IRQ2_BASE + 31)
  6716. +
  6717. +#define ARM_IRQ0_BASE 64
  6718. +#define INTERRUPT_ARM_TIMER (ARM_IRQ0_BASE + 0)
  6719. +#define INTERRUPT_ARM_MAILBOX (ARM_IRQ0_BASE + 1)
  6720. +#define INTERRUPT_ARM_DOORBELL_0 (ARM_IRQ0_BASE + 2)
  6721. +#define INTERRUPT_ARM_DOORBELL_1 (ARM_IRQ0_BASE + 3)
  6722. +#define INTERRUPT_VPU0_HALTED (ARM_IRQ0_BASE + 4)
  6723. +#define INTERRUPT_VPU1_HALTED (ARM_IRQ0_BASE + 5)
  6724. +#define INTERRUPT_ILLEGAL_TYPE0 (ARM_IRQ0_BASE + 6)
  6725. +#define INTERRUPT_ILLEGAL_TYPE1 (ARM_IRQ0_BASE + 7)
  6726. +#define INTERRUPT_PENDING1 (ARM_IRQ0_BASE + 8)
  6727. +#define INTERRUPT_PENDING2 (ARM_IRQ0_BASE + 9)
  6728. +#define INTERRUPT_JPEG (ARM_IRQ0_BASE + 10)
  6729. +#define INTERRUPT_USB (ARM_IRQ0_BASE + 11)
  6730. +#define INTERRUPT_3D (ARM_IRQ0_BASE + 12)
  6731. +#define INTERRUPT_DMA2 (ARM_IRQ0_BASE + 13)
  6732. +#define INTERRUPT_DMA3 (ARM_IRQ0_BASE + 14)
  6733. +#define INTERRUPT_I2C (ARM_IRQ0_BASE + 15)
  6734. +#define INTERRUPT_SPI (ARM_IRQ0_BASE + 16)
  6735. +#define INTERRUPT_I2SPCM (ARM_IRQ0_BASE + 17)
  6736. +#define INTERRUPT_SDIO (ARM_IRQ0_BASE + 18)
  6737. +#define INTERRUPT_UART (ARM_IRQ0_BASE + 19)
  6738. +#define INTERRUPT_ARASANSDIO (ARM_IRQ0_BASE + 20)
  6739. +
  6740. +#define MAXIRQNUM (32 + 32 + 20)
  6741. +#define MAXFIQNUM (32 + 32 + 20)
  6742. +
  6743. +#define MAX_TIMER 2
  6744. +#define MAX_PERIOD 699050
  6745. +#define TICKS_PER_uSEC 1
  6746. +
  6747. +/*
  6748. + * These are useconds NOT ticks.
  6749. + *
  6750. + */
  6751. +#define mSEC_1 1000
  6752. +#define mSEC_5 (mSEC_1 * 5)
  6753. +#define mSEC_10 (mSEC_1 * 10)
  6754. +#define mSEC_25 (mSEC_1 * 25)
  6755. +#define SEC_1 (mSEC_1 * 1000)
  6756. +
  6757. +/*
  6758. + * Watchdog
  6759. + */
  6760. +#define PM_RSTC (PM_BASE+0x1c)
  6761. +#define PM_RSTS (PM_BASE+0x20)
  6762. +#define PM_WDOG (PM_BASE+0x24)
  6763. +
  6764. +#define PM_WDOG_RESET 0000000000
  6765. +#define PM_PASSWORD 0x5a000000
  6766. +#define PM_WDOG_TIME_SET 0x000fffff
  6767. +#define PM_RSTC_WRCFG_CLR 0xffffffcf
  6768. +#define PM_RSTC_WRCFG_SET 0x00000030
  6769. +#define PM_RSTC_WRCFG_FULL_RESET 0x00000020
  6770. +#define PM_RSTC_RESET 0x00000102
  6771. +
  6772. +#define PM_RSTS_HADPOR_SET 0x00001000
  6773. +#define PM_RSTS_HADSRH_SET 0x00000400
  6774. +#define PM_RSTS_HADSRF_SET 0x00000200
  6775. +#define PM_RSTS_HADSRQ_SET 0x00000100
  6776. +#define PM_RSTS_HADWRH_SET 0x00000040
  6777. +#define PM_RSTS_HADWRF_SET 0x00000020
  6778. +#define PM_RSTS_HADWRQ_SET 0x00000010
  6779. +#define PM_RSTS_HADDRH_SET 0x00000004
  6780. +#define PM_RSTS_HADDRF_SET 0x00000002
  6781. +#define PM_RSTS_HADDRQ_SET 0x00000001
  6782. +
  6783. +#define UART0_CLOCK 3000000
  6784. +
  6785. +#endif
  6786. +
  6787. +/* END */
  6788. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/power.h linux-3.12.11/arch/arm/mach-bcm2708/include/mach/power.h
  6789. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/power.h 1970-01-01 01:00:00.000000000 +0100
  6790. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/power.h 2014-02-18 11:52:14.000000000 +0100
  6791. @@ -0,0 +1,26 @@
  6792. +/*
  6793. + * linux/arch/arm/mach-bcm2708/power.h
  6794. + *
  6795. + * Copyright (C) 2010 Broadcom
  6796. + *
  6797. + * This program is free software; you can redistribute it and/or modify
  6798. + * it under the terms of the GNU General Public License version 2 as
  6799. + * published by the Free Software Foundation.
  6800. + *
  6801. + * This device provides a shared mechanism for controlling the power to
  6802. + * VideoCore subsystems.
  6803. + */
  6804. +
  6805. +#ifndef _MACH_BCM2708_POWER_H
  6806. +#define _MACH_BCM2708_POWER_H
  6807. +
  6808. +#include <linux/types.h>
  6809. +#include <mach/arm_power.h>
  6810. +
  6811. +typedef unsigned int BCM_POWER_HANDLE_T;
  6812. +
  6813. +extern int bcm_power_open(BCM_POWER_HANDLE_T *handle);
  6814. +extern int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request);
  6815. +extern int bcm_power_close(BCM_POWER_HANDLE_T handle);
  6816. +
  6817. +#endif
  6818. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/system.h linux-3.12.11/arch/arm/mach-bcm2708/include/mach/system.h
  6819. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/system.h 1970-01-01 01:00:00.000000000 +0100
  6820. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/system.h 2014-02-18 11:52:14.000000000 +0100
  6821. @@ -0,0 +1,38 @@
  6822. +/*
  6823. + * arch/arm/mach-bcm2708/include/mach/system.h
  6824. + *
  6825. + * Copyright (C) 2010 Broadcom
  6826. + * Copyright (C) 2003 ARM Limited
  6827. + * Copyright (C) 2000 Deep Blue Solutions Ltd
  6828. + *
  6829. + * This program is free software; you can redistribute it and/or modify
  6830. + * it under the terms of the GNU General Public License as published by
  6831. + * the Free Software Foundation; either version 2 of the License, or
  6832. + * (at your option) any later version.
  6833. + *
  6834. + * This program is distributed in the hope that it will be useful,
  6835. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6836. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6837. + * GNU General Public License for more details.
  6838. + *
  6839. + * You should have received a copy of the GNU General Public License
  6840. + * along with this program; if not, write to the Free Software
  6841. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6842. + */
  6843. +#ifndef __ASM_ARCH_SYSTEM_H
  6844. +#define __ASM_ARCH_SYSTEM_H
  6845. +
  6846. +#include <linux/io.h>
  6847. +#include <mach/hardware.h>
  6848. +#include <mach/platform.h>
  6849. +
  6850. +static inline void arch_idle(void)
  6851. +{
  6852. + /*
  6853. + * This should do all the clock switching
  6854. + * and wait for interrupt tricks
  6855. + */
  6856. + cpu_do_idle();
  6857. +}
  6858. +
  6859. +#endif
  6860. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/timex.h linux-3.12.11/arch/arm/mach-bcm2708/include/mach/timex.h
  6861. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/timex.h 1970-01-01 01:00:00.000000000 +0100
  6862. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/timex.h 2014-02-18 11:52:14.000000000 +0100
  6863. @@ -0,0 +1,23 @@
  6864. +/*
  6865. + * arch/arm/mach-bcm2708/include/mach/timex.h
  6866. + *
  6867. + * BCM2708 sysem clock frequency
  6868. + *
  6869. + * Copyright (C) 2010 Broadcom
  6870. + *
  6871. + * This program is free software; you can redistribute it and/or modify
  6872. + * it under the terms of the GNU General Public License as published by
  6873. + * the Free Software Foundation; either version 2 of the License, or
  6874. + * (at your option) any later version.
  6875. + *
  6876. + * This program is distributed in the hope that it will be useful,
  6877. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6878. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6879. + * GNU General Public License for more details.
  6880. + *
  6881. + * You should have received a copy of the GNU General Public License
  6882. + * along with this program; if not, write to the Free Software
  6883. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6884. + */
  6885. +
  6886. +#define CLOCK_TICK_RATE (1000000)
  6887. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/uncompress.h linux-3.12.11/arch/arm/mach-bcm2708/include/mach/uncompress.h
  6888. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/uncompress.h 1970-01-01 01:00:00.000000000 +0100
  6889. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/uncompress.h 2014-02-18 11:52:14.000000000 +0100
  6890. @@ -0,0 +1,84 @@
  6891. +/*
  6892. + * arch/arm/mach-bcn2708/include/mach/uncompress.h
  6893. + *
  6894. + * Copyright (C) 2010 Broadcom
  6895. + * Copyright (C) 2003 ARM Limited
  6896. + *
  6897. + * This program is free software; you can redistribute it and/or modify
  6898. + * it under the terms of the GNU General Public License as published by
  6899. + * the Free Software Foundation; either version 2 of the License, or
  6900. + * (at your option) any later version.
  6901. + *
  6902. + * This program is distributed in the hope that it will be useful,
  6903. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6904. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6905. + * GNU General Public License for more details.
  6906. + *
  6907. + * You should have received a copy of the GNU General Public License
  6908. + * along with this program; if not, write to the Free Software
  6909. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6910. + */
  6911. +
  6912. +#include <linux/io.h>
  6913. +#include <linux/amba/serial.h>
  6914. +#include <mach/hardware.h>
  6915. +
  6916. +#define UART_BAUD 115200
  6917. +
  6918. +#define BCM2708_UART_DR __io(UART0_BASE + UART01x_DR)
  6919. +#define BCM2708_UART_FR __io(UART0_BASE + UART01x_FR)
  6920. +#define BCM2708_UART_IBRD __io(UART0_BASE + UART011_IBRD)
  6921. +#define BCM2708_UART_FBRD __io(UART0_BASE + UART011_FBRD)
  6922. +#define BCM2708_UART_LCRH __io(UART0_BASE + UART011_LCRH)
  6923. +#define BCM2708_UART_CR __io(UART0_BASE + UART011_CR)
  6924. +
  6925. +/*
  6926. + * This does not append a newline
  6927. + */
  6928. +static inline void putc(int c)
  6929. +{
  6930. + while (__raw_readl(BCM2708_UART_FR) & UART01x_FR_TXFF)
  6931. + barrier();
  6932. +
  6933. + __raw_writel(c, BCM2708_UART_DR);
  6934. +}
  6935. +
  6936. +static inline void flush(void)
  6937. +{
  6938. + int fr;
  6939. +
  6940. + do {
  6941. + fr = __raw_readl(BCM2708_UART_FR);
  6942. + barrier();
  6943. + } while ((fr & (UART011_FR_TXFE | UART01x_FR_BUSY)) != UART011_FR_TXFE);
  6944. +}
  6945. +
  6946. +static inline void arch_decomp_setup(void)
  6947. +{
  6948. + int temp, div, rem, frac;
  6949. +
  6950. + temp = 16 * UART_BAUD;
  6951. + div = UART0_CLOCK / temp;
  6952. + rem = UART0_CLOCK % temp;
  6953. + temp = (8 * rem) / UART_BAUD;
  6954. + frac = (temp >> 1) + (temp & 1);
  6955. +
  6956. + /* Make sure the UART is disabled before we start */
  6957. + __raw_writel(0, BCM2708_UART_CR);
  6958. +
  6959. + /* Set the baud rate */
  6960. + __raw_writel(div, BCM2708_UART_IBRD);
  6961. + __raw_writel(frac, BCM2708_UART_FBRD);
  6962. +
  6963. + /* Set the UART to 8n1, FIFO enabled */
  6964. + __raw_writel(UART01x_LCRH_WLEN_8 | UART01x_LCRH_FEN, BCM2708_UART_LCRH);
  6965. +
  6966. + /* Enable the UART */
  6967. + __raw_writel(UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_RXE,
  6968. + BCM2708_UART_CR);
  6969. +}
  6970. +
  6971. +/*
  6972. + * nothing to do
  6973. + */
  6974. +#define arch_decomp_wdog()
  6975. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/vcio.h linux-3.12.11/arch/arm/mach-bcm2708/include/mach/vcio.h
  6976. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/vcio.h 1970-01-01 01:00:00.000000000 +0100
  6977. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/vcio.h 2014-02-18 11:52:14.000000000 +0100
  6978. @@ -0,0 +1,141 @@
  6979. +/*
  6980. + * arch/arm/mach-bcm2708/include/mach/vcio.h
  6981. + *
  6982. + * Copyright (C) 2010 Broadcom
  6983. + *
  6984. + * This program is free software; you can redistribute it and/or modify
  6985. + * it under the terms of the GNU General Public License as published by
  6986. + * the Free Software Foundation; either version 2 of the License, or
  6987. + * (at your option) any later version.
  6988. + *
  6989. + * This program is distributed in the hope that it will be useful,
  6990. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6991. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6992. + * GNU General Public License for more details.
  6993. + *
  6994. + * You should have received a copy of the GNU General Public License
  6995. + * along with this program; if not, write to the Free Software
  6996. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6997. + */
  6998. +#ifndef _MACH_BCM2708_VCIO_H
  6999. +#define _MACH_BCM2708_VCIO_H
  7000. +
  7001. +/* Routines to handle I/O via the VideoCore "ARM control" registers
  7002. + * (semaphores, doorbells, mailboxes)
  7003. + */
  7004. +
  7005. +#define BCM_VCIO_DRIVER_NAME "bcm2708_vcio"
  7006. +
  7007. +/* Constants shared with the ARM identifying separate mailbox channels */
  7008. +#define MBOX_CHAN_POWER 0 /* for use by the power management interface */
  7009. +#define MBOX_CHAN_FB 1 /* for use by the frame buffer */
  7010. +#define MBOX_CHAN_VCHIQ 3 /* for use by the VCHIQ interface */
  7011. +#define MBOX_CHAN_PROPERTY 8 /* for use by the property channel */
  7012. +#define MBOX_CHAN_COUNT 9
  7013. +
  7014. +/* Mailbox property tags */
  7015. +enum {
  7016. + VCMSG_PROPERTY_END = 0x00000000,
  7017. + VCMSG_GET_FIRMWARE_REVISION = 0x00000001,
  7018. + VCMSG_GET_BOARD_MODEL = 0x00010001,
  7019. + VCMSG_GET_BOARD_REVISION = 0x00020002,
  7020. + VCMSG_GET_BOARD_MAC_ADDRESS = 0x00020003,
  7021. + VCMSG_GET_BOARD_SERIAL = 0x00020004,
  7022. + VCMSG_GET_ARM_MEMORY = 0x00020005,
  7023. + VCMSG_GET_VC_MEMORY = 0x00020006,
  7024. + VCMSG_GET_CLOCKS = 0x00020007,
  7025. + VCMSG_GET_COMMAND_LINE = 0x00050001,
  7026. + VCMSG_GET_DMA_CHANNELS = 0x00060001,
  7027. + VCMSG_GET_POWER_STATE = 0x00020001,
  7028. + VCMSG_GET_TIMING = 0x00020002,
  7029. + VCMSG_SET_POWER_STATE = 0x00028001,
  7030. + VCMSG_GET_CLOCK_STATE = 0x00030001,
  7031. + VCMSG_SET_CLOCK_STATE = 0x00038001,
  7032. + VCMSG_GET_CLOCK_RATE = 0x00030002,
  7033. + VCMSG_SET_CLOCK_RATE = 0x00038002,
  7034. + VCMSG_GET_VOLTAGE = 0x00030003,
  7035. + VCMSG_SET_VOLTAGE = 0x00038003,
  7036. + VCMSG_GET_MAX_CLOCK = 0x00030004,
  7037. + VCMSG_GET_MAX_VOLTAGE = 0x00030005,
  7038. + VCMSG_GET_TEMPERATURE = 0x00030006,
  7039. + VCMSG_GET_MIN_CLOCK = 0x00030007,
  7040. + VCMSG_GET_MIN_VOLTAGE = 0x00030008,
  7041. + VCMSG_GET_TURBO = 0x00030009,
  7042. + VCMSG_SET_TURBO = 0x00038009,
  7043. + VCMSG_SET_ALLOCATE_BUFFER = 0x00040001,
  7044. + VCMSG_SET_RELEASE_BUFFER = 0x00048001,
  7045. + VCMSG_SET_BLANK_SCREEN = 0x00040002,
  7046. + VCMSG_TST_BLANK_SCREEN = 0x00044002,
  7047. + VCMSG_GET_PHYSICAL_WIDTH_HEIGHT = 0x00040003,
  7048. + VCMSG_TST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
  7049. + VCMSG_SET_PHYSICAL_WIDTH_HEIGHT = 0x00048003,
  7050. + VCMSG_GET_VIRTUAL_WIDTH_HEIGHT = 0x00040004,
  7051. + VCMSG_TST_VIRTUAL_WIDTH_HEIGHT = 0x00044004,
  7052. + VCMSG_SET_VIRTUAL_WIDTH_HEIGHT = 0x00048004,
  7053. + VCMSG_GET_DEPTH = 0x00040005,
  7054. + VCMSG_TST_DEPTH = 0x00044005,
  7055. + VCMSG_SET_DEPTH = 0x00048005,
  7056. + VCMSG_GET_PIXEL_ORDER = 0x00040006,
  7057. + VCMSG_TST_PIXEL_ORDER = 0x00044006,
  7058. + VCMSG_SET_PIXEL_ORDER = 0x00048006,
  7059. + VCMSG_GET_ALPHA_MODE = 0x00040007,
  7060. + VCMSG_TST_ALPHA_MODE = 0x00044007,
  7061. + VCMSG_SET_ALPHA_MODE = 0x00048007,
  7062. + VCMSG_GET_PITCH = 0x00040008,
  7063. + VCMSG_TST_PITCH = 0x00044008,
  7064. + VCMSG_SET_PITCH = 0x00048008,
  7065. + VCMSG_GET_VIRTUAL_OFFSET = 0x00040009,
  7066. + VCMSG_TST_VIRTUAL_OFFSET = 0x00044009,
  7067. + VCMSG_SET_VIRTUAL_OFFSET = 0x00048009,
  7068. + VCMSG_GET_OVERSCAN = 0x0004000a,
  7069. + VCMSG_TST_OVERSCAN = 0x0004400a,
  7070. + VCMSG_SET_OVERSCAN = 0x0004800a,
  7071. + VCMSG_GET_PALETTE = 0x0004000b,
  7072. + VCMSG_TST_PALETTE = 0x0004400b,
  7073. + VCMSG_SET_PALETTE = 0x0004800b,
  7074. + VCMSG_GET_LAYER = 0x0004000c,
  7075. + VCMSG_TST_LAYER = 0x0004400c,
  7076. + VCMSG_SET_LAYER = 0x0004800c,
  7077. + VCMSG_GET_TRANSFORM = 0x0004000d,
  7078. + VCMSG_TST_TRANSFORM = 0x0004400d,
  7079. + VCMSG_SET_TRANSFORM = 0x0004800d,
  7080. +};
  7081. +
  7082. +extern int /*rc*/ bcm_mailbox_read(unsigned chan, uint32_t *data28);
  7083. +extern int /*rc*/ bcm_mailbox_write(unsigned chan, uint32_t data28);
  7084. +extern int /*rc*/ bcm_mailbox_property(void *data, int size);
  7085. +
  7086. +#include <linux/ioctl.h>
  7087. +
  7088. +/*
  7089. + * The major device number. We can't rely on dynamic
  7090. + * registration any more, because ioctls need to know
  7091. + * it.
  7092. + */
  7093. +#define MAJOR_NUM 100
  7094. +
  7095. +/*
  7096. + * Set the message of the device driver
  7097. + */
  7098. +#define IOCTL_MBOX_PROPERTY _IOWR(MAJOR_NUM, 0, char *)
  7099. +/*
  7100. + * _IOWR means that we're creating an ioctl command
  7101. + * number for passing information from a user process
  7102. + * to the kernel module and from the kernel module to user process
  7103. + *
  7104. + * The first arguments, MAJOR_NUM, is the major device
  7105. + * number we're using.
  7106. + *
  7107. + * The second argument is the number of the command
  7108. + * (there could be several with different meanings).
  7109. + *
  7110. + * The third argument is the type we want to get from
  7111. + * the process to the kernel.
  7112. + */
  7113. +
  7114. +/*
  7115. + * The name of the device file
  7116. + */
  7117. +#define DEVICE_FILE_NAME "char_dev"
  7118. +
  7119. +#endif
  7120. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/vc_mem.h linux-3.12.11/arch/arm/mach-bcm2708/include/mach/vc_mem.h
  7121. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/vc_mem.h 1970-01-01 01:00:00.000000000 +0100
  7122. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/vc_mem.h 2014-02-18 11:52:14.000000000 +0100
  7123. @@ -0,0 +1,35 @@
  7124. +/*****************************************************************************
  7125. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  7126. +*
  7127. +* Unless you and Broadcom execute a separate written software license
  7128. +* agreement governing use of this software, this software is licensed to you
  7129. +* under the terms of the GNU General Public License version 2, available at
  7130. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  7131. +*
  7132. +* Notwithstanding the above, under no circumstances may you combine this
  7133. +* software in any way with any other Broadcom software provided under a
  7134. +* license other than the GPL, without Broadcom's express prior written
  7135. +* consent.
  7136. +*****************************************************************************/
  7137. +
  7138. +#if !defined( VC_MEM_H )
  7139. +#define VC_MEM_H
  7140. +
  7141. +#include <linux/ioctl.h>
  7142. +
  7143. +#define VC_MEM_IOC_MAGIC 'v'
  7144. +
  7145. +#define VC_MEM_IOC_MEM_PHYS_ADDR _IOR( VC_MEM_IOC_MAGIC, 0, unsigned long )
  7146. +#define VC_MEM_IOC_MEM_SIZE _IOR( VC_MEM_IOC_MAGIC, 1, unsigned int )
  7147. +#define VC_MEM_IOC_MEM_BASE _IOR( VC_MEM_IOC_MAGIC, 2, unsigned int )
  7148. +#define VC_MEM_IOC_MEM_LOAD _IOR( VC_MEM_IOC_MAGIC, 3, unsigned int )
  7149. +
  7150. +#if defined( __KERNEL__ )
  7151. +#define VC_MEM_TO_ARM_ADDR_MASK 0x3FFFFFFF
  7152. +
  7153. +extern unsigned long mm_vc_mem_phys_addr;
  7154. +extern unsigned int mm_vc_mem_size;
  7155. +extern int vc_mem_get_current_size( void );
  7156. +#endif
  7157. +
  7158. +#endif /* VC_MEM_H */
  7159. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/vc_support.h linux-3.12.11/arch/arm/mach-bcm2708/include/mach/vc_support.h
  7160. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/vc_support.h 1970-01-01 01:00:00.000000000 +0100
  7161. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/vc_support.h 2014-02-18 11:52:14.000000000 +0100
  7162. @@ -0,0 +1,69 @@
  7163. +#ifndef _VC_SUPPORT_H_
  7164. +#define _VC_SUPPORT_H_
  7165. +
  7166. +/*
  7167. + * vc_support.h
  7168. + *
  7169. + * Created on: 25 Nov 2012
  7170. + * Author: Simon
  7171. + */
  7172. +
  7173. +enum {
  7174. +/*
  7175. + If a MEM_HANDLE_T is discardable, the memory manager may resize it to size
  7176. + 0 at any time when it is not locked or retained.
  7177. + */
  7178. + MEM_FLAG_DISCARDABLE = 1 << 0,
  7179. +
  7180. + /*
  7181. + If a MEM_HANDLE_T is allocating (or normal), its block of memory will be
  7182. + accessed in an allocating fashion through the cache.
  7183. + */
  7184. + MEM_FLAG_NORMAL = 0 << 2,
  7185. + MEM_FLAG_ALLOCATING = MEM_FLAG_NORMAL,
  7186. +
  7187. + /*
  7188. + If a MEM_HANDLE_T is direct, its block of memory will be accessed
  7189. + directly, bypassing the cache.
  7190. + */
  7191. + MEM_FLAG_DIRECT = 1 << 2,
  7192. +
  7193. + /*
  7194. + If a MEM_HANDLE_T is coherent, its block of memory will be accessed in a
  7195. + non-allocating fashion through the cache.
  7196. + */
  7197. + MEM_FLAG_COHERENT = 2 << 2,
  7198. +
  7199. + /*
  7200. + If a MEM_HANDLE_T is L1-nonallocating, its block of memory will be accessed by
  7201. + the VPU in a fashion which is allocating in L2, but only coherent in L1.
  7202. + */
  7203. + MEM_FLAG_L1_NONALLOCATING = (MEM_FLAG_DIRECT | MEM_FLAG_COHERENT),
  7204. +
  7205. + /*
  7206. + If a MEM_HANDLE_T is zero'd, its contents are set to 0 rather than
  7207. + MEM_HANDLE_INVALID on allocation and resize up.
  7208. + */
  7209. + MEM_FLAG_ZERO = 1 << 4,
  7210. +
  7211. + /*
  7212. + If a MEM_HANDLE_T is uninitialised, it will not be reset to a defined value
  7213. + (either zero, or all 1's) on allocation.
  7214. + */
  7215. + MEM_FLAG_NO_INIT = 1 << 5,
  7216. +
  7217. + /*
  7218. + Hints.
  7219. + */
  7220. + MEM_FLAG_HINT_PERMALOCK = 1 << 6, /* Likely to be locked for long periods of time. */
  7221. +};
  7222. +
  7223. +unsigned int AllocateVcMemory(unsigned int *pHandle, unsigned int size, unsigned int alignment, unsigned int flags);
  7224. +unsigned int ReleaseVcMemory(unsigned int handle);
  7225. +unsigned int LockVcMemory(unsigned int *pBusAddress, unsigned int handle);
  7226. +unsigned int UnlockVcMemory(unsigned int handle);
  7227. +
  7228. +unsigned int ExecuteVcCode(unsigned int code,
  7229. + unsigned int r0, unsigned int r1, unsigned int r2, unsigned int r3, unsigned int r4, unsigned int r5);
  7230. +
  7231. +#endif
  7232. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/vmalloc.h linux-3.12.11/arch/arm/mach-bcm2708/include/mach/vmalloc.h
  7233. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/include/mach/vmalloc.h 1970-01-01 01:00:00.000000000 +0100
  7234. +++ linux-3.12.11/arch/arm/mach-bcm2708/include/mach/vmalloc.h 2014-02-18 11:52:14.000000000 +0100
  7235. @@ -0,0 +1,20 @@
  7236. +/*
  7237. + * arch/arm/mach-bcm2708/include/mach/vmalloc.h
  7238. + *
  7239. + * Copyright (C) 2010 Broadcom
  7240. + *
  7241. + * This program is free software; you can redistribute it and/or modify
  7242. + * it under the terms of the GNU General Public License as published by
  7243. + * the Free Software Foundation; either version 2 of the License, or
  7244. + * (at your option) any later version.
  7245. + *
  7246. + * This program is distributed in the hope that it will be useful,
  7247. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7248. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7249. + * GNU General Public License for more details.
  7250. + *
  7251. + * You should have received a copy of the GNU General Public License
  7252. + * along with this program; if not, write to the Free Software
  7253. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  7254. + */
  7255. +#define VMALLOC_END (0xe8000000)
  7256. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/Kconfig linux-3.12.11/arch/arm/mach-bcm2708/Kconfig
  7257. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/Kconfig 1970-01-01 01:00:00.000000000 +0100
  7258. +++ linux-3.12.11/arch/arm/mach-bcm2708/Kconfig 2014-02-18 11:52:14.000000000 +0100
  7259. @@ -0,0 +1,49 @@
  7260. +menu "Broadcom BCM2708 Implementations"
  7261. + depends on ARCH_BCM2708
  7262. +
  7263. +config MACH_BCM2708
  7264. + bool "Broadcom BCM2708 Development Platform"
  7265. + select NEED_MACH_MEMORY_H
  7266. + select NEED_MACH_IO_H
  7267. + select CPU_V6
  7268. + help
  7269. + Include support for the Broadcom(R) BCM2708 platform.
  7270. +
  7271. +config BCM2708_GPIO
  7272. + bool "BCM2708 gpio support"
  7273. + depends on MACH_BCM2708
  7274. + select ARCH_REQUIRE_GPIOLIB
  7275. + default y
  7276. + help
  7277. + Include support for the Broadcom(R) BCM2708 gpio.
  7278. +
  7279. +config BCM2708_VCMEM
  7280. + bool "Videocore Memory"
  7281. + depends on MACH_BCM2708
  7282. + default y
  7283. + help
  7284. + Helper for videocore memory access and total size allocation.
  7285. +
  7286. +config BCM2708_NOL2CACHE
  7287. + bool "Videocore L2 cache disable"
  7288. + depends on MACH_BCM2708
  7289. + default n
  7290. + help
  7291. + Do not allow ARM to use GPU's L2 cache. Requires disable_l2cache in config.txt.
  7292. +
  7293. +config BCM2708_SPIDEV
  7294. + bool "Bind spidev to SPI0 master"
  7295. + depends on MACH_BCM2708
  7296. + depends on SPI
  7297. + default y
  7298. + help
  7299. + Binds spidev driver to the SPI0 master
  7300. +
  7301. +config BCM2708_DMAER
  7302. + tristate "BCM2708 DMA helper"
  7303. + depends on MACH_BCM2708
  7304. + default n
  7305. + help
  7306. + Enable DMA helper for accelerating X composition
  7307. +
  7308. +endmenu
  7309. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/Makefile linux-3.12.11/arch/arm/mach-bcm2708/Makefile
  7310. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/Makefile 1970-01-01 01:00:00.000000000 +0100
  7311. +++ linux-3.12.11/arch/arm/mach-bcm2708/Makefile 2014-02-18 11:52:14.000000000 +0100
  7312. @@ -0,0 +1,10 @@
  7313. +#
  7314. +# Makefile for the linux kernel.
  7315. +#
  7316. +
  7317. +obj-$(CONFIG_MACH_BCM2708) += clock.o bcm2708.o armctrl.o vcio.o power.o dma.o
  7318. +obj-$(CONFIG_BCM2708_GPIO) += bcm2708_gpio.o
  7319. +obj-$(CONFIG_BCM2708_VCMEM) += vc_mem.o
  7320. +
  7321. +obj-$(CONFIG_BCM2708_DMAER) += dmaer_master.o
  7322. +dmaer_master-objs := dmaer.o vc_support.o
  7323. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/Makefile.boot linux-3.12.11/arch/arm/mach-bcm2708/Makefile.boot
  7324. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/Makefile.boot 1970-01-01 01:00:00.000000000 +0100
  7325. +++ linux-3.12.11/arch/arm/mach-bcm2708/Makefile.boot 2014-02-18 11:52:14.000000000 +0100
  7326. @@ -0,0 +1,3 @@
  7327. + zreladdr-y := 0x00008000
  7328. +params_phys-y := 0x00000100
  7329. +initrd_phys-y := 0x00800000
  7330. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/power.c linux-3.12.11/arch/arm/mach-bcm2708/power.c
  7331. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/power.c 1970-01-01 01:00:00.000000000 +0100
  7332. +++ linux-3.12.11/arch/arm/mach-bcm2708/power.c 2014-02-18 11:52:14.000000000 +0100
  7333. @@ -0,0 +1,194 @@
  7334. +/*
  7335. + * linux/arch/arm/mach-bcm2708/power.c
  7336. + *
  7337. + * Copyright (C) 2010 Broadcom
  7338. + *
  7339. + * This program is free software; you can redistribute it and/or modify
  7340. + * it under the terms of the GNU General Public License version 2 as
  7341. + * published by the Free Software Foundation.
  7342. + *
  7343. + * This device provides a shared mechanism for controlling the power to
  7344. + * VideoCore subsystems.
  7345. + */
  7346. +
  7347. +#include <linux/module.h>
  7348. +#include <linux/semaphore.h>
  7349. +#include <linux/bug.h>
  7350. +#include <mach/power.h>
  7351. +#include <mach/vcio.h>
  7352. +#include <mach/arm_power.h>
  7353. +
  7354. +#define DRIVER_NAME "bcm2708_power"
  7355. +
  7356. +#define BCM_POWER_MAXCLIENTS 4
  7357. +#define BCM_POWER_NOCLIENT (1<<31)
  7358. +
  7359. +/* Some drivers expect there devices to be permanently powered */
  7360. +#define BCM_POWER_ALWAYS_ON (BCM_POWER_USB)
  7361. +
  7362. +#if 1
  7363. +#define DPRINTK printk
  7364. +#else
  7365. +#define DPRINTK if (0) printk
  7366. +#endif
  7367. +
  7368. +struct state_struct {
  7369. + uint32_t global_request;
  7370. + uint32_t client_request[BCM_POWER_MAXCLIENTS];
  7371. + struct semaphore client_mutex;
  7372. + struct semaphore mutex;
  7373. +} g_state;
  7374. +
  7375. +int bcm_power_open(BCM_POWER_HANDLE_T *handle)
  7376. +{
  7377. + BCM_POWER_HANDLE_T i;
  7378. + int ret = -EBUSY;
  7379. +
  7380. + down(&g_state.client_mutex);
  7381. +
  7382. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  7383. + if (g_state.client_request[i] == BCM_POWER_NOCLIENT) {
  7384. + g_state.client_request[i] = BCM_POWER_NONE;
  7385. + *handle = i;
  7386. + ret = 0;
  7387. + break;
  7388. + }
  7389. + }
  7390. +
  7391. + up(&g_state.client_mutex);
  7392. +
  7393. + DPRINTK("bcm_power_open() -> %d\n", *handle);
  7394. +
  7395. + return ret;
  7396. +}
  7397. +EXPORT_SYMBOL_GPL(bcm_power_open);
  7398. +
  7399. +int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request)
  7400. +{
  7401. + int rc = 0;
  7402. +
  7403. + DPRINTK("bcm_power_request(%d, %x)\n", handle, request);
  7404. +
  7405. + if ((handle < BCM_POWER_MAXCLIENTS) &&
  7406. + (g_state.client_request[handle] != BCM_POWER_NOCLIENT)) {
  7407. + if (down_interruptible(&g_state.mutex) != 0) {
  7408. + DPRINTK("bcm_power_request -> interrupted\n");
  7409. + return -EINTR;
  7410. + }
  7411. +
  7412. + if (request != g_state.client_request[handle]) {
  7413. + uint32_t others_request = 0;
  7414. + uint32_t global_request;
  7415. + BCM_POWER_HANDLE_T i;
  7416. +
  7417. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  7418. + if (i != handle)
  7419. + others_request |=
  7420. + g_state.client_request[i];
  7421. + }
  7422. + others_request &= ~BCM_POWER_NOCLIENT;
  7423. +
  7424. + global_request = request | others_request;
  7425. + if (global_request != g_state.global_request) {
  7426. + uint32_t actual;
  7427. +
  7428. + /* Send a request to VideoCore */
  7429. + bcm_mailbox_write(MBOX_CHAN_POWER,
  7430. + global_request << 4);
  7431. +
  7432. + /* Wait for a response during power-up */
  7433. + if (global_request & ~g_state.global_request) {
  7434. + rc = bcm_mailbox_read(MBOX_CHAN_POWER,
  7435. + &actual);
  7436. + DPRINTK
  7437. + ("bcm_mailbox_read -> %08x, %d\n",
  7438. + actual, rc);
  7439. + actual >>= 4;
  7440. + } else {
  7441. + rc = 0;
  7442. + actual = global_request;
  7443. + }
  7444. +
  7445. + if (rc == 0) {
  7446. + if (actual != global_request) {
  7447. + printk(KERN_ERR
  7448. + "%s: prev global %x, new global %x, actual %x, request %x, others_request %x\n",
  7449. + __func__,
  7450. + g_state.global_request,
  7451. + global_request, actual, request, others_request);
  7452. + /* A failure */
  7453. + BUG_ON((others_request & actual)
  7454. + != others_request);
  7455. + request &= actual;
  7456. + rc = -EIO;
  7457. + }
  7458. +
  7459. + g_state.global_request = actual;
  7460. + g_state.client_request[handle] =
  7461. + request;
  7462. + }
  7463. + }
  7464. + }
  7465. + up(&g_state.mutex);
  7466. + } else {
  7467. + rc = -EINVAL;
  7468. + }
  7469. + DPRINTK("bcm_power_request -> %d\n", rc);
  7470. + return rc;
  7471. +}
  7472. +EXPORT_SYMBOL_GPL(bcm_power_request);
  7473. +
  7474. +int bcm_power_close(BCM_POWER_HANDLE_T handle)
  7475. +{
  7476. + int rc;
  7477. +
  7478. + DPRINTK("bcm_power_close(%d)\n", handle);
  7479. +
  7480. + rc = bcm_power_request(handle, BCM_POWER_NONE);
  7481. + if (rc == 0)
  7482. + g_state.client_request[handle] = BCM_POWER_NOCLIENT;
  7483. +
  7484. + return rc;
  7485. +}
  7486. +EXPORT_SYMBOL_GPL(bcm_power_close);
  7487. +
  7488. +static int __init bcm_power_init(void)
  7489. +{
  7490. +#if defined(BCM_POWER_ALWAYS_ON)
  7491. + BCM_POWER_HANDLE_T always_on_handle;
  7492. +#endif
  7493. + int rc = 0;
  7494. + int i;
  7495. +
  7496. + printk(KERN_INFO "bcm_power: Broadcom power driver\n");
  7497. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  7498. +
  7499. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++)
  7500. + g_state.client_request[i] = BCM_POWER_NOCLIENT;
  7501. +
  7502. + sema_init(&g_state.client_mutex, 1);
  7503. + sema_init(&g_state.mutex, 1);
  7504. +
  7505. + g_state.global_request = 0;
  7506. +
  7507. +#if defined(BCM_POWER_ALWAYS_ON)
  7508. + if (BCM_POWER_ALWAYS_ON) {
  7509. + bcm_power_open(&always_on_handle);
  7510. + bcm_power_request(always_on_handle, BCM_POWER_ALWAYS_ON);
  7511. + }
  7512. +#endif
  7513. +
  7514. + return rc;
  7515. +}
  7516. +
  7517. +static void __exit bcm_power_exit(void)
  7518. +{
  7519. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  7520. +}
  7521. +
  7522. +arch_initcall(bcm_power_init); /* Initialize early */
  7523. +module_exit(bcm_power_exit);
  7524. +
  7525. +MODULE_AUTHOR("Phil Elwell");
  7526. +MODULE_DESCRIPTION("Interface to BCM2708 power management");
  7527. +MODULE_LICENSE("GPL");
  7528. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/vcio.c linux-3.12.11/arch/arm/mach-bcm2708/vcio.c
  7529. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/vcio.c 1970-01-01 01:00:00.000000000 +0100
  7530. +++ linux-3.12.11/arch/arm/mach-bcm2708/vcio.c 2014-02-18 11:52:14.000000000 +0100
  7531. @@ -0,0 +1,474 @@
  7532. +/*
  7533. + * linux/arch/arm/mach-bcm2708/vcio.c
  7534. + *
  7535. + * Copyright (C) 2010 Broadcom
  7536. + *
  7537. + * This program is free software; you can redistribute it and/or modify
  7538. + * it under the terms of the GNU General Public License version 2 as
  7539. + * published by the Free Software Foundation.
  7540. + *
  7541. + * This device provides a shared mechanism for writing to the mailboxes,
  7542. + * semaphores, doorbells etc. that are shared between the ARM and the
  7543. + * VideoCore processor
  7544. + */
  7545. +
  7546. +#if defined(CONFIG_SERIAL_BCM_MBOX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  7547. +#define SUPPORT_SYSRQ
  7548. +#endif
  7549. +
  7550. +#include <linux/module.h>
  7551. +#include <linux/console.h>
  7552. +#include <linux/serial_core.h>
  7553. +#include <linux/serial.h>
  7554. +#include <linux/errno.h>
  7555. +#include <linux/device.h>
  7556. +#include <linux/init.h>
  7557. +#include <linux/mm.h>
  7558. +#include <linux/dma-mapping.h>
  7559. +#include <linux/platform_device.h>
  7560. +#include <linux/sysrq.h>
  7561. +#include <linux/delay.h>
  7562. +#include <linux/slab.h>
  7563. +#include <linux/interrupt.h>
  7564. +#include <linux/irq.h>
  7565. +
  7566. +#include <linux/io.h>
  7567. +
  7568. +#include <mach/vcio.h>
  7569. +#include <mach/platform.h>
  7570. +
  7571. +#include <asm/uaccess.h>
  7572. +
  7573. +
  7574. +#define DRIVER_NAME BCM_VCIO_DRIVER_NAME
  7575. +
  7576. +/* ----------------------------------------------------------------------
  7577. + * Mailbox
  7578. + * -------------------------------------------------------------------- */
  7579. +
  7580. +/* offsets from a mail box base address */
  7581. +#define MAIL_WRT 0x00 /* write - and next 4 words */
  7582. +#define MAIL_RD 0x00 /* read - and next 4 words */
  7583. +#define MAIL_POL 0x10 /* read without popping the fifo */
  7584. +#define MAIL_SND 0x14 /* sender ID (bottom two bits) */
  7585. +#define MAIL_STA 0x18 /* status */
  7586. +#define MAIL_CNF 0x1C /* configuration */
  7587. +
  7588. +#define MBOX_MSG(chan, data28) (((data28) & ~0xf) | ((chan) & 0xf))
  7589. +#define MBOX_MSG_LSB(chan, data28) (((data28) << 4) | ((chan) & 0xf))
  7590. +#define MBOX_CHAN(msg) ((msg) & 0xf)
  7591. +#define MBOX_DATA28(msg) ((msg) & ~0xf)
  7592. +#define MBOX_DATA28_LSB(msg) (((uint32_t)msg) >> 4)
  7593. +
  7594. +#define MBOX_MAGIC 0xd0d0c0de
  7595. +
  7596. +struct vc_mailbox {
  7597. + struct device *dev; /* parent device */
  7598. + void __iomem *status;
  7599. + void __iomem *config;
  7600. + void __iomem *read;
  7601. + void __iomem *write;
  7602. + uint32_t msg[MBOX_CHAN_COUNT];
  7603. + struct semaphore sema[MBOX_CHAN_COUNT];
  7604. + uint32_t magic;
  7605. +};
  7606. +
  7607. +static void mbox_init(struct vc_mailbox *mbox_out, struct device *dev,
  7608. + uint32_t addr_mbox)
  7609. +{
  7610. + int i;
  7611. +
  7612. + mbox_out->dev = dev;
  7613. + mbox_out->status = __io_address(addr_mbox + MAIL_STA);
  7614. + mbox_out->config = __io_address(addr_mbox + MAIL_CNF);
  7615. + mbox_out->read = __io_address(addr_mbox + MAIL_RD);
  7616. + /* Write to the other mailbox */
  7617. + mbox_out->write =
  7618. + __io_address((addr_mbox ^ ARM_0_MAIL0_WRT ^ ARM_0_MAIL1_WRT) +
  7619. + MAIL_WRT);
  7620. +
  7621. + for (i = 0; i < MBOX_CHAN_COUNT; i++) {
  7622. + mbox_out->msg[i] = 0;
  7623. + sema_init(&mbox_out->sema[i], 0);
  7624. + }
  7625. +
  7626. + /* Enable the interrupt on data reception */
  7627. + writel(ARM_MC_IHAVEDATAIRQEN, mbox_out->config);
  7628. +
  7629. + mbox_out->magic = MBOX_MAGIC;
  7630. +}
  7631. +
  7632. +static int mbox_write(struct vc_mailbox *mbox, unsigned chan, uint32_t data28)
  7633. +{
  7634. + int rc;
  7635. +
  7636. + if (mbox->magic != MBOX_MAGIC)
  7637. + rc = -EINVAL;
  7638. + else {
  7639. + /* wait for the mailbox FIFO to have some space in it */
  7640. + while (0 != (readl(mbox->status) & ARM_MS_FULL))
  7641. + cpu_relax();
  7642. +
  7643. + writel(MBOX_MSG(chan, data28), mbox->write);
  7644. + rc = 0;
  7645. + }
  7646. + return rc;
  7647. +}
  7648. +
  7649. +static int mbox_read(struct vc_mailbox *mbox, unsigned chan, uint32_t *data28)
  7650. +{
  7651. + int rc;
  7652. +
  7653. + if (mbox->magic != MBOX_MAGIC)
  7654. + rc = -EINVAL;
  7655. + else {
  7656. + down(&mbox->sema[chan]);
  7657. + *data28 = MBOX_DATA28(mbox->msg[chan]);
  7658. + mbox->msg[chan] = 0;
  7659. + rc = 0;
  7660. + }
  7661. + return rc;
  7662. +}
  7663. +
  7664. +static irqreturn_t mbox_irq(int irq, void *dev_id)
  7665. +{
  7666. + /* wait for the mailbox FIFO to have some data in it */
  7667. + struct vc_mailbox *mbox = (struct vc_mailbox *) dev_id;
  7668. + int status = readl(mbox->status);
  7669. + int ret = IRQ_NONE;
  7670. +
  7671. + while (!(status & ARM_MS_EMPTY)) {
  7672. + uint32_t msg = readl(mbox->read);
  7673. + int chan = MBOX_CHAN(msg);
  7674. + if (chan < MBOX_CHAN_COUNT) {
  7675. + if (mbox->msg[chan]) {
  7676. + /* Overflow */
  7677. + printk(KERN_ERR DRIVER_NAME
  7678. + ": mbox chan %d overflow - drop %08x\n",
  7679. + chan, msg);
  7680. + } else {
  7681. + mbox->msg[chan] = (msg | 0xf);
  7682. + up(&mbox->sema[chan]);
  7683. + }
  7684. + } else {
  7685. + printk(KERN_ERR DRIVER_NAME
  7686. + ": invalid channel selector (msg %08x)\n", msg);
  7687. + }
  7688. + ret = IRQ_HANDLED;
  7689. + status = readl(mbox->status);
  7690. + }
  7691. + return ret;
  7692. +}
  7693. +
  7694. +static struct irqaction mbox_irqaction = {
  7695. + .name = "ARM Mailbox IRQ",
  7696. + .flags = IRQF_DISABLED | IRQF_IRQPOLL,
  7697. + .handler = mbox_irq,
  7698. +};
  7699. +
  7700. +/* ----------------------------------------------------------------------
  7701. + * Mailbox Methods
  7702. + * -------------------------------------------------------------------- */
  7703. +
  7704. +static struct device *mbox_dev; /* we assume there's only one! */
  7705. +
  7706. +static int dev_mbox_write(struct device *dev, unsigned chan, uint32_t data28)
  7707. +{
  7708. + int rc;
  7709. +
  7710. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  7711. + device_lock(dev);
  7712. + rc = mbox_write(mailbox, chan, data28);
  7713. + device_unlock(dev);
  7714. +
  7715. + return rc;
  7716. +}
  7717. +
  7718. +static int dev_mbox_read(struct device *dev, unsigned chan, uint32_t *data28)
  7719. +{
  7720. + int rc;
  7721. +
  7722. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  7723. + device_lock(dev);
  7724. + rc = mbox_read(mailbox, chan, data28);
  7725. + device_unlock(dev);
  7726. +
  7727. + return rc;
  7728. +}
  7729. +
  7730. +extern int bcm_mailbox_write(unsigned chan, uint32_t data28)
  7731. +{
  7732. + if (mbox_dev)
  7733. + return dev_mbox_write(mbox_dev, chan, data28);
  7734. + else
  7735. + return -ENODEV;
  7736. +}
  7737. +EXPORT_SYMBOL_GPL(bcm_mailbox_write);
  7738. +
  7739. +extern int bcm_mailbox_read(unsigned chan, uint32_t *data28)
  7740. +{
  7741. + if (mbox_dev)
  7742. + return dev_mbox_read(mbox_dev, chan, data28);
  7743. + else
  7744. + return -ENODEV;
  7745. +}
  7746. +EXPORT_SYMBOL_GPL(bcm_mailbox_read);
  7747. +
  7748. +static void dev_mbox_register(const char *dev_name, struct device *dev)
  7749. +{
  7750. + mbox_dev = dev;
  7751. +}
  7752. +
  7753. +static int mbox_copy_from_user(void *dst, const void *src, int size)
  7754. +{
  7755. + if ( (uint32_t)src < TASK_SIZE)
  7756. + {
  7757. + return copy_from_user(dst, src, size);
  7758. + }
  7759. + else
  7760. + {
  7761. + memcpy( dst, src, size );
  7762. + return 0;
  7763. + }
  7764. +}
  7765. +
  7766. +static int mbox_copy_to_user(void *dst, const void *src, int size)
  7767. +{
  7768. + if ( (uint32_t)dst < TASK_SIZE)
  7769. + {
  7770. + return copy_to_user(dst, src, size);
  7771. + }
  7772. + else
  7773. + {
  7774. + memcpy( dst, src, size );
  7775. + return 0;
  7776. + }
  7777. +}
  7778. +
  7779. +static DEFINE_MUTEX(mailbox_lock);
  7780. +extern int bcm_mailbox_property(void *data, int size)
  7781. +{
  7782. + uint32_t success;
  7783. + dma_addr_t mem_bus; /* the memory address accessed from videocore */
  7784. + void *mem_kern; /* the memory address accessed from driver */
  7785. + int s = 0;
  7786. +
  7787. + mutex_lock(&mailbox_lock);
  7788. + /* allocate some memory for the messages communicating with GPU */
  7789. + mem_kern = dma_alloc_coherent(NULL, PAGE_ALIGN(size), &mem_bus, GFP_ATOMIC);
  7790. + if (mem_kern) {
  7791. + /* create the message */
  7792. + mbox_copy_from_user(mem_kern, data, size);
  7793. +
  7794. + /* send the message */
  7795. + wmb();
  7796. + s = bcm_mailbox_write(MBOX_CHAN_PROPERTY, (uint32_t)mem_bus);
  7797. + if (s == 0) {
  7798. + s = bcm_mailbox_read(MBOX_CHAN_PROPERTY, &success);
  7799. + }
  7800. + if (s == 0) {
  7801. + /* copy the response */
  7802. + rmb();
  7803. + mbox_copy_to_user(data, mem_kern, size);
  7804. + }
  7805. + dma_free_coherent(NULL, PAGE_ALIGN(size), mem_kern, mem_bus);
  7806. + } else {
  7807. + s = -ENOMEM;
  7808. + }
  7809. + if (s != 0)
  7810. + printk(KERN_ERR DRIVER_NAME ": %s failed (%d)\n", __func__, s);
  7811. +
  7812. + mutex_unlock(&mailbox_lock);
  7813. + return s;
  7814. +}
  7815. +EXPORT_SYMBOL_GPL(bcm_mailbox_property);
  7816. +
  7817. +/* ----------------------------------------------------------------------
  7818. + * Platform Device for Mailbox
  7819. + * -------------------------------------------------------------------- */
  7820. +
  7821. +/*
  7822. + * Is the device open right now? Used to prevent
  7823. + * concurent access into the same device
  7824. + */
  7825. +static int Device_Open = 0;
  7826. +
  7827. +/*
  7828. + * This is called whenever a process attempts to open the device file
  7829. + */
  7830. +static int device_open(struct inode *inode, struct file *file)
  7831. +{
  7832. + /*
  7833. + * We don't want to talk to two processes at the same time
  7834. + */
  7835. + if (Device_Open)
  7836. + return -EBUSY;
  7837. +
  7838. + Device_Open++;
  7839. + /*
  7840. + * Initialize the message
  7841. + */
  7842. + try_module_get(THIS_MODULE);
  7843. + return 0;
  7844. +}
  7845. +
  7846. +static int device_release(struct inode *inode, struct file *file)
  7847. +{
  7848. + /*
  7849. + * We're now ready for our next caller
  7850. + */
  7851. + Device_Open--;
  7852. +
  7853. + module_put(THIS_MODULE);
  7854. + return 0;
  7855. +}
  7856. +
  7857. +/*
  7858. + * This function is called whenever a process tries to do an ioctl on our
  7859. + * device file. We get two extra parameters (additional to the inode and file
  7860. + * structures, which all device functions get): the number of the ioctl called
  7861. + * and the parameter given to the ioctl function.
  7862. + *
  7863. + * If the ioctl is write or read/write (meaning output is returned to the
  7864. + * calling process), the ioctl call returns the output of this function.
  7865. + *
  7866. + */
  7867. +static long device_ioctl(struct file *file, /* see include/linux/fs.h */
  7868. + unsigned int ioctl_num, /* number and param for ioctl */
  7869. + unsigned long ioctl_param)
  7870. +{
  7871. + unsigned size;
  7872. + /*
  7873. + * Switch according to the ioctl called
  7874. + */
  7875. + switch (ioctl_num) {
  7876. + case IOCTL_MBOX_PROPERTY:
  7877. + /*
  7878. + * Receive a pointer to a message (in user space) and set that
  7879. + * to be the device's message. Get the parameter given to
  7880. + * ioctl by the process.
  7881. + */
  7882. + mbox_copy_from_user(&size, (void *)ioctl_param, sizeof size);
  7883. + return bcm_mailbox_property((void *)ioctl_param, size);
  7884. + break;
  7885. + default:
  7886. + printk(KERN_ERR DRIVER_NAME "unknown ioctl: %d\n", ioctl_num);
  7887. + return -EINVAL;
  7888. + }
  7889. +
  7890. + return 0;
  7891. +}
  7892. +
  7893. +/* Module Declarations */
  7894. +
  7895. +/*
  7896. + * This structure will hold the functions to be called
  7897. + * when a process does something to the device we
  7898. + * created. Since a pointer to this structure is kept in
  7899. + * the devices table, it can't be local to
  7900. + * init_module. NULL is for unimplemented functios.
  7901. + */
  7902. +struct file_operations fops = {
  7903. + .unlocked_ioctl = device_ioctl,
  7904. + .open = device_open,
  7905. + .release = device_release, /* a.k.a. close */
  7906. +};
  7907. +
  7908. +static int bcm_vcio_probe(struct platform_device *pdev)
  7909. +{
  7910. + int ret = 0;
  7911. + struct vc_mailbox *mailbox;
  7912. +
  7913. + mailbox = kzalloc(sizeof(*mailbox), GFP_KERNEL);
  7914. + if (NULL == mailbox) {
  7915. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  7916. + "mailbox memory\n");
  7917. + ret = -ENOMEM;
  7918. + } else {
  7919. + struct resource *res;
  7920. +
  7921. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  7922. + if (res == NULL) {
  7923. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  7924. + "resource\n");
  7925. + ret = -ENODEV;
  7926. + kfree(mailbox);
  7927. + } else {
  7928. + /* should be based on the registers from res really */
  7929. + mbox_init(mailbox, &pdev->dev, ARM_0_MAIL0_RD);
  7930. +
  7931. + platform_set_drvdata(pdev, mailbox);
  7932. + dev_mbox_register(DRIVER_NAME, &pdev->dev);
  7933. +
  7934. + mbox_irqaction.dev_id = mailbox;
  7935. + setup_irq(IRQ_ARM_MAILBOX, &mbox_irqaction);
  7936. + printk(KERN_INFO DRIVER_NAME ": mailbox at %p\n",
  7937. + __io_address(ARM_0_MAIL0_RD));
  7938. + }
  7939. + }
  7940. +
  7941. + if (ret == 0) {
  7942. + /*
  7943. + * Register the character device
  7944. + */
  7945. + ret = register_chrdev(MAJOR_NUM, DEVICE_FILE_NAME, &fops);
  7946. +
  7947. + /*
  7948. + * Negative values signify an error
  7949. + */
  7950. + if (ret < 0) {
  7951. + printk(KERN_ERR DRIVER_NAME
  7952. + "Failed registering the character device %d\n", ret);
  7953. + return ret;
  7954. + }
  7955. + }
  7956. + return ret;
  7957. +}
  7958. +
  7959. +static int bcm_vcio_remove(struct platform_device *pdev)
  7960. +{
  7961. + struct vc_mailbox *mailbox = platform_get_drvdata(pdev);
  7962. +
  7963. + platform_set_drvdata(pdev, NULL);
  7964. + kfree(mailbox);
  7965. +
  7966. + return 0;
  7967. +}
  7968. +
  7969. +static struct platform_driver bcm_mbox_driver = {
  7970. + .probe = bcm_vcio_probe,
  7971. + .remove = bcm_vcio_remove,
  7972. +
  7973. + .driver = {
  7974. + .name = DRIVER_NAME,
  7975. + .owner = THIS_MODULE,
  7976. + },
  7977. +};
  7978. +
  7979. +static int __init bcm_mbox_init(void)
  7980. +{
  7981. + int ret;
  7982. +
  7983. + printk(KERN_INFO "mailbox: Broadcom VideoCore Mailbox driver\n");
  7984. +
  7985. + ret = platform_driver_register(&bcm_mbox_driver);
  7986. + if (ret != 0) {
  7987. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  7988. + "on platform\n");
  7989. + }
  7990. +
  7991. + return ret;
  7992. +}
  7993. +
  7994. +static void __exit bcm_mbox_exit(void)
  7995. +{
  7996. + platform_driver_unregister(&bcm_mbox_driver);
  7997. +}
  7998. +
  7999. +arch_initcall(bcm_mbox_init); /* Initialize early */
  8000. +module_exit(bcm_mbox_exit);
  8001. +
  8002. +MODULE_AUTHOR("Gray Girling");
  8003. +MODULE_DESCRIPTION("ARM I/O to VideoCore processor");
  8004. +MODULE_LICENSE("GPL");
  8005. +MODULE_ALIAS("platform:bcm-mbox");
  8006. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/vc_mem.c linux-3.12.11/arch/arm/mach-bcm2708/vc_mem.c
  8007. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/vc_mem.c 1970-01-01 01:00:00.000000000 +0100
  8008. +++ linux-3.12.11/arch/arm/mach-bcm2708/vc_mem.c 2014-02-18 11:52:14.000000000 +0100
  8009. @@ -0,0 +1,462 @@
  8010. +/*****************************************************************************
  8011. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  8012. +*
  8013. +* Unless you and Broadcom execute a separate written software license
  8014. +* agreement governing use of this software, this software is licensed to you
  8015. +* under the terms of the GNU General Public License version 2, available at
  8016. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  8017. +*
  8018. +* Notwithstanding the above, under no circumstances may you combine this
  8019. +* software in any way with any other Broadcom software provided under a
  8020. +* license other than the GPL, without Broadcom's express prior written
  8021. +* consent.
  8022. +*****************************************************************************/
  8023. +
  8024. +#include <linux/kernel.h>
  8025. +#include <linux/module.h>
  8026. +#include <linux/fs.h>
  8027. +#include <linux/device.h>
  8028. +#include <linux/cdev.h>
  8029. +#include <linux/mm.h>
  8030. +#include <linux/slab.h>
  8031. +#include <linux/proc_fs.h>
  8032. +#include <asm/uaccess.h>
  8033. +#include <linux/dma-mapping.h>
  8034. +
  8035. +#ifdef CONFIG_ARCH_KONA
  8036. +#include <chal/chal_ipc.h>
  8037. +#elif CONFIG_ARCH_BCM2708
  8038. +#else
  8039. +#include <csp/chal_ipc.h>
  8040. +#endif
  8041. +
  8042. +#include "mach/vc_mem.h"
  8043. +#include <mach/vcio.h>
  8044. +
  8045. +#define DRIVER_NAME "vc-mem"
  8046. +
  8047. +// Uncomment to enable debug logging
  8048. +// #define ENABLE_DBG
  8049. +
  8050. +#if defined(ENABLE_DBG)
  8051. +#define LOG_DBG( fmt, ... ) printk( KERN_INFO fmt "\n", ##__VA_ARGS__ )
  8052. +#else
  8053. +#define LOG_DBG( fmt, ... )
  8054. +#endif
  8055. +#define LOG_ERR( fmt, ... ) printk( KERN_ERR fmt "\n", ##__VA_ARGS__ )
  8056. +
  8057. +// Device (/dev) related variables
  8058. +static dev_t vc_mem_devnum = 0;
  8059. +static struct class *vc_mem_class = NULL;
  8060. +static struct cdev vc_mem_cdev;
  8061. +static int vc_mem_inited = 0;
  8062. +
  8063. +// Proc entry
  8064. +static struct proc_dir_entry *vc_mem_proc_entry;
  8065. +
  8066. +/*
  8067. + * Videocore memory addresses and size
  8068. + *
  8069. + * Drivers that wish to know the videocore memory addresses and sizes should
  8070. + * use these variables instead of the MM_IO_BASE and MM_ADDR_IO defines in
  8071. + * headers. This allows the other drivers to not be tied down to a a certain
  8072. + * address/size at compile time.
  8073. + *
  8074. + * In the future, the goal is to have the videocore memory virtual address and
  8075. + * size be calculated at boot time rather than at compile time. The decision of
  8076. + * where the videocore memory resides and its size would be in the hands of the
  8077. + * bootloader (and/or kernel). When that happens, the values of these variables
  8078. + * would be calculated and assigned in the init function.
  8079. + */
  8080. +// in the 2835 VC in mapped above ARM, but ARM has full access to VC space
  8081. +unsigned long mm_vc_mem_phys_addr = 0x00000000;
  8082. +unsigned int mm_vc_mem_size = 0;
  8083. +unsigned int mm_vc_mem_base = 0;
  8084. +
  8085. +EXPORT_SYMBOL(mm_vc_mem_phys_addr);
  8086. +EXPORT_SYMBOL(mm_vc_mem_size);
  8087. +EXPORT_SYMBOL(mm_vc_mem_base);
  8088. +
  8089. +static uint phys_addr = 0;
  8090. +static uint mem_size = 0;
  8091. +static uint mem_base = 0;
  8092. +
  8093. +
  8094. +/****************************************************************************
  8095. +*
  8096. +* vc_mem_open
  8097. +*
  8098. +***************************************************************************/
  8099. +
  8100. +static int
  8101. +vc_mem_open(struct inode *inode, struct file *file)
  8102. +{
  8103. + (void) inode;
  8104. + (void) file;
  8105. +
  8106. + LOG_DBG("%s: called file = 0x%p", __func__, file);
  8107. +
  8108. + return 0;
  8109. +}
  8110. +
  8111. +/****************************************************************************
  8112. +*
  8113. +* vc_mem_release
  8114. +*
  8115. +***************************************************************************/
  8116. +
  8117. +static int
  8118. +vc_mem_release(struct inode *inode, struct file *file)
  8119. +{
  8120. + (void) inode;
  8121. + (void) file;
  8122. +
  8123. + LOG_DBG("%s: called file = 0x%p", __func__, file);
  8124. +
  8125. + return 0;
  8126. +}
  8127. +
  8128. +/****************************************************************************
  8129. +*
  8130. +* vc_mem_get_size
  8131. +*
  8132. +***************************************************************************/
  8133. +
  8134. +static void
  8135. +vc_mem_get_size(void)
  8136. +{
  8137. +}
  8138. +
  8139. +/****************************************************************************
  8140. +*
  8141. +* vc_mem_get_base
  8142. +*
  8143. +***************************************************************************/
  8144. +
  8145. +static void
  8146. +vc_mem_get_base(void)
  8147. +{
  8148. +}
  8149. +
  8150. +/****************************************************************************
  8151. +*
  8152. +* vc_mem_get_current_size
  8153. +*
  8154. +***************************************************************************/
  8155. +
  8156. +int
  8157. +vc_mem_get_current_size(void)
  8158. +{
  8159. + return mm_vc_mem_size;
  8160. +}
  8161. +
  8162. +EXPORT_SYMBOL_GPL(vc_mem_get_current_size);
  8163. +
  8164. +/****************************************************************************
  8165. +*
  8166. +* vc_mem_ioctl
  8167. +*
  8168. +***************************************************************************/
  8169. +
  8170. +static long
  8171. +vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  8172. +{
  8173. + int rc = 0;
  8174. +
  8175. + (void) cmd;
  8176. + (void) arg;
  8177. +
  8178. + LOG_DBG("%s: called file = 0x%p", __func__, file);
  8179. +
  8180. + switch (cmd) {
  8181. + case VC_MEM_IOC_MEM_PHYS_ADDR:
  8182. + {
  8183. + LOG_DBG("%s: VC_MEM_IOC_MEM_PHYS_ADDR=0x%p",
  8184. + __func__, (void *) mm_vc_mem_phys_addr);
  8185. +
  8186. + if (copy_to_user((void *) arg, &mm_vc_mem_phys_addr,
  8187. + sizeof (mm_vc_mem_phys_addr)) != 0) {
  8188. + rc = -EFAULT;
  8189. + }
  8190. + break;
  8191. + }
  8192. + case VC_MEM_IOC_MEM_SIZE:
  8193. + {
  8194. + // Get the videocore memory size first
  8195. + vc_mem_get_size();
  8196. +
  8197. + LOG_DBG("%s: VC_MEM_IOC_MEM_SIZE=%u", __func__,
  8198. + mm_vc_mem_size);
  8199. +
  8200. + if (copy_to_user((void *) arg, &mm_vc_mem_size,
  8201. + sizeof (mm_vc_mem_size)) != 0) {
  8202. + rc = -EFAULT;
  8203. + }
  8204. + break;
  8205. + }
  8206. + case VC_MEM_IOC_MEM_BASE:
  8207. + {
  8208. + // Get the videocore memory base
  8209. + vc_mem_get_base();
  8210. +
  8211. + LOG_DBG("%s: VC_MEM_IOC_MEM_BASE=%u", __func__,
  8212. + mm_vc_mem_base);
  8213. +
  8214. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  8215. + sizeof (mm_vc_mem_base)) != 0) {
  8216. + rc = -EFAULT;
  8217. + }
  8218. + break;
  8219. + }
  8220. + case VC_MEM_IOC_MEM_LOAD:
  8221. + {
  8222. + // Get the videocore memory base
  8223. + vc_mem_get_base();
  8224. +
  8225. + LOG_DBG("%s: VC_MEM_IOC_MEM_LOAD=%u", __func__,
  8226. + mm_vc_mem_base);
  8227. +
  8228. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  8229. + sizeof (mm_vc_mem_base)) != 0) {
  8230. + rc = -EFAULT;
  8231. + }
  8232. + break;
  8233. + }
  8234. + default:
  8235. + {
  8236. + return -ENOTTY;
  8237. + }
  8238. + }
  8239. + LOG_DBG("%s: file = 0x%p returning %d", __func__, file, rc);
  8240. +
  8241. + return rc;
  8242. +}
  8243. +
  8244. +/****************************************************************************
  8245. +*
  8246. +* vc_mem_mmap
  8247. +*
  8248. +***************************************************************************/
  8249. +
  8250. +static int
  8251. +vc_mem_mmap(struct file *filp, struct vm_area_struct *vma)
  8252. +{
  8253. + int rc = 0;
  8254. + unsigned long length = vma->vm_end - vma->vm_start;
  8255. + unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  8256. +
  8257. + LOG_DBG("%s: vm_start = 0x%08lx vm_end = 0x%08lx vm_pgoff = 0x%08lx",
  8258. + __func__, (long) vma->vm_start, (long) vma->vm_end,
  8259. + (long) vma->vm_pgoff);
  8260. +
  8261. + if (offset + length > mm_vc_mem_size) {
  8262. + LOG_ERR("%s: length %ld is too big", __func__, length);
  8263. + return -EINVAL;
  8264. + }
  8265. + // Do not cache the memory map
  8266. + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  8267. +
  8268. + rc = remap_pfn_range(vma, vma->vm_start,
  8269. + (mm_vc_mem_phys_addr >> PAGE_SHIFT) +
  8270. + vma->vm_pgoff, length, vma->vm_page_prot);
  8271. + if (rc != 0) {
  8272. + LOG_ERR("%s: remap_pfn_range failed (rc=%d)", __func__, rc);
  8273. + }
  8274. +
  8275. + return rc;
  8276. +}
  8277. +
  8278. +/****************************************************************************
  8279. +*
  8280. +* File Operations for the driver.
  8281. +*
  8282. +***************************************************************************/
  8283. +
  8284. +static const struct file_operations vc_mem_fops = {
  8285. + .owner = THIS_MODULE,
  8286. + .open = vc_mem_open,
  8287. + .release = vc_mem_release,
  8288. + .unlocked_ioctl = vc_mem_ioctl,
  8289. + .mmap = vc_mem_mmap,
  8290. +};
  8291. +
  8292. +/****************************************************************************
  8293. +*
  8294. +* vc_mem_proc_read
  8295. +*
  8296. +***************************************************************************/
  8297. +
  8298. +static int
  8299. +vc_mem_proc_read(char *buf, char **start, off_t offset, int count, int *eof,
  8300. + void *data)
  8301. +{
  8302. + char *p = buf;
  8303. +
  8304. + (void) start;
  8305. + (void) count;
  8306. + (void) data;
  8307. +
  8308. + if (offset > 0) {
  8309. + *eof = 1;
  8310. + return 0;
  8311. + }
  8312. + // Get the videocore memory size first
  8313. + vc_mem_get_size();
  8314. +
  8315. + p += sprintf(p, "Videocore memory:\n");
  8316. + if (mm_vc_mem_phys_addr != 0)
  8317. + p += sprintf(p, " Physical address: 0x%p\n",
  8318. + (void *) mm_vc_mem_phys_addr);
  8319. + else
  8320. + p += sprintf(p, " Physical address: 0x00000000\n");
  8321. + p += sprintf(p, " Length (bytes): %u\n", mm_vc_mem_size);
  8322. +
  8323. + *eof = 1;
  8324. + return p - buf;
  8325. +}
  8326. +
  8327. +/****************************************************************************
  8328. +*
  8329. +* vc_mem_proc_write
  8330. +*
  8331. +***************************************************************************/
  8332. +
  8333. +static int
  8334. +vc_mem_proc_write(struct file *file, const char __user * buffer,
  8335. + unsigned long count, void *data)
  8336. +{
  8337. + int rc = -EFAULT;
  8338. + char input_str[10];
  8339. +
  8340. + memset(input_str, 0, sizeof (input_str));
  8341. +
  8342. + if (count > sizeof (input_str)) {
  8343. + LOG_ERR("%s: input string length too long", __func__);
  8344. + goto out;
  8345. + }
  8346. +
  8347. + if (copy_from_user(input_str, buffer, count - 1)) {
  8348. + LOG_ERR("%s: failed to get input string", __func__);
  8349. + goto out;
  8350. + }
  8351. +
  8352. + if (strncmp(input_str, "connect", strlen("connect")) == 0) {
  8353. + // Get the videocore memory size from the videocore
  8354. + vc_mem_get_size();
  8355. + }
  8356. +
  8357. + out:
  8358. + return rc;
  8359. +}
  8360. +
  8361. +/****************************************************************************
  8362. +*
  8363. +* vc_mem_init
  8364. +*
  8365. +***************************************************************************/
  8366. +
  8367. +static int __init
  8368. +vc_mem_init(void)
  8369. +{
  8370. + int rc = -EFAULT;
  8371. + struct device *dev;
  8372. +
  8373. + LOG_DBG("%s: called", __func__);
  8374. +
  8375. + mm_vc_mem_phys_addr = phys_addr;
  8376. + mm_vc_mem_size = mem_size;
  8377. + mm_vc_mem_base = mem_base;
  8378. +
  8379. + vc_mem_get_size();
  8380. +
  8381. + printk("vc-mem: phys_addr:0x%08lx mem_base=0x%08x mem_size:0x%08x(%u MiB)\n",
  8382. + mm_vc_mem_phys_addr, mm_vc_mem_base, mm_vc_mem_size, mm_vc_mem_size / (1024 * 1024));
  8383. +
  8384. + if ((rc = alloc_chrdev_region(&vc_mem_devnum, 0, 1, DRIVER_NAME)) < 0) {
  8385. + LOG_ERR("%s: alloc_chrdev_region failed (rc=%d)", __func__, rc);
  8386. + goto out_err;
  8387. + }
  8388. +
  8389. + cdev_init(&vc_mem_cdev, &vc_mem_fops);
  8390. + if ((rc = cdev_add(&vc_mem_cdev, vc_mem_devnum, 1)) != 0) {
  8391. + LOG_ERR("%s: cdev_add failed (rc=%d)", __func__, rc);
  8392. + goto out_unregister;
  8393. + }
  8394. +
  8395. + vc_mem_class = class_create(THIS_MODULE, DRIVER_NAME);
  8396. + if (IS_ERR(vc_mem_class)) {
  8397. + rc = PTR_ERR(vc_mem_class);
  8398. + LOG_ERR("%s: class_create failed (rc=%d)", __func__, rc);
  8399. + goto out_cdev_del;
  8400. + }
  8401. +
  8402. + dev = device_create(vc_mem_class, NULL, vc_mem_devnum, NULL,
  8403. + DRIVER_NAME);
  8404. + if (IS_ERR(dev)) {
  8405. + rc = PTR_ERR(dev);
  8406. + LOG_ERR("%s: device_create failed (rc=%d)", __func__, rc);
  8407. + goto out_class_destroy;
  8408. + }
  8409. +
  8410. +#if 0
  8411. + vc_mem_proc_entry = create_proc_entry(DRIVER_NAME, 0444, NULL);
  8412. + if (vc_mem_proc_entry == NULL) {
  8413. + rc = -EFAULT;
  8414. + LOG_ERR("%s: create_proc_entry failed", __func__);
  8415. + goto out_device_destroy;
  8416. + }
  8417. + vc_mem_proc_entry->read_proc = vc_mem_proc_read;
  8418. + vc_mem_proc_entry->write_proc = vc_mem_proc_write;
  8419. +#endif
  8420. +
  8421. + vc_mem_inited = 1;
  8422. + return 0;
  8423. +
  8424. + out_device_destroy:
  8425. + device_destroy(vc_mem_class, vc_mem_devnum);
  8426. +
  8427. + out_class_destroy:
  8428. + class_destroy(vc_mem_class);
  8429. + vc_mem_class = NULL;
  8430. +
  8431. + out_cdev_del:
  8432. + cdev_del(&vc_mem_cdev);
  8433. +
  8434. + out_unregister:
  8435. + unregister_chrdev_region(vc_mem_devnum, 1);
  8436. +
  8437. + out_err:
  8438. + return -1;
  8439. +}
  8440. +
  8441. +/****************************************************************************
  8442. +*
  8443. +* vc_mem_exit
  8444. +*
  8445. +***************************************************************************/
  8446. +
  8447. +static void __exit
  8448. +vc_mem_exit(void)
  8449. +{
  8450. + LOG_DBG("%s: called", __func__);
  8451. +
  8452. + if (vc_mem_inited) {
  8453. +#if 0
  8454. + remove_proc_entry(vc_mem_proc_entry->name, NULL);
  8455. +#endif
  8456. + device_destroy(vc_mem_class, vc_mem_devnum);
  8457. + class_destroy(vc_mem_class);
  8458. + cdev_del(&vc_mem_cdev);
  8459. + unregister_chrdev_region(vc_mem_devnum, 1);
  8460. + }
  8461. +}
  8462. +
  8463. +module_init(vc_mem_init);
  8464. +module_exit(vc_mem_exit);
  8465. +MODULE_LICENSE("GPL");
  8466. +MODULE_AUTHOR("Broadcom Corporation");
  8467. +
  8468. +module_param(phys_addr, uint, 0644);
  8469. +module_param(mem_size, uint, 0644);
  8470. +module_param(mem_base, uint, 0644);
  8471. +
  8472. diff -Nur linux-3.12.11.orig/arch/arm/mach-bcm2708/vc_support.c linux-3.12.11/arch/arm/mach-bcm2708/vc_support.c
  8473. --- linux-3.12.11.orig/arch/arm/mach-bcm2708/vc_support.c 1970-01-01 01:00:00.000000000 +0100
  8474. +++ linux-3.12.11/arch/arm/mach-bcm2708/vc_support.c 2014-02-18 11:52:14.000000000 +0100
  8475. @@ -0,0 +1,318 @@
  8476. +/*
  8477. + * vc_support.c
  8478. + *
  8479. + * Created on: 25 Nov 2012
  8480. + * Author: Simon
  8481. + */
  8482. +
  8483. +#include <linux/module.h>
  8484. +#include <mach/vcio.h>
  8485. +
  8486. +#ifdef ECLIPSE_IGNORE
  8487. +
  8488. +#define __user
  8489. +#define __init
  8490. +#define __exit
  8491. +#define __iomem
  8492. +#define KERN_DEBUG
  8493. +#define KERN_ERR
  8494. +#define KERN_WARNING
  8495. +#define KERN_INFO
  8496. +#define _IOWR(a, b, c) b
  8497. +#define _IOW(a, b, c) b
  8498. +#define _IO(a, b) b
  8499. +
  8500. +#endif
  8501. +
  8502. +/****** VC MAILBOX FUNCTIONALITY ******/
  8503. +unsigned int AllocateVcMemory(unsigned int *pHandle, unsigned int size, unsigned int alignment, unsigned int flags)
  8504. +{
  8505. + struct vc_msg
  8506. + {
  8507. + unsigned int m_msgSize;
  8508. + unsigned int m_response;
  8509. +
  8510. + struct vc_tag
  8511. + {
  8512. + unsigned int m_tagId;
  8513. + unsigned int m_sendBufferSize;
  8514. + union {
  8515. + unsigned int m_sendDataSize;
  8516. + unsigned int m_recvDataSize;
  8517. + };
  8518. +
  8519. + struct args
  8520. + {
  8521. + union {
  8522. + unsigned int m_size;
  8523. + unsigned int m_handle;
  8524. + };
  8525. + unsigned int m_alignment;
  8526. + unsigned int m_flags;
  8527. + } m_args;
  8528. + } m_tag;
  8529. +
  8530. + unsigned int m_endTag;
  8531. + } msg;
  8532. + int s;
  8533. +
  8534. + msg.m_msgSize = sizeof(msg);
  8535. + msg.m_response = 0;
  8536. + msg.m_endTag = 0;
  8537. +
  8538. + //fill in the tag for the allocation command
  8539. + msg.m_tag.m_tagId = 0x3000c;
  8540. + msg.m_tag.m_sendBufferSize = 12;
  8541. + msg.m_tag.m_sendDataSize = 12;
  8542. +
  8543. + //fill in our args
  8544. + msg.m_tag.m_args.m_size = size;
  8545. + msg.m_tag.m_args.m_alignment = alignment;
  8546. + msg.m_tag.m_args.m_flags = flags;
  8547. +
  8548. + //run the command
  8549. + s = bcm_mailbox_property(&msg, sizeof(msg));
  8550. +
  8551. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004)
  8552. + {
  8553. + *pHandle = msg.m_tag.m_args.m_handle;
  8554. + return 0;
  8555. + }
  8556. + else
  8557. + {
  8558. + printk(KERN_ERR "failed to allocate vc memory: s=%d response=%08x recv data size=%08x\n",
  8559. + s, msg.m_response, msg.m_tag.m_recvDataSize);
  8560. + return 1;
  8561. + }
  8562. +}
  8563. +
  8564. +unsigned int ReleaseVcMemory(unsigned int handle)
  8565. +{
  8566. + struct vc_msg
  8567. + {
  8568. + unsigned int m_msgSize;
  8569. + unsigned int m_response;
  8570. +
  8571. + struct vc_tag
  8572. + {
  8573. + unsigned int m_tagId;
  8574. + unsigned int m_sendBufferSize;
  8575. + union {
  8576. + unsigned int m_sendDataSize;
  8577. + unsigned int m_recvDataSize;
  8578. + };
  8579. +
  8580. + struct args
  8581. + {
  8582. + union {
  8583. + unsigned int m_handle;
  8584. + unsigned int m_error;
  8585. + };
  8586. + } m_args;
  8587. + } m_tag;
  8588. +
  8589. + unsigned int m_endTag;
  8590. + } msg;
  8591. + int s;
  8592. +
  8593. + msg.m_msgSize = sizeof(msg);
  8594. + msg.m_response = 0;
  8595. + msg.m_endTag = 0;
  8596. +
  8597. + //fill in the tag for the release command
  8598. + msg.m_tag.m_tagId = 0x3000f;
  8599. + msg.m_tag.m_sendBufferSize = 4;
  8600. + msg.m_tag.m_sendDataSize = 4;
  8601. +
  8602. + //pass across the handle
  8603. + msg.m_tag.m_args.m_handle = handle;
  8604. +
  8605. + s = bcm_mailbox_property(&msg, sizeof(msg));
  8606. +
  8607. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004 && msg.m_tag.m_args.m_error == 0)
  8608. + return 0;
  8609. + else
  8610. + {
  8611. + printk(KERN_ERR "failed to release vc memory: s=%d response=%08x recv data size=%08x error=%08x\n",
  8612. + s, msg.m_response, msg.m_tag.m_recvDataSize, msg.m_tag.m_args.m_error);
  8613. + return 1;
  8614. + }
  8615. +}
  8616. +
  8617. +unsigned int LockVcMemory(unsigned int *pBusAddress, unsigned int handle)
  8618. +{
  8619. + struct vc_msg
  8620. + {
  8621. + unsigned int m_msgSize;
  8622. + unsigned int m_response;
  8623. +
  8624. + struct vc_tag
  8625. + {
  8626. + unsigned int m_tagId;
  8627. + unsigned int m_sendBufferSize;
  8628. + union {
  8629. + unsigned int m_sendDataSize;
  8630. + unsigned int m_recvDataSize;
  8631. + };
  8632. +
  8633. + struct args
  8634. + {
  8635. + union {
  8636. + unsigned int m_handle;
  8637. + unsigned int m_busAddress;
  8638. + };
  8639. + } m_args;
  8640. + } m_tag;
  8641. +
  8642. + unsigned int m_endTag;
  8643. + } msg;
  8644. + int s;
  8645. +
  8646. + msg.m_msgSize = sizeof(msg);
  8647. + msg.m_response = 0;
  8648. + msg.m_endTag = 0;
  8649. +
  8650. + //fill in the tag for the lock command
  8651. + msg.m_tag.m_tagId = 0x3000d;
  8652. + msg.m_tag.m_sendBufferSize = 4;
  8653. + msg.m_tag.m_sendDataSize = 4;
  8654. +
  8655. + //pass across the handle
  8656. + msg.m_tag.m_args.m_handle = handle;
  8657. +
  8658. + s = bcm_mailbox_property(&msg, sizeof(msg));
  8659. +
  8660. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004)
  8661. + {
  8662. + //pick out the bus address
  8663. + *pBusAddress = msg.m_tag.m_args.m_busAddress;
  8664. + return 0;
  8665. + }
  8666. + else
  8667. + {
  8668. + printk(KERN_ERR "failed to lock vc memory: s=%d response=%08x recv data size=%08x\n",
  8669. + s, msg.m_response, msg.m_tag.m_recvDataSize);
  8670. + return 1;
  8671. + }
  8672. +}
  8673. +
  8674. +unsigned int UnlockVcMemory(unsigned int handle)
  8675. +{
  8676. + struct vc_msg
  8677. + {
  8678. + unsigned int m_msgSize;
  8679. + unsigned int m_response;
  8680. +
  8681. + struct vc_tag
  8682. + {
  8683. + unsigned int m_tagId;
  8684. + unsigned int m_sendBufferSize;
  8685. + union {
  8686. + unsigned int m_sendDataSize;
  8687. + unsigned int m_recvDataSize;
  8688. + };
  8689. +
  8690. + struct args
  8691. + {
  8692. + union {
  8693. + unsigned int m_handle;
  8694. + unsigned int m_error;
  8695. + };
  8696. + } m_args;
  8697. + } m_tag;
  8698. +
  8699. + unsigned int m_endTag;
  8700. + } msg;
  8701. + int s;
  8702. +
  8703. + msg.m_msgSize = sizeof(msg);
  8704. + msg.m_response = 0;
  8705. + msg.m_endTag = 0;
  8706. +
  8707. + //fill in the tag for the unlock command
  8708. + msg.m_tag.m_tagId = 0x3000e;
  8709. + msg.m_tag.m_sendBufferSize = 4;
  8710. + msg.m_tag.m_sendDataSize = 4;
  8711. +
  8712. + //pass across the handle
  8713. + msg.m_tag.m_args.m_handle = handle;
  8714. +
  8715. + s = bcm_mailbox_property(&msg, sizeof(msg));
  8716. +
  8717. + //check the error code too
  8718. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004 && msg.m_tag.m_args.m_error == 0)
  8719. + return 0;
  8720. + else
  8721. + {
  8722. + printk(KERN_ERR "failed to unlock vc memory: s=%d response=%08x recv data size=%08x error%08x\n",
  8723. + s, msg.m_response, msg.m_tag.m_recvDataSize, msg.m_tag.m_args.m_error);
  8724. + return 1;
  8725. + }
  8726. +}
  8727. +
  8728. +unsigned int ExecuteVcCode(unsigned int code,
  8729. + unsigned int r0, unsigned int r1, unsigned int r2, unsigned int r3, unsigned int r4, unsigned int r5)
  8730. +{
  8731. + struct vc_msg
  8732. + {
  8733. + unsigned int m_msgSize;
  8734. + unsigned int m_response;
  8735. +
  8736. + struct vc_tag
  8737. + {
  8738. + unsigned int m_tagId;
  8739. + unsigned int m_sendBufferSize;
  8740. + union {
  8741. + unsigned int m_sendDataSize;
  8742. + unsigned int m_recvDataSize;
  8743. + };
  8744. +
  8745. + struct args
  8746. + {
  8747. + union {
  8748. + unsigned int m_pCode;
  8749. + unsigned int m_return;
  8750. + };
  8751. + unsigned int m_r0;
  8752. + unsigned int m_r1;
  8753. + unsigned int m_r2;
  8754. + unsigned int m_r3;
  8755. + unsigned int m_r4;
  8756. + unsigned int m_r5;
  8757. + } m_args;
  8758. + } m_tag;
  8759. +
  8760. + unsigned int m_endTag;
  8761. + } msg;
  8762. + int s;
  8763. +
  8764. + msg.m_msgSize = sizeof(msg);
  8765. + msg.m_response = 0;
  8766. + msg.m_endTag = 0;
  8767. +
  8768. + //fill in the tag for the unlock command
  8769. + msg.m_tag.m_tagId = 0x30010;
  8770. + msg.m_tag.m_sendBufferSize = 28;
  8771. + msg.m_tag.m_sendDataSize = 28;
  8772. +
  8773. + //pass across the handle
  8774. + msg.m_tag.m_args.m_pCode = code;
  8775. + msg.m_tag.m_args.m_r0 = r0;
  8776. + msg.m_tag.m_args.m_r1 = r1;
  8777. + msg.m_tag.m_args.m_r2 = r2;
  8778. + msg.m_tag.m_args.m_r3 = r3;
  8779. + msg.m_tag.m_args.m_r4 = r4;
  8780. + msg.m_tag.m_args.m_r5 = r5;
  8781. +
  8782. + s = bcm_mailbox_property(&msg, sizeof(msg));
  8783. +
  8784. + //check the error code too
  8785. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004)
  8786. + return msg.m_tag.m_args.m_return;
  8787. + else
  8788. + {
  8789. + printk(KERN_ERR "failed to execute: s=%d response=%08x recv data size=%08x\n",
  8790. + s, msg.m_response, msg.m_tag.m_recvDataSize);
  8791. + return 1;
  8792. + }
  8793. +}
  8794. diff -Nur linux-3.12.11.orig/arch/arm/Makefile linux-3.12.11/arch/arm/Makefile
  8795. --- linux-3.12.11.orig/arch/arm/Makefile 2014-02-13 22:51:06.000000000 +0100
  8796. +++ linux-3.12.11/arch/arm/Makefile 2014-02-18 11:52:14.000000000 +0100
  8797. @@ -146,6 +146,7 @@
  8798. # by CONFIG_* macro name.
  8799. machine-$(CONFIG_ARCH_AT91) += at91
  8800. machine-$(CONFIG_ARCH_BCM) += bcm
  8801. +machine-$(CONFIG_ARCH_BCM2708) += bcm2708
  8802. machine-$(CONFIG_ARCH_BCM2835) += bcm2835
  8803. machine-$(CONFIG_ARCH_CLPS711X) += clps711x
  8804. machine-$(CONFIG_ARCH_CNS3XXX) += cns3xxx
  8805. diff -Nur linux-3.12.11.orig/arch/arm/mm/Kconfig linux-3.12.11/arch/arm/mm/Kconfig
  8806. --- linux-3.12.11.orig/arch/arm/mm/Kconfig 2014-02-13 22:51:06.000000000 +0100
  8807. +++ linux-3.12.11/arch/arm/mm/Kconfig 2014-02-18 11:52:14.000000000 +0100
  8808. @@ -358,7 +358,7 @@
  8809. # ARMv6
  8810. config CPU_V6
  8811. - bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX
  8812. + bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX || MACH_BCM2708
  8813. select CPU_32v6
  8814. select CPU_ABRT_EV6
  8815. select CPU_CACHE_V6
  8816. diff -Nur linux-3.12.11.orig/arch/arm/mm/proc-v6.S linux-3.12.11/arch/arm/mm/proc-v6.S
  8817. --- linux-3.12.11.orig/arch/arm/mm/proc-v6.S 2014-02-13 22:51:06.000000000 +0100
  8818. +++ linux-3.12.11/arch/arm/mm/proc-v6.S 2014-02-18 11:52:14.000000000 +0100
  8819. @@ -73,10 +73,19 @@
  8820. *
  8821. * IRQs are already disabled.
  8822. */
  8823. +
  8824. +/* See jira SW-5991 for details of this workaround */
  8825. ENTRY(cpu_v6_do_idle)
  8826. - mov r1, #0
  8827. - mcr p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  8828. - mcr p15, 0, r1, c7, c0, 4 @ wait for interrupt
  8829. + .align 5
  8830. + mov r1, #2
  8831. +1: subs r1, #1
  8832. + nop
  8833. + mcreq p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  8834. + mcreq p15, 0, r1, c7, c0, 4 @ wait for interrupt
  8835. + nop
  8836. + nop
  8837. + nop
  8838. + bne 1b
  8839. mov pc, lr
  8840. ENTRY(cpu_v6_dcache_clean_area)
  8841. diff -Nur linux-3.12.11.orig/arch/arm/tools/mach-types linux-3.12.11/arch/arm/tools/mach-types
  8842. --- linux-3.12.11.orig/arch/arm/tools/mach-types 2014-02-13 22:51:06.000000000 +0100
  8843. +++ linux-3.12.11/arch/arm/tools/mach-types 2014-02-18 11:52:14.000000000 +0100
  8844. @@ -522,6 +522,7 @@
  8845. prima2_evb MACH_PRIMA2_EVB PRIMA2_EVB 3103
  8846. paz00 MACH_PAZ00 PAZ00 3128
  8847. acmenetusfoxg20 MACH_ACMENETUSFOXG20 ACMENETUSFOXG20 3129
  8848. +bcm2708 MACH_BCM2708 BCM2708 3138
  8849. ag5evm MACH_AG5EVM AG5EVM 3189
  8850. ics_if_voip MACH_ICS_IF_VOIP ICS_IF_VOIP 3206
  8851. wlf_cragg_6410 MACH_WLF_CRAGG_6410 WLF_CRAGG_6410 3207
  8852. diff -Nur linux-3.12.11.orig/Documentation/video4linux/bcm2835-v4l2.txt linux-3.12.11/Documentation/video4linux/bcm2835-v4l2.txt
  8853. --- linux-3.12.11.orig/Documentation/video4linux/bcm2835-v4l2.txt 1970-01-01 01:00:00.000000000 +0100
  8854. +++ linux-3.12.11/Documentation/video4linux/bcm2835-v4l2.txt 2014-02-18 11:52:14.000000000 +0100
  8855. @@ -0,0 +1,60 @@
  8856. +
  8857. +BCM2835 (aka Raspberry Pi) V4L2 driver
  8858. +======================================
  8859. +
  8860. +1. Copyright
  8861. +============
  8862. +
  8863. +Copyright © 2013 Raspberry Pi (Trading) Ltd.
  8864. +
  8865. +2. License
  8866. +==========
  8867. +
  8868. +This program is free software; you can redistribute it and/or modify
  8869. +it under the terms of the GNU General Public License as published by
  8870. +the Free Software Foundation; either version 2 of the License, or
  8871. +(at your option) any later version.
  8872. +
  8873. +This program is distributed in the hope that it will be useful,
  8874. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  8875. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8876. +GNU General Public License for more details.
  8877. +
  8878. +You should have received a copy of the GNU General Public License
  8879. +along with this program; if not, write to the Free Software
  8880. +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  8881. +
  8882. +3. Quick Start
  8883. +==============
  8884. +
  8885. +You need a version 1.0 or later of v4l2-ctl, available from:
  8886. + git://git.linuxtv.org/v4l-utils.git
  8887. +
  8888. +$ sudo modprobe bcm2835-v4l2
  8889. +
  8890. +Turn on the overlay:
  8891. +
  8892. +$ v4l2-ctl --overlay=1
  8893. +
  8894. +Turn off the overlay:
  8895. +
  8896. +$ v4l2-ctl --overlay=0
  8897. +
  8898. +Set the capture format for video:
  8899. +
  8900. +$ v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=4
  8901. +
  8902. +(Note: 1088 not 1080).
  8903. +
  8904. +Capture:
  8905. +
  8906. +$ v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.h264
  8907. +
  8908. +Stills capture:
  8909. +
  8910. +$ v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
  8911. +$ v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=somefile.jpg
  8912. +
  8913. +List of available formats:
  8914. +
  8915. +$ v4l2-ctl --list-formats
  8916. diff -Nur linux-3.12.11.orig/drivers/char/broadcom/Kconfig linux-3.12.11/drivers/char/broadcom/Kconfig
  8917. --- linux-3.12.11.orig/drivers/char/broadcom/Kconfig 1970-01-01 01:00:00.000000000 +0100
  8918. +++ linux-3.12.11/drivers/char/broadcom/Kconfig 2014-02-18 11:52:14.000000000 +0100
  8919. @@ -0,0 +1,16 @@
  8920. +#
  8921. +# Broadcom char driver config
  8922. +#
  8923. +
  8924. +menuconfig BRCM_CHAR_DRIVERS
  8925. + bool "Broadcom Char Drivers"
  8926. + help
  8927. + Broadcom's char drivers
  8928. +
  8929. +config BCM_VC_CMA
  8930. + bool "Videocore CMA"
  8931. + depends on CMA && BRCM_CHAR_DRIVERS && BCM2708_VCHIQ
  8932. + default n
  8933. + help
  8934. + Helper for videocore CMA access.
  8935. +
  8936. diff -Nur linux-3.12.11.orig/drivers/char/broadcom/Makefile linux-3.12.11/drivers/char/broadcom/Makefile
  8937. --- linux-3.12.11.orig/drivers/char/broadcom/Makefile 1970-01-01 01:00:00.000000000 +0100
  8938. +++ linux-3.12.11/drivers/char/broadcom/Makefile 2014-02-18 11:52:14.000000000 +0100
  8939. @@ -0,0 +1 @@
  8940. +obj-$(CONFIG_BCM_VC_CMA) += vc_cma/
  8941. diff -Nur linux-3.12.11.orig/drivers/char/broadcom/vc_cma/Makefile linux-3.12.11/drivers/char/broadcom/vc_cma/Makefile
  8942. --- linux-3.12.11.orig/drivers/char/broadcom/vc_cma/Makefile 1970-01-01 01:00:00.000000000 +0100
  8943. +++ linux-3.12.11/drivers/char/broadcom/vc_cma/Makefile 2014-02-18 11:52:14.000000000 +0100
  8944. @@ -0,0 +1,14 @@
  8945. +EXTRA_CFLAGS += -Wall -Wstrict-prototypes -Wno-trigraphs
  8946. +EXTRA_CFLAGS += -Werror
  8947. +EXTRA_CFLAGS += -I"include/linux/broadcom"
  8948. +EXTRA_CFLAGS += -I"drivers/misc/vc04_services"
  8949. +EXTRA_CFLAGS += -I"drivers/misc/vc04_services/interface/vchi"
  8950. +EXTRA_CFLAGS += -I"drivers/misc/vc04_services/interface/vchiq_arm"
  8951. +
  8952. +EXTRA_CFLAGS += -D__KERNEL__
  8953. +EXTRA_CFLAGS += -D__linux__
  8954. +EXTRA_CFLAGS += -Werror
  8955. +
  8956. +obj-$(CONFIG_BCM_VC_CMA) += vc-cma.o
  8957. +
  8958. +vc-cma-objs := vc_cma.o
  8959. diff -Nur linux-3.12.11.orig/drivers/char/broadcom/vc_cma/vc_cma.c linux-3.12.11/drivers/char/broadcom/vc_cma/vc_cma.c
  8960. --- linux-3.12.11.orig/drivers/char/broadcom/vc_cma/vc_cma.c 1970-01-01 01:00:00.000000000 +0100
  8961. +++ linux-3.12.11/drivers/char/broadcom/vc_cma/vc_cma.c 2014-02-18 11:52:14.000000000 +0100
  8962. @@ -0,0 +1,1143 @@
  8963. +/**
  8964. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  8965. + *
  8966. + * Redistribution and use in source and binary forms, with or without
  8967. + * modification, are permitted provided that the following conditions
  8968. + * are met:
  8969. + * 1. Redistributions of source code must retain the above copyright
  8970. + * notice, this list of conditions, and the following disclaimer,
  8971. + * without modification.
  8972. + * 2. Redistributions in binary form must reproduce the above copyright
  8973. + * notice, this list of conditions and the following disclaimer in the
  8974. + * documentation and/or other materials provided with the distribution.
  8975. + * 3. The names of the above-listed copyright holders may not be used
  8976. + * to endorse or promote products derived from this software without
  8977. + * specific prior written permission.
  8978. + *
  8979. + * ALTERNATIVELY, this software may be distributed under the terms of the
  8980. + * GNU General Public License ("GPL") version 2, as published by the Free
  8981. + * Software Foundation.
  8982. + *
  8983. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  8984. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  8985. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  8986. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  8987. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  8988. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  8989. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  8990. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  8991. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  8992. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  8993. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  8994. + */
  8995. +
  8996. +#include <linux/kernel.h>
  8997. +#include <linux/module.h>
  8998. +#include <linux/kthread.h>
  8999. +#include <linux/fs.h>
  9000. +#include <linux/device.h>
  9001. +#include <linux/cdev.h>
  9002. +#include <linux/mm.h>
  9003. +#include <linux/proc_fs.h>
  9004. +#include <linux/seq_file.h>
  9005. +#include <linux/dma-mapping.h>
  9006. +#include <linux/dma-contiguous.h>
  9007. +#include <linux/platform_device.h>
  9008. +#include <linux/uaccess.h>
  9009. +#include <asm/cacheflush.h>
  9010. +
  9011. +#include "vc_cma.h"
  9012. +
  9013. +#include "vchiq_util.h"
  9014. +#include "vchiq_connected.h"
  9015. +//#include "debug_sym.h"
  9016. +//#include "vc_mem.h"
  9017. +
  9018. +#define DRIVER_NAME "vc-cma"
  9019. +
  9020. +#define LOG_DBG(fmt, ...) \
  9021. + if (vc_cma_debug) \
  9022. + printk(KERN_INFO fmt "\n", ##__VA_ARGS__)
  9023. +#define LOG_ERR(fmt, ...) \
  9024. + printk(KERN_ERR fmt "\n", ##__VA_ARGS__)
  9025. +
  9026. +#define VC_CMA_FOURCC VCHIQ_MAKE_FOURCC('C', 'M', 'A', ' ')
  9027. +#define VC_CMA_VERSION 2
  9028. +
  9029. +#define VC_CMA_CHUNK_ORDER 6 /* 256K */
  9030. +#define VC_CMA_CHUNK_SIZE (4096 << VC_CMA_CHUNK_ORDER)
  9031. +#define VC_CMA_MAX_PARAMS_PER_MSG \
  9032. + ((VCHIQ_MAX_MSG_SIZE - sizeof(unsigned short))/sizeof(unsigned short))
  9033. +#define VC_CMA_RESERVE_COUNT_MAX 16
  9034. +
  9035. +#define PAGES_PER_CHUNK (VC_CMA_CHUNK_SIZE / PAGE_SIZE)
  9036. +
  9037. +#define VCADDR_TO_PHYSADDR(vcaddr) (mm_vc_mem_phys_addr + vcaddr)
  9038. +
  9039. +#define loud_error(...) \
  9040. + LOG_ERR("===== " __VA_ARGS__)
  9041. +
  9042. +enum {
  9043. + VC_CMA_MSG_QUIT,
  9044. + VC_CMA_MSG_OPEN,
  9045. + VC_CMA_MSG_TICK,
  9046. + VC_CMA_MSG_ALLOC, /* chunk count */
  9047. + VC_CMA_MSG_FREE, /* chunk, chunk, ... */
  9048. + VC_CMA_MSG_ALLOCATED, /* chunk, chunk, ... */
  9049. + VC_CMA_MSG_REQUEST_ALLOC, /* chunk count */
  9050. + VC_CMA_MSG_REQUEST_FREE, /* chunk count */
  9051. + VC_CMA_MSG_RESERVE, /* bytes lo, bytes hi */
  9052. + VC_CMA_MSG_UPDATE_RESERVE,
  9053. + VC_CMA_MSG_MAX
  9054. +};
  9055. +
  9056. +struct cma_msg {
  9057. + unsigned short type;
  9058. + unsigned short params[VC_CMA_MAX_PARAMS_PER_MSG];
  9059. +};
  9060. +
  9061. +struct vc_cma_reserve_user {
  9062. + unsigned int pid;
  9063. + unsigned int reserve;
  9064. +};
  9065. +
  9066. +/* Device (/dev) related variables */
  9067. +static dev_t vc_cma_devnum;
  9068. +static struct class *vc_cma_class;
  9069. +static struct cdev vc_cma_cdev;
  9070. +static int vc_cma_inited;
  9071. +static int vc_cma_debug;
  9072. +
  9073. +/* Proc entry */
  9074. +static struct proc_dir_entry *vc_cma_proc_entry;
  9075. +
  9076. +phys_addr_t vc_cma_base;
  9077. +struct page *vc_cma_base_page;
  9078. +unsigned int vc_cma_size;
  9079. +EXPORT_SYMBOL(vc_cma_size);
  9080. +unsigned int vc_cma_initial;
  9081. +unsigned int vc_cma_chunks;
  9082. +unsigned int vc_cma_chunks_used;
  9083. +unsigned int vc_cma_chunks_reserved;
  9084. +
  9085. +static int in_loud_error;
  9086. +
  9087. +unsigned int vc_cma_reserve_total;
  9088. +unsigned int vc_cma_reserve_count;
  9089. +struct vc_cma_reserve_user vc_cma_reserve_users[VC_CMA_RESERVE_COUNT_MAX];
  9090. +static DEFINE_SEMAPHORE(vc_cma_reserve_mutex);
  9091. +static DEFINE_SEMAPHORE(vc_cma_worker_queue_push_mutex);
  9092. +
  9093. +static u64 vc_cma_dma_mask = DMA_BIT_MASK(32);
  9094. +static struct platform_device vc_cma_device = {
  9095. + .name = "vc-cma",
  9096. + .id = 0,
  9097. + .dev = {
  9098. + .dma_mask = &vc_cma_dma_mask,
  9099. + .coherent_dma_mask = DMA_BIT_MASK(32),
  9100. + },
  9101. +};
  9102. +
  9103. +static VCHIQ_INSTANCE_T cma_instance;
  9104. +static VCHIQ_SERVICE_HANDLE_T cma_service;
  9105. +static VCHIU_QUEUE_T cma_msg_queue;
  9106. +static struct task_struct *cma_worker;
  9107. +
  9108. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid);
  9109. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply);
  9110. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  9111. + VCHIQ_HEADER_T * header,
  9112. + VCHIQ_SERVICE_HANDLE_T service,
  9113. + void *bulk_userdata);
  9114. +static void send_vc_msg(unsigned short type,
  9115. + unsigned short param1, unsigned short param2);
  9116. +static bool send_worker_msg(VCHIQ_HEADER_T * msg);
  9117. +
  9118. +static int early_vc_cma_mem(char *p)
  9119. +{
  9120. + unsigned int new_size;
  9121. + printk(KERN_NOTICE "early_vc_cma_mem(%s)", p);
  9122. + vc_cma_size = memparse(p, &p);
  9123. + vc_cma_initial = vc_cma_size;
  9124. + if (*p == '/')
  9125. + vc_cma_size = memparse(p + 1, &p);
  9126. + if (*p == '@')
  9127. + vc_cma_base = memparse(p + 1, &p);
  9128. +
  9129. + new_size = (vc_cma_size - ((-vc_cma_base) & (VC_CMA_CHUNK_SIZE - 1)))
  9130. + & ~(VC_CMA_CHUNK_SIZE - 1);
  9131. + if (new_size > vc_cma_size)
  9132. + vc_cma_size = 0;
  9133. + vc_cma_initial = (vc_cma_initial + VC_CMA_CHUNK_SIZE - 1)
  9134. + & ~(VC_CMA_CHUNK_SIZE - 1);
  9135. + if (vc_cma_initial > vc_cma_size)
  9136. + vc_cma_initial = vc_cma_size;
  9137. + vc_cma_base = (vc_cma_base + VC_CMA_CHUNK_SIZE - 1)
  9138. + & ~(VC_CMA_CHUNK_SIZE - 1);
  9139. +
  9140. + printk(KERN_NOTICE " -> initial %x, size %x, base %x", vc_cma_initial,
  9141. + vc_cma_size, (unsigned int)vc_cma_base);
  9142. +
  9143. + return 0;
  9144. +}
  9145. +
  9146. +early_param("vc-cma-mem", early_vc_cma_mem);
  9147. +
  9148. +void vc_cma_early_init(void)
  9149. +{
  9150. + LOG_DBG("vc_cma_early_init - vc_cma_chunks = %d", vc_cma_chunks);
  9151. + if (vc_cma_size) {
  9152. + int rc = platform_device_register(&vc_cma_device);
  9153. + LOG_DBG("platform_device_register -> %d", rc);
  9154. + }
  9155. +}
  9156. +
  9157. +void vc_cma_reserve(void)
  9158. +{
  9159. + /* if vc_cma_size is set, then declare vc CMA area of the same
  9160. + * size from the end of memory
  9161. + */
  9162. + if (vc_cma_size) {
  9163. + if (dma_declare_contiguous(NULL /*&vc_cma_device.dev*/, vc_cma_size,
  9164. + vc_cma_base, 0) == 0) {
  9165. + } else {
  9166. + LOG_ERR("vc_cma: dma_declare_contiguous(%x,%x) failed",
  9167. + vc_cma_size, (unsigned int)vc_cma_base);
  9168. + vc_cma_size = 0;
  9169. + }
  9170. + }
  9171. + vc_cma_chunks = vc_cma_size / VC_CMA_CHUNK_SIZE;
  9172. +}
  9173. +
  9174. +/****************************************************************************
  9175. +*
  9176. +* vc_cma_open
  9177. +*
  9178. +***************************************************************************/
  9179. +
  9180. +static int vc_cma_open(struct inode *inode, struct file *file)
  9181. +{
  9182. + (void)inode;
  9183. + (void)file;
  9184. +
  9185. + return 0;
  9186. +}
  9187. +
  9188. +/****************************************************************************
  9189. +*
  9190. +* vc_cma_release
  9191. +*
  9192. +***************************************************************************/
  9193. +
  9194. +static int vc_cma_release(struct inode *inode, struct file *file)
  9195. +{
  9196. + (void)inode;
  9197. + (void)file;
  9198. +
  9199. + vc_cma_set_reserve(0, current->tgid);
  9200. +
  9201. + return 0;
  9202. +}
  9203. +
  9204. +/****************************************************************************
  9205. +*
  9206. +* vc_cma_ioctl
  9207. +*
  9208. +***************************************************************************/
  9209. +
  9210. +static long vc_cma_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  9211. +{
  9212. + int rc = 0;
  9213. +
  9214. + (void)cmd;
  9215. + (void)arg;
  9216. +
  9217. + switch (cmd) {
  9218. + case VC_CMA_IOC_RESERVE:
  9219. + rc = vc_cma_set_reserve((unsigned int)arg, current->tgid);
  9220. + if (rc >= 0)
  9221. + rc = 0;
  9222. + break;
  9223. + default:
  9224. + LOG_ERR("vc-cma: Unknown ioctl %x", cmd);
  9225. + return -ENOTTY;
  9226. + }
  9227. +
  9228. + return rc;
  9229. +}
  9230. +
  9231. +/****************************************************************************
  9232. +*
  9233. +* File Operations for the driver.
  9234. +*
  9235. +***************************************************************************/
  9236. +
  9237. +static const struct file_operations vc_cma_fops = {
  9238. + .owner = THIS_MODULE,
  9239. + .open = vc_cma_open,
  9240. + .release = vc_cma_release,
  9241. + .unlocked_ioctl = vc_cma_ioctl,
  9242. +};
  9243. +
  9244. +/****************************************************************************
  9245. +*
  9246. +* vc_cma_proc_open
  9247. +*
  9248. +***************************************************************************/
  9249. +
  9250. +static int vc_cma_show_info(struct seq_file *m, void *v)
  9251. +{
  9252. + int i;
  9253. +
  9254. + seq_printf(m, "Videocore CMA:\n");
  9255. + seq_printf(m, " Base : %08x\n", (unsigned int)vc_cma_base);
  9256. + seq_printf(m, " Length : %08x\n", vc_cma_size);
  9257. + seq_printf(m, " Initial : %08x\n", vc_cma_initial);
  9258. + seq_printf(m, " Chunk size : %08x\n", VC_CMA_CHUNK_SIZE);
  9259. + seq_printf(m, " Chunks : %4d (%d bytes)\n",
  9260. + (int)vc_cma_chunks,
  9261. + (int)(vc_cma_chunks * VC_CMA_CHUNK_SIZE));
  9262. + seq_printf(m, " Used : %4d (%d bytes)\n",
  9263. + (int)vc_cma_chunks_used,
  9264. + (int)(vc_cma_chunks_used * VC_CMA_CHUNK_SIZE));
  9265. + seq_printf(m, " Reserved : %4d (%d bytes)\n",
  9266. + (unsigned int)vc_cma_chunks_reserved,
  9267. + (int)(vc_cma_chunks_reserved * VC_CMA_CHUNK_SIZE));
  9268. +
  9269. + for (i = 0; i < vc_cma_reserve_count; i++) {
  9270. + struct vc_cma_reserve_user *user = &vc_cma_reserve_users[i];
  9271. + seq_printf(m, " PID %5d: %d bytes\n", user->pid,
  9272. + user->reserve);
  9273. + }
  9274. +
  9275. + seq_printf(m, "\n");
  9276. +
  9277. + return 0;
  9278. +}
  9279. +
  9280. +static int vc_cma_proc_open(struct inode *inode, struct file *file)
  9281. +{
  9282. + return single_open(file, vc_cma_show_info, NULL);
  9283. +}
  9284. +
  9285. +/****************************************************************************
  9286. +*
  9287. +* vc_cma_proc_write
  9288. +*
  9289. +***************************************************************************/
  9290. +
  9291. +static int vc_cma_proc_write(struct file *file,
  9292. + const char __user *buffer,
  9293. + size_t size, loff_t *ppos)
  9294. +{
  9295. + int rc = -EFAULT;
  9296. + char input_str[20];
  9297. +
  9298. + memset(input_str, 0, sizeof(input_str));
  9299. +
  9300. + if (size > sizeof(input_str)) {
  9301. + LOG_ERR("%s: input string length too long", __func__);
  9302. + goto out;
  9303. + }
  9304. +
  9305. + if (copy_from_user(input_str, buffer, size - 1)) {
  9306. + LOG_ERR("%s: failed to get input string", __func__);
  9307. + goto out;
  9308. + }
  9309. +#define ALLOC_STR "alloc"
  9310. +#define FREE_STR "free"
  9311. +#define DEBUG_STR "debug"
  9312. +#define RESERVE_STR "reserve"
  9313. + if (strncmp(input_str, ALLOC_STR, strlen(ALLOC_STR)) == 0) {
  9314. + int size;
  9315. + char *p = input_str + strlen(ALLOC_STR);
  9316. +
  9317. + while (*p == ' ')
  9318. + p++;
  9319. + size = memparse(p, NULL);
  9320. + LOG_ERR("/proc/vc-cma: alloc %d", size);
  9321. + if (size)
  9322. + send_vc_msg(VC_CMA_MSG_REQUEST_FREE,
  9323. + size / VC_CMA_CHUNK_SIZE, 0);
  9324. + else
  9325. + LOG_ERR("invalid size '%s'", p);
  9326. + rc = size;
  9327. + } else if (strncmp(input_str, FREE_STR, strlen(FREE_STR)) == 0) {
  9328. + int size;
  9329. + char *p = input_str + strlen(FREE_STR);
  9330. +
  9331. + while (*p == ' ')
  9332. + p++;
  9333. + size = memparse(p, NULL);
  9334. + LOG_ERR("/proc/vc-cma: free %d", size);
  9335. + if (size)
  9336. + send_vc_msg(VC_CMA_MSG_REQUEST_ALLOC,
  9337. + size / VC_CMA_CHUNK_SIZE, 0);
  9338. + else
  9339. + LOG_ERR("invalid size '%s'", p);
  9340. + rc = size;
  9341. + } else if (strncmp(input_str, DEBUG_STR, strlen(DEBUG_STR)) == 0) {
  9342. + char *p = input_str + strlen(DEBUG_STR);
  9343. + while (*p == ' ')
  9344. + p++;
  9345. + if ((strcmp(p, "on") == 0) || (strcmp(p, "1") == 0))
  9346. + vc_cma_debug = 1;
  9347. + else if ((strcmp(p, "off") == 0) || (strcmp(p, "0") == 0))
  9348. + vc_cma_debug = 0;
  9349. + LOG_ERR("/proc/vc-cma: debug %s", vc_cma_debug ? "on" : "off");
  9350. + rc = size;
  9351. + } else if (strncmp(input_str, RESERVE_STR, strlen(RESERVE_STR)) == 0) {
  9352. + int size;
  9353. + int reserved;
  9354. + char *p = input_str + strlen(RESERVE_STR);
  9355. + while (*p == ' ')
  9356. + p++;
  9357. + size = memparse(p, NULL);
  9358. +
  9359. + reserved = vc_cma_set_reserve(size, current->tgid);
  9360. + rc = (reserved >= 0) ? size : reserved;
  9361. + }
  9362. +
  9363. +out:
  9364. + return rc;
  9365. +}
  9366. +
  9367. +/****************************************************************************
  9368. +*
  9369. +* File Operations for /proc interface.
  9370. +*
  9371. +***************************************************************************/
  9372. +
  9373. +static const struct file_operations vc_cma_proc_fops = {
  9374. + .open = vc_cma_proc_open,
  9375. + .read = seq_read,
  9376. + .write = vc_cma_proc_write,
  9377. + .llseek = seq_lseek,
  9378. + .release = single_release
  9379. +};
  9380. +
  9381. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid)
  9382. +{
  9383. + struct vc_cma_reserve_user *user = NULL;
  9384. + int delta = 0;
  9385. + int i;
  9386. +
  9387. + if (down_interruptible(&vc_cma_reserve_mutex))
  9388. + return -ERESTARTSYS;
  9389. +
  9390. + for (i = 0; i < vc_cma_reserve_count; i++) {
  9391. + if (pid == vc_cma_reserve_users[i].pid) {
  9392. + user = &vc_cma_reserve_users[i];
  9393. + delta = reserve - user->reserve;
  9394. + if (reserve)
  9395. + user->reserve = reserve;
  9396. + else {
  9397. + /* Remove this entry by copying downwards */
  9398. + while ((i + 1) < vc_cma_reserve_count) {
  9399. + user[0].pid = user[1].pid;
  9400. + user[0].reserve = user[1].reserve;
  9401. + user++;
  9402. + i++;
  9403. + }
  9404. + vc_cma_reserve_count--;
  9405. + user = NULL;
  9406. + }
  9407. + break;
  9408. + }
  9409. + }
  9410. +
  9411. + if (reserve && !user) {
  9412. + if (vc_cma_reserve_count == VC_CMA_RESERVE_COUNT_MAX) {
  9413. + LOG_ERR("vc-cma: Too many reservations - "
  9414. + "increase CMA_RESERVE_COUNT_MAX");
  9415. + up(&vc_cma_reserve_mutex);
  9416. + return -EBUSY;
  9417. + }
  9418. + user = &vc_cma_reserve_users[vc_cma_reserve_count];
  9419. + user->pid = pid;
  9420. + user->reserve = reserve;
  9421. + delta = reserve;
  9422. + vc_cma_reserve_count++;
  9423. + }
  9424. +
  9425. + vc_cma_reserve_total += delta;
  9426. +
  9427. + send_vc_msg(VC_CMA_MSG_RESERVE,
  9428. + vc_cma_reserve_total & 0xffff, vc_cma_reserve_total >> 16);
  9429. +
  9430. + send_worker_msg((VCHIQ_HEADER_T *) VC_CMA_MSG_UPDATE_RESERVE);
  9431. +
  9432. + LOG_DBG("/proc/vc-cma: reserve %d (PID %d) - total %u",
  9433. + reserve, pid, vc_cma_reserve_total);
  9434. +
  9435. + up(&vc_cma_reserve_mutex);
  9436. +
  9437. + return vc_cma_reserve_total;
  9438. +}
  9439. +
  9440. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  9441. + VCHIQ_HEADER_T * header,
  9442. + VCHIQ_SERVICE_HANDLE_T service,
  9443. + void *bulk_userdata)
  9444. +{
  9445. + switch (reason) {
  9446. + case VCHIQ_MESSAGE_AVAILABLE:
  9447. + if (!send_worker_msg(header))
  9448. + return VCHIQ_RETRY;
  9449. + break;
  9450. + case VCHIQ_SERVICE_CLOSED:
  9451. + LOG_DBG("CMA service closed");
  9452. + break;
  9453. + default:
  9454. + LOG_ERR("Unexpected CMA callback reason %d", reason);
  9455. + break;
  9456. + }
  9457. + return VCHIQ_SUCCESS;
  9458. +}
  9459. +
  9460. +static void send_vc_msg(unsigned short type,
  9461. + unsigned short param1, unsigned short param2)
  9462. +{
  9463. + unsigned short msg[] = { type, param1, param2 };
  9464. + VCHIQ_ELEMENT_T elem = { &msg, sizeof(msg) };
  9465. + VCHIQ_STATUS_T ret;
  9466. + vchiq_use_service(cma_service);
  9467. + ret = vchiq_queue_message(cma_service, &elem, 1);
  9468. + vchiq_release_service(cma_service);
  9469. + if (ret != VCHIQ_SUCCESS)
  9470. + LOG_ERR("vchiq_queue_message returned %x", ret);
  9471. +}
  9472. +
  9473. +static bool send_worker_msg(VCHIQ_HEADER_T * msg)
  9474. +{
  9475. + if (down_interruptible(&vc_cma_worker_queue_push_mutex))
  9476. + return false;
  9477. + vchiu_queue_push(&cma_msg_queue, msg);
  9478. + up(&vc_cma_worker_queue_push_mutex);
  9479. + return true;
  9480. +}
  9481. +
  9482. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply)
  9483. +{
  9484. + int i;
  9485. + for (i = 0; i < num_chunks; i++) {
  9486. + struct page *chunk;
  9487. + unsigned int chunk_num;
  9488. + uint8_t *chunk_addr;
  9489. + size_t chunk_size = PAGES_PER_CHUNK << PAGE_SHIFT;
  9490. +
  9491. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  9492. + PAGES_PER_CHUNK,
  9493. + VC_CMA_CHUNK_ORDER);
  9494. + if (!chunk)
  9495. + break;
  9496. +
  9497. + chunk_addr = page_address(chunk);
  9498. + dmac_flush_range(chunk_addr, chunk_addr + chunk_size);
  9499. + outer_inv_range(__pa(chunk_addr), __pa(chunk_addr) +
  9500. + chunk_size);
  9501. +
  9502. + chunk_num =
  9503. + (page_to_phys(chunk) - vc_cma_base) / VC_CMA_CHUNK_SIZE;
  9504. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  9505. + VC_CMA_CHUNK_SIZE) != 0);
  9506. + if (chunk_num >= vc_cma_chunks) {
  9507. + LOG_ERR("%s: ===============================",
  9508. + __func__);
  9509. + LOG_ERR("%s: chunk phys %x, vc_cma %x-%x - "
  9510. + "bad SPARSEMEM configuration?",
  9511. + __func__, (unsigned int)page_to_phys(chunk),
  9512. + vc_cma_base, vc_cma_base + vc_cma_size - 1);
  9513. + LOG_ERR("%s: dev->cma_area = %p\n", __func__,
  9514. + (void*)0/*vc_cma_device.dev.cma_area*/);
  9515. + LOG_ERR("%s: ===============================",
  9516. + __func__);
  9517. + break;
  9518. + }
  9519. + reply->params[i] = chunk_num;
  9520. + vc_cma_chunks_used++;
  9521. + }
  9522. +
  9523. + if (i < num_chunks) {
  9524. + LOG_ERR("%s: dma_alloc_from_contiguous failed "
  9525. + "for %x bytes (alloc %d of %d, %d free)",
  9526. + __func__, VC_CMA_CHUNK_SIZE, i,
  9527. + num_chunks, vc_cma_chunks - vc_cma_chunks_used);
  9528. + num_chunks = i;
  9529. + }
  9530. +
  9531. + LOG_DBG("CMA allocated %d chunks -> %d used",
  9532. + num_chunks, vc_cma_chunks_used);
  9533. + reply->type = VC_CMA_MSG_ALLOCATED;
  9534. +
  9535. + {
  9536. + VCHIQ_ELEMENT_T elem = {
  9537. + reply,
  9538. + offsetof(struct cma_msg, params[0]) +
  9539. + num_chunks * sizeof(reply->params[0])
  9540. + };
  9541. + VCHIQ_STATUS_T ret;
  9542. + vchiq_use_service(cma_service);
  9543. + ret = vchiq_queue_message(cma_service, &elem, 1);
  9544. + vchiq_release_service(cma_service);
  9545. + if (ret != VCHIQ_SUCCESS)
  9546. + LOG_ERR("vchiq_queue_message return " "%x", ret);
  9547. + }
  9548. +
  9549. + return num_chunks;
  9550. +}
  9551. +
  9552. +static int cma_worker_proc(void *param)
  9553. +{
  9554. + static struct cma_msg reply;
  9555. + (void)param;
  9556. +
  9557. + while (1) {
  9558. + VCHIQ_HEADER_T *msg;
  9559. + static struct cma_msg msg_copy;
  9560. + struct cma_msg *cma_msg = &msg_copy;
  9561. + int type, msg_size;
  9562. +
  9563. + msg = vchiu_queue_pop(&cma_msg_queue);
  9564. + if ((unsigned int)msg >= VC_CMA_MSG_MAX) {
  9565. + msg_size = msg->size;
  9566. + memcpy(&msg_copy, msg->data, msg_size);
  9567. + type = cma_msg->type;
  9568. + vchiq_release_message(cma_service, msg);
  9569. + } else {
  9570. + msg_size = 0;
  9571. + type = (int)msg;
  9572. + if (type == VC_CMA_MSG_QUIT)
  9573. + break;
  9574. + else if (type == VC_CMA_MSG_UPDATE_RESERVE) {
  9575. + msg = NULL;
  9576. + cma_msg = NULL;
  9577. + } else {
  9578. + BUG();
  9579. + continue;
  9580. + }
  9581. + }
  9582. +
  9583. + switch (type) {
  9584. + case VC_CMA_MSG_ALLOC:{
  9585. + int num_chunks, free_chunks;
  9586. + num_chunks = cma_msg->params[0];
  9587. + free_chunks =
  9588. + vc_cma_chunks - vc_cma_chunks_used;
  9589. + LOG_DBG("CMA_MSG_ALLOC(%d chunks)", num_chunks);
  9590. + if (num_chunks > VC_CMA_MAX_PARAMS_PER_MSG) {
  9591. + LOG_ERR
  9592. + ("CMA_MSG_ALLOC - chunk count (%d) "
  9593. + "exceeds VC_CMA_MAX_PARAMS_PER_MSG (%d)",
  9594. + num_chunks,
  9595. + VC_CMA_MAX_PARAMS_PER_MSG);
  9596. + num_chunks = VC_CMA_MAX_PARAMS_PER_MSG;
  9597. + }
  9598. +
  9599. + if (num_chunks > free_chunks) {
  9600. + LOG_ERR
  9601. + ("CMA_MSG_ALLOC - chunk count (%d) "
  9602. + "exceeds free chunks (%d)",
  9603. + num_chunks, free_chunks);
  9604. + num_chunks = free_chunks;
  9605. + }
  9606. +
  9607. + vc_cma_alloc_chunks(num_chunks, &reply);
  9608. + }
  9609. + break;
  9610. +
  9611. + case VC_CMA_MSG_FREE:{
  9612. + int chunk_count =
  9613. + (msg_size -
  9614. + offsetof(struct cma_msg,
  9615. + params)) /
  9616. + sizeof(cma_msg->params[0]);
  9617. + int i;
  9618. + BUG_ON(chunk_count <= 0);
  9619. +
  9620. + LOG_DBG("CMA_MSG_FREE(%d chunks - %x, ...)",
  9621. + chunk_count, cma_msg->params[0]);
  9622. + for (i = 0; i < chunk_count; i++) {
  9623. + int chunk_num = cma_msg->params[i];
  9624. + struct page *page = vc_cma_base_page +
  9625. + chunk_num * PAGES_PER_CHUNK;
  9626. + if (chunk_num >= vc_cma_chunks) {
  9627. + LOG_ERR
  9628. + ("CMA_MSG_FREE - chunk %d of %d"
  9629. + " (value %x) exceeds maximum "
  9630. + "(%x)", i, chunk_count,
  9631. + chunk_num,
  9632. + vc_cma_chunks - 1);
  9633. + break;
  9634. + }
  9635. +
  9636. + if (!dma_release_from_contiguous
  9637. + (NULL /*&vc_cma_device.dev*/, page,
  9638. + PAGES_PER_CHUNK)) {
  9639. + LOG_ERR
  9640. + ("CMA_MSG_FREE - failed to "
  9641. + "release chunk %d (phys %x, "
  9642. + "page %x)", chunk_num,
  9643. + page_to_phys(page),
  9644. + (unsigned int)page);
  9645. + }
  9646. + vc_cma_chunks_used--;
  9647. + }
  9648. + LOG_DBG("CMA released %d chunks -> %d used",
  9649. + i, vc_cma_chunks_used);
  9650. + }
  9651. + break;
  9652. +
  9653. + case VC_CMA_MSG_UPDATE_RESERVE:{
  9654. + int chunks_needed =
  9655. + ((vc_cma_reserve_total + VC_CMA_CHUNK_SIZE -
  9656. + 1)
  9657. + / VC_CMA_CHUNK_SIZE) -
  9658. + vc_cma_chunks_reserved;
  9659. +
  9660. + LOG_DBG
  9661. + ("CMA_MSG_UPDATE_RESERVE(%d chunks needed)",
  9662. + chunks_needed);
  9663. +
  9664. + /* Cap the reservations to what is available */
  9665. + if (chunks_needed > 0) {
  9666. + if (chunks_needed >
  9667. + (vc_cma_chunks -
  9668. + vc_cma_chunks_used))
  9669. + chunks_needed =
  9670. + (vc_cma_chunks -
  9671. + vc_cma_chunks_used);
  9672. +
  9673. + chunks_needed =
  9674. + vc_cma_alloc_chunks(chunks_needed,
  9675. + &reply);
  9676. + }
  9677. +
  9678. + LOG_DBG
  9679. + ("CMA_MSG_UPDATE_RESERVE(%d chunks allocated)",
  9680. + chunks_needed);
  9681. + vc_cma_chunks_reserved += chunks_needed;
  9682. + }
  9683. + break;
  9684. +
  9685. + default:
  9686. + LOG_ERR("unexpected msg type %d", type);
  9687. + break;
  9688. + }
  9689. + }
  9690. +
  9691. + LOG_DBG("quitting...");
  9692. + return 0;
  9693. +}
  9694. +
  9695. +/****************************************************************************
  9696. +*
  9697. +* vc_cma_connected_init
  9698. +*
  9699. +* This function is called once the videocore has been connected.
  9700. +*
  9701. +***************************************************************************/
  9702. +
  9703. +static void vc_cma_connected_init(void)
  9704. +{
  9705. + VCHIQ_SERVICE_PARAMS_T service_params;
  9706. +
  9707. + LOG_DBG("vc_cma_connected_init");
  9708. +
  9709. + if (!vchiu_queue_init(&cma_msg_queue, 16)) {
  9710. + LOG_ERR("could not create CMA msg queue");
  9711. + goto fail_queue;
  9712. + }
  9713. +
  9714. + if (vchiq_initialise(&cma_instance) != VCHIQ_SUCCESS)
  9715. + goto fail_vchiq_init;
  9716. +
  9717. + vchiq_connect(cma_instance);
  9718. +
  9719. + service_params.fourcc = VC_CMA_FOURCC;
  9720. + service_params.callback = cma_service_callback;
  9721. + service_params.userdata = NULL;
  9722. + service_params.version = VC_CMA_VERSION;
  9723. + service_params.version_min = VC_CMA_VERSION;
  9724. +
  9725. + if (vchiq_open_service(cma_instance, &service_params,
  9726. + &cma_service) != VCHIQ_SUCCESS) {
  9727. + LOG_ERR("failed to open service - already in use?");
  9728. + goto fail_vchiq_open;
  9729. + }
  9730. +
  9731. + vchiq_release_service(cma_service);
  9732. +
  9733. + cma_worker = kthread_create(cma_worker_proc, NULL, "cma_worker");
  9734. + if (!cma_worker) {
  9735. + LOG_ERR("could not create CMA worker thread");
  9736. + goto fail_worker;
  9737. + }
  9738. + set_user_nice(cma_worker, -20);
  9739. + wake_up_process(cma_worker);
  9740. +
  9741. + return;
  9742. +
  9743. +fail_worker:
  9744. + vchiq_close_service(cma_service);
  9745. +fail_vchiq_open:
  9746. + vchiq_shutdown(cma_instance);
  9747. +fail_vchiq_init:
  9748. + vchiu_queue_delete(&cma_msg_queue);
  9749. +fail_queue:
  9750. + return;
  9751. +}
  9752. +
  9753. +void
  9754. +loud_error_header(void)
  9755. +{
  9756. + if (in_loud_error)
  9757. + return;
  9758. +
  9759. + LOG_ERR("============================================================"
  9760. + "================");
  9761. + LOG_ERR("============================================================"
  9762. + "================");
  9763. + LOG_ERR("=====");
  9764. +
  9765. + in_loud_error = 1;
  9766. +}
  9767. +
  9768. +void
  9769. +loud_error_footer(void)
  9770. +{
  9771. + if (!in_loud_error)
  9772. + return;
  9773. +
  9774. + LOG_ERR("=====");
  9775. + LOG_ERR("============================================================"
  9776. + "================");
  9777. + LOG_ERR("============================================================"
  9778. + "================");
  9779. +
  9780. + in_loud_error = 0;
  9781. +}
  9782. +
  9783. +#if 1
  9784. +static int check_cma_config(void) { return 1; }
  9785. +#else
  9786. +static int
  9787. +read_vc_debug_var(VC_MEM_ACCESS_HANDLE_T handle,
  9788. + const char *symbol,
  9789. + void *buf, size_t bufsize)
  9790. +{
  9791. + VC_MEM_ADDR_T vcMemAddr;
  9792. + size_t vcMemSize;
  9793. + uint8_t *mapAddr;
  9794. + off_t vcMapAddr;
  9795. +
  9796. + if (!LookupVideoCoreSymbol(handle, symbol,
  9797. + &vcMemAddr,
  9798. + &vcMemSize)) {
  9799. + loud_error_header();
  9800. + loud_error(
  9801. + "failed to find VC symbol \"%s\".",
  9802. + symbol);
  9803. + loud_error_footer();
  9804. + return 0;
  9805. + }
  9806. +
  9807. + if (vcMemSize != bufsize) {
  9808. + loud_error_header();
  9809. + loud_error(
  9810. + "VC symbol \"%s\" is the wrong size.",
  9811. + symbol);
  9812. + loud_error_footer();
  9813. + return 0;
  9814. + }
  9815. +
  9816. + vcMapAddr = (off_t)vcMemAddr & VC_MEM_TO_ARM_ADDR_MASK;
  9817. + vcMapAddr += mm_vc_mem_phys_addr;
  9818. + mapAddr = ioremap_nocache(vcMapAddr, vcMemSize);
  9819. + if (mapAddr == 0) {
  9820. + loud_error_header();
  9821. + loud_error(
  9822. + "failed to ioremap \"%s\" @ 0x%x "
  9823. + "(phys: 0x%x, size: %u).",
  9824. + symbol,
  9825. + (unsigned int)vcMapAddr,
  9826. + (unsigned int)vcMemAddr,
  9827. + (unsigned int)vcMemSize);
  9828. + loud_error_footer();
  9829. + return 0;
  9830. + }
  9831. +
  9832. + memcpy(buf, mapAddr, bufsize);
  9833. + iounmap(mapAddr);
  9834. +
  9835. + return 1;
  9836. +}
  9837. +
  9838. +
  9839. +static int
  9840. +check_cma_config(void)
  9841. +{
  9842. + VC_MEM_ACCESS_HANDLE_T mem_hndl;
  9843. + VC_MEM_ADDR_T mempool_start;
  9844. + VC_MEM_ADDR_T mempool_end;
  9845. + VC_MEM_ADDR_T mempool_offline_start;
  9846. + VC_MEM_ADDR_T mempool_offline_end;
  9847. + VC_MEM_ADDR_T cam_alloc_base;
  9848. + VC_MEM_ADDR_T cam_alloc_size;
  9849. + VC_MEM_ADDR_T cam_alloc_end;
  9850. + int success = 0;
  9851. +
  9852. + if (OpenVideoCoreMemory(&mem_hndl) != 0)
  9853. + goto out;
  9854. +
  9855. + /* Read the relevant VideoCore variables */
  9856. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_START",
  9857. + &mempool_start,
  9858. + sizeof(mempool_start)))
  9859. + goto close;
  9860. +
  9861. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_END",
  9862. + &mempool_end,
  9863. + sizeof(mempool_end)))
  9864. + goto close;
  9865. +
  9866. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_START",
  9867. + &mempool_offline_start,
  9868. + sizeof(mempool_offline_start)))
  9869. + goto close;
  9870. +
  9871. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_END",
  9872. + &mempool_offline_end,
  9873. + sizeof(mempool_offline_end)))
  9874. + goto close;
  9875. +
  9876. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_base",
  9877. + &cam_alloc_base,
  9878. + sizeof(cam_alloc_base)))
  9879. + goto close;
  9880. +
  9881. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_size",
  9882. + &cam_alloc_size,
  9883. + sizeof(cam_alloc_size)))
  9884. + goto close;
  9885. +
  9886. + cam_alloc_end = cam_alloc_base + cam_alloc_size;
  9887. +
  9888. + success = 1;
  9889. +
  9890. + /* Now the sanity checks */
  9891. + if (!mempool_offline_start)
  9892. + mempool_offline_start = mempool_start;
  9893. + if (!mempool_offline_end)
  9894. + mempool_offline_end = mempool_end;
  9895. +
  9896. + if (VCADDR_TO_PHYSADDR(mempool_offline_start) != vc_cma_base) {
  9897. + loud_error_header();
  9898. + loud_error(
  9899. + "__MEMPOOL_OFFLINE_START(%x -> %lx) doesn't match "
  9900. + "vc_cma_base(%x)",
  9901. + mempool_offline_start,
  9902. + VCADDR_TO_PHYSADDR(mempool_offline_start),
  9903. + vc_cma_base);
  9904. + success = 0;
  9905. + }
  9906. +
  9907. + if (VCADDR_TO_PHYSADDR(mempool_offline_end) !=
  9908. + (vc_cma_base + vc_cma_size)) {
  9909. + loud_error_header();
  9910. + loud_error(
  9911. + "__MEMPOOL_OFFLINE_END(%x -> %lx) doesn't match "
  9912. + "vc_cma_base(%x) + vc_cma_size(%x) = %x",
  9913. + mempool_offline_start,
  9914. + VCADDR_TO_PHYSADDR(mempool_offline_end),
  9915. + vc_cma_base, vc_cma_size, vc_cma_base + vc_cma_size);
  9916. + success = 0;
  9917. + }
  9918. +
  9919. + if (mempool_end < mempool_start) {
  9920. + loud_error_header();
  9921. + loud_error(
  9922. + "__MEMPOOL_END(%x) must not be before "
  9923. + "__MEMPOOL_START(%x)",
  9924. + mempool_end,
  9925. + mempool_start);
  9926. + success = 0;
  9927. + }
  9928. +
  9929. + if (mempool_offline_end < mempool_offline_start) {
  9930. + loud_error_header();
  9931. + loud_error(
  9932. + "__MEMPOOL_OFFLINE_END(%x) must not be before "
  9933. + "__MEMPOOL_OFFLINE_START(%x)",
  9934. + mempool_offline_end,
  9935. + mempool_offline_start);
  9936. + success = 0;
  9937. + }
  9938. +
  9939. + if (mempool_offline_start < mempool_start) {
  9940. + loud_error_header();
  9941. + loud_error(
  9942. + "__MEMPOOL_OFFLINE_START(%x) must not be before "
  9943. + "__MEMPOOL_START(%x)",
  9944. + mempool_offline_start,
  9945. + mempool_start);
  9946. + success = 0;
  9947. + }
  9948. +
  9949. + if (mempool_offline_end > mempool_end) {
  9950. + loud_error_header();
  9951. + loud_error(
  9952. + "__MEMPOOL_OFFLINE_END(%x) must not be after "
  9953. + "__MEMPOOL_END(%x)",
  9954. + mempool_offline_end,
  9955. + mempool_end);
  9956. + success = 0;
  9957. + }
  9958. +
  9959. + if ((cam_alloc_base < mempool_end) &&
  9960. + (cam_alloc_end > mempool_start)) {
  9961. + loud_error_header();
  9962. + loud_error(
  9963. + "cam_alloc pool(%x-%x) overlaps "
  9964. + "mempool(%x-%x)",
  9965. + cam_alloc_base, cam_alloc_end,
  9966. + mempool_start, mempool_end);
  9967. + success = 0;
  9968. + }
  9969. +
  9970. + loud_error_footer();
  9971. +
  9972. +close:
  9973. + CloseVideoCoreMemory(mem_hndl);
  9974. +
  9975. +out:
  9976. + return success;
  9977. +}
  9978. +#endif
  9979. +
  9980. +static int vc_cma_init(void)
  9981. +{
  9982. + int rc = -EFAULT;
  9983. + struct device *dev;
  9984. +
  9985. + if (!check_cma_config())
  9986. + goto out_release;
  9987. +
  9988. + printk(KERN_INFO "vc-cma: Videocore CMA driver\n");
  9989. + printk(KERN_INFO "vc-cma: vc_cma_base = 0x%08x\n", vc_cma_base);
  9990. + printk(KERN_INFO "vc-cma: vc_cma_size = 0x%08x (%u MiB)\n",
  9991. + vc_cma_size, vc_cma_size / (1024 * 1024));
  9992. + printk(KERN_INFO "vc-cma: vc_cma_initial = 0x%08x (%u MiB)\n",
  9993. + vc_cma_initial, vc_cma_initial / (1024 * 1024));
  9994. +
  9995. + vc_cma_base_page = phys_to_page(vc_cma_base);
  9996. +
  9997. + if (vc_cma_chunks) {
  9998. + int chunks_needed = vc_cma_initial / VC_CMA_CHUNK_SIZE;
  9999. +
  10000. + for (vc_cma_chunks_used = 0;
  10001. + vc_cma_chunks_used < chunks_needed; vc_cma_chunks_used++) {
  10002. + struct page *chunk;
  10003. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  10004. + PAGES_PER_CHUNK,
  10005. + VC_CMA_CHUNK_ORDER);
  10006. + if (!chunk)
  10007. + break;
  10008. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  10009. + VC_CMA_CHUNK_SIZE) != 0);
  10010. + }
  10011. + if (vc_cma_chunks_used != chunks_needed) {
  10012. + LOG_ERR("%s: dma_alloc_from_contiguous failed (%d "
  10013. + "bytes, allocation %d of %d)",
  10014. + __func__, VC_CMA_CHUNK_SIZE,
  10015. + vc_cma_chunks_used, chunks_needed);
  10016. + goto out_release;
  10017. + }
  10018. +
  10019. + vchiq_add_connected_callback(vc_cma_connected_init);
  10020. + }
  10021. +
  10022. + rc = alloc_chrdev_region(&vc_cma_devnum, 0, 1, DRIVER_NAME);
  10023. + if (rc < 0) {
  10024. + LOG_ERR("%s: alloc_chrdev_region failed (rc=%d)", __func__, rc);
  10025. + goto out_release;
  10026. + }
  10027. +
  10028. + cdev_init(&vc_cma_cdev, &vc_cma_fops);
  10029. + rc = cdev_add(&vc_cma_cdev, vc_cma_devnum, 1);
  10030. + if (rc != 0) {
  10031. + LOG_ERR("%s: cdev_add failed (rc=%d)", __func__, rc);
  10032. + goto out_unregister;
  10033. + }
  10034. +
  10035. + vc_cma_class = class_create(THIS_MODULE, DRIVER_NAME);
  10036. + if (IS_ERR(vc_cma_class)) {
  10037. + rc = PTR_ERR(vc_cma_class);
  10038. + LOG_ERR("%s: class_create failed (rc=%d)", __func__, rc);
  10039. + goto out_cdev_del;
  10040. + }
  10041. +
  10042. + dev = device_create(vc_cma_class, NULL, vc_cma_devnum, NULL,
  10043. + DRIVER_NAME);
  10044. + if (IS_ERR(dev)) {
  10045. + rc = PTR_ERR(dev);
  10046. + LOG_ERR("%s: device_create failed (rc=%d)", __func__, rc);
  10047. + goto out_class_destroy;
  10048. + }
  10049. +
  10050. + vc_cma_proc_entry = proc_create(DRIVER_NAME, 0444, NULL, &vc_cma_proc_fops);
  10051. + if (vc_cma_proc_entry == NULL) {
  10052. + rc = -EFAULT;
  10053. + LOG_ERR("%s: proc_create failed", __func__);
  10054. + goto out_device_destroy;
  10055. + }
  10056. +
  10057. + vc_cma_inited = 1;
  10058. + return 0;
  10059. +
  10060. +out_device_destroy:
  10061. + device_destroy(vc_cma_class, vc_cma_devnum);
  10062. +
  10063. +out_class_destroy:
  10064. + class_destroy(vc_cma_class);
  10065. + vc_cma_class = NULL;
  10066. +
  10067. +out_cdev_del:
  10068. + cdev_del(&vc_cma_cdev);
  10069. +
  10070. +out_unregister:
  10071. + unregister_chrdev_region(vc_cma_devnum, 1);
  10072. +
  10073. +out_release:
  10074. + /* It is tempting to try to clean up by calling
  10075. + dma_release_from_contiguous for all allocated chunks, but it isn't
  10076. + a very safe thing to do. If vc_cma_initial is non-zero it is because
  10077. + VideoCore is already using that memory, so giving it back to Linux
  10078. + is likely to be fatal.
  10079. + */
  10080. + return -1;
  10081. +}
  10082. +
  10083. +/****************************************************************************
  10084. +*
  10085. +* vc_cma_exit
  10086. +*
  10087. +***************************************************************************/
  10088. +
  10089. +static void __exit vc_cma_exit(void)
  10090. +{
  10091. + LOG_DBG("%s: called", __func__);
  10092. +
  10093. + if (vc_cma_inited) {
  10094. + remove_proc_entry(DRIVER_NAME, NULL);
  10095. + device_destroy(vc_cma_class, vc_cma_devnum);
  10096. + class_destroy(vc_cma_class);
  10097. + cdev_del(&vc_cma_cdev);
  10098. + unregister_chrdev_region(vc_cma_devnum, 1);
  10099. + }
  10100. +}
  10101. +
  10102. +module_init(vc_cma_init);
  10103. +module_exit(vc_cma_exit);
  10104. +MODULE_LICENSE("GPL");
  10105. +MODULE_AUTHOR("Broadcom Corporation");
  10106. diff -Nur linux-3.12.11.orig/drivers/char/hw_random/bcm2708-rng.c linux-3.12.11/drivers/char/hw_random/bcm2708-rng.c
  10107. --- linux-3.12.11.orig/drivers/char/hw_random/bcm2708-rng.c 1970-01-01 01:00:00.000000000 +0100
  10108. +++ linux-3.12.11/drivers/char/hw_random/bcm2708-rng.c 2014-02-18 11:52:14.000000000 +0100
  10109. @@ -0,0 +1,117 @@
  10110. +/**
  10111. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  10112. + *
  10113. + * Redistribution and use in source and binary forms, with or without
  10114. + * modification, are permitted provided that the following conditions
  10115. + * are met:
  10116. + * 1. Redistributions of source code must retain the above copyright
  10117. + * notice, this list of conditions, and the following disclaimer,
  10118. + * without modification.
  10119. + * 2. Redistributions in binary form must reproduce the above copyright
  10120. + * notice, this list of conditions and the following disclaimer in the
  10121. + * documentation and/or other materials provided with the distribution.
  10122. + * 3. The names of the above-listed copyright holders may not be used
  10123. + * to endorse or promote products derived from this software without
  10124. + * specific prior written permission.
  10125. + *
  10126. + * ALTERNATIVELY, this software may be distributed under the terms of the
  10127. + * GNU General Public License ("GPL") version 2, as published by the Free
  10128. + * Software Foundation.
  10129. + *
  10130. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  10131. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  10132. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  10133. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  10134. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  10135. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  10136. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  10137. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  10138. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  10139. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  10140. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  10141. + */
  10142. +
  10143. +#include <linux/kernel.h>
  10144. +#include <linux/module.h>
  10145. +#include <linux/init.h>
  10146. +#include <linux/hw_random.h>
  10147. +#include <linux/printk.h>
  10148. +
  10149. +#include <asm/io.h>
  10150. +#include <mach/hardware.h>
  10151. +#include <mach/platform.h>
  10152. +
  10153. +#define RNG_CTRL (0x0)
  10154. +#define RNG_STATUS (0x4)
  10155. +#define RNG_DATA (0x8)
  10156. +#define RNG_FF_THRESHOLD (0xc)
  10157. +
  10158. +/* enable rng */
  10159. +#define RNG_RBGEN 0x1
  10160. +/* double speed, less random mode */
  10161. +#define RNG_RBG2X 0x2
  10162. +
  10163. +/* the initial numbers generated are "less random" so will be discarded */
  10164. +#define RNG_WARMUP_COUNT 0x40000
  10165. +
  10166. +static int bcm2708_rng_data_read(struct hwrng *rng, u32 *buffer)
  10167. +{
  10168. + void __iomem *rng_base = (void __iomem *)rng->priv;
  10169. + unsigned words;
  10170. + /* wait for a random number to be in fifo */
  10171. + do {
  10172. + words = __raw_readl(rng_base + RNG_STATUS)>>24;
  10173. + }
  10174. + while (words == 0);
  10175. + /* read the random number */
  10176. + *buffer = __raw_readl(rng_base + RNG_DATA);
  10177. + return 4;
  10178. +}
  10179. +
  10180. +static struct hwrng bcm2708_rng_ops = {
  10181. + .name = "bcm2708",
  10182. + .data_read = bcm2708_rng_data_read,
  10183. +};
  10184. +
  10185. +static int __init bcm2708_rng_init(void)
  10186. +{
  10187. + void __iomem *rng_base;
  10188. + int err;
  10189. +
  10190. + /* map peripheral */
  10191. + rng_base = ioremap(RNG_BASE, 0x10);
  10192. + pr_info("bcm2708_rng_init=%p\n", rng_base);
  10193. + if (!rng_base) {
  10194. + pr_err("bcm2708_rng_init failed to ioremap\n");
  10195. + return -ENOMEM;
  10196. + }
  10197. + bcm2708_rng_ops.priv = (unsigned long)rng_base;
  10198. + /* register driver */
  10199. + err = hwrng_register(&bcm2708_rng_ops);
  10200. + if (err) {
  10201. + pr_err("bcm2708_rng_init hwrng_register()=%d\n", err);
  10202. + iounmap(rng_base);
  10203. + } else {
  10204. + /* set warm-up count & enable */
  10205. + __raw_writel(RNG_WARMUP_COUNT, rng_base + RNG_STATUS);
  10206. + __raw_writel(RNG_RBGEN, rng_base + RNG_CTRL);
  10207. + }
  10208. + return err;
  10209. +}
  10210. +
  10211. +static void __exit bcm2708_rng_exit(void)
  10212. +{
  10213. + void __iomem *rng_base = (void __iomem *)bcm2708_rng_ops.priv;
  10214. + pr_info("bcm2708_rng_exit\n");
  10215. + /* disable rng hardware */
  10216. + __raw_writel(0, rng_base + RNG_CTRL);
  10217. + /* unregister driver */
  10218. + hwrng_unregister(&bcm2708_rng_ops);
  10219. + iounmap(rng_base);
  10220. +}
  10221. +
  10222. +module_init(bcm2708_rng_init);
  10223. +module_exit(bcm2708_rng_exit);
  10224. +
  10225. +MODULE_DESCRIPTION("BCM2708 H/W Random Number Generator (RNG) driver");
  10226. +MODULE_LICENSE("GPL and additional rights");
  10227. diff -Nur linux-3.12.11.orig/drivers/char/hw_random/Kconfig linux-3.12.11/drivers/char/hw_random/Kconfig
  10228. --- linux-3.12.11.orig/drivers/char/hw_random/Kconfig 2014-02-13 22:51:06.000000000 +0100
  10229. +++ linux-3.12.11/drivers/char/hw_random/Kconfig 2014-02-18 11:52:14.000000000 +0100
  10230. @@ -314,3 +314,14 @@
  10231. module will be called tpm-rng.
  10232. If unsure, say Y.
  10233. +
  10234. +config HW_RANDOM_BCM2708
  10235. + tristate "BCM2708 generic true random number generator support"
  10236. + depends on HW_RANDOM && ARCH_BCM2708
  10237. + ---help---
  10238. + This driver provides the kernel-side support for the BCM2708 hardware.
  10239. +
  10240. + To compile this driver as a module, choose M here: the
  10241. + module will be called bcm2708-rng.
  10242. +
  10243. + If unsure, say N.
  10244. diff -Nur linux-3.12.11.orig/drivers/char/hw_random/Makefile linux-3.12.11/drivers/char/hw_random/Makefile
  10245. --- linux-3.12.11.orig/drivers/char/hw_random/Makefile 2014-02-13 22:51:06.000000000 +0100
  10246. +++ linux-3.12.11/drivers/char/hw_random/Makefile 2014-02-18 11:52:14.000000000 +0100
  10247. @@ -27,3 +27,4 @@
  10248. obj-$(CONFIG_HW_RANDOM_EXYNOS) += exynos-rng.o
  10249. obj-$(CONFIG_HW_RANDOM_TPM) += tpm-rng.o
  10250. obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o
  10251. +obj-$(CONFIG_HW_RANDOM_BCM2708) += bcm2708-rng.o
  10252. diff -Nur linux-3.12.11.orig/drivers/char/Kconfig linux-3.12.11/drivers/char/Kconfig
  10253. --- linux-3.12.11.orig/drivers/char/Kconfig 2014-02-13 22:51:06.000000000 +0100
  10254. +++ linux-3.12.11/drivers/char/Kconfig 2014-02-18 11:52:14.000000000 +0100
  10255. @@ -574,6 +574,8 @@
  10256. source "drivers/s390/char/Kconfig"
  10257. +source "drivers/char/broadcom/Kconfig"
  10258. +
  10259. config MSM_SMD_PKT
  10260. bool "Enable device interface for some SMD packet ports"
  10261. default n
  10262. diff -Nur linux-3.12.11.orig/drivers/char/Makefile linux-3.12.11/drivers/char/Makefile
  10263. --- linux-3.12.11.orig/drivers/char/Makefile 2014-02-13 22:51:06.000000000 +0100
  10264. +++ linux-3.12.11/drivers/char/Makefile 2014-02-18 11:52:14.000000000 +0100
  10265. @@ -62,3 +62,5 @@
  10266. js-rtc-y = rtc.o
  10267. obj-$(CONFIG_TILE_SROM) += tile-srom.o
  10268. +
  10269. +obj-$(CONFIG_BRCM_CHAR_DRIVERS) += broadcom/
  10270. diff -Nur linux-3.12.11.orig/drivers/cpufreq/bcm2835-cpufreq.c linux-3.12.11/drivers/cpufreq/bcm2835-cpufreq.c
  10271. --- linux-3.12.11.orig/drivers/cpufreq/bcm2835-cpufreq.c 1970-01-01 01:00:00.000000000 +0100
  10272. +++ linux-3.12.11/drivers/cpufreq/bcm2835-cpufreq.c 2014-02-18 11:52:14.000000000 +0100
  10273. @@ -0,0 +1,239 @@
  10274. +/*****************************************************************************
  10275. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  10276. +*
  10277. +* Unless you and Broadcom execute a separate written software license
  10278. +* agreement governing use of this software, this software is licensed to you
  10279. +* under the terms of the GNU General Public License version 2, available at
  10280. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  10281. +*
  10282. +* Notwithstanding the above, under no circumstances may you combine this
  10283. +* software in any way with any other Broadcom software provided under a
  10284. +* license other than the GPL, without Broadcom's express prior written
  10285. +* consent.
  10286. +*****************************************************************************/
  10287. +
  10288. +/*****************************************************************************
  10289. +* FILENAME: bcm2835-cpufreq.h
  10290. +* DESCRIPTION: This driver dynamically manages the CPU Frequency of the ARM
  10291. +* processor. Messages are sent to Videocore either setting or requesting the
  10292. +* frequency of the ARM in order to match an appropiate frequency to the current
  10293. +* usage of the processor. The policy which selects the frequency to use is
  10294. +* defined in the kernel .config file, but can be changed during runtime.
  10295. +*****************************************************************************/
  10296. +
  10297. +/* ---------- INCLUDES ---------- */
  10298. +#include <linux/kernel.h>
  10299. +#include <linux/init.h>
  10300. +#include <linux/module.h>
  10301. +#include <linux/cpufreq.h>
  10302. +#include <mach/vcio.h>
  10303. +
  10304. +/* ---------- DEFINES ---------- */
  10305. +/*#define CPUFREQ_DEBUG_ENABLE*/ /* enable debugging */
  10306. +#define MODULE_NAME "bcm2835-cpufreq"
  10307. +
  10308. +#define VCMSG_ID_ARM_CLOCK 0x000000003 /* Clock/Voltage ID's */
  10309. +
  10310. +/* debug printk macros */
  10311. +#ifdef CPUFREQ_DEBUG_ENABLE
  10312. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  10313. +#else
  10314. +#define print_debug(fmt,...)
  10315. +#endif
  10316. +#define print_err(fmt,...) pr_err("%s:%s:%d: "fmt, MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  10317. +#define print_info(fmt,...) pr_info("%s: "fmt, MODULE_NAME, ##__VA_ARGS__)
  10318. +
  10319. +/* tag part of the message */
  10320. +struct vc_msg_tag {
  10321. + uint32_t tag_id; /* the message id */
  10322. + uint32_t buffer_size; /* size of the buffer (which in this case is always 8 bytes) */
  10323. + uint32_t data_size; /* amount of data being sent or received */
  10324. + uint32_t dev_id; /* the ID of the clock/voltage to get or set */
  10325. + uint32_t val; /* the value (e.g. rate (in Hz)) to set */
  10326. +};
  10327. +
  10328. +/* message structure to be sent to videocore */
  10329. +struct vc_msg {
  10330. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  10331. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  10332. + struct vc_msg_tag tag; /* the tag structure above to make */
  10333. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  10334. +};
  10335. +
  10336. +/* ---------- GLOBALS ---------- */
  10337. +static struct cpufreq_driver bcm2835_cpufreq_driver; /* the cpufreq driver global */
  10338. +
  10339. +/*
  10340. + ===============================================
  10341. + clk_rate either gets or sets the clock rates.
  10342. + ===============================================
  10343. +*/
  10344. +static uint32_t bcm2835_cpufreq_set_clock(int cur_rate, int arm_rate)
  10345. +{
  10346. + int s, actual_rate=0;
  10347. + struct vc_msg msg;
  10348. +
  10349. + /* wipe all previous message data */
  10350. + memset(&msg, 0, sizeof msg);
  10351. +
  10352. + msg.msg_size = sizeof msg;
  10353. +
  10354. + msg.tag.tag_id = VCMSG_SET_CLOCK_RATE;
  10355. + msg.tag.buffer_size = 8;
  10356. + msg.tag.data_size = 8; /* we're sending the clock ID and the new rates which is a total of 2 words */
  10357. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  10358. + msg.tag.val = arm_rate * 1000;
  10359. +
  10360. + /* send the message */
  10361. + s = bcm_mailbox_property(&msg, sizeof msg);
  10362. +
  10363. + /* check if it was all ok and return the rate in KHz */
  10364. + if (s == 0 && (msg.request_code & 0x80000000))
  10365. + actual_rate = msg.tag.val/1000;
  10366. +
  10367. + print_debug("Setting new frequency = %d -> %d (actual %d)\n", cur_rate, arm_rate, actual_rate);
  10368. + return actual_rate;
  10369. +}
  10370. +
  10371. +static uint32_t bcm2835_cpufreq_get_clock(int tag)
  10372. +{
  10373. + int s;
  10374. + int arm_rate = 0;
  10375. + struct vc_msg msg;
  10376. +
  10377. + /* wipe all previous message data */
  10378. + memset(&msg, 0, sizeof msg);
  10379. +
  10380. + msg.msg_size = sizeof msg;
  10381. + msg.tag.tag_id = tag;
  10382. + msg.tag.buffer_size = 8;
  10383. + msg.tag.data_size = 4; /* we're just sending the clock ID which is one word long */
  10384. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  10385. +
  10386. + /* send the message */
  10387. + s = bcm_mailbox_property(&msg, sizeof msg);
  10388. +
  10389. + /* check if it was all ok and return the rate in KHz */
  10390. + if (s == 0 && (msg.request_code & 0x80000000))
  10391. + arm_rate = msg.tag.val/1000;
  10392. +
  10393. + print_debug("%s frequency = %d\n",
  10394. + tag == VCMSG_GET_CLOCK_RATE ? "Current":
  10395. + tag == VCMSG_GET_MIN_CLOCK ? "Min":
  10396. + tag == VCMSG_GET_MAX_CLOCK ? "Max":
  10397. + "Unexpected", arm_rate);
  10398. +
  10399. + return arm_rate;
  10400. +}
  10401. +
  10402. +/*
  10403. + ====================================================
  10404. + Module Initialisation registers the cpufreq driver
  10405. + ====================================================
  10406. +*/
  10407. +static int __init bcm2835_cpufreq_module_init(void)
  10408. +{
  10409. + print_debug("IN\n");
  10410. + return cpufreq_register_driver(&bcm2835_cpufreq_driver);
  10411. +}
  10412. +
  10413. +/*
  10414. + =============
  10415. + Module exit
  10416. + =============
  10417. +*/
  10418. +static void __exit bcm2835_cpufreq_module_exit(void)
  10419. +{
  10420. + print_debug("IN\n");
  10421. + cpufreq_unregister_driver(&bcm2835_cpufreq_driver);
  10422. + return;
  10423. +}
  10424. +
  10425. +/*
  10426. + ==============================================================
  10427. + Initialisation function sets up the CPU policy for first use
  10428. + ==============================================================
  10429. +*/
  10430. +static int bcm2835_cpufreq_driver_init(struct cpufreq_policy *policy)
  10431. +{
  10432. + /* measured value of how long it takes to change frequency */
  10433. + policy->cpuinfo.transition_latency = 355000; /* ns */
  10434. +
  10435. + /* now find out what the maximum and minimum frequencies are */
  10436. + policy->min = policy->cpuinfo.min_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MIN_CLOCK);
  10437. + policy->max = policy->cpuinfo.max_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MAX_CLOCK);
  10438. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  10439. +
  10440. + print_info("min=%d max=%d cur=%d\n", policy->min, policy->max, policy->cur);
  10441. + return 0;
  10442. +}
  10443. +
  10444. +/*
  10445. + =================================================================================
  10446. + Target function chooses the most appropriate frequency from the table to enable
  10447. + =================================================================================
  10448. +*/
  10449. +
  10450. +static int bcm2835_cpufreq_driver_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation)
  10451. +{
  10452. + unsigned int target = target_freq;
  10453. +#ifdef CPUFREQ_DEBUG_ENABLE
  10454. + unsigned int cur = policy->cur;
  10455. +#endif
  10456. + print_debug("%s: min=%d max=%d cur=%d target=%d\n",policy->governor->name,policy->min,policy->max,policy->cur,target_freq);
  10457. +
  10458. + /* if we are above min and using ondemand, then just use max */
  10459. + if (strcmp("ondemand", policy->governor->name)==0 && target > policy->min)
  10460. + target = policy->max;
  10461. + /* if the frequency is the same, just quit */
  10462. + if (target == policy->cur)
  10463. + return 0;
  10464. +
  10465. + /* otherwise were good to set the clock frequency */
  10466. + policy->cur = bcm2835_cpufreq_set_clock(policy->cur, target);
  10467. +
  10468. + if (!policy->cur)
  10469. + {
  10470. + print_err("Error occurred setting a new frequency (%d)!\n", target);
  10471. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  10472. + return -EINVAL;
  10473. + }
  10474. + print_debug("Freq %d->%d (min=%d max=%d target=%d request=%d)\n", cur, policy->cur, policy->min, policy->max, target_freq, target);
  10475. + return 0;
  10476. +}
  10477. +
  10478. +static unsigned int bcm2835_cpufreq_driver_get(unsigned int cpu)
  10479. +{
  10480. + unsigned int actual_rate = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  10481. + print_debug("cpu=%d\n", actual_rate);
  10482. + return actual_rate;
  10483. +}
  10484. +
  10485. +/*
  10486. + =================================================================================
  10487. + Verify ensures that when a policy is changed, it is suitable for the CPU to use
  10488. + =================================================================================
  10489. +*/
  10490. +
  10491. +static int bcm2835_cpufreq_driver_verify(struct cpufreq_policy *policy)
  10492. +{
  10493. + print_info("switching to governor %s\n", policy->governor->name);
  10494. + return 0;
  10495. +}
  10496. +
  10497. +
  10498. +/* the CPUFreq driver */
  10499. +static struct cpufreq_driver bcm2835_cpufreq_driver = {
  10500. + .name = "BCM2835 CPUFreq",
  10501. + .init = bcm2835_cpufreq_driver_init,
  10502. + .verify = bcm2835_cpufreq_driver_verify,
  10503. + .target = bcm2835_cpufreq_driver_target,
  10504. + .get = bcm2835_cpufreq_driver_get
  10505. +};
  10506. +
  10507. +MODULE_AUTHOR("Dorian Peake and Dom Cobley");
  10508. +MODULE_DESCRIPTION("CPU frequency driver for BCM2835 chip");
  10509. +MODULE_LICENSE("GPL");
  10510. +
  10511. +module_init(bcm2835_cpufreq_module_init);
  10512. +module_exit(bcm2835_cpufreq_module_exit);
  10513. diff -Nur linux-3.12.11.orig/drivers/cpufreq/Kconfig.arm linux-3.12.11/drivers/cpufreq/Kconfig.arm
  10514. --- linux-3.12.11.orig/drivers/cpufreq/Kconfig.arm 2014-02-13 22:51:06.000000000 +0100
  10515. +++ linux-3.12.11/drivers/cpufreq/Kconfig.arm 2014-02-18 11:52:14.000000000 +0100
  10516. @@ -228,6 +228,14 @@
  10517. help
  10518. This adds the CPUFreq driver support for SPEAr SOCs.
  10519. +config ARM_BCM2835_CPUFREQ
  10520. + bool "BCM2835 Driver"
  10521. + default y
  10522. + help
  10523. + This adds the CPUFreq driver for BCM2835
  10524. +
  10525. + If in doubt, say N.
  10526. +
  10527. config ARM_TEGRA_CPUFREQ
  10528. bool "TEGRA CPUFreq support"
  10529. depends on ARCH_TEGRA
  10530. diff -Nur linux-3.12.11.orig/drivers/cpufreq/Makefile linux-3.12.11/drivers/cpufreq/Makefile
  10531. --- linux-3.12.11.orig/drivers/cpufreq/Makefile 2014-02-13 22:51:06.000000000 +0100
  10532. +++ linux-3.12.11/drivers/cpufreq/Makefile 2014-02-18 11:52:14.000000000 +0100
  10533. @@ -76,6 +76,7 @@
  10534. obj-$(CONFIG_ARM_SA1100_CPUFREQ) += sa1100-cpufreq.o
  10535. obj-$(CONFIG_ARM_SA1110_CPUFREQ) += sa1110-cpufreq.o
  10536. obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o
  10537. +obj-$(CONFIG_ARM_BCM2835_CPUFREQ) += bcm2835-cpufreq.o
  10538. obj-$(CONFIG_ARM_TEGRA_CPUFREQ) += tegra-cpufreq.o
  10539. ##################################################################################
  10540. diff -Nur linux-3.12.11.orig/drivers/dma/bcm2708-dmaengine.c linux-3.12.11/drivers/dma/bcm2708-dmaengine.c
  10541. --- linux-3.12.11.orig/drivers/dma/bcm2708-dmaengine.c 1970-01-01 01:00:00.000000000 +0100
  10542. +++ linux-3.12.11/drivers/dma/bcm2708-dmaengine.c 2014-02-18 11:52:14.000000000 +0100
  10543. @@ -0,0 +1,588 @@
  10544. +/*
  10545. + * BCM2708 DMA engine support
  10546. + *
  10547. + * This driver only supports cyclic DMA transfers
  10548. + * as needed for the I2S module.
  10549. + *
  10550. + * Author: Florian Meier <florian.meier@koalo.de>
  10551. + * Copyright 2013
  10552. + *
  10553. + * Based on
  10554. + * OMAP DMAengine support by Russell King
  10555. + *
  10556. + * BCM2708 DMA Driver
  10557. + * Copyright (C) 2010 Broadcom
  10558. + *
  10559. + * Raspberry Pi PCM I2S ALSA Driver
  10560. + * Copyright (c) by Phil Poole 2013
  10561. + *
  10562. + * MARVELL MMP Peripheral DMA Driver
  10563. + * Copyright 2012 Marvell International Ltd.
  10564. + *
  10565. + * This program is free software; you can redistribute it and/or modify
  10566. + * it under the terms of the GNU General Public License as published by
  10567. + * the Free Software Foundation; either version 2 of the License, or
  10568. + * (at your option) any later version.
  10569. + *
  10570. + * This program is distributed in the hope that it will be useful,
  10571. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10572. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10573. + * GNU General Public License for more details.
  10574. + */
  10575. +#include <linux/dmaengine.h>
  10576. +#include <linux/dma-mapping.h>
  10577. +#include <linux/err.h>
  10578. +#include <linux/init.h>
  10579. +#include <linux/interrupt.h>
  10580. +#include <linux/list.h>
  10581. +#include <linux/module.h>
  10582. +#include <linux/platform_device.h>
  10583. +#include <linux/slab.h>
  10584. +#include <linux/io.h>
  10585. +#include <linux/spinlock.h>
  10586. +#include <linux/irq.h>
  10587. +
  10588. +#include "virt-dma.h"
  10589. +
  10590. +#include <mach/dma.h>
  10591. +#include <mach/irqs.h>
  10592. +
  10593. +struct bcm2708_dmadev {
  10594. + struct dma_device ddev;
  10595. + spinlock_t lock;
  10596. + void __iomem *base;
  10597. + struct device_dma_parameters dma_parms;
  10598. +};
  10599. +
  10600. +struct bcm2708_chan {
  10601. + struct virt_dma_chan vc;
  10602. + struct list_head node;
  10603. +
  10604. + struct dma_slave_config cfg;
  10605. + bool cyclic;
  10606. +
  10607. + int ch;
  10608. + struct bcm2708_desc *desc;
  10609. +
  10610. + void __iomem *chan_base;
  10611. + int irq_number;
  10612. +};
  10613. +
  10614. +struct bcm2708_desc {
  10615. + struct virt_dma_desc vd;
  10616. + enum dma_transfer_direction dir;
  10617. +
  10618. + unsigned int control_block_size;
  10619. + struct bcm2708_dma_cb *control_block_base;
  10620. + dma_addr_t control_block_base_phys;
  10621. +
  10622. + unsigned frames;
  10623. + size_t size;
  10624. +};
  10625. +
  10626. +#define BCM2708_DMA_DATA_TYPE_S8 1
  10627. +#define BCM2708_DMA_DATA_TYPE_S16 2
  10628. +#define BCM2708_DMA_DATA_TYPE_S32 4
  10629. +#define BCM2708_DMA_DATA_TYPE_S128 16
  10630. +
  10631. +static inline struct bcm2708_dmadev *to_bcm2708_dma_dev(struct dma_device *d)
  10632. +{
  10633. + return container_of(d, struct bcm2708_dmadev, ddev);
  10634. +}
  10635. +
  10636. +static inline struct bcm2708_chan *to_bcm2708_dma_chan(struct dma_chan *c)
  10637. +{
  10638. + return container_of(c, struct bcm2708_chan, vc.chan);
  10639. +}
  10640. +
  10641. +static inline struct bcm2708_desc *to_bcm2708_dma_desc(
  10642. + struct dma_async_tx_descriptor *t)
  10643. +{
  10644. + return container_of(t, struct bcm2708_desc, vd.tx);
  10645. +}
  10646. +
  10647. +static void bcm2708_dma_desc_free(struct virt_dma_desc *vd)
  10648. +{
  10649. + struct bcm2708_desc *desc = container_of(vd, struct bcm2708_desc, vd);
  10650. + dma_free_coherent(desc->vd.tx.chan->device->dev,
  10651. + desc->control_block_size,
  10652. + desc->control_block_base,
  10653. + desc->control_block_base_phys);
  10654. + kfree(desc);
  10655. +}
  10656. +
  10657. +static void bcm2708_dma_start_desc(struct bcm2708_chan *c)
  10658. +{
  10659. + struct virt_dma_desc *vd = vchan_next_desc(&c->vc);
  10660. + struct bcm2708_desc *d;
  10661. +
  10662. + if (!vd) {
  10663. + c->desc = NULL;
  10664. + return;
  10665. + }
  10666. +
  10667. + list_del(&vd->node);
  10668. +
  10669. + c->desc = d = to_bcm2708_dma_desc(&vd->tx);
  10670. +
  10671. + bcm_dma_start(c->chan_base, d->control_block_base_phys);
  10672. +}
  10673. +
  10674. +static irqreturn_t bcm2708_dma_callback(int irq, void *data)
  10675. +{
  10676. + struct bcm2708_chan *c = data;
  10677. + struct bcm2708_desc *d;
  10678. + unsigned long flags;
  10679. +
  10680. + spin_lock_irqsave(&c->vc.lock, flags);
  10681. +
  10682. + /* Acknowledge interrupt */
  10683. + writel(BCM2708_DMA_INT, c->chan_base + BCM2708_DMA_CS);
  10684. +
  10685. + d = c->desc;
  10686. +
  10687. + if (d) {
  10688. + /* TODO Only works for cyclic DMA */
  10689. + vchan_cyclic_callback(&d->vd);
  10690. + }
  10691. +
  10692. + /* Keep the DMA engine running */
  10693. + dsb(); /* ARM synchronization barrier */
  10694. + writel(BCM2708_DMA_ACTIVE, c->chan_base + BCM2708_DMA_CS);
  10695. +
  10696. + spin_unlock_irqrestore(&c->vc.lock, flags);
  10697. +
  10698. + return IRQ_HANDLED;
  10699. +}
  10700. +
  10701. +static int bcm2708_dma_alloc_chan_resources(struct dma_chan *chan)
  10702. +{
  10703. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  10704. +
  10705. + return request_irq(c->irq_number,
  10706. + bcm2708_dma_callback, 0, "DMA IRQ", c);
  10707. +}
  10708. +
  10709. +static void bcm2708_dma_free_chan_resources(struct dma_chan *chan)
  10710. +{
  10711. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  10712. +
  10713. + vchan_free_chan_resources(&c->vc);
  10714. + free_irq(c->irq_number, c);
  10715. +
  10716. + dev_dbg(c->vc.chan.device->dev, "Freeing DMA channel %u\n", c->ch);
  10717. +}
  10718. +
  10719. +static size_t bcm2708_dma_desc_size(struct bcm2708_desc *d)
  10720. +{
  10721. + return d->size;
  10722. +}
  10723. +
  10724. +static size_t bcm2708_dma_desc_size_pos(struct bcm2708_desc *d, dma_addr_t addr)
  10725. +{
  10726. + unsigned i;
  10727. + size_t size;
  10728. +
  10729. + for (size = i = 0; i < d->frames; i++) {
  10730. + struct bcm2708_dma_cb *control_block =
  10731. + &d->control_block_base[i];
  10732. + size_t this_size = control_block->length;
  10733. + dma_addr_t dma;
  10734. +
  10735. + if (d->dir == DMA_DEV_TO_MEM)
  10736. + dma = control_block->dst;
  10737. + else
  10738. + dma = control_block->src;
  10739. +
  10740. + if (size)
  10741. + size += this_size;
  10742. + else if (addr >= dma && addr < dma + this_size)
  10743. + size += dma + this_size - addr;
  10744. + }
  10745. +
  10746. + return size;
  10747. +}
  10748. +
  10749. +static enum dma_status bcm2708_dma_tx_status(struct dma_chan *chan,
  10750. + dma_cookie_t cookie, struct dma_tx_state *txstate)
  10751. +{
  10752. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  10753. + struct virt_dma_desc *vd;
  10754. + enum dma_status ret;
  10755. + unsigned long flags;
  10756. +
  10757. + ret = dma_cookie_status(chan, cookie, txstate);
  10758. + if (ret == DMA_SUCCESS || !txstate)
  10759. + return ret;
  10760. +
  10761. + spin_lock_irqsave(&c->vc.lock, flags);
  10762. + vd = vchan_find_desc(&c->vc, cookie);
  10763. + if (vd) {
  10764. + txstate->residue =
  10765. + bcm2708_dma_desc_size(to_bcm2708_dma_desc(&vd->tx));
  10766. + } else if (c->desc && c->desc->vd.tx.cookie == cookie) {
  10767. + struct bcm2708_desc *d = c->desc;
  10768. + dma_addr_t pos;
  10769. +
  10770. + if (d->dir == DMA_MEM_TO_DEV)
  10771. + pos = readl(c->chan_base + BCM2708_DMA_SOURCE_AD);
  10772. + else if (d->dir == DMA_DEV_TO_MEM)
  10773. + pos = readl(c->chan_base + BCM2708_DMA_DEST_AD);
  10774. + else
  10775. + pos = 0;
  10776. +
  10777. + txstate->residue = bcm2708_dma_desc_size_pos(d, pos);
  10778. + } else {
  10779. + txstate->residue = 0;
  10780. + }
  10781. +
  10782. + spin_unlock_irqrestore(&c->vc.lock, flags);
  10783. +
  10784. + return ret;
  10785. +}
  10786. +
  10787. +static void bcm2708_dma_issue_pending(struct dma_chan *chan)
  10788. +{
  10789. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  10790. + unsigned long flags;
  10791. +
  10792. + c->cyclic = true; /* Nothing else is implemented */
  10793. +
  10794. + spin_lock_irqsave(&c->vc.lock, flags);
  10795. + if (vchan_issue_pending(&c->vc) && !c->desc)
  10796. + bcm2708_dma_start_desc(c);
  10797. +
  10798. + spin_unlock_irqrestore(&c->vc.lock, flags);
  10799. +}
  10800. +
  10801. +static struct dma_async_tx_descriptor *bcm2708_dma_prep_dma_cyclic(
  10802. + struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
  10803. + size_t period_len, enum dma_transfer_direction direction,
  10804. + unsigned long flags, void *context)
  10805. +{
  10806. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  10807. + enum dma_slave_buswidth dev_width;
  10808. + struct bcm2708_desc *d;
  10809. + dma_addr_t dev_addr;
  10810. + unsigned es, sync_type;
  10811. + unsigned frame;
  10812. +
  10813. + /* Grab configuration */
  10814. + if (direction == DMA_DEV_TO_MEM) {
  10815. + dev_addr = c->cfg.src_addr;
  10816. + dev_width = c->cfg.src_addr_width;
  10817. + sync_type = BCM2708_DMA_S_DREQ;
  10818. + } else if (direction == DMA_MEM_TO_DEV) {
  10819. + dev_addr = c->cfg.dst_addr;
  10820. + dev_width = c->cfg.dst_addr_width;
  10821. + sync_type = BCM2708_DMA_D_DREQ;
  10822. + } else {
  10823. + dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
  10824. + return NULL;
  10825. + }
  10826. +
  10827. + /* Bus width translates to the element size (ES) */
  10828. + switch (dev_width) {
  10829. + case DMA_SLAVE_BUSWIDTH_4_BYTES:
  10830. + es = BCM2708_DMA_DATA_TYPE_S32;
  10831. + break;
  10832. + default:
  10833. + return NULL;
  10834. + }
  10835. +
  10836. + /* Now allocate and setup the descriptor. */
  10837. + d = kzalloc(sizeof(*d), GFP_NOWAIT);
  10838. + if (!d)
  10839. + return NULL;
  10840. +
  10841. + d->dir = direction;
  10842. + d->frames = buf_len / period_len;
  10843. +
  10844. + /* Allocate memory for control blocks */
  10845. + d->control_block_size = d->frames * sizeof(struct bcm2708_dma_cb);
  10846. + d->control_block_base = dma_zalloc_coherent(chan->device->dev,
  10847. + d->control_block_size, &d->control_block_base_phys,
  10848. + GFP_NOWAIT);
  10849. +
  10850. + if (!d->control_block_base) {
  10851. + kfree(d);
  10852. + return NULL;
  10853. + }
  10854. +
  10855. + /*
  10856. + * Iterate over all frames, create a control block
  10857. + * for each frame and link them together.
  10858. + */
  10859. + for (frame = 0; frame < d->frames; frame++) {
  10860. + struct bcm2708_dma_cb *control_block =
  10861. + &d->control_block_base[frame];
  10862. +
  10863. + /* Setup adresses */
  10864. + if (d->dir == DMA_DEV_TO_MEM) {
  10865. + control_block->info = BCM2708_DMA_D_INC;
  10866. + control_block->src = dev_addr;
  10867. + control_block->dst = buf_addr + frame * period_len;
  10868. + } else {
  10869. + control_block->info = BCM2708_DMA_S_INC;
  10870. + control_block->src = buf_addr + frame * period_len;
  10871. + control_block->dst = dev_addr;
  10872. + }
  10873. +
  10874. + /* Enable interrupt */
  10875. + control_block->info |= BCM2708_DMA_INT_EN;
  10876. +
  10877. + /* Setup synchronization */
  10878. + if (sync_type != 0)
  10879. + control_block->info |= sync_type;
  10880. +
  10881. + /* Setup DREQ channel */
  10882. + if (c->cfg.slave_id != 0)
  10883. + control_block->info |=
  10884. + BCM2708_DMA_PER_MAP(c->cfg.slave_id);
  10885. +
  10886. + /* Length of a frame */
  10887. + control_block->length = period_len;
  10888. + d->size += control_block->length;
  10889. +
  10890. + /*
  10891. + * Next block is the next frame.
  10892. + * This DMA engine driver currently only supports cyclic DMA.
  10893. + * Therefore, wrap around at number of frames.
  10894. + */
  10895. + control_block->next = d->control_block_base_phys +
  10896. + sizeof(struct bcm2708_dma_cb)
  10897. + * ((frame + 1) % d->frames);
  10898. + }
  10899. +
  10900. + return vchan_tx_prep(&c->vc, &d->vd, flags);
  10901. +}
  10902. +
  10903. +static int bcm2708_dma_slave_config(struct bcm2708_chan *c,
  10904. + struct dma_slave_config *cfg)
  10905. +{
  10906. + if ((cfg->direction == DMA_DEV_TO_MEM &&
  10907. + cfg->src_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  10908. + (cfg->direction == DMA_MEM_TO_DEV &&
  10909. + cfg->dst_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  10910. + !is_slave_direction(cfg->direction)) {
  10911. + return -EINVAL;
  10912. + }
  10913. +
  10914. + c->cfg = *cfg;
  10915. +
  10916. + return 0;
  10917. +}
  10918. +
  10919. +static int bcm2708_dma_terminate_all(struct bcm2708_chan *c)
  10920. +{
  10921. + struct bcm2708_dmadev *d = to_bcm2708_dma_dev(c->vc.chan.device);
  10922. + unsigned long flags;
  10923. + int timeout = 10000;
  10924. + LIST_HEAD(head);
  10925. +
  10926. + spin_lock_irqsave(&c->vc.lock, flags);
  10927. +
  10928. + /* Prevent this channel being scheduled */
  10929. + spin_lock(&d->lock);
  10930. + list_del_init(&c->node);
  10931. + spin_unlock(&d->lock);
  10932. +
  10933. + /*
  10934. + * Stop DMA activity: we assume the callback will not be called
  10935. + * after bcm_dma_abort() returns (even if it does, it will see
  10936. + * c->desc is NULL and exit.)
  10937. + */
  10938. + if (c->desc) {
  10939. + c->desc = NULL;
  10940. + bcm_dma_abort(c->chan_base);
  10941. +
  10942. + /* Wait for stopping */
  10943. + while (timeout > 0) {
  10944. + timeout--;
  10945. + if (!(readl(c->chan_base + BCM2708_DMA_CS) &
  10946. + BCM2708_DMA_ACTIVE))
  10947. + break;
  10948. +
  10949. + cpu_relax();
  10950. + }
  10951. +
  10952. + if (timeout <= 0)
  10953. + dev_err(d->ddev.dev, "DMA transfer could not be terminated\n");
  10954. + }
  10955. +
  10956. + vchan_get_all_descriptors(&c->vc, &head);
  10957. + spin_unlock_irqrestore(&c->vc.lock, flags);
  10958. + vchan_dma_desc_free_list(&c->vc, &head);
  10959. +
  10960. + return 0;
  10961. +}
  10962. +
  10963. +static int bcm2708_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  10964. + unsigned long arg)
  10965. +{
  10966. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  10967. +
  10968. + switch (cmd) {
  10969. + case DMA_SLAVE_CONFIG:
  10970. + return bcm2708_dma_slave_config(c,
  10971. + (struct dma_slave_config *)arg);
  10972. +
  10973. + case DMA_TERMINATE_ALL:
  10974. + return bcm2708_dma_terminate_all(c);
  10975. +
  10976. + default:
  10977. + return -ENXIO;
  10978. + }
  10979. +}
  10980. +
  10981. +static int bcm2708_dma_chan_init(struct bcm2708_dmadev *d, void __iomem* chan_base,
  10982. + int chan_id, int irq)
  10983. +{
  10984. + struct bcm2708_chan *c;
  10985. +
  10986. + c = devm_kzalloc(d->ddev.dev, sizeof(*c), GFP_KERNEL);
  10987. + if (!c)
  10988. + return -ENOMEM;
  10989. +
  10990. + c->vc.desc_free = bcm2708_dma_desc_free;
  10991. + vchan_init(&c->vc, &d->ddev);
  10992. + INIT_LIST_HEAD(&c->node);
  10993. +
  10994. + d->ddev.chancnt++;
  10995. +
  10996. + c->chan_base = chan_base;
  10997. + c->ch = chan_id;
  10998. + c->irq_number = irq;
  10999. +
  11000. + return 0;
  11001. +}
  11002. +
  11003. +static void bcm2708_dma_free(struct bcm2708_dmadev *od)
  11004. +{
  11005. + while (!list_empty(&od->ddev.channels)) {
  11006. + struct bcm2708_chan *c = list_first_entry(&od->ddev.channels,
  11007. + struct bcm2708_chan, vc.chan.device_node);
  11008. +
  11009. + list_del(&c->vc.chan.device_node);
  11010. + tasklet_kill(&c->vc.task);
  11011. + }
  11012. +}
  11013. +
  11014. +static int bcm2708_dma_probe(struct platform_device *pdev)
  11015. +{
  11016. + struct bcm2708_dmadev *od;
  11017. + int rc, i;
  11018. +
  11019. + if (!pdev->dev.dma_mask)
  11020. + pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
  11021. +
  11022. + rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  11023. + if (rc)
  11024. + return rc;
  11025. + dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  11026. +
  11027. + od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
  11028. + if (!od)
  11029. + return -ENOMEM;
  11030. +
  11031. + pdev->dev.dma_parms = &od->dma_parms;
  11032. + dma_set_max_seg_size(&pdev->dev, 0x3FFFFFFF);
  11033. +
  11034. + dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
  11035. + dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask);
  11036. + od->ddev.device_alloc_chan_resources = bcm2708_dma_alloc_chan_resources;
  11037. + od->ddev.device_free_chan_resources = bcm2708_dma_free_chan_resources;
  11038. + od->ddev.device_tx_status = bcm2708_dma_tx_status;
  11039. + od->ddev.device_issue_pending = bcm2708_dma_issue_pending;
  11040. + od->ddev.device_prep_dma_cyclic = bcm2708_dma_prep_dma_cyclic;
  11041. + od->ddev.device_control = bcm2708_dma_control;
  11042. + od->ddev.dev = &pdev->dev;
  11043. + INIT_LIST_HEAD(&od->ddev.channels);
  11044. + spin_lock_init(&od->lock);
  11045. +
  11046. + platform_set_drvdata(pdev, od);
  11047. +
  11048. + for (i = 0; i < 16; i++) {
  11049. + void __iomem* chan_base;
  11050. + int chan_id, irq;
  11051. +
  11052. + chan_id = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST,
  11053. + &chan_base,
  11054. + &irq);
  11055. +
  11056. + if (chan_id < 0)
  11057. + break;
  11058. +
  11059. + rc = bcm2708_dma_chan_init(od, chan_base, chan_id, irq);
  11060. + if (rc) {
  11061. + bcm2708_dma_free(od);
  11062. + return rc;
  11063. + }
  11064. + }
  11065. +
  11066. + rc = dma_async_device_register(&od->ddev);
  11067. + if (rc) {
  11068. + dev_err(&pdev->dev,
  11069. + "Failed to register slave DMA engine device: %d\n", rc);
  11070. + bcm2708_dma_free(od);
  11071. + return rc;
  11072. + }
  11073. +
  11074. + dev_dbg(&pdev->dev, "Load BCM2708 DMA engine driver\n");
  11075. +
  11076. + return rc;
  11077. +}
  11078. +
  11079. +static int bcm2708_dma_remove(struct platform_device *pdev)
  11080. +{
  11081. + struct bcm2708_dmadev *od = platform_get_drvdata(pdev);
  11082. +
  11083. + dma_async_device_unregister(&od->ddev);
  11084. + bcm2708_dma_free(od);
  11085. +
  11086. + return 0;
  11087. +}
  11088. +
  11089. +static struct platform_driver bcm2708_dma_driver = {
  11090. + .probe = bcm2708_dma_probe,
  11091. + .remove = bcm2708_dma_remove,
  11092. + .driver = {
  11093. + .name = "bcm2708-dmaengine",
  11094. + .owner = THIS_MODULE,
  11095. + },
  11096. +};
  11097. +
  11098. +static struct platform_device *pdev;
  11099. +
  11100. +static const struct platform_device_info bcm2708_dma_dev_info = {
  11101. + .name = "bcm2708-dmaengine",
  11102. + .id = -1,
  11103. +};
  11104. +
  11105. +static int bcm2708_dma_init(void)
  11106. +{
  11107. + int rc = platform_driver_register(&bcm2708_dma_driver);
  11108. +
  11109. + if (rc == 0) {
  11110. + pdev = platform_device_register_full(&bcm2708_dma_dev_info);
  11111. + if (IS_ERR(pdev)) {
  11112. + platform_driver_unregister(&bcm2708_dma_driver);
  11113. + rc = PTR_ERR(pdev);
  11114. + }
  11115. + }
  11116. +
  11117. + return rc;
  11118. +}
  11119. +subsys_initcall(bcm2708_dma_init);
  11120. +
  11121. +static void __exit bcm2708_dma_exit(void)
  11122. +{
  11123. + platform_device_unregister(pdev);
  11124. + platform_driver_unregister(&bcm2708_dma_driver);
  11125. +}
  11126. +module_exit(bcm2708_dma_exit);
  11127. +
  11128. +MODULE_ALIAS("platform:bcm2708-dma");
  11129. +MODULE_DESCRIPTION("BCM2708 DMA engine driver");
  11130. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  11131. +MODULE_LICENSE("GPL v2");
  11132. diff -Nur linux-3.12.11.orig/drivers/dma/Kconfig linux-3.12.11/drivers/dma/Kconfig
  11133. --- linux-3.12.11.orig/drivers/dma/Kconfig 2014-02-13 22:51:06.000000000 +0100
  11134. +++ linux-3.12.11/drivers/dma/Kconfig 2014-02-18 11:52:14.000000000 +0100
  11135. @@ -288,6 +288,12 @@
  11136. select DMA_ENGINE
  11137. select DMA_VIRTUAL_CHANNELS
  11138. +config DMA_BCM2708
  11139. + tristate "BCM2708 DMA engine support"
  11140. + depends on MACH_BCM2708
  11141. + select DMA_ENGINE
  11142. + select DMA_VIRTUAL_CHANNELS
  11143. +
  11144. config TI_CPPI41
  11145. tristate "AM33xx CPPI41 DMA support"
  11146. depends on ARCH_OMAP
  11147. diff -Nur linux-3.12.11.orig/drivers/dma/Makefile linux-3.12.11/drivers/dma/Makefile
  11148. --- linux-3.12.11.orig/drivers/dma/Makefile 2014-02-13 22:51:06.000000000 +0100
  11149. +++ linux-3.12.11/drivers/dma/Makefile 2014-02-18 11:52:14.000000000 +0100
  11150. @@ -37,6 +37,7 @@
  11151. obj-$(CONFIG_DMA_SA11X0) += sa11x0-dma.o
  11152. obj-$(CONFIG_MMP_TDMA) += mmp_tdma.o
  11153. obj-$(CONFIG_DMA_OMAP) += omap-dma.o
  11154. +obj-$(CONFIG_DMA_BCM2708) += bcm2708-dmaengine.o
  11155. obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o
  11156. obj-$(CONFIG_DMA_JZ4740) += dma-jz4740.o
  11157. obj-$(CONFIG_TI_CPPI41) += cppi41.o
  11158. diff -Nur linux-3.12.11.orig/drivers/hwmon/bcm2835-hwmon.c linux-3.12.11/drivers/hwmon/bcm2835-hwmon.c
  11159. --- linux-3.12.11.orig/drivers/hwmon/bcm2835-hwmon.c 1970-01-01 01:00:00.000000000 +0100
  11160. +++ linux-3.12.11/drivers/hwmon/bcm2835-hwmon.c 2014-02-18 11:52:14.000000000 +0100
  11161. @@ -0,0 +1,219 @@
  11162. +/*****************************************************************************
  11163. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  11164. +*
  11165. +* Unless you and Broadcom execute a separate written software license
  11166. +* agreement governing use of this software, this software is licensed to you
  11167. +* under the terms of the GNU General Public License version 2, available at
  11168. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  11169. +*
  11170. +* Notwithstanding the above, under no circumstances may you combine this
  11171. +* software in any way with any other Broadcom software provided under a
  11172. +* license other than the GPL, without Broadcom's express prior written
  11173. +* consent.
  11174. +*****************************************************************************/
  11175. +
  11176. +#include <linux/kernel.h>
  11177. +#include <linux/module.h>
  11178. +#include <linux/init.h>
  11179. +#include <linux/hwmon.h>
  11180. +#include <linux/hwmon-sysfs.h>
  11181. +#include <linux/platform_device.h>
  11182. +#include <linux/sysfs.h>
  11183. +#include <mach/vcio.h>
  11184. +#include <linux/slab.h>
  11185. +#include <linux/err.h>
  11186. +
  11187. +#define MODULE_NAME "bcm2835_hwmon"
  11188. +
  11189. +/*#define HWMON_DEBUG_ENABLE*/
  11190. +
  11191. +#ifdef HWMON_DEBUG_ENABLE
  11192. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  11193. +#else
  11194. +#define print_debug(fmt,...)
  11195. +#endif
  11196. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  11197. +#define print_info(fmt,...) printk(KERN_INFO "%s: "fmt"\n", MODULE_NAME, ##__VA_ARGS__)
  11198. +
  11199. +#define VC_TAG_GET_TEMP 0x00030006
  11200. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  11201. +
  11202. +/* --- STRUCTS --- */
  11203. +struct bcm2835_hwmon_data {
  11204. + struct device *hwmon_dev;
  11205. +};
  11206. +
  11207. +/* tag part of the message */
  11208. +struct vc_msg_tag {
  11209. + uint32_t tag_id; /* the tag ID for the temperature */
  11210. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  11211. + uint32_t request_code; /* identifies message as a request (should be 0) */
  11212. + uint32_t id; /* extra ID field (should be 0) */
  11213. + uint32_t val; /* returned value of the temperature */
  11214. +};
  11215. +
  11216. +/* message structure to be sent to videocore */
  11217. +struct vc_msg {
  11218. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  11219. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  11220. + struct vc_msg_tag tag; /* the tag structure above to make */
  11221. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  11222. +};
  11223. +
  11224. +typedef enum {
  11225. + TEMP,
  11226. + MAX_TEMP,
  11227. +} temp_type;
  11228. +
  11229. +/* --- PROTOTYPES --- */
  11230. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf);
  11231. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf);
  11232. +
  11233. +/* --- GLOBALS --- */
  11234. +
  11235. +static struct bcm2835_hwmon_data *bcm2835_data;
  11236. +static struct platform_driver bcm2835_hwmon_driver;
  11237. +
  11238. +static SENSOR_DEVICE_ATTR(name, S_IRUGO,bcm2835_get_name,NULL,0);
  11239. +static SENSOR_DEVICE_ATTR(temp1_input,S_IRUGO,bcm2835_get_temp,NULL,TEMP);
  11240. +static SENSOR_DEVICE_ATTR(temp1_max,S_IRUGO,bcm2835_get_temp,NULL,MAX_TEMP);
  11241. +
  11242. +static struct attribute* bcm2835_attributes[] = {
  11243. + &sensor_dev_attr_name.dev_attr.attr,
  11244. + &sensor_dev_attr_temp1_input.dev_attr.attr,
  11245. + &sensor_dev_attr_temp1_max.dev_attr.attr,
  11246. + NULL,
  11247. +};
  11248. +
  11249. +static struct attribute_group bcm2835_attr_group = {
  11250. + .attrs = bcm2835_attributes,
  11251. +};
  11252. +
  11253. +/* --- FUNCTIONS --- */
  11254. +
  11255. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf)
  11256. +{
  11257. + return sprintf(buf,"bcm2835_hwmon\n");
  11258. +}
  11259. +
  11260. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf)
  11261. +{
  11262. + struct vc_msg msg;
  11263. + int result;
  11264. + uint temp = 0;
  11265. + int index = ((struct sensor_device_attribute*)to_sensor_dev_attr(attr))->index;
  11266. +
  11267. + print_debug("IN");
  11268. +
  11269. + /* wipe all previous message data */
  11270. + memset(&msg, 0, sizeof msg);
  11271. +
  11272. + /* determine the message type */
  11273. + if(index == TEMP)
  11274. + msg.tag.tag_id = VC_TAG_GET_TEMP;
  11275. + else if (index == MAX_TEMP)
  11276. + msg.tag.tag_id = VC_TAG_GET_MAX_TEMP;
  11277. + else
  11278. + {
  11279. + print_debug("Unknown temperature message!");
  11280. + return -EINVAL;
  11281. + }
  11282. +
  11283. + msg.msg_size = sizeof msg;
  11284. + msg.tag.buffer_size = 8;
  11285. +
  11286. + /* send the message */
  11287. + result = bcm_mailbox_property(&msg, sizeof msg);
  11288. +
  11289. + /* check if it was all ok and return the rate in milli degrees C */
  11290. + if (result == 0 && (msg.request_code & 0x80000000))
  11291. + temp = (uint)msg.tag.val;
  11292. + #ifdef HWMON_DEBUG_ENABLE
  11293. + else
  11294. + print_debug("Failed to get temperature!");
  11295. + #endif
  11296. + print_debug("Got temperature as %u",temp);
  11297. + print_debug("OUT");
  11298. + return sprintf(buf, "%u\n", temp);
  11299. +}
  11300. +
  11301. +
  11302. +static int bcm2835_hwmon_probe(struct platform_device *pdev)
  11303. +{
  11304. + int err;
  11305. +
  11306. + print_debug("IN");
  11307. + print_debug("HWMON Driver has been probed!");
  11308. +
  11309. + /* check that the device isn't null!*/
  11310. + if(pdev == NULL)
  11311. + {
  11312. + print_debug("Platform device is empty!");
  11313. + return -ENODEV;
  11314. + }
  11315. +
  11316. + /* allocate memory for neccessary data */
  11317. + bcm2835_data = kzalloc(sizeof(struct bcm2835_hwmon_data),GFP_KERNEL);
  11318. + if(!bcm2835_data)
  11319. + {
  11320. + print_debug("Unable to allocate memory for hwmon data!");
  11321. + err = -ENOMEM;
  11322. + goto kzalloc_error;
  11323. + }
  11324. +
  11325. + /* create the sysfs files */
  11326. + if(sysfs_create_group(&pdev->dev.kobj, &bcm2835_attr_group))
  11327. + {
  11328. + print_debug("Unable to create sysfs files!");
  11329. + err = -EFAULT;
  11330. + goto sysfs_error;
  11331. + }
  11332. +
  11333. + /* register the hwmon device */
  11334. + bcm2835_data->hwmon_dev = hwmon_device_register(&pdev->dev);
  11335. + if (IS_ERR(bcm2835_data->hwmon_dev))
  11336. + {
  11337. + err = PTR_ERR(bcm2835_data->hwmon_dev);
  11338. + goto hwmon_error;
  11339. + }
  11340. + print_debug("OUT");
  11341. + return 0;
  11342. +
  11343. + /* error goto's */
  11344. + hwmon_error:
  11345. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  11346. +
  11347. + sysfs_error:
  11348. + kfree(bcm2835_data);
  11349. +
  11350. + kzalloc_error:
  11351. +
  11352. + return err;
  11353. +
  11354. +}
  11355. +
  11356. +static int bcm2835_hwmon_remove(struct platform_device *pdev)
  11357. +{
  11358. + print_debug("IN");
  11359. + hwmon_device_unregister(bcm2835_data->hwmon_dev);
  11360. +
  11361. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  11362. + print_debug("OUT");
  11363. + return 0;
  11364. +}
  11365. +
  11366. +/* Hwmon Driver */
  11367. +static struct platform_driver bcm2835_hwmon_driver = {
  11368. + .probe = bcm2835_hwmon_probe,
  11369. + .remove = bcm2835_hwmon_remove,
  11370. + .driver = {
  11371. + .name = "bcm2835_hwmon",
  11372. + .owner = THIS_MODULE,
  11373. + },
  11374. +};
  11375. +
  11376. +MODULE_LICENSE("GPL");
  11377. +MODULE_AUTHOR("Dorian Peake");
  11378. +MODULE_DESCRIPTION("HW Monitor driver for bcm2835 chip");
  11379. +
  11380. +module_platform_driver(bcm2835_hwmon_driver);
  11381. diff -Nur linux-3.12.11.orig/drivers/hwmon/Kconfig linux-3.12.11/drivers/hwmon/Kconfig
  11382. --- linux-3.12.11.orig/drivers/hwmon/Kconfig 2014-02-13 22:51:06.000000000 +0100
  11383. +++ linux-3.12.11/drivers/hwmon/Kconfig 2014-02-18 11:52:14.000000000 +0100
  11384. @@ -1553,6 +1553,16 @@
  11385. help
  11386. Support for the A/D converter on MC13783 and MC13892 PMIC.
  11387. +config SENSORS_BCM2835
  11388. + depends on THERMAL_BCM2835=n
  11389. + tristate "Broadcom BCM2835 HWMON Driver"
  11390. + help
  11391. + If you say yes here you get support for the hardware
  11392. + monitoring features of the BCM2835 Chip
  11393. +
  11394. + This driver can also be built as a module. If so, the module
  11395. + will be called bcm2835-hwmon.
  11396. +
  11397. if ACPI
  11398. comment "ACPI drivers"
  11399. diff -Nur linux-3.12.11.orig/drivers/hwmon/Makefile linux-3.12.11/drivers/hwmon/Makefile
  11400. --- linux-3.12.11.orig/drivers/hwmon/Makefile 2014-02-13 22:51:06.000000000 +0100
  11401. +++ linux-3.12.11/drivers/hwmon/Makefile 2014-02-18 11:52:14.000000000 +0100
  11402. @@ -142,6 +142,7 @@
  11403. obj-$(CONFIG_SENSORS_W83L786NG) += w83l786ng.o
  11404. obj-$(CONFIG_SENSORS_WM831X) += wm831x-hwmon.o
  11405. obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o
  11406. +obj-$(CONFIG_SENSORS_BCM2835) += bcm2835-hwmon.o
  11407. obj-$(CONFIG_PMBUS) += pmbus/
  11408. diff -Nur linux-3.12.11.orig/drivers/i2c/busses/i2c-bcm2708.c linux-3.12.11/drivers/i2c/busses/i2c-bcm2708.c
  11409. --- linux-3.12.11.orig/drivers/i2c/busses/i2c-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  11410. +++ linux-3.12.11/drivers/i2c/busses/i2c-bcm2708.c 2014-02-18 11:52:14.000000000 +0100
  11411. @@ -0,0 +1,408 @@
  11412. +/*
  11413. + * Driver for Broadcom BCM2708 BSC Controllers
  11414. + *
  11415. + * Copyright (C) 2012 Chris Boot & Frank Buss
  11416. + *
  11417. + * This driver is inspired by:
  11418. + * i2c-ocores.c, by Peter Korsgaard <jacmet@sunsite.dk>
  11419. + *
  11420. + * This program is free software; you can redistribute it and/or modify
  11421. + * it under the terms of the GNU General Public License as published by
  11422. + * the Free Software Foundation; either version 2 of the License, or
  11423. + * (at your option) any later version.
  11424. + *
  11425. + * This program is distributed in the hope that it will be useful,
  11426. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11427. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11428. + * GNU General Public License for more details.
  11429. + *
  11430. + * You should have received a copy of the GNU General Public License
  11431. + * along with this program; if not, write to the Free Software
  11432. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  11433. + */
  11434. +
  11435. +#include <linux/kernel.h>
  11436. +#include <linux/module.h>
  11437. +#include <linux/spinlock.h>
  11438. +#include <linux/clk.h>
  11439. +#include <linux/err.h>
  11440. +#include <linux/platform_device.h>
  11441. +#include <linux/io.h>
  11442. +#include <linux/slab.h>
  11443. +#include <linux/i2c.h>
  11444. +#include <linux/interrupt.h>
  11445. +#include <linux/sched.h>
  11446. +#include <linux/wait.h>
  11447. +
  11448. +/* BSC register offsets */
  11449. +#define BSC_C 0x00
  11450. +#define BSC_S 0x04
  11451. +#define BSC_DLEN 0x08
  11452. +#define BSC_A 0x0c
  11453. +#define BSC_FIFO 0x10
  11454. +#define BSC_DIV 0x14
  11455. +#define BSC_DEL 0x18
  11456. +#define BSC_CLKT 0x1c
  11457. +
  11458. +/* Bitfields in BSC_C */
  11459. +#define BSC_C_I2CEN 0x00008000
  11460. +#define BSC_C_INTR 0x00000400
  11461. +#define BSC_C_INTT 0x00000200
  11462. +#define BSC_C_INTD 0x00000100
  11463. +#define BSC_C_ST 0x00000080
  11464. +#define BSC_C_CLEAR_1 0x00000020
  11465. +#define BSC_C_CLEAR_2 0x00000010
  11466. +#define BSC_C_READ 0x00000001
  11467. +
  11468. +/* Bitfields in BSC_S */
  11469. +#define BSC_S_CLKT 0x00000200
  11470. +#define BSC_S_ERR 0x00000100
  11471. +#define BSC_S_RXF 0x00000080
  11472. +#define BSC_S_TXE 0x00000040
  11473. +#define BSC_S_RXD 0x00000020
  11474. +#define BSC_S_TXD 0x00000010
  11475. +#define BSC_S_RXR 0x00000008
  11476. +#define BSC_S_TXW 0x00000004
  11477. +#define BSC_S_DONE 0x00000002
  11478. +#define BSC_S_TA 0x00000001
  11479. +
  11480. +#define I2C_TIMEOUT_MS 150
  11481. +
  11482. +#define DRV_NAME "bcm2708_i2c"
  11483. +
  11484. +static unsigned int baudrate = CONFIG_I2C_BCM2708_BAUDRATE;
  11485. +module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  11486. +MODULE_PARM_DESC(baudrate, "The I2C baudrate");
  11487. +
  11488. +
  11489. +struct bcm2708_i2c {
  11490. + struct i2c_adapter adapter;
  11491. +
  11492. + spinlock_t lock;
  11493. + void __iomem *base;
  11494. + int irq;
  11495. + struct clk *clk;
  11496. +
  11497. + struct completion done;
  11498. +
  11499. + struct i2c_msg *msg;
  11500. + int pos;
  11501. + int nmsgs;
  11502. + bool error;
  11503. +};
  11504. +
  11505. +/*
  11506. + * This function sets the ALT mode on the I2C pins so that we can use them with
  11507. + * the BSC hardware.
  11508. + *
  11509. + * FIXME: This is a hack. Use pinmux / pinctrl.
  11510. + */
  11511. +static void bcm2708_i2c_init_pinmode(int id)
  11512. +{
  11513. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  11514. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  11515. +
  11516. + int pin;
  11517. + u32 *gpio = ioremap(0x20200000, SZ_16K);
  11518. +
  11519. + BUG_ON(id != 0 && id != 1);
  11520. + /* BSC0 is on GPIO 0 & 1, BSC1 is on GPIO 2 & 3 */
  11521. + for (pin = id*2+0; pin <= id*2+1; pin++) {
  11522. +printk("bcm2708_i2c_init_pinmode(%d,%d)\n", id, pin);
  11523. + INP_GPIO(pin); /* set mode to GPIO input first */
  11524. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  11525. + }
  11526. +
  11527. + iounmap(gpio);
  11528. +
  11529. +#undef INP_GPIO
  11530. +#undef SET_GPIO_ALT
  11531. +}
  11532. +
  11533. +static inline u32 bcm2708_rd(struct bcm2708_i2c *bi, unsigned reg)
  11534. +{
  11535. + return readl(bi->base + reg);
  11536. +}
  11537. +
  11538. +static inline void bcm2708_wr(struct bcm2708_i2c *bi, unsigned reg, u32 val)
  11539. +{
  11540. + writel(val, bi->base + reg);
  11541. +}
  11542. +
  11543. +static inline void bcm2708_bsc_reset(struct bcm2708_i2c *bi)
  11544. +{
  11545. + bcm2708_wr(bi, BSC_C, 0);
  11546. + bcm2708_wr(bi, BSC_S, BSC_S_CLKT | BSC_S_ERR | BSC_S_DONE);
  11547. +}
  11548. +
  11549. +static inline void bcm2708_bsc_fifo_drain(struct bcm2708_i2c *bi)
  11550. +{
  11551. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_RXD) && (bi->pos < bi->msg->len))
  11552. + bi->msg->buf[bi->pos++] = bcm2708_rd(bi, BSC_FIFO);
  11553. +}
  11554. +
  11555. +static inline void bcm2708_bsc_fifo_fill(struct bcm2708_i2c *bi)
  11556. +{
  11557. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_TXD) && (bi->pos < bi->msg->len))
  11558. + bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
  11559. +}
  11560. +
  11561. +static inline void bcm2708_bsc_setup(struct bcm2708_i2c *bi)
  11562. +{
  11563. + unsigned long bus_hz;
  11564. + u32 cdiv;
  11565. + u32 c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_ST | BSC_C_CLEAR_1;
  11566. +
  11567. + bus_hz = clk_get_rate(bi->clk);
  11568. + cdiv = bus_hz / baudrate;
  11569. +
  11570. + if (bi->msg->flags & I2C_M_RD)
  11571. + c |= BSC_C_INTR | BSC_C_READ;
  11572. + else
  11573. + c |= BSC_C_INTT;
  11574. +
  11575. + bcm2708_wr(bi, BSC_DIV, cdiv);
  11576. + bcm2708_wr(bi, BSC_A, bi->msg->addr);
  11577. + bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
  11578. + bcm2708_wr(bi, BSC_C, c);
  11579. +}
  11580. +
  11581. +static irqreturn_t bcm2708_i2c_interrupt(int irq, void *dev_id)
  11582. +{
  11583. + struct bcm2708_i2c *bi = dev_id;
  11584. + bool handled = true;
  11585. + u32 s;
  11586. +
  11587. + spin_lock(&bi->lock);
  11588. +
  11589. + /* we may see camera interrupts on the "other" I2C channel
  11590. + Just return if we've not sent anything */
  11591. + if (!bi->nmsgs || !bi->msg )
  11592. + goto early_exit;
  11593. +
  11594. + s = bcm2708_rd(bi, BSC_S);
  11595. +
  11596. + if (s & (BSC_S_CLKT | BSC_S_ERR)) {
  11597. + bcm2708_bsc_reset(bi);
  11598. + bi->error = true;
  11599. +
  11600. + /* wake up our bh */
  11601. + complete(&bi->done);
  11602. + } else if (s & BSC_S_DONE) {
  11603. + bi->nmsgs--;
  11604. +
  11605. + if (bi->msg->flags & I2C_M_RD)
  11606. + bcm2708_bsc_fifo_drain(bi);
  11607. +
  11608. + bcm2708_bsc_reset(bi);
  11609. +
  11610. + if (bi->nmsgs) {
  11611. + /* advance to next message */
  11612. + bi->msg++;
  11613. + bi->pos = 0;
  11614. + bcm2708_bsc_setup(bi);
  11615. + } else {
  11616. + /* wake up our bh */
  11617. + complete(&bi->done);
  11618. + }
  11619. + } else if (s & BSC_S_TXW) {
  11620. + bcm2708_bsc_fifo_fill(bi);
  11621. + } else if (s & BSC_S_RXR) {
  11622. + bcm2708_bsc_fifo_drain(bi);
  11623. + } else {
  11624. + handled = false;
  11625. + }
  11626. +
  11627. +early_exit:
  11628. + spin_unlock(&bi->lock);
  11629. +
  11630. + return handled ? IRQ_HANDLED : IRQ_NONE;
  11631. +}
  11632. +
  11633. +static int bcm2708_i2c_master_xfer(struct i2c_adapter *adap,
  11634. + struct i2c_msg *msgs, int num)
  11635. +{
  11636. + struct bcm2708_i2c *bi = adap->algo_data;
  11637. + unsigned long flags;
  11638. + int ret;
  11639. +
  11640. + spin_lock_irqsave(&bi->lock, flags);
  11641. +
  11642. + INIT_COMPLETION(bi->done);
  11643. + bi->msg = msgs;
  11644. + bi->pos = 0;
  11645. + bi->nmsgs = num;
  11646. + bi->error = false;
  11647. +
  11648. + spin_unlock_irqrestore(&bi->lock, flags);
  11649. +
  11650. + bcm2708_bsc_setup(bi);
  11651. +
  11652. + ret = wait_for_completion_timeout(&bi->done,
  11653. + msecs_to_jiffies(I2C_TIMEOUT_MS));
  11654. + if (ret == 0) {
  11655. + dev_err(&adap->dev, "transfer timed out\n");
  11656. + spin_lock_irqsave(&bi->lock, flags);
  11657. + bcm2708_bsc_reset(bi);
  11658. + spin_unlock_irqrestore(&bi->lock, flags);
  11659. + return -ETIMEDOUT;
  11660. + }
  11661. +
  11662. + return bi->error ? -EIO : num;
  11663. +}
  11664. +
  11665. +static u32 bcm2708_i2c_functionality(struct i2c_adapter *adap)
  11666. +{
  11667. + return I2C_FUNC_I2C | /*I2C_FUNC_10BIT_ADDR |*/ I2C_FUNC_SMBUS_EMUL;
  11668. +}
  11669. +
  11670. +static struct i2c_algorithm bcm2708_i2c_algorithm = {
  11671. + .master_xfer = bcm2708_i2c_master_xfer,
  11672. + .functionality = bcm2708_i2c_functionality,
  11673. +};
  11674. +
  11675. +static int bcm2708_i2c_probe(struct platform_device *pdev)
  11676. +{
  11677. + struct resource *regs;
  11678. + int irq, err = -ENOMEM;
  11679. + struct clk *clk;
  11680. + struct bcm2708_i2c *bi;
  11681. + struct i2c_adapter *adap;
  11682. +
  11683. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  11684. + if (!regs) {
  11685. + dev_err(&pdev->dev, "could not get IO memory\n");
  11686. + return -ENXIO;
  11687. + }
  11688. +
  11689. + irq = platform_get_irq(pdev, 0);
  11690. + if (irq < 0) {
  11691. + dev_err(&pdev->dev, "could not get IRQ\n");
  11692. + return irq;
  11693. + }
  11694. +
  11695. + clk = clk_get(&pdev->dev, NULL);
  11696. + if (IS_ERR(clk)) {
  11697. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  11698. + return PTR_ERR(clk);
  11699. + }
  11700. +
  11701. + bcm2708_i2c_init_pinmode(pdev->id);
  11702. +
  11703. + bi = kzalloc(sizeof(*bi), GFP_KERNEL);
  11704. + if (!bi)
  11705. + goto out_clk_put;
  11706. +
  11707. + platform_set_drvdata(pdev, bi);
  11708. +
  11709. + adap = &bi->adapter;
  11710. + adap->class = I2C_CLASS_HWMON | I2C_CLASS_DDC;
  11711. + adap->algo = &bcm2708_i2c_algorithm;
  11712. + adap->algo_data = bi;
  11713. + adap->dev.parent = &pdev->dev;
  11714. + adap->nr = pdev->id;
  11715. + strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
  11716. +
  11717. + switch (pdev->id) {
  11718. + case 0:
  11719. + adap->class = I2C_CLASS_HWMON;
  11720. + break;
  11721. + case 1:
  11722. + adap->class = I2C_CLASS_DDC;
  11723. + break;
  11724. + default:
  11725. + dev_err(&pdev->dev, "can only bind to BSC 0 or 1\n");
  11726. + err = -ENXIO;
  11727. + goto out_free_bi;
  11728. + }
  11729. +
  11730. + spin_lock_init(&bi->lock);
  11731. + init_completion(&bi->done);
  11732. +
  11733. + bi->base = ioremap(regs->start, resource_size(regs));
  11734. + if (!bi->base) {
  11735. + dev_err(&pdev->dev, "could not remap memory\n");
  11736. + goto out_free_bi;
  11737. + }
  11738. +
  11739. + bi->irq = irq;
  11740. + bi->clk = clk;
  11741. +
  11742. + err = request_irq(irq, bcm2708_i2c_interrupt, IRQF_SHARED,
  11743. + dev_name(&pdev->dev), bi);
  11744. + if (err) {
  11745. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  11746. + goto out_iounmap;
  11747. + }
  11748. +
  11749. + bcm2708_bsc_reset(bi);
  11750. +
  11751. + err = i2c_add_numbered_adapter(adap);
  11752. + if (err < 0) {
  11753. + dev_err(&pdev->dev, "could not add I2C adapter: %d\n", err);
  11754. + goto out_free_irq;
  11755. + }
  11756. +
  11757. + dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %dk)\n",
  11758. + pdev->id, (unsigned long)regs->start, irq, baudrate/1000);
  11759. +
  11760. + return 0;
  11761. +
  11762. +out_free_irq:
  11763. + free_irq(bi->irq, bi);
  11764. +out_iounmap:
  11765. + iounmap(bi->base);
  11766. +out_free_bi:
  11767. + kfree(bi);
  11768. +out_clk_put:
  11769. + clk_put(clk);
  11770. + return err;
  11771. +}
  11772. +
  11773. +static int bcm2708_i2c_remove(struct platform_device *pdev)
  11774. +{
  11775. + struct bcm2708_i2c *bi = platform_get_drvdata(pdev);
  11776. +
  11777. + platform_set_drvdata(pdev, NULL);
  11778. +
  11779. + i2c_del_adapter(&bi->adapter);
  11780. + free_irq(bi->irq, bi);
  11781. + iounmap(bi->base);
  11782. + clk_disable(bi->clk);
  11783. + clk_put(bi->clk);
  11784. + kfree(bi);
  11785. +
  11786. + return 0;
  11787. +}
  11788. +
  11789. +static struct platform_driver bcm2708_i2c_driver = {
  11790. + .driver = {
  11791. + .name = DRV_NAME,
  11792. + .owner = THIS_MODULE,
  11793. + },
  11794. + .probe = bcm2708_i2c_probe,
  11795. + .remove = bcm2708_i2c_remove,
  11796. +};
  11797. +
  11798. +// module_platform_driver(bcm2708_i2c_driver);
  11799. +
  11800. +
  11801. +static int __init bcm2708_i2c_init(void)
  11802. +{
  11803. + return platform_driver_register(&bcm2708_i2c_driver);
  11804. +}
  11805. +
  11806. +static void __exit bcm2708_i2c_exit(void)
  11807. +{
  11808. + platform_driver_unregister(&bcm2708_i2c_driver);
  11809. +}
  11810. +
  11811. +module_init(bcm2708_i2c_init);
  11812. +module_exit(bcm2708_i2c_exit);
  11813. +
  11814. +
  11815. +
  11816. +MODULE_DESCRIPTION("BSC controller driver for Broadcom BCM2708");
  11817. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  11818. +MODULE_LICENSE("GPL v2");
  11819. +MODULE_ALIAS("platform:" DRV_NAME);
  11820. diff -Nur linux-3.12.11.orig/drivers/i2c/busses/Kconfig linux-3.12.11/drivers/i2c/busses/Kconfig
  11821. --- linux-3.12.11.orig/drivers/i2c/busses/Kconfig 2014-02-13 22:51:06.000000000 +0100
  11822. +++ linux-3.12.11/drivers/i2c/busses/Kconfig 2014-02-18 11:52:14.000000000 +0100
  11823. @@ -346,6 +346,25 @@
  11824. This support is also available as a module. If so, the module
  11825. will be called i2c-bcm2835.
  11826. +config I2C_BCM2708
  11827. + tristate "BCM2708 BSC"
  11828. + depends on MACH_BCM2708
  11829. + help
  11830. + Enabling this option will add BSC (Broadcom Serial Controller)
  11831. + support for the BCM2708. BSC is a Broadcom proprietary bus compatible
  11832. + with I2C/TWI/SMBus.
  11833. +
  11834. +config I2C_BCM2708_BAUDRATE
  11835. + prompt "BCM2708 I2C baudrate"
  11836. + depends on I2C_BCM2708
  11837. + int
  11838. + default 100000
  11839. + help
  11840. + Set the I2C baudrate. This will alter the default value. A
  11841. + different baudrate can be set by using a module parameter as well. If
  11842. + no parameter is provided when loading, this is the value that will be
  11843. + used.
  11844. +
  11845. config I2C_BLACKFIN_TWI
  11846. tristate "Blackfin TWI I2C support"
  11847. depends on BLACKFIN
  11848. diff -Nur linux-3.12.11.orig/drivers/i2c/busses/Makefile linux-3.12.11/drivers/i2c/busses/Makefile
  11849. --- linux-3.12.11.orig/drivers/i2c/busses/Makefile 2014-02-13 22:51:06.000000000 +0100
  11850. +++ linux-3.12.11/drivers/i2c/busses/Makefile 2014-02-18 11:52:14.000000000 +0100
  11851. @@ -32,6 +32,7 @@
  11852. obj-$(CONFIG_I2C_AT91) += i2c-at91.o
  11853. obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
  11854. obj-$(CONFIG_I2C_BCM2835) += i2c-bcm2835.o
  11855. +obj-$(CONFIG_I2C_BCM2708) += i2c-bcm2708.o
  11856. obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
  11857. obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o
  11858. obj-$(CONFIG_I2C_CPM) += i2c-cpm.o
  11859. diff -Nur linux-3.12.11.orig/drivers/media/dvb-core/dvb-usb-ids.h linux-3.12.11/drivers/media/dvb-core/dvb-usb-ids.h
  11860. --- linux-3.12.11.orig/drivers/media/dvb-core/dvb-usb-ids.h 2014-02-13 22:51:06.000000000 +0100
  11861. +++ linux-3.12.11/drivers/media/dvb-core/dvb-usb-ids.h 2014-02-18 11:52:14.000000000 +0100
  11862. @@ -366,6 +366,7 @@
  11863. #define USB_PID_TERRATEC_DVBS2CI_V2 0x10ac
  11864. #define USB_PID_TECHNISAT_USB2_HDCI_V1 0x0001
  11865. #define USB_PID_TECHNISAT_USB2_HDCI_V2 0x0002
  11866. +#define USB_PID_TECHNISAT_USB2_CABLESTAR_HDCI 0x0003
  11867. #define USB_PID_TECHNISAT_AIRSTAR_TELESTICK_2 0x0004
  11868. #define USB_PID_TECHNISAT_USB2_DVB_S2 0x0500
  11869. #define USB_PID_CPYTO_REDI_PC50A 0xa803
  11870. diff -Nur linux-3.12.11.orig/drivers/media/platform/bcm2835/bcm2835-camera.c linux-3.12.11/drivers/media/platform/bcm2835/bcm2835-camera.c
  11871. --- linux-3.12.11.orig/drivers/media/platform/bcm2835/bcm2835-camera.c 1970-01-01 01:00:00.000000000 +0100
  11872. +++ linux-3.12.11/drivers/media/platform/bcm2835/bcm2835-camera.c 2014-02-18 11:52:14.000000000 +0100
  11873. @@ -0,0 +1,1622 @@
  11874. +/*
  11875. + * Broadcom BM2835 V4L2 driver
  11876. + *
  11877. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  11878. + *
  11879. + * This file is subject to the terms and conditions of the GNU General Public
  11880. + * License. See the file COPYING in the main directory of this archive
  11881. + * for more details.
  11882. + *
  11883. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  11884. + * Dave Stevenson <dsteve@broadcom.com>
  11885. + * Simon Mellor <simellor@broadcom.com>
  11886. + * Luke Diamand <luked@broadcom.com>
  11887. + */
  11888. +
  11889. +#include <linux/errno.h>
  11890. +#include <linux/kernel.h>
  11891. +#include <linux/module.h>
  11892. +#include <linux/slab.h>
  11893. +#include <media/videobuf2-vmalloc.h>
  11894. +#include <media/videobuf2-dma-contig.h>
  11895. +#include <media/v4l2-device.h>
  11896. +#include <media/v4l2-ioctl.h>
  11897. +#include <media/v4l2-ctrls.h>
  11898. +#include <media/v4l2-fh.h>
  11899. +#include <media/v4l2-event.h>
  11900. +#include <media/v4l2-common.h>
  11901. +#include <linux/delay.h>
  11902. +
  11903. +#include "mmal-common.h"
  11904. +#include "mmal-encodings.h"
  11905. +#include "mmal-vchiq.h"
  11906. +#include "mmal-msg.h"
  11907. +#include "mmal-parameters.h"
  11908. +#include "bcm2835-camera.h"
  11909. +
  11910. +#define BM2835_MMAL_VERSION "0.0.2"
  11911. +#define BM2835_MMAL_MODULE_NAME "bcm2835-v4l2"
  11912. +
  11913. +#define MAX_WIDTH 2592
  11914. +#define MAX_HEIGHT 1944
  11915. +#define MIN_BUFFER_SIZE (80*1024)
  11916. +
  11917. +#define MAX_VIDEO_MODE_WIDTH 1280
  11918. +#define MAX_VIDEO_MODE_HEIGHT 720
  11919. +
  11920. +MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
  11921. +MODULE_AUTHOR("Vincent Sanders");
  11922. +MODULE_LICENSE("GPL");
  11923. +MODULE_VERSION(BM2835_MMAL_VERSION);
  11924. +
  11925. +int bcm2835_v4l2_debug;
  11926. +module_param_named(debug, bcm2835_v4l2_debug, int, 0644);
  11927. +MODULE_PARM_DESC(bcm2835_v4l2_debug, "Debug level 0-2");
  11928. +
  11929. +static struct bm2835_mmal_dev *gdev; /* global device data */
  11930. +
  11931. +#define FPS_MIN 1
  11932. +#define FPS_MAX 30
  11933. +
  11934. +/* timeperframe: min/max and default */
  11935. +static const struct v4l2_fract
  11936. + tpf_min = {.numerator = 1, .denominator = FPS_MAX},
  11937. + tpf_max = {.numerator = 1, .denominator = FPS_MIN},
  11938. + tpf_default = {.numerator = 1000, .denominator = 30000};
  11939. +
  11940. +/* video formats */
  11941. +static struct mmal_fmt formats[] = {
  11942. + {
  11943. + .name = "4:2:0, packed YUV",
  11944. + .fourcc = V4L2_PIX_FMT_YUV420,
  11945. + .mmal = MMAL_ENCODING_I420,
  11946. + .depth = 12,
  11947. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11948. + },
  11949. + {
  11950. + .name = "4:2:2, packed, YUYV",
  11951. + .fourcc = V4L2_PIX_FMT_YUYV,
  11952. + .mmal = MMAL_ENCODING_YUYV,
  11953. + .depth = 16,
  11954. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11955. + },
  11956. + {
  11957. + .name = "RGB24 (BE)",
  11958. + .fourcc = V4L2_PIX_FMT_BGR24,
  11959. + .mmal = MMAL_ENCODING_BGR24,
  11960. + .depth = 24,
  11961. + .mmal_component = MMAL_COMPONENT_CAMERA,
  11962. + },
  11963. + {
  11964. + .name = "JPEG",
  11965. + .fourcc = V4L2_PIX_FMT_JPEG,
  11966. + .mmal = MMAL_ENCODING_JPEG,
  11967. + .depth = 8,
  11968. + .mmal_component = MMAL_COMPONENT_IMAGE_ENCODE,
  11969. + },
  11970. + {
  11971. + .name = "H264",
  11972. + .fourcc = V4L2_PIX_FMT_H264,
  11973. + .mmal = MMAL_ENCODING_H264,
  11974. + .depth = 8,
  11975. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  11976. + }
  11977. +};
  11978. +
  11979. +static struct mmal_fmt *get_format(struct v4l2_format *f)
  11980. +{
  11981. + struct mmal_fmt *fmt;
  11982. + unsigned int k;
  11983. +
  11984. + for (k = 0; k < ARRAY_SIZE(formats); k++) {
  11985. + fmt = &formats[k];
  11986. + if (fmt->fourcc == f->fmt.pix.pixelformat)
  11987. + break;
  11988. + }
  11989. +
  11990. + if (k == ARRAY_SIZE(formats))
  11991. + return NULL;
  11992. +
  11993. + return &formats[k];
  11994. +}
  11995. +
  11996. +/* ------------------------------------------------------------------
  11997. + Videobuf queue operations
  11998. + ------------------------------------------------------------------*/
  11999. +
  12000. +static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
  12001. + unsigned int *nbuffers, unsigned int *nplanes,
  12002. + unsigned int sizes[], void *alloc_ctxs[])
  12003. +{
  12004. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  12005. + unsigned long size;
  12006. +
  12007. + /* refuse queue setup if port is not configured */
  12008. + if (dev->capture.port == NULL) {
  12009. + v4l2_err(&dev->v4l2_dev,
  12010. + "%s: capture port not configured\n", __func__);
  12011. + return -EINVAL;
  12012. + }
  12013. +
  12014. + size = dev->capture.port->current_buffer.size;
  12015. + if (size == 0) {
  12016. + v4l2_err(&dev->v4l2_dev,
  12017. + "%s: capture port buffer size is zero\n", __func__);
  12018. + return -EINVAL;
  12019. + }
  12020. +
  12021. + if (*nbuffers < (dev->capture.port->current_buffer.num + 2))
  12022. + *nbuffers = (dev->capture.port->current_buffer.num + 2);
  12023. +
  12024. + *nplanes = 1;
  12025. +
  12026. + sizes[0] = size;
  12027. +
  12028. + /*
  12029. + * videobuf2-vmalloc allocator is context-less so no need to set
  12030. + * alloc_ctxs array.
  12031. + */
  12032. +
  12033. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  12034. + __func__, dev);
  12035. +
  12036. + return 0;
  12037. +}
  12038. +
  12039. +static int buffer_prepare(struct vb2_buffer *vb)
  12040. +{
  12041. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  12042. + unsigned long size;
  12043. +
  12044. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  12045. + __func__, dev);
  12046. +
  12047. + BUG_ON(dev->capture.port == NULL);
  12048. + BUG_ON(dev->capture.fmt == NULL);
  12049. +
  12050. + size = dev->capture.stride * dev->capture.height;
  12051. + if (vb2_plane_size(vb, 0) < size) {
  12052. + v4l2_err(&dev->v4l2_dev,
  12053. + "%s data will not fit into plane (%lu < %lu)\n",
  12054. + __func__, vb2_plane_size(vb, 0), size);
  12055. + return -EINVAL;
  12056. + }
  12057. +
  12058. + return 0;
  12059. +}
  12060. +
  12061. +static inline bool is_capturing(struct bm2835_mmal_dev *dev)
  12062. +{
  12063. + return dev->capture.camera_port ==
  12064. + &dev->
  12065. + component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
  12066. +}
  12067. +
  12068. +static void buffer_cb(struct vchiq_mmal_instance *instance,
  12069. + struct vchiq_mmal_port *port,
  12070. + int status,
  12071. + struct mmal_buffer *buf,
  12072. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts)
  12073. +{
  12074. + struct bm2835_mmal_dev *dev = port->cb_ctx;
  12075. +
  12076. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12077. + "%s: status:%d, buf:%p, length:%lu, flags %u, pts %lld\n",
  12078. + __func__, status, buf, length, mmal_flags, pts);
  12079. +
  12080. + if (status != 0) {
  12081. + /* error in transfer */
  12082. + if (buf != NULL) {
  12083. + /* there was a buffer with the error so return it */
  12084. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  12085. + }
  12086. + return;
  12087. + } else if (length == 0) {
  12088. + /* stream ended */
  12089. + if (buf != NULL) {
  12090. + /* this should only ever happen if the port is
  12091. + * disabled and there are buffers still queued
  12092. + */
  12093. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  12094. + pr_debug("Empty buffer");
  12095. + } else if (dev->capture.frame_count) {
  12096. + /* grab another frame */
  12097. + if (is_capturing(dev)) {
  12098. + pr_debug("Grab another frame");
  12099. + vchiq_mmal_port_parameter_set(
  12100. + instance,
  12101. + dev->capture.
  12102. + camera_port,
  12103. + MMAL_PARAMETER_CAPTURE,
  12104. + &dev->capture.
  12105. + frame_count,
  12106. + sizeof(dev->capture.frame_count));
  12107. + }
  12108. + } else {
  12109. + /* signal frame completion */
  12110. + complete(&dev->capture.frame_cmplt);
  12111. + }
  12112. + } else {
  12113. + if (dev->capture.frame_count) {
  12114. + if (dev->capture.vc_start_timestamp != -1 &&
  12115. + pts != 0) {
  12116. + s64 runtime_us = pts -
  12117. + dev->capture.vc_start_timestamp;
  12118. + u32 div = 0;
  12119. + u32 rem = 0;
  12120. +
  12121. + div =
  12122. + div_u64_rem(runtime_us, USEC_PER_SEC, &rem);
  12123. + buf->vb.v4l2_buf.timestamp.tv_sec =
  12124. + dev->capture.kernel_start_ts.tv_sec - 1 +
  12125. + div;
  12126. + buf->vb.v4l2_buf.timestamp.tv_usec =
  12127. + dev->capture.kernel_start_ts.tv_usec + rem;
  12128. +
  12129. + if (buf->vb.v4l2_buf.timestamp.tv_usec >=
  12130. + USEC_PER_SEC) {
  12131. + buf->vb.v4l2_buf.timestamp.tv_sec++;
  12132. + buf->vb.v4l2_buf.timestamp.tv_usec -=
  12133. + USEC_PER_SEC;
  12134. + }
  12135. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12136. + "Convert start time %d.%06d and %llu "
  12137. + "with offset %llu to %d.%06d\n",
  12138. + (int)dev->capture.kernel_start_ts.
  12139. + tv_sec,
  12140. + (int)dev->capture.kernel_start_ts.
  12141. + tv_usec,
  12142. + dev->capture.vc_start_timestamp, pts,
  12143. + (int)buf->vb.v4l2_buf.timestamp.tv_sec,
  12144. + (int)buf->vb.v4l2_buf.timestamp.
  12145. + tv_usec);
  12146. + } else {
  12147. + v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
  12148. + }
  12149. +
  12150. + vb2_set_plane_payload(&buf->vb, 0, length);
  12151. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
  12152. +
  12153. + if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
  12154. + is_capturing(dev)) {
  12155. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12156. + "Grab another frame as buffer has EOS");
  12157. + vchiq_mmal_port_parameter_set(
  12158. + instance,
  12159. + dev->capture.
  12160. + camera_port,
  12161. + MMAL_PARAMETER_CAPTURE,
  12162. + &dev->capture.
  12163. + frame_count,
  12164. + sizeof(dev->capture.frame_count));
  12165. + }
  12166. + } else {
  12167. + /* signal frame completion */
  12168. + complete(&dev->capture.frame_cmplt);
  12169. + }
  12170. + }
  12171. +}
  12172. +
  12173. +static int enable_camera(struct bm2835_mmal_dev *dev)
  12174. +{
  12175. + int ret;
  12176. + if (!dev->camera_use_count) {
  12177. + ret = vchiq_mmal_component_enable(
  12178. + dev->instance,
  12179. + dev->component[MMAL_COMPONENT_CAMERA]);
  12180. + if (ret < 0) {
  12181. + v4l2_err(&dev->v4l2_dev,
  12182. + "Failed enabling camera, ret %d\n", ret);
  12183. + return -EINVAL;
  12184. + }
  12185. + }
  12186. + dev->camera_use_count++;
  12187. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12188. + &dev->v4l2_dev, "enabled camera (refcount %d)\n",
  12189. + dev->camera_use_count);
  12190. + return 0;
  12191. +}
  12192. +
  12193. +static int disable_camera(struct bm2835_mmal_dev *dev)
  12194. +{
  12195. + int ret;
  12196. + if (!dev->camera_use_count) {
  12197. + v4l2_err(&dev->v4l2_dev,
  12198. + "Disabled the camera when already disabled\n");
  12199. + return -EINVAL;
  12200. + }
  12201. + dev->camera_use_count--;
  12202. + if (!dev->camera_use_count) {
  12203. + unsigned int i = 0xFFFFFFFF;
  12204. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12205. + "Disabling camera\n");
  12206. + ret =
  12207. + vchiq_mmal_component_disable(
  12208. + dev->instance,
  12209. + dev->component[MMAL_COMPONENT_CAMERA]);
  12210. + if (ret < 0) {
  12211. + v4l2_err(&dev->v4l2_dev,
  12212. + "Failed disabling camera, ret %d\n", ret);
  12213. + return -EINVAL;
  12214. + }
  12215. + vchiq_mmal_port_parameter_set(
  12216. + dev->instance,
  12217. + &dev->component[MMAL_COMPONENT_CAMERA]->control,
  12218. + MMAL_PARAMETER_CAMERA_NUM, &i,
  12219. + sizeof(i));
  12220. + }
  12221. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12222. + "Camera refcount now %d\n", dev->camera_use_count);
  12223. + return 0;
  12224. +}
  12225. +
  12226. +static void buffer_queue(struct vb2_buffer *vb)
  12227. +{
  12228. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  12229. + struct mmal_buffer *buf = container_of(vb, struct mmal_buffer, vb);
  12230. + int ret;
  12231. +
  12232. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12233. + "%s: dev:%p buf:%p\n", __func__, dev, buf);
  12234. +
  12235. + buf->buffer = vb2_plane_vaddr(&buf->vb, 0);
  12236. + buf->buffer_size = vb2_plane_size(&buf->vb, 0);
  12237. +
  12238. + ret = vchiq_mmal_submit_buffer(dev->instance, dev->capture.port, buf);
  12239. + if (ret < 0)
  12240. + v4l2_err(&dev->v4l2_dev, "%s: error submitting buffer\n",
  12241. + __func__);
  12242. +}
  12243. +
  12244. +static int start_streaming(struct vb2_queue *vq, unsigned int count)
  12245. +{
  12246. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  12247. + int ret;
  12248. + int parameter_size;
  12249. +
  12250. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  12251. + __func__, dev);
  12252. +
  12253. + /* ensure a format has actually been set */
  12254. + if (dev->capture.port == NULL)
  12255. + return -EINVAL;
  12256. +
  12257. + if (enable_camera(dev) < 0) {
  12258. + v4l2_err(&dev->v4l2_dev, "Failed to enable camera\n");
  12259. + return -EINVAL;
  12260. + }
  12261. +
  12262. + /*init_completion(&dev->capture.frame_cmplt); */
  12263. +
  12264. + /* enable frame capture */
  12265. + dev->capture.frame_count = 1;
  12266. +
  12267. + /* if the preview is not already running, wait for a few frames for AGC
  12268. + * to settle down.
  12269. + */
  12270. + if (!dev->component[MMAL_COMPONENT_PREVIEW]->enabled)
  12271. + msleep(300);
  12272. +
  12273. + /* enable the connection from camera to encoder (if applicable) */
  12274. + if (dev->capture.camera_port != dev->capture.port
  12275. + && dev->capture.camera_port) {
  12276. + ret = vchiq_mmal_port_enable(dev->instance,
  12277. + dev->capture.camera_port, NULL);
  12278. + if (ret) {
  12279. + v4l2_err(&dev->v4l2_dev,
  12280. + "Failed to enable encode tunnel - error %d\n",
  12281. + ret);
  12282. + return -1;
  12283. + }
  12284. + }
  12285. +
  12286. + /* Get VC timestamp at this point in time */
  12287. + parameter_size = sizeof(dev->capture.vc_start_timestamp);
  12288. + if (vchiq_mmal_port_parameter_get(dev->instance,
  12289. + dev->capture.camera_port,
  12290. + MMAL_PARAMETER_SYSTEM_TIME,
  12291. + &dev->capture.vc_start_timestamp,
  12292. + &parameter_size)) {
  12293. + v4l2_err(&dev->v4l2_dev,
  12294. + "Failed to get VC start time - update your VC f/w\n");
  12295. +
  12296. + /* Flag to indicate just to rely on kernel timestamps */
  12297. + dev->capture.vc_start_timestamp = -1;
  12298. + } else
  12299. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12300. + "Start time %lld size %d\n",
  12301. + dev->capture.vc_start_timestamp, parameter_size);
  12302. +
  12303. + v4l2_get_timestamp(&dev->capture.kernel_start_ts);
  12304. +
  12305. + /* enable the camera port */
  12306. + dev->capture.port->cb_ctx = dev;
  12307. + ret =
  12308. + vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb);
  12309. + if (ret) {
  12310. + v4l2_err(&dev->v4l2_dev,
  12311. + "Failed to enable capture port - error %d. "
  12312. + "Disabling camera port again\n", ret);
  12313. +
  12314. + vchiq_mmal_port_disable(dev->instance,
  12315. + dev->capture.camera_port);
  12316. + if (disable_camera(dev) < 0) {
  12317. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
  12318. + return -EINVAL;
  12319. + }
  12320. + return -1;
  12321. + }
  12322. +
  12323. + /* capture the first frame */
  12324. + vchiq_mmal_port_parameter_set(dev->instance,
  12325. + dev->capture.camera_port,
  12326. + MMAL_PARAMETER_CAPTURE,
  12327. + &dev->capture.frame_count,
  12328. + sizeof(dev->capture.frame_count));
  12329. + return 0;
  12330. +}
  12331. +
  12332. +/* abort streaming and wait for last buffer */
  12333. +static int stop_streaming(struct vb2_queue *vq)
  12334. +{
  12335. + int ret;
  12336. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  12337. +
  12338. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  12339. + __func__, dev);
  12340. +
  12341. + init_completion(&dev->capture.frame_cmplt);
  12342. + dev->capture.frame_count = 0;
  12343. +
  12344. + /* ensure a format has actually been set */
  12345. + if (dev->capture.port == NULL)
  12346. + return -EINVAL;
  12347. +
  12348. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "stopping capturing\n");
  12349. +
  12350. + /* stop capturing frames */
  12351. + vchiq_mmal_port_parameter_set(dev->instance,
  12352. + dev->capture.camera_port,
  12353. + MMAL_PARAMETER_CAPTURE,
  12354. + &dev->capture.frame_count,
  12355. + sizeof(dev->capture.frame_count));
  12356. +
  12357. + /* wait for last frame to complete */
  12358. + ret = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ);
  12359. + if (ret <= 0)
  12360. + v4l2_err(&dev->v4l2_dev,
  12361. + "error %d waiting for frame completion\n", ret);
  12362. +
  12363. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12364. + "disabling connection\n");
  12365. +
  12366. + /* disable the connection from camera to encoder */
  12367. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.camera_port);
  12368. + if (!ret && dev->capture.camera_port != dev->capture.port) {
  12369. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12370. + "disabling port\n");
  12371. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.port);
  12372. + } else if (dev->capture.camera_port != dev->capture.port) {
  12373. + v4l2_err(&dev->v4l2_dev, "port_disable failed, error %d\n",
  12374. + ret);
  12375. + }
  12376. +
  12377. + if (disable_camera(dev) < 0) {
  12378. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
  12379. + return -EINVAL;
  12380. + }
  12381. +
  12382. + return ret;
  12383. +}
  12384. +
  12385. +static void bm2835_mmal_lock(struct vb2_queue *vq)
  12386. +{
  12387. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  12388. + mutex_lock(&dev->mutex);
  12389. +}
  12390. +
  12391. +static void bm2835_mmal_unlock(struct vb2_queue *vq)
  12392. +{
  12393. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  12394. + mutex_unlock(&dev->mutex);
  12395. +}
  12396. +
  12397. +static struct vb2_ops bm2835_mmal_video_qops = {
  12398. + .queue_setup = queue_setup,
  12399. + .buf_prepare = buffer_prepare,
  12400. + .buf_queue = buffer_queue,
  12401. + .start_streaming = start_streaming,
  12402. + .stop_streaming = stop_streaming,
  12403. + .wait_prepare = bm2835_mmal_unlock,
  12404. + .wait_finish = bm2835_mmal_lock,
  12405. +};
  12406. +
  12407. +/* ------------------------------------------------------------------
  12408. + IOCTL operations
  12409. + ------------------------------------------------------------------*/
  12410. +
  12411. +/* overlay ioctl */
  12412. +static int vidioc_enum_fmt_vid_overlay(struct file *file, void *priv,
  12413. + struct v4l2_fmtdesc *f)
  12414. +{
  12415. + struct mmal_fmt *fmt;
  12416. +
  12417. + if (f->index >= ARRAY_SIZE(formats))
  12418. + return -EINVAL;
  12419. +
  12420. + fmt = &formats[f->index];
  12421. +
  12422. + strlcpy(f->description, fmt->name, sizeof(f->description));
  12423. + f->pixelformat = fmt->fourcc;
  12424. +
  12425. + return 0;
  12426. +}
  12427. +
  12428. +static int vidioc_g_fmt_vid_overlay(struct file *file, void *priv,
  12429. + struct v4l2_format *f)
  12430. +{
  12431. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12432. +
  12433. + f->fmt.win = dev->overlay;
  12434. +
  12435. + return 0;
  12436. +}
  12437. +
  12438. +static int vidioc_try_fmt_vid_overlay(struct file *file, void *priv,
  12439. + struct v4l2_format *f)
  12440. +{
  12441. + /* Only support one format so get the current one. */
  12442. + vidioc_g_fmt_vid_overlay(file, priv, f);
  12443. +
  12444. + /* todo: allow the size and/or offset to be changed. */
  12445. + return 0;
  12446. +}
  12447. +
  12448. +static int vidioc_s_fmt_vid_overlay(struct file *file, void *priv,
  12449. + struct v4l2_format *f)
  12450. +{
  12451. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12452. +
  12453. + vidioc_try_fmt_vid_overlay(file, priv, f);
  12454. +
  12455. + dev->overlay = f->fmt.win;
  12456. +
  12457. + /* todo: program the preview port parameters */
  12458. + return 0;
  12459. +}
  12460. +
  12461. +static int vidioc_overlay(struct file *file, void *f, unsigned int on)
  12462. +{
  12463. + int ret;
  12464. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12465. + struct vchiq_mmal_port *src;
  12466. + struct vchiq_mmal_port *dst;
  12467. + struct mmal_parameter_displayregion prev_config = {
  12468. + .set = MMAL_DISPLAY_SET_LAYER | MMAL_DISPLAY_SET_ALPHA |
  12469. + MMAL_DISPLAY_SET_DEST_RECT | MMAL_DISPLAY_SET_FULLSCREEN,
  12470. + .layer = PREVIEW_LAYER,
  12471. + .alpha = 255,
  12472. + .fullscreen = 0,
  12473. + .dest_rect = {
  12474. + .x = dev->overlay.w.left,
  12475. + .y = dev->overlay.w.top,
  12476. + .width = dev->overlay.w.width,
  12477. + .height = dev->overlay.w.height,
  12478. + },
  12479. + };
  12480. +
  12481. + if ((on && dev->component[MMAL_COMPONENT_PREVIEW]->enabled) ||
  12482. + (!on && !dev->component[MMAL_COMPONENT_PREVIEW]->enabled))
  12483. + return 0; /* already in requested state */
  12484. +
  12485. + src =
  12486. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12487. + output[MMAL_CAMERA_PORT_PREVIEW];
  12488. +
  12489. + if (!on) {
  12490. + /* disconnect preview ports and disable component */
  12491. + ret = vchiq_mmal_port_disable(dev->instance, src);
  12492. + if (!ret)
  12493. + ret =
  12494. + vchiq_mmal_port_connect_tunnel(dev->instance, src,
  12495. + NULL);
  12496. + if (ret >= 0)
  12497. + ret = vchiq_mmal_component_disable(
  12498. + dev->instance,
  12499. + dev->component[MMAL_COMPONENT_PREVIEW]);
  12500. +
  12501. + disable_camera(dev);
  12502. + return ret;
  12503. + }
  12504. +
  12505. + /* set preview port format and connect it to output */
  12506. + dst = &dev->component[MMAL_COMPONENT_PREVIEW]->input[0];
  12507. +
  12508. + ret = vchiq_mmal_port_set_format(dev->instance, src);
  12509. + if (ret < 0)
  12510. + goto error;
  12511. +
  12512. + ret = vchiq_mmal_port_parameter_set(dev->instance, dst,
  12513. + MMAL_PARAMETER_DISPLAYREGION,
  12514. + &prev_config, sizeof(prev_config));
  12515. + if (ret < 0)
  12516. + goto error;
  12517. +
  12518. + if (enable_camera(dev) < 0)
  12519. + goto error;
  12520. +
  12521. + ret = vchiq_mmal_component_enable(
  12522. + dev->instance,
  12523. + dev->component[MMAL_COMPONENT_PREVIEW]);
  12524. + if (ret < 0)
  12525. + goto error;
  12526. +
  12527. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "connecting %p to %p\n",
  12528. + src, dst);
  12529. + ret = vchiq_mmal_port_connect_tunnel(dev->instance, src, dst);
  12530. + if (!ret)
  12531. + ret = vchiq_mmal_port_enable(dev->instance, src, NULL);
  12532. +error:
  12533. + return ret;
  12534. +}
  12535. +
  12536. +static int vidioc_g_fbuf(struct file *file, void *fh,
  12537. + struct v4l2_framebuffer *a)
  12538. +{
  12539. + /* The video overlay must stay within the framebuffer and can't be
  12540. + positioned independently. */
  12541. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12542. + struct vchiq_mmal_port *preview_port =
  12543. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12544. + output[MMAL_CAMERA_PORT_PREVIEW];
  12545. + a->flags = V4L2_FBUF_FLAG_OVERLAY;
  12546. + a->fmt.width = preview_port->es.video.width;
  12547. + a->fmt.height = preview_port->es.video.height;
  12548. + a->fmt.pixelformat = V4L2_PIX_FMT_YUV420;
  12549. + a->fmt.bytesperline = (preview_port->es.video.width * 3)>>1;
  12550. + a->fmt.sizeimage = (preview_port->es.video.width *
  12551. + preview_port->es.video.height * 3)>>1;
  12552. + a->fmt.colorspace = V4L2_COLORSPACE_SMPTE170M;
  12553. +
  12554. + return 0;
  12555. +}
  12556. +
  12557. +/* input ioctls */
  12558. +static int vidioc_enum_input(struct file *file, void *priv,
  12559. + struct v4l2_input *inp)
  12560. +{
  12561. + /* only a single camera input */
  12562. + if (inp->index != 0)
  12563. + return -EINVAL;
  12564. +
  12565. + inp->type = V4L2_INPUT_TYPE_CAMERA;
  12566. + sprintf(inp->name, "Camera %u", inp->index);
  12567. + return 0;
  12568. +}
  12569. +
  12570. +static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  12571. +{
  12572. + *i = 0;
  12573. + return 0;
  12574. +}
  12575. +
  12576. +static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  12577. +{
  12578. + if (i != 0)
  12579. + return -EINVAL;
  12580. +
  12581. + return 0;
  12582. +}
  12583. +
  12584. +/* capture ioctls */
  12585. +static int vidioc_querycap(struct file *file, void *priv,
  12586. + struct v4l2_capability *cap)
  12587. +{
  12588. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12589. + u32 major;
  12590. + u32 minor;
  12591. +
  12592. + vchiq_mmal_version(dev->instance, &major, &minor);
  12593. +
  12594. + strcpy(cap->driver, "bm2835 mmal");
  12595. + snprintf(cap->card, sizeof(cap->card), "mmal service %d.%d",
  12596. + major, minor);
  12597. +
  12598. + snprintf(cap->bus_info, sizeof(cap->bus_info),
  12599. + "platform:%s", dev->v4l2_dev.name);
  12600. + cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY |
  12601. + V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
  12602. + cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
  12603. +
  12604. + return 0;
  12605. +}
  12606. +
  12607. +static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  12608. + struct v4l2_fmtdesc *f)
  12609. +{
  12610. + struct mmal_fmt *fmt;
  12611. +
  12612. + if (f->index >= ARRAY_SIZE(formats))
  12613. + return -EINVAL;
  12614. +
  12615. + fmt = &formats[f->index];
  12616. +
  12617. + strlcpy(f->description, fmt->name, sizeof(f->description));
  12618. + f->pixelformat = fmt->fourcc;
  12619. + return 0;
  12620. +}
  12621. +
  12622. +static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
  12623. + struct v4l2_format *f)
  12624. +{
  12625. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12626. +
  12627. + f->fmt.pix.width = dev->capture.width;
  12628. + f->fmt.pix.height = dev->capture.height;
  12629. + f->fmt.pix.field = V4L2_FIELD_NONE;
  12630. + f->fmt.pix.pixelformat = dev->capture.fmt->fourcc;
  12631. + f->fmt.pix.bytesperline =
  12632. + (f->fmt.pix.width * dev->capture.fmt->depth) >> 3;
  12633. + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
  12634. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_JPEG
  12635. + && f->fmt.pix.sizeimage < (100 << 10)) {
  12636. + /* Need a minimum size for JPEG to account for EXIF. */
  12637. + f->fmt.pix.sizeimage = (100 << 10);
  12638. + }
  12639. +
  12640. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_YUYV ||
  12641. + dev->capture.fmt->fourcc == V4L2_PIX_FMT_UYVY)
  12642. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  12643. + else
  12644. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  12645. + f->fmt.pix.priv = 0;
  12646. +
  12647. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  12648. + __func__);
  12649. + return 0;
  12650. +}
  12651. +
  12652. +static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
  12653. + struct v4l2_format *f)
  12654. +{
  12655. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12656. + struct mmal_fmt *mfmt;
  12657. +
  12658. + mfmt = get_format(f);
  12659. + if (!mfmt) {
  12660. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12661. + "Fourcc format (0x%08x) unknown.\n",
  12662. + f->fmt.pix.pixelformat);
  12663. + f->fmt.pix.pixelformat = formats[0].fourcc;
  12664. + mfmt = get_format(f);
  12665. + }
  12666. +
  12667. + f->fmt.pix.field = V4L2_FIELD_NONE;
  12668. + /* image must be a multiple of 32 pixels wide and 16 lines high */
  12669. + v4l_bound_align_image(&f->fmt.pix.width, 48, MAX_WIDTH, 5,
  12670. + &f->fmt.pix.height, 32, MAX_HEIGHT, 4, 0);
  12671. + f->fmt.pix.bytesperline = (f->fmt.pix.width * mfmt->depth) >> 3;
  12672. + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
  12673. + if (f->fmt.pix.sizeimage < MIN_BUFFER_SIZE)
  12674. + f->fmt.pix.sizeimage = MIN_BUFFER_SIZE;
  12675. +
  12676. + if (mfmt->fourcc == V4L2_PIX_FMT_YUYV ||
  12677. + mfmt->fourcc == V4L2_PIX_FMT_UYVY)
  12678. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  12679. + else
  12680. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  12681. + f->fmt.pix.priv = 0;
  12682. +
  12683. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  12684. + __func__);
  12685. + return 0;
  12686. +}
  12687. +
  12688. +static int mmal_setup_components(struct bm2835_mmal_dev *dev,
  12689. + struct v4l2_format *f)
  12690. +{
  12691. + int ret;
  12692. + struct vchiq_mmal_port *port = NULL, *camera_port = NULL;
  12693. + struct vchiq_mmal_component *encode_component = NULL;
  12694. + struct mmal_fmt *mfmt = get_format(f);
  12695. +
  12696. + BUG_ON(!mfmt);
  12697. +
  12698. + if (dev->capture.encode_component) {
  12699. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12700. + "vid_cap - disconnect previous tunnel\n");
  12701. +
  12702. + /* Disconnect any previous connection */
  12703. + vchiq_mmal_port_connect_tunnel(dev->instance,
  12704. + dev->capture.camera_port, NULL);
  12705. + dev->capture.camera_port = NULL;
  12706. + ret = vchiq_mmal_component_disable(dev->instance,
  12707. + dev->capture.
  12708. + encode_component);
  12709. + if (ret)
  12710. + v4l2_err(&dev->v4l2_dev,
  12711. + "Failed to disable encode component %d\n",
  12712. + ret);
  12713. +
  12714. + dev->capture.encode_component = NULL;
  12715. + }
  12716. + /* format dependant port setup */
  12717. + switch (mfmt->mmal_component) {
  12718. + case MMAL_COMPONENT_CAMERA:
  12719. + /* Make a further decision on port based on resolution */
  12720. + if (f->fmt.pix.width <= MAX_VIDEO_MODE_WIDTH
  12721. + && f->fmt.pix.height <= MAX_VIDEO_MODE_HEIGHT)
  12722. + camera_port = port =
  12723. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12724. + output[MMAL_CAMERA_PORT_VIDEO];
  12725. + else
  12726. + camera_port = port =
  12727. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12728. + output[MMAL_CAMERA_PORT_CAPTURE];
  12729. + break;
  12730. + case MMAL_COMPONENT_IMAGE_ENCODE:
  12731. + encode_component = dev->component[MMAL_COMPONENT_IMAGE_ENCODE];
  12732. + port = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  12733. + camera_port =
  12734. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12735. + output[MMAL_CAMERA_PORT_CAPTURE];
  12736. + break;
  12737. + case MMAL_COMPONENT_VIDEO_ENCODE:
  12738. + encode_component = dev->component[MMAL_COMPONENT_VIDEO_ENCODE];
  12739. + port = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  12740. + camera_port =
  12741. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12742. + output[MMAL_CAMERA_PORT_VIDEO];
  12743. + break;
  12744. + default:
  12745. + break;
  12746. + }
  12747. +
  12748. + if (!port)
  12749. + return -EINVAL;
  12750. +
  12751. + if (encode_component)
  12752. + camera_port->format.encoding = MMAL_ENCODING_OPAQUE;
  12753. + else
  12754. + camera_port->format.encoding = mfmt->mmal;
  12755. +
  12756. + camera_port->format.encoding_variant = 0;
  12757. + camera_port->es.video.width = f->fmt.pix.width;
  12758. + camera_port->es.video.height = f->fmt.pix.height;
  12759. + camera_port->es.video.crop.x = 0;
  12760. + camera_port->es.video.crop.y = 0;
  12761. + camera_port->es.video.crop.width = f->fmt.pix.width;
  12762. + camera_port->es.video.crop.height = f->fmt.pix.height;
  12763. + camera_port->es.video.frame_rate.num =
  12764. + dev->capture.timeperframe.denominator;
  12765. + camera_port->es.video.frame_rate.den =
  12766. + dev->capture.timeperframe.numerator;
  12767. +
  12768. + ret = vchiq_mmal_port_set_format(dev->instance, camera_port);
  12769. +
  12770. + if (!ret
  12771. + && camera_port ==
  12772. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12773. + output[MMAL_CAMERA_PORT_VIDEO]) {
  12774. + bool overlay_enabled =
  12775. + !!dev->component[MMAL_COMPONENT_PREVIEW]->enabled;
  12776. + struct vchiq_mmal_port *preview_port =
  12777. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12778. + output[MMAL_CAMERA_PORT_PREVIEW];
  12779. + /* Preview and encode ports need to match on resolution */
  12780. + if (overlay_enabled) {
  12781. + /* Need to disable the overlay before we can update
  12782. + * the resolution
  12783. + */
  12784. + ret =
  12785. + vchiq_mmal_port_disable(dev->instance,
  12786. + preview_port);
  12787. + if (!ret)
  12788. + ret =
  12789. + vchiq_mmal_port_connect_tunnel(
  12790. + dev->instance,
  12791. + preview_port,
  12792. + NULL);
  12793. + }
  12794. + preview_port->es.video.width = f->fmt.pix.width;
  12795. + preview_port->es.video.height = f->fmt.pix.height;
  12796. + preview_port->es.video.crop.x = 0;
  12797. + preview_port->es.video.crop.y = 0;
  12798. + preview_port->es.video.crop.width = f->fmt.pix.width;
  12799. + preview_port->es.video.crop.height = f->fmt.pix.height;
  12800. + preview_port->es.video.frame_rate.num = 30;
  12801. + preview_port->es.video.frame_rate.den = 1;
  12802. + ret = vchiq_mmal_port_set_format(dev->instance, preview_port);
  12803. + if (overlay_enabled) {
  12804. + ret = vchiq_mmal_port_connect_tunnel(
  12805. + dev->instance,
  12806. + preview_port,
  12807. + &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
  12808. + if (!ret)
  12809. + ret = vchiq_mmal_port_enable(dev->instance,
  12810. + preview_port,
  12811. + NULL);
  12812. + }
  12813. + }
  12814. +
  12815. + if (ret) {
  12816. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12817. + "%s failed to set format\n", __func__);
  12818. + /* ensure capture is not going to be tried */
  12819. + dev->capture.port = NULL;
  12820. + } else {
  12821. + if (encode_component) {
  12822. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12823. + "vid_cap - set up encode comp\n");
  12824. +
  12825. + /* configure buffering */
  12826. + camera_port->current_buffer.size =
  12827. + camera_port->recommended_buffer.size;
  12828. + camera_port->current_buffer.num =
  12829. + camera_port->recommended_buffer.num;
  12830. +
  12831. + ret =
  12832. + vchiq_mmal_port_connect_tunnel(
  12833. + dev->instance,
  12834. + camera_port,
  12835. + &encode_component->input[0]);
  12836. + if (ret) {
  12837. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12838. + &dev->v4l2_dev,
  12839. + "%s failed to create connection\n",
  12840. + __func__);
  12841. + /* ensure capture is not going to be tried */
  12842. + dev->capture.port = NULL;
  12843. + } else {
  12844. + port->es.video.width = f->fmt.pix.width;
  12845. + port->es.video.height = f->fmt.pix.height;
  12846. + port->es.video.crop.x = 0;
  12847. + port->es.video.crop.y = 0;
  12848. + port->es.video.crop.width = f->fmt.pix.width;
  12849. + port->es.video.crop.height = f->fmt.pix.height;
  12850. + port->es.video.frame_rate.num =
  12851. + dev->capture.timeperframe.denominator;
  12852. + port->es.video.frame_rate.den =
  12853. + dev->capture.timeperframe.numerator;
  12854. +
  12855. + port->format.encoding = mfmt->mmal;
  12856. + port->format.encoding_variant = 0;
  12857. + /* Set any encoding specific parameters */
  12858. + switch (mfmt->mmal_component) {
  12859. + case MMAL_COMPONENT_VIDEO_ENCODE:
  12860. + port->format.bitrate =
  12861. + dev->capture.encode_bitrate;
  12862. + break;
  12863. + case MMAL_COMPONENT_IMAGE_ENCODE:
  12864. + /* Could set EXIF parameters here */
  12865. + break;
  12866. + default:
  12867. + break;
  12868. + }
  12869. + ret = vchiq_mmal_port_set_format(dev->instance,
  12870. + port);
  12871. + if (ret)
  12872. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12873. + &dev->v4l2_dev,
  12874. + "%s failed to set format\n",
  12875. + __func__);
  12876. + }
  12877. +
  12878. + if (!ret) {
  12879. + ret = vchiq_mmal_component_enable(
  12880. + dev->instance,
  12881. + encode_component);
  12882. + if (ret) {
  12883. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12884. + &dev->v4l2_dev,
  12885. + "%s Failed to enable encode components\n",
  12886. + __func__);
  12887. + }
  12888. + }
  12889. + if (!ret) {
  12890. + /* configure buffering */
  12891. + port->current_buffer.num = 1;
  12892. + port->current_buffer.size =
  12893. + f->fmt.pix.sizeimage;
  12894. + if (port->format.encoding ==
  12895. + MMAL_ENCODING_JPEG) {
  12896. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12897. + &dev->v4l2_dev,
  12898. + "JPG - buf size now %d was %d\n",
  12899. + f->fmt.pix.sizeimage,
  12900. + port->current_buffer.size);
  12901. + port->current_buffer.size =
  12902. + (f->fmt.pix.sizeimage <
  12903. + (100 << 10))
  12904. + ? (100 << 10) : f->fmt.pix.
  12905. + sizeimage;
  12906. + }
  12907. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12908. + &dev->v4l2_dev,
  12909. + "vid_cap - cur_buf.size set to %d\n",
  12910. + f->fmt.pix.sizeimage);
  12911. + port->current_buffer.alignment = 0;
  12912. + }
  12913. + } else {
  12914. + /* configure buffering */
  12915. + camera_port->current_buffer.num = 1;
  12916. + camera_port->current_buffer.size = f->fmt.pix.sizeimage;
  12917. + camera_port->current_buffer.alignment = 0;
  12918. + }
  12919. +
  12920. + if (!ret) {
  12921. + dev->capture.fmt = mfmt;
  12922. + dev->capture.stride = f->fmt.pix.bytesperline;
  12923. + dev->capture.width = camera_port->es.video.crop.width;
  12924. + dev->capture.height = camera_port->es.video.crop.height;
  12925. +
  12926. + /* select port for capture */
  12927. + dev->capture.port = port;
  12928. + dev->capture.camera_port = camera_port;
  12929. + dev->capture.encode_component = encode_component;
  12930. + v4l2_dbg(1, bcm2835_v4l2_debug,
  12931. + &dev->v4l2_dev,
  12932. + "Set dev->capture.fmt %08X, %dx%d, stride %d",
  12933. + port->format.encoding,
  12934. + dev->capture.width, dev->capture.height,
  12935. + dev->capture.stride);
  12936. + }
  12937. + }
  12938. +
  12939. + /* todo: Need to convert the vchiq/mmal error into a v4l2 error. */
  12940. + return ret;
  12941. +}
  12942. +
  12943. +static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  12944. + struct v4l2_format *f)
  12945. +{
  12946. + int ret;
  12947. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  12948. + struct mmal_fmt *mfmt;
  12949. +
  12950. + /* try the format to set valid parameters */
  12951. + ret = vidioc_try_fmt_vid_cap(file, priv, f);
  12952. + if (ret) {
  12953. + v4l2_err(&dev->v4l2_dev,
  12954. + "vid_cap - vidioc_try_fmt_vid_cap failed\n");
  12955. + return ret;
  12956. + }
  12957. +
  12958. + /* if a capture is running refuse to set format */
  12959. + if (vb2_is_busy(&dev->capture.vb_vidq)) {
  12960. + v4l2_info(&dev->v4l2_dev, "%s device busy\n", __func__);
  12961. + return -EBUSY;
  12962. + }
  12963. +
  12964. + /* If the format is unsupported v4l2 says we should switch to
  12965. + * a supported one and not return an error. */
  12966. + mfmt = get_format(f);
  12967. + if (!mfmt) {
  12968. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  12969. + "Fourcc format (0x%08x) unknown.\n",
  12970. + f->fmt.pix.pixelformat);
  12971. + f->fmt.pix.pixelformat = formats[0].fourcc;
  12972. + mfmt = get_format(f);
  12973. + }
  12974. +
  12975. + ret = mmal_setup_components(dev, f);
  12976. + if (ret != 0)
  12977. + v4l2_err(&dev->v4l2_dev,
  12978. + "%s: failed to setup mmal components: %d\n",
  12979. + __func__, ret);
  12980. +
  12981. + return ret;
  12982. +}
  12983. +
  12984. +/* timeperframe is arbitrary and continous */
  12985. +static int vidioc_enum_frameintervals(struct file *file, void *priv,
  12986. + struct v4l2_frmivalenum *fival)
  12987. +{
  12988. + if (fival->index)
  12989. + return -EINVAL;
  12990. +
  12991. + /* regarding width & height - we support any */
  12992. +
  12993. + fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
  12994. +
  12995. + /* fill in stepwise (step=1.0 is requred by V4L2 spec) */
  12996. + fival->stepwise.min = tpf_min;
  12997. + fival->stepwise.max = tpf_max;
  12998. + fival->stepwise.step = (struct v4l2_fract) {1, 1};
  12999. +
  13000. + return 0;
  13001. +}
  13002. +
  13003. +static int vidioc_g_parm(struct file *file, void *priv,
  13004. + struct v4l2_streamparm *parm)
  13005. +{
  13006. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  13007. +
  13008. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  13009. + return -EINVAL;
  13010. +
  13011. + parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
  13012. + parm->parm.capture.timeperframe = dev->capture.timeperframe;
  13013. + parm->parm.capture.readbuffers = 1;
  13014. + return 0;
  13015. +}
  13016. +
  13017. +#define FRACT_CMP(a, OP, b) \
  13018. + ((u64)(a).numerator * (b).denominator OP \
  13019. + (u64)(b).numerator * (a).denominator)
  13020. +
  13021. +static int vidioc_s_parm(struct file *file, void *priv,
  13022. + struct v4l2_streamparm *parm)
  13023. +{
  13024. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  13025. + struct v4l2_fract tpf;
  13026. + struct mmal_parameter_rational fps_param;
  13027. + int ret;
  13028. +
  13029. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  13030. + return -EINVAL;
  13031. +
  13032. + tpf = parm->parm.capture.timeperframe;
  13033. +
  13034. + /* tpf: {*, 0} resets timing; clip to [min, max]*/
  13035. + tpf = tpf.denominator ? tpf : tpf_default;
  13036. + tpf = FRACT_CMP(tpf, <, tpf_min) ? tpf_min : tpf;
  13037. + tpf = FRACT_CMP(tpf, >, tpf_max) ? tpf_max : tpf;
  13038. +
  13039. + dev->capture.timeperframe = tpf;
  13040. + parm->parm.capture.timeperframe = tpf;
  13041. + parm->parm.capture.readbuffers = 1;
  13042. +
  13043. + fps_param.num = dev->capture.timeperframe.denominator;
  13044. + fps_param.den = dev->capture.timeperframe.numerator;
  13045. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  13046. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13047. + output[MMAL_CAMERA_PORT_PREVIEW],
  13048. + MMAL_PARAMETER_VIDEO_FRAME_RATE,
  13049. + &fps_param, sizeof(fps_param));
  13050. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  13051. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13052. + output[MMAL_CAMERA_PORT_VIDEO],
  13053. + MMAL_PARAMETER_VIDEO_FRAME_RATE,
  13054. + &fps_param, sizeof(fps_param));
  13055. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  13056. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13057. + output[MMAL_CAMERA_PORT_CAPTURE],
  13058. + MMAL_PARAMETER_VIDEO_FRAME_RATE,
  13059. + &fps_param, sizeof(fps_param));
  13060. + if (ret)
  13061. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13062. + "Failed to set fps ret %d\n",
  13063. + ret);
  13064. +
  13065. + return 0;
  13066. +}
  13067. +
  13068. +static const struct v4l2_ioctl_ops camera0_ioctl_ops = {
  13069. + /* overlay */
  13070. + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  13071. + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
  13072. + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
  13073. + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
  13074. + .vidioc_overlay = vidioc_overlay,
  13075. + .vidioc_g_fbuf = vidioc_g_fbuf,
  13076. +
  13077. + /* inputs */
  13078. + .vidioc_enum_input = vidioc_enum_input,
  13079. + .vidioc_g_input = vidioc_g_input,
  13080. + .vidioc_s_input = vidioc_s_input,
  13081. +
  13082. + /* capture */
  13083. + .vidioc_querycap = vidioc_querycap,
  13084. + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  13085. + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  13086. + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  13087. + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  13088. +
  13089. + /* buffer management */
  13090. + .vidioc_reqbufs = vb2_ioctl_reqbufs,
  13091. + .vidioc_create_bufs = vb2_ioctl_create_bufs,
  13092. + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  13093. + .vidioc_querybuf = vb2_ioctl_querybuf,
  13094. + .vidioc_qbuf = vb2_ioctl_qbuf,
  13095. + .vidioc_dqbuf = vb2_ioctl_dqbuf,
  13096. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  13097. + .vidioc_g_parm = vidioc_g_parm,
  13098. + .vidioc_s_parm = vidioc_s_parm,
  13099. + .vidioc_streamon = vb2_ioctl_streamon,
  13100. + .vidioc_streamoff = vb2_ioctl_streamoff,
  13101. +
  13102. + .vidioc_log_status = v4l2_ctrl_log_status,
  13103. + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  13104. + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  13105. +};
  13106. +
  13107. +/* ------------------------------------------------------------------
  13108. + Driver init/finalise
  13109. + ------------------------------------------------------------------*/
  13110. +
  13111. +static const struct v4l2_file_operations camera0_fops = {
  13112. + .owner = THIS_MODULE,
  13113. + .open = v4l2_fh_open,
  13114. + .release = vb2_fop_release,
  13115. + .read = vb2_fop_read,
  13116. + .poll = vb2_fop_poll,
  13117. + .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
  13118. + .mmap = vb2_fop_mmap,
  13119. +};
  13120. +
  13121. +static struct video_device vdev_template = {
  13122. + .name = "camera0",
  13123. + .fops = &camera0_fops,
  13124. + .ioctl_ops = &camera0_ioctl_ops,
  13125. + .release = video_device_release_empty,
  13126. +};
  13127. +
  13128. +static int set_camera_parameters(struct vchiq_mmal_instance *instance,
  13129. + struct vchiq_mmal_component *camera)
  13130. +{
  13131. + int ret;
  13132. + struct mmal_parameter_camera_config cam_config = {
  13133. + .max_stills_w = MAX_WIDTH,
  13134. + .max_stills_h = MAX_HEIGHT,
  13135. + .stills_yuv422 = 1,
  13136. + .one_shot_stills = 1,
  13137. + .max_preview_video_w = 1920,
  13138. + .max_preview_video_h = 1088,
  13139. + .num_preview_video_frames = 3,
  13140. + .stills_capture_circular_buffer_height = 0,
  13141. + .fast_preview_resume = 0,
  13142. + .use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RAW_STC
  13143. + };
  13144. +
  13145. + ret = vchiq_mmal_port_parameter_set(instance, &camera->control,
  13146. + MMAL_PARAMETER_CAMERA_CONFIG,
  13147. + &cam_config, sizeof(cam_config));
  13148. + return ret;
  13149. +}
  13150. +
  13151. +/* MMAL instance and component init */
  13152. +static int __init mmal_init(struct bm2835_mmal_dev *dev)
  13153. +{
  13154. + int ret;
  13155. + struct mmal_es_format *format;
  13156. +
  13157. + ret = vchiq_mmal_init(&dev->instance);
  13158. + if (ret < 0)
  13159. + return ret;
  13160. +
  13161. + /* get the camera component ready */
  13162. + ret = vchiq_mmal_component_init(dev->instance, "ril.camera",
  13163. + &dev->component[MMAL_COMPONENT_CAMERA]);
  13164. + if (ret < 0)
  13165. + goto unreg_mmal;
  13166. +
  13167. + if (dev->component[MMAL_COMPONENT_CAMERA]->outputs <
  13168. + MMAL_CAMERA_PORT_COUNT) {
  13169. + ret = -EINVAL;
  13170. + goto unreg_camera;
  13171. + }
  13172. +
  13173. + ret = set_camera_parameters(dev->instance,
  13174. + dev->component[MMAL_COMPONENT_CAMERA]);
  13175. + if (ret < 0)
  13176. + goto unreg_camera;
  13177. +
  13178. + format =
  13179. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13180. + output[MMAL_CAMERA_PORT_PREVIEW].format;
  13181. +
  13182. + format->encoding = MMAL_ENCODING_OPAQUE;
  13183. + format->encoding_variant = MMAL_ENCODING_I420;
  13184. +
  13185. + format->es->video.width = 1024;
  13186. + format->es->video.height = 768;
  13187. + format->es->video.crop.x = 0;
  13188. + format->es->video.crop.y = 0;
  13189. + format->es->video.crop.width = 1024;
  13190. + format->es->video.crop.height = 768;
  13191. + format->es->video.frame_rate.num =
  13192. + dev->capture.timeperframe.denominator;
  13193. + format->es->video.frame_rate.den =
  13194. + dev->capture.timeperframe.numerator;
  13195. +
  13196. + format =
  13197. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13198. + output[MMAL_CAMERA_PORT_VIDEO].format;
  13199. +
  13200. + format->encoding = MMAL_ENCODING_OPAQUE;
  13201. + format->encoding_variant = MMAL_ENCODING_I420;
  13202. +
  13203. + format->es->video.width = 1024;
  13204. + format->es->video.height = 768;
  13205. + format->es->video.crop.x = 0;
  13206. + format->es->video.crop.y = 0;
  13207. + format->es->video.crop.width = 1024;
  13208. + format->es->video.crop.height = 768;
  13209. + format->es->video.frame_rate.num =
  13210. + dev->capture.timeperframe.denominator;
  13211. + format->es->video.frame_rate.den =
  13212. + dev->capture.timeperframe.numerator;
  13213. +
  13214. + format =
  13215. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13216. + output[MMAL_CAMERA_PORT_CAPTURE].format;
  13217. +
  13218. + format->encoding = MMAL_ENCODING_OPAQUE;
  13219. +
  13220. + format->es->video.width = 2592;
  13221. + format->es->video.height = 1944;
  13222. + format->es->video.crop.x = 0;
  13223. + format->es->video.crop.y = 0;
  13224. + format->es->video.crop.width = 2592;
  13225. + format->es->video.crop.height = 1944;
  13226. + format->es->video.frame_rate.num = 30;
  13227. + format->es->video.frame_rate.den = 1;
  13228. +
  13229. + dev->capture.width = format->es->video.width;
  13230. + dev->capture.height = format->es->video.height;
  13231. + dev->capture.fmt = &formats[0];
  13232. + dev->capture.encode_component = NULL;
  13233. + dev->capture.timeperframe = tpf_default;
  13234. +
  13235. + /* get the preview component ready */
  13236. + ret = vchiq_mmal_component_init(
  13237. + dev->instance, "ril.video_render",
  13238. + &dev->component[MMAL_COMPONENT_PREVIEW]);
  13239. + if (ret < 0)
  13240. + goto unreg_camera;
  13241. +
  13242. + if (dev->component[MMAL_COMPONENT_PREVIEW]->inputs < 1) {
  13243. + ret = -EINVAL;
  13244. + pr_debug("too few input ports %d needed %d\n",
  13245. + dev->component[MMAL_COMPONENT_PREVIEW]->inputs, 1);
  13246. + goto unreg_preview;
  13247. + }
  13248. +
  13249. + /* get the image encoder component ready */
  13250. + ret = vchiq_mmal_component_init(
  13251. + dev->instance, "ril.image_encode",
  13252. + &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  13253. + if (ret < 0)
  13254. + goto unreg_preview;
  13255. +
  13256. + if (dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs < 1) {
  13257. + ret = -EINVAL;
  13258. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  13259. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs,
  13260. + 1);
  13261. + goto unreg_image_encoder;
  13262. + }
  13263. +
  13264. + /* get the video encoder component ready */
  13265. + ret = vchiq_mmal_component_init(dev->instance, "ril.video_encode",
  13266. + &dev->
  13267. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  13268. + if (ret < 0)
  13269. + goto unreg_image_encoder;
  13270. +
  13271. + if (dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs < 1) {
  13272. + ret = -EINVAL;
  13273. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  13274. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs,
  13275. + 1);
  13276. + goto unreg_vid_encoder;
  13277. + }
  13278. +
  13279. + {
  13280. + unsigned int enable = 1;
  13281. + vchiq_mmal_port_parameter_set(
  13282. + dev->instance,
  13283. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  13284. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  13285. + &enable, sizeof(enable));
  13286. +
  13287. + vchiq_mmal_port_parameter_set(dev->instance,
  13288. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  13289. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  13290. + &enable,
  13291. + sizeof(enable));
  13292. + }
  13293. + ret = bm2835_mmal_set_all_camera_controls(dev);
  13294. + if (ret < 0)
  13295. + goto unreg_vid_encoder;
  13296. +
  13297. + return 0;
  13298. +
  13299. +unreg_vid_encoder:
  13300. + pr_err("Cleanup: Destroy video encoder\n");
  13301. + vchiq_mmal_component_finalise(
  13302. + dev->instance,
  13303. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
  13304. +
  13305. +unreg_image_encoder:
  13306. + pr_err("Cleanup: Destroy image encoder\n");
  13307. + vchiq_mmal_component_finalise(
  13308. + dev->instance,
  13309. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  13310. +
  13311. +unreg_preview:
  13312. + pr_err("Cleanup: Destroy video render\n");
  13313. + vchiq_mmal_component_finalise(dev->instance,
  13314. + dev->component[MMAL_COMPONENT_PREVIEW]);
  13315. +
  13316. +unreg_camera:
  13317. + pr_err("Cleanup: Destroy camera\n");
  13318. + vchiq_mmal_component_finalise(dev->instance,
  13319. + dev->component[MMAL_COMPONENT_CAMERA]);
  13320. +
  13321. +unreg_mmal:
  13322. + vchiq_mmal_finalise(dev->instance);
  13323. + return ret;
  13324. +}
  13325. +
  13326. +static int __init bm2835_mmal_init_device(struct bm2835_mmal_dev *dev,
  13327. + struct video_device *vfd)
  13328. +{
  13329. + int ret;
  13330. +
  13331. + *vfd = vdev_template;
  13332. +
  13333. + vfd->v4l2_dev = &dev->v4l2_dev;
  13334. +
  13335. + vfd->lock = &dev->mutex;
  13336. +
  13337. + vfd->queue = &dev->capture.vb_vidq;
  13338. +
  13339. + set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
  13340. +
  13341. + /* video device needs to be able to access instance data */
  13342. + video_set_drvdata(vfd, dev);
  13343. +
  13344. + ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
  13345. + if (ret < 0)
  13346. + return ret;
  13347. +
  13348. + v4l2_info(vfd->v4l2_dev, "V4L2 device registered as %s\n",
  13349. + video_device_node_name(vfd));
  13350. +
  13351. + return 0;
  13352. +}
  13353. +
  13354. +static struct v4l2_format default_v4l2_format = {
  13355. + .fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG,
  13356. + .fmt.pix.width = 1024,
  13357. + .fmt.pix.bytesperline = 1024 * 3 / 2,
  13358. + .fmt.pix.height = 768,
  13359. + .fmt.pix.sizeimage = 1<<18,
  13360. +};
  13361. +
  13362. +static int __init bm2835_mmal_init(void)
  13363. +{
  13364. + int ret;
  13365. + struct bm2835_mmal_dev *dev;
  13366. + struct vb2_queue *q;
  13367. +
  13368. + dev = kzalloc(sizeof(*gdev), GFP_KERNEL);
  13369. + if (!dev)
  13370. + return -ENOMEM;
  13371. +
  13372. + /* setup device defaults */
  13373. + dev->overlay.w.left = 150;
  13374. + dev->overlay.w.top = 50;
  13375. + dev->overlay.w.width = 1024;
  13376. + dev->overlay.w.height = 768;
  13377. + dev->overlay.clipcount = 0;
  13378. + dev->overlay.field = V4L2_FIELD_NONE;
  13379. +
  13380. + dev->capture.fmt = &formats[3]; /* JPEG */
  13381. +
  13382. + /* v4l device registration */
  13383. + snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
  13384. + "%s", BM2835_MMAL_MODULE_NAME);
  13385. + ret = v4l2_device_register(NULL, &dev->v4l2_dev);
  13386. + if (ret)
  13387. + goto free_dev;
  13388. +
  13389. + /* setup v4l controls */
  13390. + ret = bm2835_mmal_init_controls(dev, &dev->ctrl_handler);
  13391. + if (ret < 0)
  13392. + goto unreg_dev;
  13393. + dev->v4l2_dev.ctrl_handler = &dev->ctrl_handler;
  13394. +
  13395. + /* mmal init */
  13396. + ret = mmal_init(dev);
  13397. + if (ret < 0)
  13398. + goto unreg_dev;
  13399. +
  13400. + /* initialize queue */
  13401. + q = &dev->capture.vb_vidq;
  13402. + memset(q, 0, sizeof(*q));
  13403. + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  13404. + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
  13405. + q->drv_priv = dev;
  13406. + q->buf_struct_size = sizeof(struct mmal_buffer);
  13407. + q->ops = &bm2835_mmal_video_qops;
  13408. + q->mem_ops = &vb2_vmalloc_memops;
  13409. + q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  13410. + ret = vb2_queue_init(q);
  13411. + if (ret < 0)
  13412. + goto unreg_dev;
  13413. +
  13414. + /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */
  13415. + mutex_init(&dev->mutex);
  13416. +
  13417. + /* initialise video devices */
  13418. + ret = bm2835_mmal_init_device(dev, &dev->vdev);
  13419. + if (ret < 0)
  13420. + goto unreg_dev;
  13421. +
  13422. + ret = mmal_setup_components(dev, &default_v4l2_format);
  13423. + if (ret < 0) {
  13424. + v4l2_err(&dev->v4l2_dev,
  13425. + "%s: could not setup components\n", __func__);
  13426. + goto unreg_dev;
  13427. + }
  13428. +
  13429. + v4l2_info(&dev->v4l2_dev,
  13430. + "Broadcom 2835 MMAL video capture ver %s loaded.\n",
  13431. + BM2835_MMAL_VERSION);
  13432. +
  13433. + gdev = dev;
  13434. + return 0;
  13435. +
  13436. +unreg_dev:
  13437. + v4l2_ctrl_handler_free(&dev->ctrl_handler);
  13438. + v4l2_device_unregister(&dev->v4l2_dev);
  13439. +
  13440. +free_dev:
  13441. + kfree(dev);
  13442. +
  13443. + v4l2_err(&dev->v4l2_dev,
  13444. + "%s: error %d while loading driver\n",
  13445. + BM2835_MMAL_MODULE_NAME, ret);
  13446. +
  13447. + return ret;
  13448. +}
  13449. +
  13450. +static void __exit bm2835_mmal_exit(void)
  13451. +{
  13452. + if (!gdev)
  13453. + return;
  13454. +
  13455. + v4l2_info(&gdev->v4l2_dev, "unregistering %s\n",
  13456. + video_device_node_name(&gdev->vdev));
  13457. +
  13458. + video_unregister_device(&gdev->vdev);
  13459. +
  13460. + if (gdev->capture.encode_component) {
  13461. + v4l2_dbg(1, bcm2835_v4l2_debug, &gdev->v4l2_dev,
  13462. + "mmal_exit - disconnect tunnel\n");
  13463. + vchiq_mmal_port_connect_tunnel(gdev->instance,
  13464. + gdev->capture.camera_port, NULL);
  13465. + vchiq_mmal_component_disable(gdev->instance,
  13466. + gdev->capture.encode_component);
  13467. + }
  13468. + vchiq_mmal_component_disable(gdev->instance,
  13469. + gdev->component[MMAL_COMPONENT_CAMERA]);
  13470. +
  13471. + vchiq_mmal_component_finalise(gdev->instance,
  13472. + gdev->
  13473. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  13474. +
  13475. + vchiq_mmal_component_finalise(gdev->instance,
  13476. + gdev->
  13477. + component[MMAL_COMPONENT_IMAGE_ENCODE]);
  13478. +
  13479. + vchiq_mmal_component_finalise(gdev->instance,
  13480. + gdev->component[MMAL_COMPONENT_PREVIEW]);
  13481. +
  13482. + vchiq_mmal_component_finalise(gdev->instance,
  13483. + gdev->component[MMAL_COMPONENT_CAMERA]);
  13484. +
  13485. + vchiq_mmal_finalise(gdev->instance);
  13486. +
  13487. + v4l2_ctrl_handler_free(&gdev->ctrl_handler);
  13488. +
  13489. + v4l2_device_unregister(&gdev->v4l2_dev);
  13490. +
  13491. + kfree(gdev);
  13492. +}
  13493. +
  13494. +module_init(bm2835_mmal_init);
  13495. +module_exit(bm2835_mmal_exit);
  13496. diff -Nur linux-3.12.11.orig/drivers/media/platform/bcm2835/bcm2835-camera.h linux-3.12.11/drivers/media/platform/bcm2835/bcm2835-camera.h
  13497. --- linux-3.12.11.orig/drivers/media/platform/bcm2835/bcm2835-camera.h 1970-01-01 01:00:00.000000000 +0100
  13498. +++ linux-3.12.11/drivers/media/platform/bcm2835/bcm2835-camera.h 2014-02-18 11:52:14.000000000 +0100
  13499. @@ -0,0 +1,113 @@
  13500. +/*
  13501. + * Broadcom BM2835 V4L2 driver
  13502. + *
  13503. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  13504. + *
  13505. + * This file is subject to the terms and conditions of the GNU General Public
  13506. + * License. See the file COPYING in the main directory of this archive
  13507. + * for more details.
  13508. + *
  13509. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  13510. + * Dave Stevenson <dsteve@broadcom.com>
  13511. + * Simon Mellor <simellor@broadcom.com>
  13512. + * Luke Diamand <luked@broadcom.com>
  13513. + *
  13514. + * core driver device
  13515. + */
  13516. +
  13517. +#define V4L2_CTRL_COUNT 21 /* number of v4l controls */
  13518. +
  13519. +enum {
  13520. + MMAL_COMPONENT_CAMERA = 0,
  13521. + MMAL_COMPONENT_PREVIEW,
  13522. + MMAL_COMPONENT_IMAGE_ENCODE,
  13523. + MMAL_COMPONENT_VIDEO_ENCODE,
  13524. + MMAL_COMPONENT_COUNT
  13525. +};
  13526. +
  13527. +enum {
  13528. + MMAL_CAMERA_PORT_PREVIEW = 0,
  13529. + MMAL_CAMERA_PORT_VIDEO,
  13530. + MMAL_CAMERA_PORT_CAPTURE,
  13531. + MMAL_CAMERA_PORT_COUNT
  13532. +};
  13533. +
  13534. +#define PREVIEW_LAYER 2
  13535. +
  13536. +extern int bcm2835_v4l2_debug;
  13537. +
  13538. +struct bm2835_mmal_dev {
  13539. + /* v4l2 devices */
  13540. + struct v4l2_device v4l2_dev;
  13541. + struct video_device vdev;
  13542. + struct mutex mutex;
  13543. +
  13544. + /* controls */
  13545. + struct v4l2_ctrl_handler ctrl_handler;
  13546. + struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT];
  13547. + struct mmal_colourfx colourfx;
  13548. + int hflip;
  13549. + int vflip;
  13550. + enum mmal_parameter_exposuremode exposure_mode;
  13551. + unsigned int manual_shutter_speed;
  13552. +
  13553. + /* allocated mmal instance and components */
  13554. + struct vchiq_mmal_instance *instance;
  13555. + struct vchiq_mmal_component *component[MMAL_COMPONENT_COUNT];
  13556. + int camera_use_count;
  13557. +
  13558. + struct v4l2_window overlay;
  13559. +
  13560. + struct {
  13561. + unsigned int width; /* width */
  13562. + unsigned int height; /* height */
  13563. + unsigned int stride; /* stride */
  13564. + struct mmal_fmt *fmt;
  13565. + struct v4l2_fract timeperframe;
  13566. +
  13567. + /* H264 encode bitrate */
  13568. + int encode_bitrate;
  13569. + /* H264 bitrate mode. CBR/VBR */
  13570. + int encode_bitrate_mode;
  13571. + /* JPEG Q-factor */
  13572. + int q_factor;
  13573. +
  13574. + struct vb2_queue vb_vidq;
  13575. +
  13576. + /* VC start timestamp for streaming */
  13577. + s64 vc_start_timestamp;
  13578. + /* Kernel start timestamp for streaming */
  13579. + struct timeval kernel_start_ts;
  13580. +
  13581. + struct vchiq_mmal_port *port; /* port being used for capture */
  13582. + /* camera port being used for capture */
  13583. + struct vchiq_mmal_port *camera_port;
  13584. + /* component being used for encode */
  13585. + struct vchiq_mmal_component *encode_component;
  13586. + /* number of frames remaining which driver should capture */
  13587. + unsigned int frame_count;
  13588. + /* last frame completion */
  13589. + struct completion frame_cmplt;
  13590. +
  13591. + } capture;
  13592. +
  13593. +};
  13594. +
  13595. +int bm2835_mmal_init_controls(
  13596. + struct bm2835_mmal_dev *dev,
  13597. + struct v4l2_ctrl_handler *hdl);
  13598. +
  13599. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev);
  13600. +
  13601. +
  13602. +/* Debug helpers */
  13603. +
  13604. +#define v4l2_dump_pix_format(level, debug, dev, pix_fmt, desc) \
  13605. +{ \
  13606. + v4l2_dbg(level, debug, dev, \
  13607. +"%s: w %u h %u field %u pfmt 0x%x bpl %u sz_img %u colorspace 0x%x priv %u\n", \
  13608. + desc == NULL ? "" : desc, \
  13609. + (pix_fmt)->width, (pix_fmt)->height, (pix_fmt)->field, \
  13610. + (pix_fmt)->pixelformat, (pix_fmt)->bytesperline, \
  13611. + (pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \
  13612. +}
  13613. diff -Nur linux-3.12.11.orig/drivers/media/platform/bcm2835/controls.c linux-3.12.11/drivers/media/platform/bcm2835/controls.c
  13614. --- linux-3.12.11.orig/drivers/media/platform/bcm2835/controls.c 1970-01-01 01:00:00.000000000 +0100
  13615. +++ linux-3.12.11/drivers/media/platform/bcm2835/controls.c 2014-02-18 11:52:14.000000000 +0100
  13616. @@ -0,0 +1,902 @@
  13617. +/*
  13618. + * Broadcom BM2835 V4L2 driver
  13619. + *
  13620. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  13621. + *
  13622. + * This file is subject to the terms and conditions of the GNU General Public
  13623. + * License. See the file COPYING in the main directory of this archive
  13624. + * for more details.
  13625. + *
  13626. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  13627. + * Dave Stevenson <dsteve@broadcom.com>
  13628. + * Simon Mellor <simellor@broadcom.com>
  13629. + * Luke Diamand <luked@broadcom.com>
  13630. + */
  13631. +
  13632. +#include <linux/errno.h>
  13633. +#include <linux/kernel.h>
  13634. +#include <linux/module.h>
  13635. +#include <linux/slab.h>
  13636. +#include <media/videobuf2-vmalloc.h>
  13637. +#include <media/v4l2-device.h>
  13638. +#include <media/v4l2-ioctl.h>
  13639. +#include <media/v4l2-ctrls.h>
  13640. +#include <media/v4l2-fh.h>
  13641. +#include <media/v4l2-event.h>
  13642. +#include <media/v4l2-common.h>
  13643. +
  13644. +#include "mmal-common.h"
  13645. +#include "mmal-vchiq.h"
  13646. +#include "mmal-parameters.h"
  13647. +#include "bcm2835-camera.h"
  13648. +
  13649. +/* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -4.0 to +4.0.
  13650. + * MMAL values are in 1/6th increments so the MMAL range is -24 to +24.
  13651. + * V4L2 docs say value "is expressed in terms of EV, drivers should interpret
  13652. + * the values as 0.001 EV units, where the value 1000 stands for +1 EV."
  13653. + * V4L2 is limited to a max of 32 values in a menu, so count in 1/3rds from
  13654. + * -4 to +4
  13655. + */
  13656. +static const s64 ev_bias_qmenu[] = {
  13657. + -4000, -3667, -3333,
  13658. + -3000, -2667, -2333,
  13659. + -2000, -1667, -1333,
  13660. + -1000, -667, -333,
  13661. + 0, 333, 667,
  13662. + 1000, 1333, 1667,
  13663. + 2000, 2333, 2667,
  13664. + 3000, 3333, 3667,
  13665. + 4000
  13666. +};
  13667. +
  13668. +/* Supported ISO values
  13669. + * ISOO = auto ISO
  13670. + */
  13671. +static const s64 iso_qmenu[] = {
  13672. + 0, 100, 200, 400, 800,
  13673. +};
  13674. +
  13675. +static const s64 mains_freq_qmenu[] = {
  13676. + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED,
  13677. + V4L2_CID_POWER_LINE_FREQUENCY_50HZ,
  13678. + V4L2_CID_POWER_LINE_FREQUENCY_60HZ,
  13679. + V4L2_CID_POWER_LINE_FREQUENCY_AUTO
  13680. +};
  13681. +
  13682. +/* Supported video encode modes */
  13683. +static const s64 bitrate_mode_qmenu[] = {
  13684. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
  13685. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
  13686. +};
  13687. +
  13688. +
  13689. +enum bm2835_mmal_ctrl_type {
  13690. + MMAL_CONTROL_TYPE_STD,
  13691. + MMAL_CONTROL_TYPE_STD_MENU,
  13692. + MMAL_CONTROL_TYPE_INT_MENU,
  13693. + MMAL_CONTROL_TYPE_CLUSTER, /* special cluster entry */
  13694. +};
  13695. +
  13696. +struct bm2835_mmal_v4l2_ctrl;
  13697. +
  13698. +typedef int(bm2835_mmal_v4l2_ctrl_cb)(
  13699. + struct bm2835_mmal_dev *dev,
  13700. + struct v4l2_ctrl *ctrl,
  13701. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl);
  13702. +
  13703. +struct bm2835_mmal_v4l2_ctrl {
  13704. + u32 id; /* v4l2 control identifier */
  13705. + enum bm2835_mmal_ctrl_type type;
  13706. + /* control minimum value or
  13707. + * mask for MMAL_CONTROL_TYPE_STD_MENU */
  13708. + s32 min;
  13709. + s32 max; /* maximum value of control */
  13710. + s32 def; /* default value of control */
  13711. + s32 step; /* step size of the control */
  13712. + const s64 *imenu; /* integer menu array */
  13713. + u32 mmal_id; /* mmal parameter id */
  13714. + bm2835_mmal_v4l2_ctrl_cb *setter;
  13715. + bool ignore_errors;
  13716. +};
  13717. +
  13718. +struct v4l2_to_mmal_effects_setting {
  13719. + u32 v4l2_effect;
  13720. + u32 mmal_effect;
  13721. + s32 col_fx_enable;
  13722. + s32 col_fx_fixed_cbcr;
  13723. + u32 u;
  13724. + u32 v;
  13725. + u32 num_effect_params;
  13726. + u32 effect_params[MMAL_MAX_IMAGEFX_PARAMETERS];
  13727. +};
  13728. +
  13729. +static const struct v4l2_to_mmal_effects_setting
  13730. + v4l2_to_mmal_effects_values[] = {
  13731. + { V4L2_COLORFX_NONE, MMAL_PARAM_IMAGEFX_NONE,
  13732. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13733. + { V4L2_COLORFX_BW, MMAL_PARAM_IMAGEFX_NONE,
  13734. + 1, 0, 128, 128, 0, {0, 0, 0, 0, 0} },
  13735. + { V4L2_COLORFX_SEPIA, MMAL_PARAM_IMAGEFX_NONE,
  13736. + 1, 0, 87, 151, 0, {0, 0, 0, 0, 0} },
  13737. + { V4L2_COLORFX_NEGATIVE, MMAL_PARAM_IMAGEFX_NEGATIVE,
  13738. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13739. + { V4L2_COLORFX_EMBOSS, MMAL_PARAM_IMAGEFX_EMBOSS,
  13740. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13741. + { V4L2_COLORFX_SKETCH, MMAL_PARAM_IMAGEFX_SKETCH,
  13742. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13743. + { V4L2_COLORFX_SKY_BLUE, MMAL_PARAM_IMAGEFX_PASTEL,
  13744. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13745. + { V4L2_COLORFX_GRASS_GREEN, MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  13746. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13747. + { V4L2_COLORFX_SKIN_WHITEN, MMAL_PARAM_IMAGEFX_WASHEDOUT,
  13748. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13749. + { V4L2_COLORFX_VIVID, MMAL_PARAM_IMAGEFX_SATURATION,
  13750. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13751. + { V4L2_COLORFX_AQUA, MMAL_PARAM_IMAGEFX_NONE,
  13752. + 1, 0, 171, 121, 0, {0, 0, 0, 0, 0} },
  13753. + { V4L2_COLORFX_ART_FREEZE, MMAL_PARAM_IMAGEFX_HATCH,
  13754. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13755. + { V4L2_COLORFX_SILHOUETTE, MMAL_PARAM_IMAGEFX_FILM,
  13756. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  13757. + { V4L2_COLORFX_SOLARIZATION, MMAL_PARAM_IMAGEFX_SOLARIZE,
  13758. + 0, 0, 0, 0, 5, {1, 128, 160, 160, 48} },
  13759. + { V4L2_COLORFX_ANTIQUE, MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  13760. + 0, 0, 0, 0, 3, {108, 274, 238, 0, 0} },
  13761. + { V4L2_COLORFX_SET_CBCR, MMAL_PARAM_IMAGEFX_NONE,
  13762. + 1, 1, 0, 0, 0, {0, 0, 0, 0, 0} }
  13763. +};
  13764. +
  13765. +
  13766. +/* control handlers*/
  13767. +
  13768. +static int ctrl_set_rational(struct bm2835_mmal_dev *dev,
  13769. + struct v4l2_ctrl *ctrl,
  13770. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13771. +{
  13772. + struct mmal_parameter_rational rational_value;
  13773. + struct vchiq_mmal_port *control;
  13774. +
  13775. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13776. +
  13777. + rational_value.num = ctrl->val;
  13778. + rational_value.den = 100;
  13779. +
  13780. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13781. + mmal_ctrl->mmal_id,
  13782. + &rational_value,
  13783. + sizeof(rational_value));
  13784. +}
  13785. +
  13786. +static int ctrl_set_value(struct bm2835_mmal_dev *dev,
  13787. + struct v4l2_ctrl *ctrl,
  13788. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13789. +{
  13790. + u32 u32_value;
  13791. + struct vchiq_mmal_port *control;
  13792. +
  13793. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13794. +
  13795. + u32_value = ctrl->val;
  13796. +
  13797. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13798. + mmal_ctrl->mmal_id,
  13799. + &u32_value, sizeof(u32_value));
  13800. +}
  13801. +
  13802. +static int ctrl_set_value_menu(struct bm2835_mmal_dev *dev,
  13803. + struct v4l2_ctrl *ctrl,
  13804. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13805. +{
  13806. + u32 u32_value;
  13807. + struct vchiq_mmal_port *control;
  13808. +
  13809. + if (ctrl->val > mmal_ctrl->max || ctrl->val < mmal_ctrl->min)
  13810. + return 1;
  13811. +
  13812. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13813. +
  13814. + u32_value = mmal_ctrl->imenu[ctrl->val];
  13815. +
  13816. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13817. + mmal_ctrl->mmal_id,
  13818. + &u32_value, sizeof(u32_value));
  13819. +}
  13820. +
  13821. +static int ctrl_set_value_ev(struct bm2835_mmal_dev *dev,
  13822. + struct v4l2_ctrl *ctrl,
  13823. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13824. +{
  13825. + s32 s32_value;
  13826. + struct vchiq_mmal_port *control;
  13827. +
  13828. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13829. +
  13830. + s32_value = (ctrl->val-12)*2; /* Convert from index to 1/6ths */
  13831. +
  13832. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13833. + mmal_ctrl->mmal_id,
  13834. + &s32_value, sizeof(s32_value));
  13835. +}
  13836. +
  13837. +static int ctrl_set_rotate(struct bm2835_mmal_dev *dev,
  13838. + struct v4l2_ctrl *ctrl,
  13839. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13840. +{
  13841. + int ret;
  13842. + u32 u32_value;
  13843. + struct vchiq_mmal_component *camera;
  13844. +
  13845. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  13846. +
  13847. + u32_value = ((ctrl->val % 360) / 90) * 90;
  13848. +
  13849. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  13850. + mmal_ctrl->mmal_id,
  13851. + &u32_value, sizeof(u32_value));
  13852. + if (ret < 0)
  13853. + return ret;
  13854. +
  13855. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  13856. + mmal_ctrl->mmal_id,
  13857. + &u32_value, sizeof(u32_value));
  13858. + if (ret < 0)
  13859. + return ret;
  13860. +
  13861. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  13862. + mmal_ctrl->mmal_id,
  13863. + &u32_value, sizeof(u32_value));
  13864. +
  13865. + return ret;
  13866. +}
  13867. +
  13868. +static int ctrl_set_flip(struct bm2835_mmal_dev *dev,
  13869. + struct v4l2_ctrl *ctrl,
  13870. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13871. +{
  13872. + int ret;
  13873. + u32 u32_value;
  13874. + struct vchiq_mmal_component *camera;
  13875. +
  13876. + if (ctrl->id == V4L2_CID_HFLIP)
  13877. + dev->hflip = ctrl->val;
  13878. + else
  13879. + dev->vflip = ctrl->val;
  13880. +
  13881. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  13882. +
  13883. + if (dev->hflip && dev->vflip)
  13884. + u32_value = MMAL_PARAM_MIRROR_BOTH;
  13885. + else if (dev->hflip)
  13886. + u32_value = MMAL_PARAM_MIRROR_HORIZONTAL;
  13887. + else if (dev->vflip)
  13888. + u32_value = MMAL_PARAM_MIRROR_VERTICAL;
  13889. + else
  13890. + u32_value = MMAL_PARAM_MIRROR_NONE;
  13891. +
  13892. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  13893. + mmal_ctrl->mmal_id,
  13894. + &u32_value, sizeof(u32_value));
  13895. + if (ret < 0)
  13896. + return ret;
  13897. +
  13898. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  13899. + mmal_ctrl->mmal_id,
  13900. + &u32_value, sizeof(u32_value));
  13901. + if (ret < 0)
  13902. + return ret;
  13903. +
  13904. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  13905. + mmal_ctrl->mmal_id,
  13906. + &u32_value, sizeof(u32_value));
  13907. +
  13908. + return ret;
  13909. +
  13910. +}
  13911. +
  13912. +static int ctrl_set_exposure(struct bm2835_mmal_dev *dev,
  13913. + struct v4l2_ctrl *ctrl,
  13914. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13915. +{
  13916. + enum mmal_parameter_exposuremode exp_mode = dev->exposure_mode;
  13917. + u32 shutter_speed = 0;
  13918. + struct vchiq_mmal_port *control;
  13919. + int ret = 0;
  13920. +
  13921. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13922. +
  13923. + if (mmal_ctrl->mmal_id == MMAL_PARAMETER_SHUTTER_SPEED) {
  13924. + /* V4L2 is in 100usec increments.
  13925. + * MMAL is 1usec.
  13926. + */
  13927. + dev->manual_shutter_speed = ctrl->val * 100;
  13928. + } else if (mmal_ctrl->mmal_id == MMAL_PARAMETER_EXPOSURE_MODE) {
  13929. + switch (ctrl->val) {
  13930. + case V4L2_EXPOSURE_AUTO:
  13931. + exp_mode = MMAL_PARAM_EXPOSUREMODE_AUTO;
  13932. + break;
  13933. +
  13934. + case V4L2_EXPOSURE_MANUAL:
  13935. + exp_mode = MMAL_PARAM_EXPOSUREMODE_OFF;
  13936. + break;
  13937. +
  13938. + case V4L2_EXPOSURE_SHUTTER_PRIORITY:
  13939. + exp_mode = MMAL_PARAM_EXPOSUREMODE_SPORTS;
  13940. + break;
  13941. +
  13942. + case V4L2_EXPOSURE_APERTURE_PRIORITY:
  13943. + exp_mode = MMAL_PARAM_EXPOSUREMODE_NIGHT;
  13944. + break;
  13945. +
  13946. + }
  13947. + dev->exposure_mode = exp_mode;
  13948. + }
  13949. +
  13950. + if (dev->exposure_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  13951. + shutter_speed = dev->manual_shutter_speed;
  13952. +
  13953. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  13954. + MMAL_PARAMETER_SHUTTER_SPEED,
  13955. + &shutter_speed, sizeof(shutter_speed));
  13956. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  13957. + MMAL_PARAMETER_EXPOSURE_MODE,
  13958. + &exp_mode, sizeof(u32));
  13959. + return ret;
  13960. +}
  13961. +
  13962. +static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev,
  13963. + struct v4l2_ctrl *ctrl,
  13964. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13965. +{
  13966. + u32 u32_value;
  13967. + struct vchiq_mmal_port *control;
  13968. +
  13969. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13970. +
  13971. + switch (ctrl->val) {
  13972. + case V4L2_EXPOSURE_METERING_AVERAGE:
  13973. + u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
  13974. + break;
  13975. +
  13976. + case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
  13977. + u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT;
  13978. + break;
  13979. +
  13980. + case V4L2_EXPOSURE_METERING_SPOT:
  13981. + u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT;
  13982. + break;
  13983. +
  13984. + /* todo matrix weighting not added to Linux API till 3.9
  13985. + case V4L2_EXPOSURE_METERING_MATRIX:
  13986. + u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX;
  13987. + break;
  13988. + */
  13989. +
  13990. + }
  13991. +
  13992. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13993. + mmal_ctrl->mmal_id,
  13994. + &u32_value, sizeof(u32_value));
  13995. +}
  13996. +
  13997. +static int ctrl_set_flicker_avoidance(struct bm2835_mmal_dev *dev,
  13998. + struct v4l2_ctrl *ctrl,
  13999. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14000. +{
  14001. + u32 u32_value;
  14002. + struct vchiq_mmal_port *control;
  14003. +
  14004. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14005. +
  14006. + switch (ctrl->val) {
  14007. + case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
  14008. + u32_value = MMAL_PARAM_FLICKERAVOID_OFF;
  14009. + break;
  14010. + case V4L2_CID_POWER_LINE_FREQUENCY_50HZ:
  14011. + u32_value = MMAL_PARAM_FLICKERAVOID_50HZ;
  14012. + break;
  14013. + case V4L2_CID_POWER_LINE_FREQUENCY_60HZ:
  14014. + u32_value = MMAL_PARAM_FLICKERAVOID_60HZ;
  14015. + break;
  14016. + case V4L2_CID_POWER_LINE_FREQUENCY_AUTO:
  14017. + u32_value = MMAL_PARAM_FLICKERAVOID_AUTO;
  14018. + break;
  14019. + }
  14020. +
  14021. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  14022. + mmal_ctrl->mmal_id,
  14023. + &u32_value, sizeof(u32_value));
  14024. +}
  14025. +
  14026. +static int ctrl_set_awb_mode(struct bm2835_mmal_dev *dev,
  14027. + struct v4l2_ctrl *ctrl,
  14028. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14029. +{
  14030. + u32 u32_value;
  14031. + struct vchiq_mmal_port *control;
  14032. +
  14033. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14034. +
  14035. + switch (ctrl->val) {
  14036. + case V4L2_WHITE_BALANCE_MANUAL:
  14037. + u32_value = MMAL_PARAM_AWBMODE_OFF;
  14038. + break;
  14039. +
  14040. + case V4L2_WHITE_BALANCE_AUTO:
  14041. + u32_value = MMAL_PARAM_AWBMODE_AUTO;
  14042. + break;
  14043. +
  14044. + case V4L2_WHITE_BALANCE_INCANDESCENT:
  14045. + u32_value = MMAL_PARAM_AWBMODE_INCANDESCENT;
  14046. + break;
  14047. +
  14048. + case V4L2_WHITE_BALANCE_FLUORESCENT:
  14049. + u32_value = MMAL_PARAM_AWBMODE_FLUORESCENT;
  14050. + break;
  14051. +
  14052. + case V4L2_WHITE_BALANCE_FLUORESCENT_H:
  14053. + u32_value = MMAL_PARAM_AWBMODE_TUNGSTEN;
  14054. + break;
  14055. +
  14056. + case V4L2_WHITE_BALANCE_HORIZON:
  14057. + u32_value = MMAL_PARAM_AWBMODE_HORIZON;
  14058. + break;
  14059. +
  14060. + case V4L2_WHITE_BALANCE_DAYLIGHT:
  14061. + u32_value = MMAL_PARAM_AWBMODE_SUNLIGHT;
  14062. + break;
  14063. +
  14064. + case V4L2_WHITE_BALANCE_FLASH:
  14065. + u32_value = MMAL_PARAM_AWBMODE_FLASH;
  14066. + break;
  14067. +
  14068. + case V4L2_WHITE_BALANCE_CLOUDY:
  14069. + u32_value = MMAL_PARAM_AWBMODE_CLOUDY;
  14070. + break;
  14071. +
  14072. + case V4L2_WHITE_BALANCE_SHADE:
  14073. + u32_value = MMAL_PARAM_AWBMODE_SHADE;
  14074. + break;
  14075. +
  14076. + }
  14077. +
  14078. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  14079. + mmal_ctrl->mmal_id,
  14080. + &u32_value, sizeof(u32_value));
  14081. +}
  14082. +
  14083. +static int ctrl_set_image_effect(struct bm2835_mmal_dev *dev,
  14084. + struct v4l2_ctrl *ctrl,
  14085. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14086. +{
  14087. + int ret = -EINVAL;
  14088. + int i, j;
  14089. + struct vchiq_mmal_port *control;
  14090. + struct mmal_parameter_imagefx_parameters imagefx;
  14091. +
  14092. + for (i = 0; i < ARRAY_SIZE(v4l2_to_mmal_effects_values); i++) {
  14093. + if (ctrl->val == v4l2_to_mmal_effects_values[i].v4l2_effect) {
  14094. +
  14095. + imagefx.effect =
  14096. + v4l2_to_mmal_effects_values[i].mmal_effect;
  14097. + imagefx.num_effect_params =
  14098. + v4l2_to_mmal_effects_values[i].num_effect_params;
  14099. +
  14100. + if (imagefx.num_effect_params > MMAL_MAX_IMAGEFX_PARAMETERS)
  14101. + imagefx.num_effect_params = MMAL_MAX_IMAGEFX_PARAMETERS;
  14102. +
  14103. + for (j = 0; j < imagefx.num_effect_params; j++)
  14104. + imagefx.effect_parameter[j] =
  14105. + v4l2_to_mmal_effects_values[i].effect_params[j];
  14106. +
  14107. + dev->colourfx.enable =
  14108. + v4l2_to_mmal_effects_values[i].col_fx_enable;
  14109. + if (!v4l2_to_mmal_effects_values[i].col_fx_fixed_cbcr) {
  14110. + dev->colourfx.u =
  14111. + v4l2_to_mmal_effects_values[i].u;
  14112. + dev->colourfx.v =
  14113. + v4l2_to_mmal_effects_values[i].v;
  14114. + }
  14115. +
  14116. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14117. +
  14118. + ret = vchiq_mmal_port_parameter_set(
  14119. + dev->instance, control,
  14120. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  14121. + &imagefx, sizeof(imagefx));
  14122. + if (ret)
  14123. + goto exit;
  14124. +
  14125. + ret = vchiq_mmal_port_parameter_set(
  14126. + dev->instance, control,
  14127. + MMAL_PARAMETER_COLOUR_EFFECT,
  14128. + &dev->colourfx, sizeof(dev->colourfx));
  14129. + }
  14130. + }
  14131. +
  14132. +exit:
  14133. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14134. + "mmal_ctrl:%p ctrl id:0x%x ctrl val:%d imagefx:0x%x color_effect:%s u:%d v:%d ret %d(%d)\n",
  14135. + mmal_ctrl, ctrl->id, ctrl->val, imagefx.effect,
  14136. + dev->colourfx.enable ? "true" : "false",
  14137. + dev->colourfx.u, dev->colourfx.v,
  14138. + ret, (ret == 0 ? 0 : -EINVAL));
  14139. + return (ret == 0 ? 0 : EINVAL);
  14140. +}
  14141. +
  14142. +static int ctrl_set_colfx(struct bm2835_mmal_dev *dev,
  14143. + struct v4l2_ctrl *ctrl,
  14144. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14145. +{
  14146. + int ret = -EINVAL;
  14147. + struct vchiq_mmal_port *control;
  14148. +
  14149. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  14150. +
  14151. + dev->colourfx.enable = (ctrl->val & 0xff00) >> 8;
  14152. + dev->colourfx.enable = ctrl->val & 0xff;
  14153. +
  14154. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  14155. + MMAL_PARAMETER_COLOUR_EFFECT,
  14156. + &dev->colourfx, sizeof(dev->colourfx));
  14157. +
  14158. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  14159. + "After: mmal_ctrl:%p ctrl id:0x%x ctrl val:%d ret %d(%d)\n",
  14160. + mmal_ctrl, ctrl->id, ctrl->val, ret,
  14161. + (ret == 0 ? 0 : -EINVAL));
  14162. + return (ret == 0 ? 0 : EINVAL);
  14163. +}
  14164. +
  14165. +static int ctrl_set_bitrate(struct bm2835_mmal_dev *dev,
  14166. + struct v4l2_ctrl *ctrl,
  14167. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14168. +{
  14169. + int ret;
  14170. + struct vchiq_mmal_port *encoder_out;
  14171. +
  14172. + dev->capture.encode_bitrate = ctrl->val;
  14173. +
  14174. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  14175. +
  14176. + ret = vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  14177. + mmal_ctrl->mmal_id,
  14178. + &ctrl->val, sizeof(ctrl->val));
  14179. + ret = 0;
  14180. + return ret;
  14181. +}
  14182. +
  14183. +static int ctrl_set_bitrate_mode(struct bm2835_mmal_dev *dev,
  14184. + struct v4l2_ctrl *ctrl,
  14185. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14186. +{
  14187. + u32 bitrate_mode;
  14188. + struct vchiq_mmal_port *encoder_out;
  14189. +
  14190. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  14191. +
  14192. + dev->capture.encode_bitrate_mode = ctrl->val;
  14193. + switch (ctrl->val) {
  14194. + default:
  14195. + case V4L2_MPEG_VIDEO_BITRATE_MODE_VBR:
  14196. + bitrate_mode = MMAL_VIDEO_RATECONTROL_VARIABLE;
  14197. + break;
  14198. + case V4L2_MPEG_VIDEO_BITRATE_MODE_CBR:
  14199. + bitrate_mode = MMAL_VIDEO_RATECONTROL_CONSTANT;
  14200. + break;
  14201. + }
  14202. +
  14203. + vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  14204. + mmal_ctrl->mmal_id,
  14205. + &bitrate_mode,
  14206. + sizeof(bitrate_mode));
  14207. + return 0;
  14208. +}
  14209. +
  14210. +static int ctrl_set_image_encode_output(struct bm2835_mmal_dev *dev,
  14211. + struct v4l2_ctrl *ctrl,
  14212. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14213. +{
  14214. + u32 u32_value;
  14215. + struct vchiq_mmal_port *jpeg_out;
  14216. +
  14217. + jpeg_out = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  14218. +
  14219. + u32_value = ctrl->val;
  14220. +
  14221. + return vchiq_mmal_port_parameter_set(dev->instance, jpeg_out,
  14222. + mmal_ctrl->mmal_id,
  14223. + &u32_value, sizeof(u32_value));
  14224. +}
  14225. +
  14226. +static int ctrl_set_video_encode_param_output(struct bm2835_mmal_dev *dev,
  14227. + struct v4l2_ctrl *ctrl,
  14228. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  14229. +{
  14230. + u32 u32_value;
  14231. + struct vchiq_mmal_port *vid_enc_ctl;
  14232. +
  14233. + vid_enc_ctl = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  14234. +
  14235. + u32_value = ctrl->val;
  14236. +
  14237. + return vchiq_mmal_port_parameter_set(dev->instance, vid_enc_ctl,
  14238. + mmal_ctrl->mmal_id,
  14239. + &u32_value, sizeof(u32_value));
  14240. +}
  14241. +
  14242. +static int bm2835_mmal_s_ctrl(struct v4l2_ctrl *ctrl)
  14243. +{
  14244. + struct bm2835_mmal_dev *dev =
  14245. + container_of(ctrl->handler, struct bm2835_mmal_dev,
  14246. + ctrl_handler);
  14247. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl = ctrl->priv;
  14248. + int ret;
  14249. +
  14250. + if ((mmal_ctrl == NULL) ||
  14251. + (mmal_ctrl->id != ctrl->id) ||
  14252. + (mmal_ctrl->setter == NULL)) {
  14253. + pr_warn("mmal_ctrl:%p ctrl id:%d\n", mmal_ctrl, ctrl->id);
  14254. + return -EINVAL;
  14255. + }
  14256. +
  14257. + ret = mmal_ctrl->setter(dev, ctrl, mmal_ctrl);
  14258. + if (mmal_ctrl->ignore_errors)
  14259. + ret = 0;
  14260. + return ret;
  14261. +}
  14262. +
  14263. +static const struct v4l2_ctrl_ops bm2835_mmal_ctrl_ops = {
  14264. + .s_ctrl = bm2835_mmal_s_ctrl,
  14265. +};
  14266. +
  14267. +
  14268. +
  14269. +static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
  14270. + {
  14271. + V4L2_CID_SATURATION, MMAL_CONTROL_TYPE_STD,
  14272. + -100, 100, 0, 1, NULL,
  14273. + MMAL_PARAMETER_SATURATION,
  14274. + &ctrl_set_rational,
  14275. + false
  14276. + },
  14277. + {
  14278. + V4L2_CID_SHARPNESS, MMAL_CONTROL_TYPE_STD,
  14279. + -100, 100, 0, 1, NULL,
  14280. + MMAL_PARAMETER_SHARPNESS,
  14281. + &ctrl_set_rational,
  14282. + false
  14283. + },
  14284. + {
  14285. + V4L2_CID_CONTRAST, MMAL_CONTROL_TYPE_STD,
  14286. + -100, 100, 0, 1, NULL,
  14287. + MMAL_PARAMETER_CONTRAST,
  14288. + &ctrl_set_rational,
  14289. + false
  14290. + },
  14291. + {
  14292. + V4L2_CID_BRIGHTNESS, MMAL_CONTROL_TYPE_STD,
  14293. + 0, 100, 50, 1, NULL,
  14294. + MMAL_PARAMETER_BRIGHTNESS,
  14295. + &ctrl_set_rational,
  14296. + false
  14297. + },
  14298. + {
  14299. + V4L2_CID_ISO_SENSITIVITY, MMAL_CONTROL_TYPE_INT_MENU,
  14300. + 0, ARRAY_SIZE(iso_qmenu) - 1, 0, 1, iso_qmenu,
  14301. + MMAL_PARAMETER_ISO,
  14302. + &ctrl_set_value_menu,
  14303. + false
  14304. + },
  14305. + {
  14306. + V4L2_CID_IMAGE_STABILIZATION, MMAL_CONTROL_TYPE_STD,
  14307. + 0, 1, 0, 1, NULL,
  14308. + MMAL_PARAMETER_VIDEO_STABILISATION,
  14309. + &ctrl_set_value,
  14310. + false
  14311. + },
  14312. +/* {
  14313. + 0, MMAL_CONTROL_TYPE_CLUSTER, 3, 1, 0, NULL, 0, NULL
  14314. + },
  14315. +*/ {
  14316. + V4L2_CID_EXPOSURE_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
  14317. + ~0x03, 3, V4L2_EXPOSURE_AUTO, 0, NULL,
  14318. + MMAL_PARAMETER_EXPOSURE_MODE,
  14319. + &ctrl_set_exposure,
  14320. + false
  14321. + },
  14322. +/* todo this needs mixing in with set exposure
  14323. + {
  14324. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  14325. + },
  14326. + */
  14327. + {
  14328. + V4L2_CID_EXPOSURE_ABSOLUTE, MMAL_CONTROL_TYPE_STD,
  14329. + /* Units of 100usecs */
  14330. + 1, 1*1000*10, 100*10, 1, NULL,
  14331. + MMAL_PARAMETER_SHUTTER_SPEED,
  14332. + &ctrl_set_exposure,
  14333. + false
  14334. + },
  14335. + {
  14336. + V4L2_CID_AUTO_EXPOSURE_BIAS, MMAL_CONTROL_TYPE_INT_MENU,
  14337. + 0, ARRAY_SIZE(ev_bias_qmenu) - 1,
  14338. + (ARRAY_SIZE(ev_bias_qmenu)+1)/2 - 1, 0, ev_bias_qmenu,
  14339. + MMAL_PARAMETER_EXPOSURE_COMP,
  14340. + &ctrl_set_value_ev,
  14341. + false
  14342. + },
  14343. + {
  14344. + V4L2_CID_EXPOSURE_METERING,
  14345. + MMAL_CONTROL_TYPE_STD_MENU,
  14346. + ~0x7, 2, V4L2_EXPOSURE_METERING_AVERAGE, 0, NULL,
  14347. + MMAL_PARAMETER_EXP_METERING_MODE,
  14348. + &ctrl_set_metering_mode,
  14349. + false
  14350. + },
  14351. + {
  14352. + V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
  14353. + MMAL_CONTROL_TYPE_STD_MENU,
  14354. + ~0x3fe, 9, V4L2_WHITE_BALANCE_AUTO, 0, NULL,
  14355. + MMAL_PARAMETER_AWB_MODE,
  14356. + &ctrl_set_awb_mode,
  14357. + false
  14358. + },
  14359. + {
  14360. + V4L2_CID_COLORFX, MMAL_CONTROL_TYPE_STD_MENU,
  14361. + 0, 15, V4L2_COLORFX_NONE, 0, NULL,
  14362. + MMAL_PARAMETER_IMAGE_EFFECT,
  14363. + &ctrl_set_image_effect,
  14364. + false
  14365. + },
  14366. + {
  14367. + V4L2_CID_COLORFX_CBCR, MMAL_CONTROL_TYPE_STD,
  14368. + 0, 0xffff, 0x8080, 1, NULL,
  14369. + MMAL_PARAMETER_COLOUR_EFFECT,
  14370. + &ctrl_set_colfx,
  14371. + false
  14372. + },
  14373. + {
  14374. + V4L2_CID_ROTATE, MMAL_CONTROL_TYPE_STD,
  14375. + 0, 360, 0, 90, NULL,
  14376. + MMAL_PARAMETER_ROTATION,
  14377. + &ctrl_set_rotate,
  14378. + false
  14379. + },
  14380. + {
  14381. + V4L2_CID_HFLIP, MMAL_CONTROL_TYPE_STD,
  14382. + 0, 1, 0, 1, NULL,
  14383. + MMAL_PARAMETER_MIRROR,
  14384. + &ctrl_set_flip,
  14385. + false
  14386. + },
  14387. + {
  14388. + V4L2_CID_VFLIP, MMAL_CONTROL_TYPE_STD,
  14389. + 0, 1, 0, 1, NULL,
  14390. + MMAL_PARAMETER_MIRROR,
  14391. + &ctrl_set_flip,
  14392. + false
  14393. + },
  14394. + {
  14395. + V4L2_CID_MPEG_VIDEO_BITRATE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  14396. + 0, ARRAY_SIZE(bitrate_mode_qmenu) - 1,
  14397. + 0, 0, bitrate_mode_qmenu,
  14398. + MMAL_PARAMETER_RATECONTROL,
  14399. + &ctrl_set_bitrate_mode,
  14400. + false
  14401. + },
  14402. + {
  14403. + V4L2_CID_MPEG_VIDEO_BITRATE, MMAL_CONTROL_TYPE_STD,
  14404. + 25*1000, 25*1000*1000, 10*1000*1000, 25*1000, NULL,
  14405. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  14406. + &ctrl_set_bitrate,
  14407. + false
  14408. + },
  14409. + {
  14410. + V4L2_CID_JPEG_COMPRESSION_QUALITY, MMAL_CONTROL_TYPE_STD,
  14411. + 1, 100,
  14412. + 30, 1, NULL,
  14413. + MMAL_PARAMETER_JPEG_Q_FACTOR,
  14414. + &ctrl_set_image_encode_output,
  14415. + false
  14416. + },
  14417. + {
  14418. + V4L2_CID_POWER_LINE_FREQUENCY, MMAL_CONTROL_TYPE_STD_MENU,
  14419. + 0, ARRAY_SIZE(mains_freq_qmenu) - 1,
  14420. + 1, 1, NULL,
  14421. + MMAL_PARAMETER_FLICKER_AVOID,
  14422. + &ctrl_set_flicker_avoidance,
  14423. + false
  14424. + },
  14425. + {
  14426. + V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, MMAL_CONTROL_TYPE_STD,
  14427. + 0, 1,
  14428. + 0, 1, NULL,
  14429. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER,
  14430. + &ctrl_set_video_encode_param_output,
  14431. + true /* Errors ignored as requires latest firmware to work */
  14432. + },
  14433. +};
  14434. +
  14435. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev)
  14436. +{
  14437. + int c;
  14438. + int ret = 0;
  14439. +
  14440. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  14441. + if ((dev->ctrls[c]) && (v4l2_ctrls[c].setter)) {
  14442. + ret = v4l2_ctrls[c].setter(dev, dev->ctrls[c],
  14443. + &v4l2_ctrls[c]);
  14444. + if (!v4l2_ctrls[c]. ignore_errors && ret)
  14445. + break;
  14446. + }
  14447. + }
  14448. + return ret;
  14449. +}
  14450. +
  14451. +int bm2835_mmal_init_controls(struct bm2835_mmal_dev *dev,
  14452. + struct v4l2_ctrl_handler *hdl)
  14453. +{
  14454. + int c;
  14455. + const struct bm2835_mmal_v4l2_ctrl *ctrl;
  14456. +
  14457. + v4l2_ctrl_handler_init(hdl, V4L2_CTRL_COUNT);
  14458. +
  14459. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  14460. + ctrl = &v4l2_ctrls[c];
  14461. +
  14462. + switch (ctrl->type) {
  14463. + case MMAL_CONTROL_TYPE_STD:
  14464. + dev->ctrls[c] = v4l2_ctrl_new_std(hdl,
  14465. + &bm2835_mmal_ctrl_ops, ctrl->id,
  14466. + ctrl->min, ctrl->max, ctrl->step, ctrl->def);
  14467. + break;
  14468. +
  14469. + case MMAL_CONTROL_TYPE_STD_MENU:
  14470. + dev->ctrls[c] = v4l2_ctrl_new_std_menu(hdl,
  14471. + &bm2835_mmal_ctrl_ops, ctrl->id,
  14472. + ctrl->max, ctrl->min, ctrl->def);
  14473. + break;
  14474. +
  14475. + case MMAL_CONTROL_TYPE_INT_MENU:
  14476. + dev->ctrls[c] = v4l2_ctrl_new_int_menu(hdl,
  14477. + &bm2835_mmal_ctrl_ops, ctrl->id,
  14478. + ctrl->max, ctrl->def, ctrl->imenu);
  14479. + break;
  14480. +
  14481. + case MMAL_CONTROL_TYPE_CLUSTER:
  14482. + /* skip this entry when constructing controls */
  14483. + continue;
  14484. + }
  14485. +
  14486. + if (hdl->error)
  14487. + break;
  14488. +
  14489. + dev->ctrls[c]->priv = (void *)ctrl;
  14490. + }
  14491. +
  14492. + if (hdl->error) {
  14493. + pr_err("error adding control %d/%d id 0x%x\n", c,
  14494. + V4L2_CTRL_COUNT, ctrl->id);
  14495. + return hdl->error;
  14496. + }
  14497. +
  14498. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  14499. + ctrl = &v4l2_ctrls[c];
  14500. +
  14501. + switch (ctrl->type) {
  14502. + case MMAL_CONTROL_TYPE_CLUSTER:
  14503. + v4l2_ctrl_auto_cluster(ctrl->min,
  14504. + &dev->ctrls[c+1],
  14505. + ctrl->max,
  14506. + ctrl->def);
  14507. + break;
  14508. +
  14509. + case MMAL_CONTROL_TYPE_STD:
  14510. + case MMAL_CONTROL_TYPE_STD_MENU:
  14511. + case MMAL_CONTROL_TYPE_INT_MENU:
  14512. + break;
  14513. + }
  14514. +
  14515. + }
  14516. +
  14517. + return 0;
  14518. +}
  14519. diff -Nur linux-3.12.11.orig/drivers/media/platform/bcm2835/Kconfig linux-3.12.11/drivers/media/platform/bcm2835/Kconfig
  14520. --- linux-3.12.11.orig/drivers/media/platform/bcm2835/Kconfig 1970-01-01 01:00:00.000000000 +0100
  14521. +++ linux-3.12.11/drivers/media/platform/bcm2835/Kconfig 2014-02-18 11:52:14.000000000 +0100
  14522. @@ -0,0 +1,25 @@
  14523. +# Broadcom VideoCore IV v4l2 camera support
  14524. +
  14525. +config VIDEO_BCM2835
  14526. + bool "Broadcom BCM2835 camera interface driver"
  14527. + depends on VIDEO_V4L2 && ARCH_BCM2708
  14528. + ---help---
  14529. + Say Y here to enable camera host interface devices for
  14530. + Broadcom BCM2835 SoC. This operates over the VCHIQ interface
  14531. + to a service running on VideoCore.
  14532. +
  14533. +
  14534. +if VIDEO_BCM2835
  14535. +
  14536. +config VIDEO_BCM2835_MMAL
  14537. + tristate "Broadcom BM2835 MMAL camera interface driver"
  14538. + depends on BCM2708_VCHIQ
  14539. + select VIDEOBUF2_VMALLOC
  14540. + ---help---
  14541. + This is a V4L2 driver for the Broadcom BCM2835 MMAL camera host interface
  14542. +
  14543. + To compile this driver as a module, choose M here: the
  14544. + module will be called bcm2835-v4l2.o
  14545. +
  14546. +
  14547. +endif # VIDEO_BM2835
  14548. diff -Nur linux-3.12.11.orig/drivers/media/platform/bcm2835/Makefile linux-3.12.11/drivers/media/platform/bcm2835/Makefile
  14549. --- linux-3.12.11.orig/drivers/media/platform/bcm2835/Makefile 1970-01-01 01:00:00.000000000 +0100
  14550. +++ linux-3.12.11/drivers/media/platform/bcm2835/Makefile 2014-02-18 11:52:14.000000000 +0100
  14551. @@ -0,0 +1,5 @@
  14552. +bcm2835-v4l2-objs := bcm2835-camera.o controls.o mmal-vchiq.o
  14553. +
  14554. +obj-$(CONFIG_VIDEO_BCM2835_MMAL) += bcm2835-v4l2.o
  14555. +
  14556. +ccflags-$(CONFIG_VIDEO_BCM2835) += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  14557. diff -Nur linux-3.12.11.orig/drivers/media/platform/bcm2835/mmal-common.h linux-3.12.11/drivers/media/platform/bcm2835/mmal-common.h
  14558. --- linux-3.12.11.orig/drivers/media/platform/bcm2835/mmal-common.h 1970-01-01 01:00:00.000000000 +0100
  14559. +++ linux-3.12.11/drivers/media/platform/bcm2835/mmal-common.h 2014-02-18 11:52:14.000000000 +0100
  14560. @@ -0,0 +1,52 @@
  14561. +/*
  14562. + * Broadcom BM2835 V4L2 driver
  14563. + *
  14564. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14565. + *
  14566. + * This file is subject to the terms and conditions of the GNU General Public
  14567. + * License. See the file COPYING in the main directory of this archive
  14568. + * for more details.
  14569. + *
  14570. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14571. + * Dave Stevenson <dsteve@broadcom.com>
  14572. + * Simon Mellor <simellor@broadcom.com>
  14573. + * Luke Diamand <luked@broadcom.com>
  14574. + *
  14575. + * MMAL structures
  14576. + *
  14577. + */
  14578. +
  14579. +#define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
  14580. +#define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l')
  14581. +
  14582. +/** Special value signalling that time is not known */
  14583. +#define MMAL_TIME_UNKNOWN (1LL<<63)
  14584. +
  14585. +/* mapping between v4l and mmal video modes */
  14586. +struct mmal_fmt {
  14587. + char *name;
  14588. + u32 fourcc; /* v4l2 format id */
  14589. + u32 mmal;
  14590. + int depth;
  14591. + u32 mmal_component; /* MMAL component index to be used to encode */
  14592. +};
  14593. +
  14594. +/* buffer for one video frame */
  14595. +struct mmal_buffer {
  14596. + /* v4l buffer data -- must be first */
  14597. + struct vb2_buffer vb;
  14598. +
  14599. + /* list of buffers available */
  14600. + struct list_head list;
  14601. +
  14602. + void *buffer; /* buffer pointer */
  14603. + unsigned long buffer_size; /* size of allocated buffer */
  14604. +};
  14605. +
  14606. +/* */
  14607. +struct mmal_colourfx {
  14608. + s32 enable;
  14609. + u32 u;
  14610. + u32 v;
  14611. +};
  14612. +
  14613. diff -Nur linux-3.12.11.orig/drivers/media/platform/bcm2835/mmal-encodings.h linux-3.12.11/drivers/media/platform/bcm2835/mmal-encodings.h
  14614. --- linux-3.12.11.orig/drivers/media/platform/bcm2835/mmal-encodings.h 1970-01-01 01:00:00.000000000 +0100
  14615. +++ linux-3.12.11/drivers/media/platform/bcm2835/mmal-encodings.h 2014-02-18 11:52:14.000000000 +0100
  14616. @@ -0,0 +1,93 @@
  14617. +/*
  14618. + * Broadcom BM2835 V4L2 driver
  14619. + *
  14620. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14621. + *
  14622. + * This file is subject to the terms and conditions of the GNU General Public
  14623. + * License. See the file COPYING in the main directory of this archive
  14624. + * for more details.
  14625. + *
  14626. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14627. + * Dave Stevenson <dsteve@broadcom.com>
  14628. + * Simon Mellor <simellor@broadcom.com>
  14629. + * Luke Diamand <luked@broadcom.com>
  14630. + */
  14631. +
  14632. +#define MMAL_ENCODING_H264 MMAL_FOURCC('H', '2', '6', '4')
  14633. +#define MMAL_ENCODING_H263 MMAL_FOURCC('H', '2', '6', '3')
  14634. +#define MMAL_ENCODING_MP4V MMAL_FOURCC('M', 'P', '4', 'V')
  14635. +#define MMAL_ENCODING_MP2V MMAL_FOURCC('M', 'P', '2', 'V')
  14636. +#define MMAL_ENCODING_MP1V MMAL_FOURCC('M', 'P', '1', 'V')
  14637. +#define MMAL_ENCODING_WMV3 MMAL_FOURCC('W', 'M', 'V', '3')
  14638. +#define MMAL_ENCODING_WMV2 MMAL_FOURCC('W', 'M', 'V', '2')
  14639. +#define MMAL_ENCODING_WMV1 MMAL_FOURCC('W', 'M', 'V', '1')
  14640. +#define MMAL_ENCODING_WVC1 MMAL_FOURCC('W', 'V', 'C', '1')
  14641. +#define MMAL_ENCODING_VP8 MMAL_FOURCC('V', 'P', '8', ' ')
  14642. +#define MMAL_ENCODING_VP7 MMAL_FOURCC('V', 'P', '7', ' ')
  14643. +#define MMAL_ENCODING_VP6 MMAL_FOURCC('V', 'P', '6', ' ')
  14644. +#define MMAL_ENCODING_THEORA MMAL_FOURCC('T', 'H', 'E', 'O')
  14645. +#define MMAL_ENCODING_SPARK MMAL_FOURCC('S', 'P', 'R', 'K')
  14646. +
  14647. +#define MMAL_ENCODING_JPEG MMAL_FOURCC('J', 'P', 'E', 'G')
  14648. +#define MMAL_ENCODING_GIF MMAL_FOURCC('G', 'I', 'F', ' ')
  14649. +#define MMAL_ENCODING_PNG MMAL_FOURCC('P', 'N', 'G', ' ')
  14650. +#define MMAL_ENCODING_PPM MMAL_FOURCC('P', 'P', 'M', ' ')
  14651. +#define MMAL_ENCODING_TGA MMAL_FOURCC('T', 'G', 'A', ' ')
  14652. +#define MMAL_ENCODING_BMP MMAL_FOURCC('B', 'M', 'P', ' ')
  14653. +
  14654. +#define MMAL_ENCODING_I420 MMAL_FOURCC('I', '4', '2', '0')
  14655. +#define MMAL_ENCODING_I420_SLICE MMAL_FOURCC('S', '4', '2', '0')
  14656. +#define MMAL_ENCODING_YV12 MMAL_FOURCC('Y', 'V', '1', '2')
  14657. +#define MMAL_ENCODING_I422 MMAL_FOURCC('I', '4', '2', '2')
  14658. +#define MMAL_ENCODING_I422_SLICE MMAL_FOURCC('S', '4', '2', '2')
  14659. +#define MMAL_ENCODING_YUYV MMAL_FOURCC('Y', 'U', 'Y', 'V')
  14660. +#define MMAL_ENCODING_YVYU MMAL_FOURCC('Y', 'V', 'Y', 'U')
  14661. +#define MMAL_ENCODING_UYVY MMAL_FOURCC('U', 'Y', 'V', 'Y')
  14662. +#define MMAL_ENCODING_VYUY MMAL_FOURCC('V', 'Y', 'U', 'Y')
  14663. +#define MMAL_ENCODING_NV12 MMAL_FOURCC('N', 'V', '1', '2')
  14664. +#define MMAL_ENCODING_NV21 MMAL_FOURCC('N', 'V', '2', '1')
  14665. +#define MMAL_ENCODING_ARGB MMAL_FOURCC('A', 'R', 'G', 'B')
  14666. +#define MMAL_ENCODING_RGBA MMAL_FOURCC('R', 'G', 'B', 'A')
  14667. +#define MMAL_ENCODING_ABGR MMAL_FOURCC('A', 'B', 'G', 'R')
  14668. +#define MMAL_ENCODING_BGRA MMAL_FOURCC('B', 'G', 'R', 'A')
  14669. +#define MMAL_ENCODING_RGB16 MMAL_FOURCC('R', 'G', 'B', '2')
  14670. +#define MMAL_ENCODING_RGB24 MMAL_FOURCC('R', 'G', 'B', '3')
  14671. +#define MMAL_ENCODING_RGB32 MMAL_FOURCC('R', 'G', 'B', '4')
  14672. +#define MMAL_ENCODING_BGR16 MMAL_FOURCC('B', 'G', 'R', '2')
  14673. +#define MMAL_ENCODING_BGR24 MMAL_FOURCC('B', 'G', 'R', '3')
  14674. +#define MMAL_ENCODING_BGR32 MMAL_FOURCC('B', 'G', 'R', '4')
  14675. +
  14676. +/** SAND Video (YUVUV128) format, native format understood by VideoCore.
  14677. + * This format is *not* opaque - if requested you will receive full frames
  14678. + * of YUV_UV video.
  14679. + */
  14680. +#define MMAL_ENCODING_YUVUV128 MMAL_FOURCC('S', 'A', 'N', 'D')
  14681. +
  14682. +/** VideoCore opaque image format, image handles are returned to
  14683. + * the host but not the actual image data.
  14684. + */
  14685. +#define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V')
  14686. +
  14687. +/** An EGL image handle
  14688. + */
  14689. +#define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I')
  14690. +
  14691. +/* }@ */
  14692. +
  14693. +/** \name Pre-defined audio encodings */
  14694. +/* @{ */
  14695. +#define MMAL_ENCODING_PCM_UNSIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'U')
  14696. +#define MMAL_ENCODING_PCM_UNSIGNED_LE MMAL_FOURCC('p', 'c', 'm', 'u')
  14697. +#define MMAL_ENCODING_PCM_SIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'S')
  14698. +#define MMAL_ENCODING_PCM_SIGNED_LE MMAL_FOURCC('p', 'c', 'm', 's')
  14699. +#define MMAL_ENCODING_PCM_FLOAT_BE MMAL_FOURCC('P', 'C', 'M', 'F')
  14700. +#define MMAL_ENCODING_PCM_FLOAT_LE MMAL_FOURCC('p', 'c', 'm', 'f')
  14701. +
  14702. +/* Pre-defined H264 encoding variants */
  14703. +
  14704. +/** ISO 14496-10 Annex B byte stream format */
  14705. +#define MMAL_ENCODING_VARIANT_H264_DEFAULT 0
  14706. +/** ISO 14496-15 AVC stream format */
  14707. +#define MMAL_ENCODING_VARIANT_H264_AVC1 MMAL_FOURCC('A', 'V', 'C', '1')
  14708. +/** Implicitly delineated NAL units without emulation prevention */
  14709. +#define MMAL_ENCODING_VARIANT_H264_RAW MMAL_FOURCC('R', 'A', 'W', ' ')
  14710. diff -Nur linux-3.12.11.orig/drivers/media/platform/bcm2835/mmal-msg-common.h linux-3.12.11/drivers/media/platform/bcm2835/mmal-msg-common.h
  14711. --- linux-3.12.11.orig/drivers/media/platform/bcm2835/mmal-msg-common.h 1970-01-01 01:00:00.000000000 +0100
  14712. +++ linux-3.12.11/drivers/media/platform/bcm2835/mmal-msg-common.h 2014-02-18 11:52:14.000000000 +0100
  14713. @@ -0,0 +1,50 @@
  14714. +/*
  14715. + * Broadcom BM2835 V4L2 driver
  14716. + *
  14717. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14718. + *
  14719. + * This file is subject to the terms and conditions of the GNU General Public
  14720. + * License. See the file COPYING in the main directory of this archive
  14721. + * for more details.
  14722. + *
  14723. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14724. + * Dave Stevenson <dsteve@broadcom.com>
  14725. + * Simon Mellor <simellor@broadcom.com>
  14726. + * Luke Diamand <luked@broadcom.com>
  14727. + */
  14728. +
  14729. +#ifndef MMAL_MSG_COMMON_H
  14730. +#define MMAL_MSG_COMMON_H
  14731. +
  14732. +enum mmal_msg_status {
  14733. + MMAL_MSG_STATUS_SUCCESS = 0, /**< Success */
  14734. + MMAL_MSG_STATUS_ENOMEM, /**< Out of memory */
  14735. + MMAL_MSG_STATUS_ENOSPC, /**< Out of resources other than memory */
  14736. + MMAL_MSG_STATUS_EINVAL, /**< Argument is invalid */
  14737. + MMAL_MSG_STATUS_ENOSYS, /**< Function not implemented */
  14738. + MMAL_MSG_STATUS_ENOENT, /**< No such file or directory */
  14739. + MMAL_MSG_STATUS_ENXIO, /**< No such device or address */
  14740. + MMAL_MSG_STATUS_EIO, /**< I/O error */
  14741. + MMAL_MSG_STATUS_ESPIPE, /**< Illegal seek */
  14742. + MMAL_MSG_STATUS_ECORRUPT, /**< Data is corrupt \attention */
  14743. + MMAL_MSG_STATUS_ENOTREADY, /**< Component is not ready */
  14744. + MMAL_MSG_STATUS_ECONFIG, /**< Component is not configured */
  14745. + MMAL_MSG_STATUS_EISCONN, /**< Port is already connected */
  14746. + MMAL_MSG_STATUS_ENOTCONN, /**< Port is disconnected */
  14747. + MMAL_MSG_STATUS_EAGAIN, /**< Resource temporarily unavailable. */
  14748. + MMAL_MSG_STATUS_EFAULT, /**< Bad address */
  14749. +};
  14750. +
  14751. +struct mmal_rect {
  14752. + s32 x; /**< x coordinate (from left) */
  14753. + s32 y; /**< y coordinate (from top) */
  14754. + s32 width; /**< width */
  14755. + s32 height; /**< height */
  14756. +};
  14757. +
  14758. +struct mmal_rational {
  14759. + s32 num; /**< Numerator */
  14760. + s32 den; /**< Denominator */
  14761. +};
  14762. +
  14763. +#endif /* MMAL_MSG_COMMON_H */
  14764. diff -Nur linux-3.12.11.orig/drivers/media/platform/bcm2835/mmal-msg-format.h linux-3.12.11/drivers/media/platform/bcm2835/mmal-msg-format.h
  14765. --- linux-3.12.11.orig/drivers/media/platform/bcm2835/mmal-msg-format.h 1970-01-01 01:00:00.000000000 +0100
  14766. +++ linux-3.12.11/drivers/media/platform/bcm2835/mmal-msg-format.h 2014-02-18 11:52:14.000000000 +0100
  14767. @@ -0,0 +1,81 @@
  14768. +/*
  14769. + * Broadcom BM2835 V4L2 driver
  14770. + *
  14771. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14772. + *
  14773. + * This file is subject to the terms and conditions of the GNU General Public
  14774. + * License. See the file COPYING in the main directory of this archive
  14775. + * for more details.
  14776. + *
  14777. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14778. + * Dave Stevenson <dsteve@broadcom.com>
  14779. + * Simon Mellor <simellor@broadcom.com>
  14780. + * Luke Diamand <luked@broadcom.com>
  14781. + */
  14782. +
  14783. +#ifndef MMAL_MSG_FORMAT_H
  14784. +#define MMAL_MSG_FORMAT_H
  14785. +
  14786. +#include "mmal-msg-common.h"
  14787. +
  14788. +/* MMAL_ES_FORMAT_T */
  14789. +
  14790. +
  14791. +struct mmal_audio_format {
  14792. + u32 channels; /**< Number of audio channels */
  14793. + u32 sample_rate; /**< Sample rate */
  14794. +
  14795. + u32 bits_per_sample; /**< Bits per sample */
  14796. + u32 block_align; /**< Size of a block of data */
  14797. +};
  14798. +
  14799. +struct mmal_video_format {
  14800. + u32 width; /**< Width of frame in pixels */
  14801. + u32 height; /**< Height of frame in rows of pixels */
  14802. + struct mmal_rect crop; /**< Visible region of the frame */
  14803. + struct mmal_rational frame_rate; /**< Frame rate */
  14804. + struct mmal_rational par; /**< Pixel aspect ratio */
  14805. +
  14806. + /* FourCC specifying the color space of the video stream. See the
  14807. + * \ref MmalColorSpace "pre-defined color spaces" for some examples.
  14808. + */
  14809. + u32 color_space;
  14810. +};
  14811. +
  14812. +struct mmal_subpicture_format {
  14813. + u32 x_offset;
  14814. + u32 y_offset;
  14815. +};
  14816. +
  14817. +union mmal_es_specific_format {
  14818. + struct mmal_audio_format audio;
  14819. + struct mmal_video_format video;
  14820. + struct mmal_subpicture_format subpicture;
  14821. +};
  14822. +
  14823. +/** Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
  14824. +struct mmal_es_format {
  14825. + u32 type; /* enum mmal_es_type */
  14826. +
  14827. + u32 encoding; /* FourCC specifying encoding of the elementary stream.*/
  14828. + u32 encoding_variant; /* FourCC specifying the specific
  14829. + * encoding variant of the elementary
  14830. + * stream.
  14831. + */
  14832. +
  14833. + union mmal_es_specific_format *es; /* TODO: pointers in
  14834. + * message serialisation?!?
  14835. + */
  14836. + /* Type specific
  14837. + * information for the
  14838. + * elementary stream
  14839. + */
  14840. +
  14841. + u32 bitrate; /**< Bitrate in bits per second */
  14842. + u32 flags; /**< Flags describing properties of the elementary stream. */
  14843. +
  14844. + u32 extradata_size; /**< Size of the codec specific data */
  14845. + u8 *extradata; /**< Codec specific data */
  14846. +};
  14847. +
  14848. +#endif /* MMAL_MSG_FORMAT_H */
  14849. diff -Nur linux-3.12.11.orig/drivers/media/platform/bcm2835/mmal-msg.h linux-3.12.11/drivers/media/platform/bcm2835/mmal-msg.h
  14850. --- linux-3.12.11.orig/drivers/media/platform/bcm2835/mmal-msg.h 1970-01-01 01:00:00.000000000 +0100
  14851. +++ linux-3.12.11/drivers/media/platform/bcm2835/mmal-msg.h 2014-02-18 11:52:14.000000000 +0100
  14852. @@ -0,0 +1,404 @@
  14853. +/*
  14854. + * Broadcom BM2835 V4L2 driver
  14855. + *
  14856. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14857. + *
  14858. + * This file is subject to the terms and conditions of the GNU General Public
  14859. + * License. See the file COPYING in the main directory of this archive
  14860. + * for more details.
  14861. + *
  14862. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14863. + * Dave Stevenson <dsteve@broadcom.com>
  14864. + * Simon Mellor <simellor@broadcom.com>
  14865. + * Luke Diamand <luked@broadcom.com>
  14866. + */
  14867. +
  14868. +/* all the data structures which serialise the MMAL protocol. note
  14869. + * these are directly mapped onto the recived message data.
  14870. + *
  14871. + * BEWARE: They seem to *assume* pointers are u32 and that there is no
  14872. + * structure padding!
  14873. + *
  14874. + * NOTE: this implementation uses kernel types to ensure sizes. Rather
  14875. + * than assigning values to enums to force their size the
  14876. + * implementation uses fixed size types and not the enums (though the
  14877. + * comments have the actual enum type
  14878. + */
  14879. +
  14880. +#define VC_MMAL_VER 15
  14881. +#define VC_MMAL_MIN_VER 10
  14882. +#define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
  14883. +
  14884. +/* max total message size is 512 bytes */
  14885. +#define MMAL_MSG_MAX_SIZE 512
  14886. +/* with six 32bit header elements max payload is therefore 488 bytes */
  14887. +#define MMAL_MSG_MAX_PAYLOAD 488
  14888. +
  14889. +#include "mmal-msg-common.h"
  14890. +#include "mmal-msg-format.h"
  14891. +#include "mmal-msg-port.h"
  14892. +
  14893. +enum mmal_msg_type {
  14894. + MMAL_MSG_TYPE_QUIT = 1,
  14895. + MMAL_MSG_TYPE_SERVICE_CLOSED,
  14896. + MMAL_MSG_TYPE_GET_VERSION,
  14897. + MMAL_MSG_TYPE_COMPONENT_CREATE,
  14898. + MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
  14899. + MMAL_MSG_TYPE_COMPONENT_ENABLE,
  14900. + MMAL_MSG_TYPE_COMPONENT_DISABLE,
  14901. + MMAL_MSG_TYPE_PORT_INFO_GET,
  14902. + MMAL_MSG_TYPE_PORT_INFO_SET,
  14903. + MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
  14904. + MMAL_MSG_TYPE_BUFFER_FROM_HOST,
  14905. + MMAL_MSG_TYPE_BUFFER_TO_HOST,
  14906. + MMAL_MSG_TYPE_GET_STATS,
  14907. + MMAL_MSG_TYPE_PORT_PARAMETER_SET,
  14908. + MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
  14909. + MMAL_MSG_TYPE_EVENT_TO_HOST,
  14910. + MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
  14911. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
  14912. + MMAL_MSG_TYPE_CONSUME_MEM,
  14913. + MMAL_MSG_TYPE_LMK, /* 20 */
  14914. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
  14915. + MMAL_MSG_TYPE_DRM_GET_LHS32,
  14916. + MMAL_MSG_TYPE_DRM_GET_TIME,
  14917. + MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
  14918. + MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
  14919. + MMAL_MSG_TYPE_HOST_LOG,
  14920. + MMAL_MSG_TYPE_MSG_LAST
  14921. +};
  14922. +
  14923. +/* port action request messages differ depending on the action type */
  14924. +enum mmal_msg_port_action_type {
  14925. + MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unkown action */
  14926. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
  14927. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
  14928. + MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
  14929. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
  14930. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
  14931. + MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
  14932. +};
  14933. +
  14934. +struct mmal_msg_header {
  14935. + u32 magic;
  14936. + u32 type; /** enum mmal_msg_type */
  14937. +
  14938. + /* Opaque handle to the control service */
  14939. + struct mmal_control_service *control_service;
  14940. +
  14941. + struct mmal_msg_context *context; /** a u32 per message context */
  14942. + u32 status; /** The status of the vchiq operation */
  14943. + u32 padding;
  14944. +};
  14945. +
  14946. +/* Send from VC to host to report version */
  14947. +struct mmal_msg_version {
  14948. + u32 flags;
  14949. + u32 major;
  14950. + u32 minor;
  14951. + u32 minimum;
  14952. +};
  14953. +
  14954. +/* request to VC to create component */
  14955. +struct mmal_msg_component_create {
  14956. + void *client_component; /* component context */
  14957. + char name[128];
  14958. + u32 pid; /* For debug */
  14959. +};
  14960. +
  14961. +/* reply from VC to component creation request */
  14962. +struct mmal_msg_component_create_reply {
  14963. + u32 status; /** enum mmal_msg_status - how does this differ to
  14964. + * the one in the header?
  14965. + */
  14966. + u32 component_handle; /* VideoCore handle for component */
  14967. + u32 input_num; /* Number of input ports */
  14968. + u32 output_num; /* Number of output ports */
  14969. + u32 clock_num; /* Number of clock ports */
  14970. +};
  14971. +
  14972. +/* request to VC to destroy a component */
  14973. +struct mmal_msg_component_destroy {
  14974. + u32 component_handle;
  14975. +};
  14976. +
  14977. +struct mmal_msg_component_destroy_reply {
  14978. + u32 status; /** The component destruction status */
  14979. +};
  14980. +
  14981. +
  14982. +/* request and reply to VC to enable a component */
  14983. +struct mmal_msg_component_enable {
  14984. + u32 component_handle;
  14985. +};
  14986. +
  14987. +struct mmal_msg_component_enable_reply {
  14988. + u32 status; /** The component enable status */
  14989. +};
  14990. +
  14991. +
  14992. +/* request and reply to VC to disable a component */
  14993. +struct mmal_msg_component_disable {
  14994. + u32 component_handle;
  14995. +};
  14996. +
  14997. +struct mmal_msg_component_disable_reply {
  14998. + u32 status; /** The component disable status */
  14999. +};
  15000. +
  15001. +/* request to VC to get port information */
  15002. +struct mmal_msg_port_info_get {
  15003. + u32 component_handle; /* component handle port is associated with */
  15004. + u32 port_type; /* enum mmal_msg_port_type */
  15005. + u32 index; /* port index to query */
  15006. +};
  15007. +
  15008. +/* reply from VC to get port info request */
  15009. +struct mmal_msg_port_info_get_reply {
  15010. + u32 status; /** enum mmal_msg_status */
  15011. + u32 component_handle; /* component handle port is associated with */
  15012. + u32 port_type; /* enum mmal_msg_port_type */
  15013. + u32 port_index; /* port indexed in query */
  15014. + s32 found; /* unused */
  15015. + u32 port_handle; /**< Handle to use for this port */
  15016. + struct mmal_port port;
  15017. + struct mmal_es_format format; /* elementry stream format */
  15018. + union mmal_es_specific_format es; /* es type specific data */
  15019. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
  15020. +};
  15021. +
  15022. +/* request to VC to set port information */
  15023. +struct mmal_msg_port_info_set {
  15024. + u32 component_handle;
  15025. + u32 port_type; /* enum mmal_msg_port_type */
  15026. + u32 port_index; /* port indexed in query */
  15027. + struct mmal_port port;
  15028. + struct mmal_es_format format;
  15029. + union mmal_es_specific_format es;
  15030. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  15031. +};
  15032. +
  15033. +/* reply from VC to port info set request */
  15034. +struct mmal_msg_port_info_set_reply {
  15035. + u32 status;
  15036. + u32 component_handle; /* component handle port is associated with */
  15037. + u32 port_type; /* enum mmal_msg_port_type */
  15038. + u32 index; /* port indexed in query */
  15039. + s32 found; /* unused */
  15040. + u32 port_handle; /**< Handle to use for this port */
  15041. + struct mmal_port port;
  15042. + struct mmal_es_format format;
  15043. + union mmal_es_specific_format es;
  15044. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  15045. +};
  15046. +
  15047. +
  15048. +/* port action requests that take a mmal_port as a parameter */
  15049. +struct mmal_msg_port_action_port {
  15050. + u32 component_handle;
  15051. + u32 port_handle;
  15052. + u32 action; /* enum mmal_msg_port_action_type */
  15053. + struct mmal_port port;
  15054. +};
  15055. +
  15056. +/* port action requests that take handles as a parameter */
  15057. +struct mmal_msg_port_action_handle {
  15058. + u32 component_handle;
  15059. + u32 port_handle;
  15060. + u32 action; /* enum mmal_msg_port_action_type */
  15061. + u32 connect_component_handle;
  15062. + u32 connect_port_handle;
  15063. +};
  15064. +
  15065. +struct mmal_msg_port_action_reply {
  15066. + u32 status; /** The port action operation status */
  15067. +};
  15068. +
  15069. +
  15070. +
  15071. +
  15072. +/* MMAL buffer transfer */
  15073. +
  15074. +/** Size of space reserved in a buffer message for short messages. */
  15075. +#define MMAL_VC_SHORT_DATA 128
  15076. +
  15077. +/** Signals that the current payload is the end of the stream of data */
  15078. +#define MMAL_BUFFER_HEADER_FLAG_EOS (1<<0)
  15079. +/** Signals that the start of the current payload starts a frame */
  15080. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_START (1<<1)
  15081. +/** Signals that the end of the current payload ends a frame */
  15082. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_END (1<<2)
  15083. +/** Signals that the current payload contains only complete frames (>1) */
  15084. +#define MMAL_BUFFER_HEADER_FLAG_FRAME \
  15085. + (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
  15086. +/** Signals that the current payload is a keyframe (i.e. self decodable) */
  15087. +#define MMAL_BUFFER_HEADER_FLAG_KEYFRAME (1<<3)
  15088. +/** Signals a discontinuity in the stream of data (e.g. after a seek).
  15089. + * Can be used for instance by a decoder to reset its state */
  15090. +#define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY (1<<4)
  15091. +/** Signals a buffer containing some kind of config data for the component
  15092. + * (e.g. codec config data) */
  15093. +#define MMAL_BUFFER_HEADER_FLAG_CONFIG (1<<5)
  15094. +/** Signals an encrypted payload */
  15095. +#define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED (1<<6)
  15096. +/** Signals a buffer containing side information */
  15097. +#define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO (1<<7)
  15098. +/** Signals a buffer which is the snapshot/postview image from a stills
  15099. + * capture
  15100. + */
  15101. +#define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT (1<<8)
  15102. +/** Signals a buffer which contains data known to be corrupted */
  15103. +#define MMAL_BUFFER_HEADER_FLAG_CORRUPTED (1<<9)
  15104. +/** Signals that a buffer failed to be transmitted */
  15105. +#define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED (1<<10)
  15106. +
  15107. +struct mmal_driver_buffer {
  15108. + u32 magic;
  15109. + u32 component_handle;
  15110. + u32 port_handle;
  15111. + void *client_context;
  15112. +};
  15113. +
  15114. +/* buffer header */
  15115. +struct mmal_buffer_header {
  15116. + struct mmal_buffer_header *next; /* next header */
  15117. + void *priv; /* framework private data */
  15118. + u32 cmd;
  15119. + void *data;
  15120. + u32 alloc_size;
  15121. + u32 length;
  15122. + u32 offset;
  15123. + u32 flags;
  15124. + s64 pts;
  15125. + s64 dts;
  15126. + void *type;
  15127. + void *user_data;
  15128. +};
  15129. +
  15130. +struct mmal_buffer_header_type_specific {
  15131. + union {
  15132. + struct {
  15133. + u32 planes;
  15134. + u32 offset[4];
  15135. + u32 pitch[4];
  15136. + u32 flags;
  15137. + } video;
  15138. + } u;
  15139. +};
  15140. +
  15141. +struct mmal_msg_buffer_from_host {
  15142. + /* The front 32 bytes of the buffer header are copied
  15143. + * back to us in the reply to allow for context. This
  15144. + * area is used to store two mmal_driver_buffer structures to
  15145. + * allow for multiple concurrent service users.
  15146. + */
  15147. + /* control data */
  15148. + struct mmal_driver_buffer drvbuf;
  15149. +
  15150. + /* referenced control data for passthrough buffer management */
  15151. + struct mmal_driver_buffer drvbuf_ref;
  15152. + struct mmal_buffer_header buffer_header; /* buffer header itself */
  15153. + struct mmal_buffer_header_type_specific buffer_header_type_specific;
  15154. + s32 is_zero_copy;
  15155. + s32 has_reference;
  15156. +
  15157. + /** allows short data to be xfered in control message */
  15158. + u32 payload_in_message;
  15159. + u8 short_data[MMAL_VC_SHORT_DATA];
  15160. +};
  15161. +
  15162. +
  15163. +/* port parameter setting */
  15164. +
  15165. +#define MMAL_WORKER_PORT_PARAMETER_SPACE 96
  15166. +
  15167. +struct mmal_msg_port_parameter_set {
  15168. + u32 component_handle; /* component */
  15169. + u32 port_handle; /* port */
  15170. + u32 id; /* Parameter ID */
  15171. + u32 size; /* Parameter size */
  15172. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  15173. +};
  15174. +
  15175. +struct mmal_msg_port_parameter_set_reply {
  15176. + u32 status; /** enum mmal_msg_status todo: how does this
  15177. + * differ to the one in the header?
  15178. + */
  15179. +};
  15180. +
  15181. +/* port parameter getting */
  15182. +
  15183. +struct mmal_msg_port_parameter_get {
  15184. + u32 component_handle; /* component */
  15185. + u32 port_handle; /* port */
  15186. + u32 id; /* Parameter ID */
  15187. + u32 size; /* Parameter size */
  15188. +};
  15189. +
  15190. +struct mmal_msg_port_parameter_get_reply {
  15191. + u32 status; /* Status of mmal_port_parameter_get call */
  15192. + u32 id; /* Parameter ID */
  15193. + u32 size; /* Parameter size */
  15194. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  15195. +};
  15196. +
  15197. +/* event messages */
  15198. +#define MMAL_WORKER_EVENT_SPACE 256
  15199. +
  15200. +struct mmal_msg_event_to_host {
  15201. + void *client_component; /* component context */
  15202. +
  15203. + u32 port_type;
  15204. + u32 port_num;
  15205. +
  15206. + u32 cmd;
  15207. + u32 length;
  15208. + u8 data[MMAL_WORKER_EVENT_SPACE];
  15209. + struct mmal_buffer_header *delayed_buffer;
  15210. +};
  15211. +
  15212. +/* all mmal messages are serialised through this structure */
  15213. +struct mmal_msg {
  15214. + /* header */
  15215. + struct mmal_msg_header h;
  15216. + /* payload */
  15217. + union {
  15218. + struct mmal_msg_version version;
  15219. +
  15220. + struct mmal_msg_component_create component_create;
  15221. + struct mmal_msg_component_create_reply component_create_reply;
  15222. +
  15223. + struct mmal_msg_component_destroy component_destroy;
  15224. + struct mmal_msg_component_destroy_reply component_destroy_reply;
  15225. +
  15226. + struct mmal_msg_component_enable component_enable;
  15227. + struct mmal_msg_component_enable_reply component_enable_reply;
  15228. +
  15229. + struct mmal_msg_component_disable component_disable;
  15230. + struct mmal_msg_component_disable_reply component_disable_reply;
  15231. +
  15232. + struct mmal_msg_port_info_get port_info_get;
  15233. + struct mmal_msg_port_info_get_reply port_info_get_reply;
  15234. +
  15235. + struct mmal_msg_port_info_set port_info_set;
  15236. + struct mmal_msg_port_info_set_reply port_info_set_reply;
  15237. +
  15238. + struct mmal_msg_port_action_port port_action_port;
  15239. + struct mmal_msg_port_action_handle port_action_handle;
  15240. + struct mmal_msg_port_action_reply port_action_reply;
  15241. +
  15242. + struct mmal_msg_buffer_from_host buffer_from_host;
  15243. +
  15244. + struct mmal_msg_port_parameter_set port_parameter_set;
  15245. + struct mmal_msg_port_parameter_set_reply
  15246. + port_parameter_set_reply;
  15247. + struct mmal_msg_port_parameter_get
  15248. + port_parameter_get;
  15249. + struct mmal_msg_port_parameter_get_reply
  15250. + port_parameter_get_reply;
  15251. +
  15252. + struct mmal_msg_event_to_host event_to_host;
  15253. +
  15254. + u8 payload[MMAL_MSG_MAX_PAYLOAD];
  15255. + } u;
  15256. +};
  15257. diff -Nur linux-3.12.11.orig/drivers/media/platform/bcm2835/mmal-msg-port.h linux-3.12.11/drivers/media/platform/bcm2835/mmal-msg-port.h
  15258. --- linux-3.12.11.orig/drivers/media/platform/bcm2835/mmal-msg-port.h 1970-01-01 01:00:00.000000000 +0100
  15259. +++ linux-3.12.11/drivers/media/platform/bcm2835/mmal-msg-port.h 2014-02-18 11:52:14.000000000 +0100
  15260. @@ -0,0 +1,107 @@
  15261. +/*
  15262. + * Broadcom BM2835 V4L2 driver
  15263. + *
  15264. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15265. + *
  15266. + * This file is subject to the terms and conditions of the GNU General Public
  15267. + * License. See the file COPYING in the main directory of this archive
  15268. + * for more details.
  15269. + *
  15270. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15271. + * Dave Stevenson <dsteve@broadcom.com>
  15272. + * Simon Mellor <simellor@broadcom.com>
  15273. + * Luke Diamand <luked@broadcom.com>
  15274. + */
  15275. +
  15276. +/* MMAL_PORT_TYPE_T */
  15277. +enum mmal_port_type {
  15278. + MMAL_PORT_TYPE_UNKNOWN = 0, /**< Unknown port type */
  15279. + MMAL_PORT_TYPE_CONTROL, /**< Control port */
  15280. + MMAL_PORT_TYPE_INPUT, /**< Input port */
  15281. + MMAL_PORT_TYPE_OUTPUT, /**< Output port */
  15282. + MMAL_PORT_TYPE_CLOCK, /**< Clock port */
  15283. +};
  15284. +
  15285. +/** The port is pass-through and doesn't need buffer headers allocated */
  15286. +#define MMAL_PORT_CAPABILITY_PASSTHROUGH 0x01
  15287. +/** The port wants to allocate the buffer payloads.
  15288. + * This signals a preference that payload allocation should be done
  15289. + * on this port for efficiency reasons. */
  15290. +#define MMAL_PORT_CAPABILITY_ALLOCATION 0x02
  15291. +/** The port supports format change events.
  15292. + * This applies to input ports and is used to let the client know
  15293. + * whether the port supports being reconfigured via a format
  15294. + * change event (i.e. without having to disable the port). */
  15295. +#define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE 0x04
  15296. +
  15297. +/* mmal port structure (MMAL_PORT_T)
  15298. + *
  15299. + * most elements are informational only, the pointer values for
  15300. + * interogation messages are generally provided as additional
  15301. + * strucures within the message. When used to set values only teh
  15302. + * buffer_num, buffer_size and userdata parameters are writable.
  15303. + */
  15304. +struct mmal_port {
  15305. + void *priv; /* Private member used by the framework */
  15306. + const char *name; /* Port name. Used for debugging purposes (RO) */
  15307. +
  15308. + u32 type; /* Type of the port (RO) enum mmal_port_type */
  15309. + u16 index; /* Index of the port in its type list (RO) */
  15310. + u16 index_all; /* Index of the port in the list of all ports (RO) */
  15311. +
  15312. + u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
  15313. + struct mmal_es_format *format; /* Format of the elementary stream */
  15314. +
  15315. + u32 buffer_num_min; /* Minimum number of buffers the port
  15316. + * requires (RO). This is set by the
  15317. + * component.
  15318. + */
  15319. +
  15320. + u32 buffer_size_min; /* Minimum size of buffers the port
  15321. + * requires (RO). This is set by the
  15322. + * component.
  15323. + */
  15324. +
  15325. + u32 buffer_alignment_min; /* Minimum alignment requirement for
  15326. + * the buffers (RO). A value of
  15327. + * zero means no special alignment
  15328. + * requirements. This is set by the
  15329. + * component.
  15330. + */
  15331. +
  15332. + u32 buffer_num_recommended; /* Number of buffers the port
  15333. + * recommends for optimal
  15334. + * performance (RO). A value of
  15335. + * zero means no special
  15336. + * recommendation. This is set
  15337. + * by the component.
  15338. + */
  15339. +
  15340. + u32 buffer_size_recommended; /* Size of buffers the port
  15341. + * recommends for optimal
  15342. + * performance (RO). A value of
  15343. + * zero means no special
  15344. + * recommendation. This is set
  15345. + * by the component.
  15346. + */
  15347. +
  15348. + u32 buffer_num; /* Actual number of buffers the port will use.
  15349. + * This is set by the client.
  15350. + */
  15351. +
  15352. + u32 buffer_size; /* Actual maximum size of the buffers that
  15353. + * will be sent to the port. This is set by
  15354. + * the client.
  15355. + */
  15356. +
  15357. + void *component; /* Component this port belongs to (Read Only) */
  15358. +
  15359. + void *userdata; /* Field reserved for use by the client */
  15360. +
  15361. + u32 capabilities; /* Flags describing the capabilities of a
  15362. + * port (RO). Bitwise combination of \ref
  15363. + * portcapabilities "Port capabilities"
  15364. + * values.
  15365. + */
  15366. +
  15367. +};
  15368. diff -Nur linux-3.12.11.orig/drivers/media/platform/bcm2835/mmal-parameters.h linux-3.12.11/drivers/media/platform/bcm2835/mmal-parameters.h
  15369. --- linux-3.12.11.orig/drivers/media/platform/bcm2835/mmal-parameters.h 1970-01-01 01:00:00.000000000 +0100
  15370. +++ linux-3.12.11/drivers/media/platform/bcm2835/mmal-parameters.h 2014-02-18 11:52:14.000000000 +0100
  15371. @@ -0,0 +1,562 @@
  15372. +/*
  15373. + * Broadcom BM2835 V4L2 driver
  15374. + *
  15375. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15376. + *
  15377. + * This file is subject to the terms and conditions of the GNU General Public
  15378. + * License. See the file COPYING in the main directory of this archive
  15379. + * for more details.
  15380. + *
  15381. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15382. + * Dave Stevenson <dsteve@broadcom.com>
  15383. + * Simon Mellor <simellor@broadcom.com>
  15384. + * Luke Diamand <luked@broadcom.com>
  15385. + */
  15386. +
  15387. +/* common parameters */
  15388. +
  15389. +/** @name Parameter groups
  15390. + * Parameters are divided into groups, and then allocated sequentially within
  15391. + * a group using an enum.
  15392. + * @{
  15393. + */
  15394. +
  15395. +/** Common parameter ID group, used with many types of component. */
  15396. +#define MMAL_PARAMETER_GROUP_COMMON (0<<16)
  15397. +/** Camera-specific parameter ID group. */
  15398. +#define MMAL_PARAMETER_GROUP_CAMERA (1<<16)
  15399. +/** Video-specific parameter ID group. */
  15400. +#define MMAL_PARAMETER_GROUP_VIDEO (2<<16)
  15401. +/** Audio-specific parameter ID group. */
  15402. +#define MMAL_PARAMETER_GROUP_AUDIO (3<<16)
  15403. +/** Clock-specific parameter ID group. */
  15404. +#define MMAL_PARAMETER_GROUP_CLOCK (4<<16)
  15405. +/** Miracast-specific parameter ID group. */
  15406. +#define MMAL_PARAMETER_GROUP_MIRACAST (5<<16)
  15407. +
  15408. +/* Common parameters */
  15409. +enum mmal_parameter_common_type {
  15410. + MMAL_PARAMETER_UNUSED /**< Never a valid parameter ID */
  15411. + = MMAL_PARAMETER_GROUP_COMMON,
  15412. + MMAL_PARAMETER_SUPPORTED_ENCODINGS, /**< MMAL_PARAMETER_ENCODING_T */
  15413. + MMAL_PARAMETER_URI, /**< MMAL_PARAMETER_URI_T */
  15414. +
  15415. + /** MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T */
  15416. + MMAL_PARAMETER_CHANGE_EVENT_REQUEST,
  15417. +
  15418. + /** MMAL_PARAMETER_BOOLEAN_T */
  15419. + MMAL_PARAMETER_ZERO_COPY,
  15420. +
  15421. + /**< MMAL_PARAMETER_BUFFER_REQUIREMENTS_T */
  15422. + MMAL_PARAMETER_BUFFER_REQUIREMENTS,
  15423. +
  15424. + MMAL_PARAMETER_STATISTICS, /**< MMAL_PARAMETER_STATISTICS_T */
  15425. + MMAL_PARAMETER_CORE_STATISTICS, /**< MMAL_PARAMETER_CORE_STATISTICS_T */
  15426. + MMAL_PARAMETER_MEM_USAGE, /**< MMAL_PARAMETER_MEM_USAGE_T */
  15427. + MMAL_PARAMETER_BUFFER_FLAG_FILTER, /**< MMAL_PARAMETER_UINT32_T */
  15428. + MMAL_PARAMETER_SEEK, /**< MMAL_PARAMETER_SEEK_T */
  15429. + MMAL_PARAMETER_POWERMON_ENABLE, /**< MMAL_PARAMETER_BOOLEAN_T */
  15430. + MMAL_PARAMETER_LOGGING, /**< MMAL_PARAMETER_LOGGING_T */
  15431. + MMAL_PARAMETER_SYSTEM_TIME /**< MMAL_PARAMETER_UINT64_T */
  15432. +};
  15433. +
  15434. +/* camera parameters */
  15435. +
  15436. +enum mmal_parameter_camera_type {
  15437. + /* 0 */
  15438. + /** @ref MMAL_PARAMETER_THUMBNAIL_CONFIG_T */
  15439. + MMAL_PARAMETER_THUMBNAIL_CONFIGURATION
  15440. + = MMAL_PARAMETER_GROUP_CAMERA,
  15441. + MMAL_PARAMETER_CAPTURE_QUALITY, /**< Unused? */
  15442. + MMAL_PARAMETER_ROTATION, /**< @ref MMAL_PARAMETER_INT32_T */
  15443. + MMAL_PARAMETER_EXIF_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15444. + MMAL_PARAMETER_EXIF, /**< @ref MMAL_PARAMETER_EXIF_T */
  15445. + MMAL_PARAMETER_AWB_MODE, /**< @ref MMAL_PARAM_AWBMODE_T */
  15446. + MMAL_PARAMETER_IMAGE_EFFECT, /**< @ref MMAL_PARAMETER_IMAGEFX_T */
  15447. + MMAL_PARAMETER_COLOUR_EFFECT, /**< @ref MMAL_PARAMETER_COLOURFX_T */
  15448. + MMAL_PARAMETER_FLICKER_AVOID, /**< @ref MMAL_PARAMETER_FLICKERAVOID_T */
  15449. + MMAL_PARAMETER_FLASH, /**< @ref MMAL_PARAMETER_FLASH_T */
  15450. + MMAL_PARAMETER_REDEYE, /**< @ref MMAL_PARAMETER_REDEYE_T */
  15451. + MMAL_PARAMETER_FOCUS, /**< @ref MMAL_PARAMETER_FOCUS_T */
  15452. + MMAL_PARAMETER_FOCAL_LENGTHS, /**< Unused? */
  15453. + MMAL_PARAMETER_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  15454. + MMAL_PARAMETER_ZOOM, /**< @ref MMAL_PARAMETER_SCALEFACTOR_T */
  15455. + MMAL_PARAMETER_MIRROR, /**< @ref MMAL_PARAMETER_MIRROR_T */
  15456. +
  15457. + /* 0x10 */
  15458. + MMAL_PARAMETER_CAMERA_NUM, /**< @ref MMAL_PARAMETER_UINT32_T */
  15459. + MMAL_PARAMETER_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15460. + MMAL_PARAMETER_EXPOSURE_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMODE_T */
  15461. + MMAL_PARAMETER_EXP_METERING_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMETERINGMODE_T */
  15462. + MMAL_PARAMETER_FOCUS_STATUS, /**< @ref MMAL_PARAMETER_FOCUS_STATUS_T */
  15463. + MMAL_PARAMETER_CAMERA_CONFIG, /**< @ref MMAL_PARAMETER_CAMERA_CONFIG_T */
  15464. + MMAL_PARAMETER_CAPTURE_STATUS, /**< @ref MMAL_PARAMETER_CAPTURE_STATUS_T */
  15465. + MMAL_PARAMETER_FACE_TRACK, /**< @ref MMAL_PARAMETER_FACE_TRACK_T */
  15466. + MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15467. + MMAL_PARAMETER_JPEG_Q_FACTOR, /**< @ref MMAL_PARAMETER_UINT32_T */
  15468. + MMAL_PARAMETER_FRAME_RATE, /**< @ref MMAL_PARAMETER_FRAME_RATE_T */
  15469. + MMAL_PARAMETER_USE_STC, /**< @ref MMAL_PARAMETER_CAMERA_STC_MODE_T */
  15470. + MMAL_PARAMETER_CAMERA_INFO, /**< @ref MMAL_PARAMETER_CAMERA_INFO_T */
  15471. + MMAL_PARAMETER_VIDEO_STABILISATION, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15472. + MMAL_PARAMETER_FACE_TRACK_RESULTS, /**< @ref MMAL_PARAMETER_FACE_TRACK_RESULTS_T */
  15473. + MMAL_PARAMETER_ENABLE_RAW_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15474. +
  15475. + /* 0x20 */
  15476. + MMAL_PARAMETER_DPF_FILE, /**< @ref MMAL_PARAMETER_URI_T */
  15477. + MMAL_PARAMETER_ENABLE_DPF_FILE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15478. + MMAL_PARAMETER_DPF_FAIL_IS_FATAL, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15479. + MMAL_PARAMETER_CAPTURE_MODE, /**< @ref MMAL_PARAMETER_CAPTUREMODE_T */
  15480. + MMAL_PARAMETER_FOCUS_REGIONS, /**< @ref MMAL_PARAMETER_FOCUS_REGIONS_T */
  15481. + MMAL_PARAMETER_INPUT_CROP, /**< @ref MMAL_PARAMETER_INPUT_CROP_T */
  15482. + MMAL_PARAMETER_SENSOR_INFORMATION, /**< @ref MMAL_PARAMETER_SENSOR_INFORMATION_T */
  15483. + MMAL_PARAMETER_FLASH_SELECT, /**< @ref MMAL_PARAMETER_FLASH_SELECT_T */
  15484. + MMAL_PARAMETER_FIELD_OF_VIEW, /**< @ref MMAL_PARAMETER_FIELD_OF_VIEW_T */
  15485. + MMAL_PARAMETER_HIGH_DYNAMIC_RANGE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15486. + MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION, /**< @ref MMAL_PARAMETER_DRC_T */
  15487. + MMAL_PARAMETER_ALGORITHM_CONTROL, /**< @ref MMAL_PARAMETER_ALGORITHM_CONTROL_T */
  15488. + MMAL_PARAMETER_SHARPNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  15489. + MMAL_PARAMETER_CONTRAST, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  15490. + MMAL_PARAMETER_BRIGHTNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  15491. + MMAL_PARAMETER_SATURATION, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  15492. +
  15493. + /* 0x30 */
  15494. + MMAL_PARAMETER_ISO, /**< @ref MMAL_PARAMETER_UINT32_T */
  15495. + MMAL_PARAMETER_ANTISHAKE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15496. +
  15497. + /** @ref MMAL_PARAMETER_IMAGEFX_PARAMETERS_T */
  15498. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  15499. +
  15500. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15501. + MMAL_PARAMETER_CAMERA_BURST_CAPTURE,
  15502. +
  15503. + /** @ref MMAL_PARAMETER_UINT32_T */
  15504. + MMAL_PARAMETER_CAMERA_MIN_ISO,
  15505. +
  15506. + /** @ref MMAL_PARAMETER_CAMERA_USE_CASE_T */
  15507. + MMAL_PARAMETER_CAMERA_USE_CASE,
  15508. +
  15509. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15510. + MMAL_PARAMETER_CAPTURE_STATS_PASS,
  15511. +
  15512. + /** @ref MMAL_PARAMETER_UINT32_T */
  15513. + MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG,
  15514. +
  15515. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15516. + MMAL_PARAMETER_ENABLE_REGISTER_FILE,
  15517. +
  15518. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15519. + MMAL_PARAMETER_REGISTER_FAIL_IS_FATAL,
  15520. +
  15521. + /** @ref MMAL_PARAMETER_CONFIGFILE_T */
  15522. + MMAL_PARAMETER_CONFIGFILE_REGISTERS,
  15523. +
  15524. + /** @ref MMAL_PARAMETER_CONFIGFILE_CHUNK_T */
  15525. + MMAL_PARAMETER_CONFIGFILE_CHUNK_REGISTERS,
  15526. + MMAL_PARAMETER_JPEG_ATTACH_LOG, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15527. + MMAL_PARAMETER_ZERO_SHUTTER_LAG, /**< @ref MMAL_PARAMETER_ZEROSHUTTERLAG_T */
  15528. + MMAL_PARAMETER_FPS_RANGE, /**< @ref MMAL_PARAMETER_FPS_RANGE_T */
  15529. + MMAL_PARAMETER_CAPTURE_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  15530. +
  15531. + /* 0x40 */
  15532. + MMAL_PARAMETER_SW_SHARPEN_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15533. + MMAL_PARAMETER_FLASH_REQUIRED, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15534. + MMAL_PARAMETER_SW_SATURATION_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15535. + MMAL_PARAMETER_SHUTTER_SPEED /**< Takes a @ref MMAL_PARAMETER_UINT32_T */
  15536. +};
  15537. +
  15538. +struct mmal_parameter_rational {
  15539. + s32 num; /**< Numerator */
  15540. + s32 den; /**< Denominator */
  15541. +};
  15542. +
  15543. +enum mmal_parameter_camera_config_timestamp_mode {
  15544. + MMAL_PARAM_TIMESTAMP_MODE_ZERO = 0, /* Always timestamp frames as 0 */
  15545. + MMAL_PARAM_TIMESTAMP_MODE_RAW_STC, /* Use the raw STC value
  15546. + * for the frame timestamp
  15547. + */
  15548. + MMAL_PARAM_TIMESTAMP_MODE_RESET_STC, /* Use the STC timestamp
  15549. + * but subtract the
  15550. + * timestamp of the first
  15551. + * frame sent to give a
  15552. + * zero based timestamp.
  15553. + */
  15554. +};
  15555. +
  15556. +/* camera configuration parameter */
  15557. +struct mmal_parameter_camera_config {
  15558. + /* Parameters for setting up the image pools */
  15559. + u32 max_stills_w; /* Max size of stills capture */
  15560. + u32 max_stills_h;
  15561. + u32 stills_yuv422; /* Allow YUV422 stills capture */
  15562. + u32 one_shot_stills; /* Continuous or one shot stills captures. */
  15563. +
  15564. + u32 max_preview_video_w; /* Max size of the preview or video
  15565. + * capture frames
  15566. + */
  15567. + u32 max_preview_video_h;
  15568. + u32 num_preview_video_frames;
  15569. +
  15570. + /** Sets the height of the circular buffer for stills capture. */
  15571. + u32 stills_capture_circular_buffer_height;
  15572. +
  15573. + /** Allows preview/encode to resume as fast as possible after the stills
  15574. + * input frame has been received, and then processes the still frame in
  15575. + * the background whilst preview/encode has resumed.
  15576. + * Actual mode is controlled by MMAL_PARAMETER_CAPTURE_MODE.
  15577. + */
  15578. + u32 fast_preview_resume;
  15579. +
  15580. + /** Selects algorithm for timestamping frames if
  15581. + * there is no clock component connected.
  15582. + * enum mmal_parameter_camera_config_timestamp_mode
  15583. + */
  15584. + s32 use_stc_timestamp;
  15585. +};
  15586. +
  15587. +
  15588. +enum mmal_parameter_exposuremode {
  15589. + MMAL_PARAM_EXPOSUREMODE_OFF,
  15590. + MMAL_PARAM_EXPOSUREMODE_AUTO,
  15591. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  15592. + MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW,
  15593. + MMAL_PARAM_EXPOSUREMODE_BACKLIGHT,
  15594. + MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT,
  15595. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  15596. + MMAL_PARAM_EXPOSUREMODE_SNOW,
  15597. + MMAL_PARAM_EXPOSUREMODE_BEACH,
  15598. + MMAL_PARAM_EXPOSUREMODE_VERYLONG,
  15599. + MMAL_PARAM_EXPOSUREMODE_FIXEDFPS,
  15600. + MMAL_PARAM_EXPOSUREMODE_ANTISHAKE,
  15601. + MMAL_PARAM_EXPOSUREMODE_FIREWORKS,
  15602. +};
  15603. +
  15604. +enum mmal_parameter_exposuremeteringmode {
  15605. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE,
  15606. + MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT,
  15607. + MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT,
  15608. + MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX,
  15609. +};
  15610. +
  15611. +enum mmal_parameter_awbmode {
  15612. + MMAL_PARAM_AWBMODE_OFF,
  15613. + MMAL_PARAM_AWBMODE_AUTO,
  15614. + MMAL_PARAM_AWBMODE_SUNLIGHT,
  15615. + MMAL_PARAM_AWBMODE_CLOUDY,
  15616. + MMAL_PARAM_AWBMODE_SHADE,
  15617. + MMAL_PARAM_AWBMODE_TUNGSTEN,
  15618. + MMAL_PARAM_AWBMODE_FLUORESCENT,
  15619. + MMAL_PARAM_AWBMODE_INCANDESCENT,
  15620. + MMAL_PARAM_AWBMODE_FLASH,
  15621. + MMAL_PARAM_AWBMODE_HORIZON,
  15622. +};
  15623. +
  15624. +enum mmal_parameter_imagefx {
  15625. + MMAL_PARAM_IMAGEFX_NONE,
  15626. + MMAL_PARAM_IMAGEFX_NEGATIVE,
  15627. + MMAL_PARAM_IMAGEFX_SOLARIZE,
  15628. + MMAL_PARAM_IMAGEFX_POSTERIZE,
  15629. + MMAL_PARAM_IMAGEFX_WHITEBOARD,
  15630. + MMAL_PARAM_IMAGEFX_BLACKBOARD,
  15631. + MMAL_PARAM_IMAGEFX_SKETCH,
  15632. + MMAL_PARAM_IMAGEFX_DENOISE,
  15633. + MMAL_PARAM_IMAGEFX_EMBOSS,
  15634. + MMAL_PARAM_IMAGEFX_OILPAINT,
  15635. + MMAL_PARAM_IMAGEFX_HATCH,
  15636. + MMAL_PARAM_IMAGEFX_GPEN,
  15637. + MMAL_PARAM_IMAGEFX_PASTEL,
  15638. + MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  15639. + MMAL_PARAM_IMAGEFX_FILM,
  15640. + MMAL_PARAM_IMAGEFX_BLUR,
  15641. + MMAL_PARAM_IMAGEFX_SATURATION,
  15642. + MMAL_PARAM_IMAGEFX_COLOURSWAP,
  15643. + MMAL_PARAM_IMAGEFX_WASHEDOUT,
  15644. + MMAL_PARAM_IMAGEFX_POSTERISE,
  15645. + MMAL_PARAM_IMAGEFX_COLOURPOINT,
  15646. + MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  15647. + MMAL_PARAM_IMAGEFX_CARTOON,
  15648. +};
  15649. +
  15650. +enum MMAL_PARAM_FLICKERAVOID_T {
  15651. + MMAL_PARAM_FLICKERAVOID_OFF,
  15652. + MMAL_PARAM_FLICKERAVOID_AUTO,
  15653. + MMAL_PARAM_FLICKERAVOID_50HZ,
  15654. + MMAL_PARAM_FLICKERAVOID_60HZ,
  15655. + MMAL_PARAM_FLICKERAVOID_MAX = 0x7FFFFFFF
  15656. +};
  15657. +
  15658. +/** Manner of video rate control */
  15659. +enum mmal_parameter_rate_control_mode {
  15660. + MMAL_VIDEO_RATECONTROL_DEFAULT,
  15661. + MMAL_VIDEO_RATECONTROL_VARIABLE,
  15662. + MMAL_VIDEO_RATECONTROL_CONSTANT,
  15663. + MMAL_VIDEO_RATECONTROL_VARIABLE_SKIP_FRAMES,
  15664. + MMAL_VIDEO_RATECONTROL_CONSTANT_SKIP_FRAMES
  15665. +};
  15666. +
  15667. +/* video parameters */
  15668. +
  15669. +enum mmal_parameter_video_type {
  15670. + /** @ref MMAL_DISPLAYREGION_T */
  15671. + MMAL_PARAMETER_DISPLAYREGION = MMAL_PARAMETER_GROUP_VIDEO,
  15672. +
  15673. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  15674. + MMAL_PARAMETER_SUPPORTED_PROFILES,
  15675. +
  15676. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  15677. + MMAL_PARAMETER_PROFILE,
  15678. +
  15679. + /** @ref MMAL_PARAMETER_UINT32_T */
  15680. + MMAL_PARAMETER_INTRAPERIOD,
  15681. +
  15682. + /** @ref MMAL_PARAMETER_VIDEO_RATECONTROL_T */
  15683. + MMAL_PARAMETER_RATECONTROL,
  15684. +
  15685. + /** @ref MMAL_PARAMETER_VIDEO_NALUNITFORMAT_T */
  15686. + MMAL_PARAMETER_NALUNITFORMAT,
  15687. +
  15688. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15689. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  15690. +
  15691. + /** @ref MMAL_PARAMETER_UINT32_T.
  15692. + * Setting the value to zero resets to the default (one slice per frame).
  15693. + */
  15694. + MMAL_PARAMETER_MB_ROWS_PER_SLICE,
  15695. +
  15696. + /** @ref MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION_T */
  15697. + MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION,
  15698. +
  15699. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_ENABLE_T */
  15700. + MMAL_PARAMETER_VIDEO_EEDE_ENABLE,
  15701. +
  15702. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE_T */
  15703. + MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE,
  15704. +
  15705. + /** @ref MMAL_PARAMETER_BOOLEAN_T. Request an I-frame. */
  15706. + MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME,
  15707. + /** @ref MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T */
  15708. + MMAL_PARAMETER_VIDEO_INTRA_REFRESH,
  15709. +
  15710. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15711. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  15712. +
  15713. + /** @ref MMAL_PARAMETER_UINT32_T. Run-time bit rate control */
  15714. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  15715. +
  15716. + /** @ref MMAL_PARAMETER_FRAME_RATE_T */
  15717. + MMAL_PARAMETER_VIDEO_FRAME_RATE,
  15718. +
  15719. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15720. + MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT,
  15721. +
  15722. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15723. + MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT,
  15724. +
  15725. + /** @ref MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL_T. */
  15726. + MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL,
  15727. +
  15728. + MMAL_PARAMETER_EXTRA_BUFFERS, /**< @ref MMAL_PARAMETER_UINT32_T. */
  15729. + /** @ref MMAL_PARAMETER_UINT32_T.
  15730. + * Changing this parameter from the default can reduce frame rate
  15731. + * because image buffers need to be re-pitched.
  15732. + */
  15733. + MMAL_PARAMETER_VIDEO_ALIGN_HORIZ,
  15734. +
  15735. + /** @ref MMAL_PARAMETER_UINT32_T.
  15736. + * Changing this parameter from the default can reduce frame rate
  15737. + * because image buffers need to be re-pitched.
  15738. + */
  15739. + MMAL_PARAMETER_VIDEO_ALIGN_VERT,
  15740. +
  15741. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15742. + MMAL_PARAMETER_VIDEO_DROPPABLE_PFRAMES,
  15743. +
  15744. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15745. + MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT,
  15746. +
  15747. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  15748. + MMAL_PARAMETER_VIDEO_ENCODE_QP_P,
  15749. +
  15750. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  15751. + MMAL_PARAMETER_VIDEO_ENCODE_RC_SLICE_DQUANT,
  15752. +
  15753. + /** @ref MMAL_PARAMETER_UINT32_T */
  15754. + MMAL_PARAMETER_VIDEO_ENCODE_FRAME_LIMIT_BITS,
  15755. +
  15756. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15757. + MMAL_PARAMETER_VIDEO_ENCODE_PEAK_RATE,
  15758. +
  15759. + /* H264 specific parameters */
  15760. +
  15761. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15762. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DISABLE_CABAC,
  15763. +
  15764. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15765. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_LATENCY,
  15766. +
  15767. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15768. + MMAL_PARAMETER_VIDEO_ENCODE_H264_AU_DELIMITERS,
  15769. +
  15770. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15771. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DEBLOCK_IDC,
  15772. +
  15773. + /** @ref MMAL_PARAMETER_VIDEO_ENCODER_H264_MB_INTRA_MODES_T. */
  15774. + MMAL_PARAMETER_VIDEO_ENCODE_H264_MB_INTRA_MODE,
  15775. +
  15776. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15777. + MMAL_PARAMETER_VIDEO_ENCODE_HEADER_ON_OPEN,
  15778. +
  15779. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15780. + MMAL_PARAMETER_VIDEO_ENCODE_PRECODE_FOR_QP,
  15781. +
  15782. + /** @ref MMAL_PARAMETER_VIDEO_DRM_INIT_INFO_T. */
  15783. + MMAL_PARAMETER_VIDEO_DRM_INIT_INFO,
  15784. +
  15785. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15786. + MMAL_PARAMETER_VIDEO_TIMESTAMP_FIFO,
  15787. +
  15788. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15789. + MMAL_PARAMETER_VIDEO_DECODE_ERROR_CONCEALMENT,
  15790. +
  15791. + /** @ref MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER_T. */
  15792. + MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER,
  15793. +
  15794. + /** @ref MMAL_PARAMETER_BYTES_T */
  15795. + MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3,
  15796. +
  15797. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15798. + MMAL_PARAMETER_VIDEO_ENCODE_H264_VCL_HRD_PARAMETERS,
  15799. +
  15800. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15801. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_DELAY_HRD_FLAG,
  15802. +
  15803. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15804. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER
  15805. +};
  15806. +
  15807. +/** Valid mirror modes */
  15808. +enum mmal_parameter_mirror {
  15809. + MMAL_PARAM_MIRROR_NONE,
  15810. + MMAL_PARAM_MIRROR_VERTICAL,
  15811. + MMAL_PARAM_MIRROR_HORIZONTAL,
  15812. + MMAL_PARAM_MIRROR_BOTH,
  15813. +};
  15814. +
  15815. +enum mmal_parameter_displaytransform {
  15816. + MMAL_DISPLAY_ROT0 = 0,
  15817. + MMAL_DISPLAY_MIRROR_ROT0 = 1,
  15818. + MMAL_DISPLAY_MIRROR_ROT180 = 2,
  15819. + MMAL_DISPLAY_ROT180 = 3,
  15820. + MMAL_DISPLAY_MIRROR_ROT90 = 4,
  15821. + MMAL_DISPLAY_ROT270 = 5,
  15822. + MMAL_DISPLAY_ROT90 = 6,
  15823. + MMAL_DISPLAY_MIRROR_ROT270 = 7,
  15824. +};
  15825. +
  15826. +enum mmal_parameter_displaymode {
  15827. + MMAL_DISPLAY_MODE_FILL = 0,
  15828. + MMAL_DISPLAY_MODE_LETTERBOX = 1,
  15829. +};
  15830. +
  15831. +enum mmal_parameter_displayset {
  15832. + MMAL_DISPLAY_SET_NONE = 0,
  15833. + MMAL_DISPLAY_SET_NUM = 1,
  15834. + MMAL_DISPLAY_SET_FULLSCREEN = 2,
  15835. + MMAL_DISPLAY_SET_TRANSFORM = 4,
  15836. + MMAL_DISPLAY_SET_DEST_RECT = 8,
  15837. + MMAL_DISPLAY_SET_SRC_RECT = 0x10,
  15838. + MMAL_DISPLAY_SET_MODE = 0x20,
  15839. + MMAL_DISPLAY_SET_PIXEL = 0x40,
  15840. + MMAL_DISPLAY_SET_NOASPECT = 0x80,
  15841. + MMAL_DISPLAY_SET_LAYER = 0x100,
  15842. + MMAL_DISPLAY_SET_COPYPROTECT = 0x200,
  15843. + MMAL_DISPLAY_SET_ALPHA = 0x400,
  15844. +};
  15845. +
  15846. +struct mmal_parameter_displayregion {
  15847. + /** Bitfield that indicates which fields are set and should be
  15848. + * used. All other fields will maintain their current value.
  15849. + * \ref MMAL_DISPLAYSET_T defines the bits that can be
  15850. + * combined.
  15851. + */
  15852. + u32 set;
  15853. +
  15854. + /** Describes the display output device, with 0 typically
  15855. + * being a directly connected LCD display. The actual values
  15856. + * will depend on the hardware. Code using hard-wired numbers
  15857. + * (e.g. 2) is certain to fail.
  15858. + */
  15859. +
  15860. + u32 display_num;
  15861. + /** Indicates that we are using the full device screen area,
  15862. + * rather than a window of the display. If zero, then
  15863. + * dest_rect is used to specify a region of the display to
  15864. + * use.
  15865. + */
  15866. +
  15867. + s32 fullscreen;
  15868. + /** Indicates any rotation or flipping used to map frames onto
  15869. + * the natural display orientation.
  15870. + */
  15871. + u32 transform; /* enum mmal_parameter_displaytransform */
  15872. +
  15873. + /** Where to display the frame within the screen, if
  15874. + * fullscreen is zero.
  15875. + */
  15876. + struct vchiq_mmal_rect dest_rect;
  15877. +
  15878. + /** Indicates which area of the frame to display. If all
  15879. + * values are zero, the whole frame will be used.
  15880. + */
  15881. + struct vchiq_mmal_rect src_rect;
  15882. +
  15883. + /** If set to non-zero, indicates that any display scaling
  15884. + * should disregard the aspect ratio of the frame region being
  15885. + * displayed.
  15886. + */
  15887. + s32 noaspect;
  15888. +
  15889. + /** Indicates how the image should be scaled to fit the
  15890. + * display. \code MMAL_DISPLAY_MODE_FILL \endcode indicates
  15891. + * that the image should fill the screen by potentially
  15892. + * cropping the frames. Setting \code mode \endcode to \code
  15893. + * MMAL_DISPLAY_MODE_LETTERBOX \endcode indicates that all the
  15894. + * source region should be displayed and black bars added if
  15895. + * necessary.
  15896. + */
  15897. + u32 mode; /* enum mmal_parameter_displaymode */
  15898. +
  15899. + /** If non-zero, defines the width of a source pixel relative
  15900. + * to \code pixel_y \endcode. If zero, then pixels default to
  15901. + * being square.
  15902. + */
  15903. + u32 pixel_x;
  15904. +
  15905. + /** If non-zero, defines the height of a source pixel relative
  15906. + * to \code pixel_x \endcode. If zero, then pixels default to
  15907. + * being square.
  15908. + */
  15909. + u32 pixel_y;
  15910. +
  15911. + /** Sets the relative depth of the images, with greater values
  15912. + * being in front of smaller values.
  15913. + */
  15914. + u32 layer;
  15915. +
  15916. + /** Set to non-zero to ensure copy protection is used on
  15917. + * output.
  15918. + */
  15919. + s32 copyprotect_required;
  15920. +
  15921. + /** Level of opacity of the layer, where zero is fully
  15922. + * transparent and 255 is fully opaque.
  15923. + */
  15924. + u32 alpha;
  15925. +};
  15926. +
  15927. +#define MMAL_MAX_IMAGEFX_PARAMETERS 5
  15928. +
  15929. +struct mmal_parameter_imagefx_parameters {
  15930. + enum mmal_parameter_imagefx effect;
  15931. + u32 num_effect_params;
  15932. + u32 effect_parameter[MMAL_MAX_IMAGEFX_PARAMETERS];
  15933. +};
  15934. diff -Nur linux-3.12.11.orig/drivers/media/platform/bcm2835/mmal-vchiq.c linux-3.12.11/drivers/media/platform/bcm2835/mmal-vchiq.c
  15935. --- linux-3.12.11.orig/drivers/media/platform/bcm2835/mmal-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  15936. +++ linux-3.12.11/drivers/media/platform/bcm2835/mmal-vchiq.c 2014-02-18 11:52:14.000000000 +0100
  15937. @@ -0,0 +1,1916 @@
  15938. +/*
  15939. + * Broadcom BM2835 V4L2 driver
  15940. + *
  15941. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15942. + *
  15943. + * This file is subject to the terms and conditions of the GNU General Public
  15944. + * License. See the file COPYING in the main directory of this archive
  15945. + * for more details.
  15946. + *
  15947. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15948. + * Dave Stevenson <dsteve@broadcom.com>
  15949. + * Simon Mellor <simellor@broadcom.com>
  15950. + * Luke Diamand <luked@broadcom.com>
  15951. + *
  15952. + * V4L2 driver MMAL vchiq interface code
  15953. + */
  15954. +
  15955. +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  15956. +
  15957. +#include <linux/errno.h>
  15958. +#include <linux/kernel.h>
  15959. +#include <linux/mutex.h>
  15960. +#include <linux/mm.h>
  15961. +#include <linux/slab.h>
  15962. +#include <linux/completion.h>
  15963. +#include <linux/vmalloc.h>
  15964. +#include <asm/cacheflush.h>
  15965. +#include <media/videobuf2-vmalloc.h>
  15966. +
  15967. +#include "mmal-common.h"
  15968. +#include "mmal-vchiq.h"
  15969. +#include "mmal-msg.h"
  15970. +
  15971. +#define USE_VCHIQ_ARM
  15972. +#include "interface/vchi/vchi.h"
  15973. +
  15974. +/* maximum number of components supported */
  15975. +#define VCHIQ_MMAL_MAX_COMPONENTS 4
  15976. +
  15977. +/*#define FULL_MSG_DUMP 1*/
  15978. +
  15979. +#ifdef DEBUG
  15980. +static const char *const msg_type_names[] = {
  15981. + "UNKNOWN",
  15982. + "QUIT",
  15983. + "SERVICE_CLOSED",
  15984. + "GET_VERSION",
  15985. + "COMPONENT_CREATE",
  15986. + "COMPONENT_DESTROY",
  15987. + "COMPONENT_ENABLE",
  15988. + "COMPONENT_DISABLE",
  15989. + "PORT_INFO_GET",
  15990. + "PORT_INFO_SET",
  15991. + "PORT_ACTION",
  15992. + "BUFFER_FROM_HOST",
  15993. + "BUFFER_TO_HOST",
  15994. + "GET_STATS",
  15995. + "PORT_PARAMETER_SET",
  15996. + "PORT_PARAMETER_GET",
  15997. + "EVENT_TO_HOST",
  15998. + "GET_CORE_STATS_FOR_PORT",
  15999. + "OPAQUE_ALLOCATOR",
  16000. + "CONSUME_MEM",
  16001. + "LMK",
  16002. + "OPAQUE_ALLOCATOR_DESC",
  16003. + "DRM_GET_LHS32",
  16004. + "DRM_GET_TIME",
  16005. + "BUFFER_FROM_HOST_ZEROLEN",
  16006. + "PORT_FLUSH",
  16007. + "HOST_LOG",
  16008. +};
  16009. +#endif
  16010. +
  16011. +static const char *const port_action_type_names[] = {
  16012. + "UNKNOWN",
  16013. + "ENABLE",
  16014. + "DISABLE",
  16015. + "FLUSH",
  16016. + "CONNECT",
  16017. + "DISCONNECT",
  16018. + "SET_REQUIREMENTS",
  16019. +};
  16020. +
  16021. +#if defined(DEBUG)
  16022. +#if defined(FULL_MSG_DUMP)
  16023. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  16024. + do { \
  16025. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  16026. + msg_type_names[(MSG)->h.type], \
  16027. + (MSG)->h.type, (MSG_LEN)); \
  16028. + print_hex_dump(KERN_DEBUG, "<<h: ", DUMP_PREFIX_OFFSET, \
  16029. + 16, 4, (MSG), \
  16030. + sizeof(struct mmal_msg_header), 1); \
  16031. + print_hex_dump(KERN_DEBUG, "<<p: ", DUMP_PREFIX_OFFSET, \
  16032. + 16, 4, \
  16033. + ((u8 *)(MSG)) + sizeof(struct mmal_msg_header),\
  16034. + (MSG_LEN) - sizeof(struct mmal_msg_header), 1); \
  16035. + } while (0)
  16036. +#else
  16037. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  16038. + { \
  16039. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  16040. + msg_type_names[(MSG)->h.type], \
  16041. + (MSG)->h.type, (MSG_LEN)); \
  16042. + }
  16043. +#endif
  16044. +#else
  16045. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE)
  16046. +#endif
  16047. +
  16048. +/* normal message context */
  16049. +struct mmal_msg_context {
  16050. + union {
  16051. + struct {
  16052. + /* work struct for defered callback - must come first */
  16053. + struct work_struct work;
  16054. + /* mmal instance */
  16055. + struct vchiq_mmal_instance *instance;
  16056. + /* mmal port */
  16057. + struct vchiq_mmal_port *port;
  16058. + /* actual buffer used to store bulk reply */
  16059. + struct mmal_buffer *buffer;
  16060. + /* amount of buffer used */
  16061. + unsigned long buffer_used;
  16062. + /* MMAL buffer flags */
  16063. + u32 mmal_flags;
  16064. + /* Presentation and Decode timestamps */
  16065. + s64 pts;
  16066. + s64 dts;
  16067. +
  16068. + int status; /* context status */
  16069. +
  16070. + } bulk; /* bulk data */
  16071. +
  16072. + struct {
  16073. + /* message handle to release */
  16074. + VCHI_HELD_MSG_T msg_handle;
  16075. + /* pointer to received message */
  16076. + struct mmal_msg *msg;
  16077. + /* received message length */
  16078. + u32 msg_len;
  16079. + /* completion upon reply */
  16080. + struct completion cmplt;
  16081. + } sync; /* synchronous response */
  16082. + } u;
  16083. +
  16084. +};
  16085. +
  16086. +struct vchiq_mmal_instance {
  16087. + VCHI_SERVICE_HANDLE_T handle;
  16088. +
  16089. + /* ensure serialised access to service */
  16090. + struct mutex vchiq_mutex;
  16091. +
  16092. + /* ensure serialised access to bulk operations */
  16093. + struct mutex bulk_mutex;
  16094. +
  16095. + /* vmalloc page to receive scratch bulk xfers into */
  16096. + void *bulk_scratch;
  16097. +
  16098. + /* component to use next */
  16099. + int component_idx;
  16100. + struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
  16101. +};
  16102. +
  16103. +static struct mmal_msg_context *get_msg_context(struct vchiq_mmal_instance
  16104. + *instance)
  16105. +{
  16106. + struct mmal_msg_context *msg_context;
  16107. +
  16108. + /* todo: should this be allocated from a pool to avoid kmalloc */
  16109. + msg_context = kmalloc(sizeof(*msg_context), GFP_KERNEL);
  16110. + memset(msg_context, 0, sizeof(*msg_context));
  16111. +
  16112. + return msg_context;
  16113. +}
  16114. +
  16115. +static void release_msg_context(struct mmal_msg_context *msg_context)
  16116. +{
  16117. + kfree(msg_context);
  16118. +}
  16119. +
  16120. +/* deals with receipt of event to host message */
  16121. +static void event_to_host_cb(struct vchiq_mmal_instance *instance,
  16122. + struct mmal_msg *msg, u32 msg_len)
  16123. +{
  16124. + pr_debug("unhandled event\n");
  16125. + pr_debug("component:%p port type:%d num:%d cmd:0x%x length:%d\n",
  16126. + msg->u.event_to_host.client_component,
  16127. + msg->u.event_to_host.port_type,
  16128. + msg->u.event_to_host.port_num,
  16129. + msg->u.event_to_host.cmd, msg->u.event_to_host.length);
  16130. +}
  16131. +
  16132. +/* workqueue scheduled callback
  16133. + *
  16134. + * we do this because it is important we do not call any other vchiq
  16135. + * sync calls from witin the message delivery thread
  16136. + */
  16137. +static void buffer_work_cb(struct work_struct *work)
  16138. +{
  16139. + struct mmal_msg_context *msg_context = (struct mmal_msg_context *)work;
  16140. +
  16141. + msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
  16142. + msg_context->u.bulk.port,
  16143. + msg_context->u.bulk.status,
  16144. + msg_context->u.bulk.buffer,
  16145. + msg_context->u.bulk.buffer_used,
  16146. + msg_context->u.bulk.mmal_flags,
  16147. + msg_context->u.bulk.dts,
  16148. + msg_context->u.bulk.pts);
  16149. +
  16150. + /* release message context */
  16151. + release_msg_context(msg_context);
  16152. +}
  16153. +
  16154. +/* enqueue a bulk receive for a given message context */
  16155. +static int bulk_receive(struct vchiq_mmal_instance *instance,
  16156. + struct mmal_msg *msg,
  16157. + struct mmal_msg_context *msg_context)
  16158. +{
  16159. + unsigned long rd_len;
  16160. + unsigned long flags = 0;
  16161. + int ret;
  16162. +
  16163. + /* bulk mutex stops other bulk operations while we have a
  16164. + * receive in progress - released in callback
  16165. + */
  16166. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  16167. + if (ret != 0)
  16168. + return ret;
  16169. +
  16170. + rd_len = msg->u.buffer_from_host.buffer_header.length;
  16171. +
  16172. + /* take buffer from queue */
  16173. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  16174. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  16175. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  16176. + pr_err("buffer list empty trying to submit bulk receive\n");
  16177. +
  16178. + /* todo: this is a serious error, we should never have
  16179. + * commited a buffer_to_host operation to the mmal
  16180. + * port without the buffer to back it up (underflow
  16181. + * handling) and there is no obvious way to deal with
  16182. + * this - how is the mmal servie going to react when
  16183. + * we fail to do the xfer and reschedule a buffer when
  16184. + * it arrives? perhaps a starved flag to indicate a
  16185. + * waiting bulk receive?
  16186. + */
  16187. +
  16188. + mutex_unlock(&instance->bulk_mutex);
  16189. +
  16190. + return -EINVAL;
  16191. + }
  16192. +
  16193. + msg_context->u.bulk.buffer =
  16194. + list_entry(msg_context->u.bulk.port->buffers.next,
  16195. + struct mmal_buffer, list);
  16196. + list_del(&msg_context->u.bulk.buffer->list);
  16197. +
  16198. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  16199. +
  16200. + /* ensure we do not overrun the available buffer */
  16201. + if (rd_len > msg_context->u.bulk.buffer->buffer_size) {
  16202. + rd_len = msg_context->u.bulk.buffer->buffer_size;
  16203. + pr_warn("short read as not enough receive buffer space\n");
  16204. + /* todo: is this the correct response, what happens to
  16205. + * the rest of the message data?
  16206. + */
  16207. + }
  16208. +
  16209. + /* store length */
  16210. + msg_context->u.bulk.buffer_used = rd_len;
  16211. + msg_context->u.bulk.mmal_flags =
  16212. + msg->u.buffer_from_host.buffer_header.flags;
  16213. + msg_context->u.bulk.dts = msg->u.buffer_from_host.buffer_header.dts;
  16214. + msg_context->u.bulk.pts = msg->u.buffer_from_host.buffer_header.pts;
  16215. +
  16216. + // only need to flush L1 cache here, as VCHIQ takes care of the L2
  16217. + // cache.
  16218. + __cpuc_flush_dcache_area(msg_context->u.bulk.buffer->buffer, rd_len);
  16219. +
  16220. + /* queue the bulk submission */
  16221. + vchi_service_use(instance->handle);
  16222. + ret = vchi_bulk_queue_receive(instance->handle,
  16223. + msg_context->u.bulk.buffer->buffer,
  16224. + /* Actual receive needs to be a multiple
  16225. + * of 4 bytes
  16226. + */
  16227. + (rd_len + 3) & ~3,
  16228. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  16229. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  16230. + msg_context);
  16231. +
  16232. + vchi_service_release(instance->handle);
  16233. +
  16234. + if (ret != 0) {
  16235. + /* callback will not be clearing the mutex */
  16236. + mutex_unlock(&instance->bulk_mutex);
  16237. + }
  16238. +
  16239. + return ret;
  16240. +}
  16241. +
  16242. +/* enque a dummy bulk receive for a given message context */
  16243. +static int dummy_bulk_receive(struct vchiq_mmal_instance *instance,
  16244. + struct mmal_msg_context *msg_context)
  16245. +{
  16246. + int ret;
  16247. +
  16248. + /* bulk mutex stops other bulk operations while we have a
  16249. + * receive in progress - released in callback
  16250. + */
  16251. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  16252. + if (ret != 0)
  16253. + return ret;
  16254. +
  16255. + /* zero length indicates this was a dummy transfer */
  16256. + msg_context->u.bulk.buffer_used = 0;
  16257. +
  16258. + /* queue the bulk submission */
  16259. + vchi_service_use(instance->handle);
  16260. +
  16261. + ret = vchi_bulk_queue_receive(instance->handle,
  16262. + instance->bulk_scratch,
  16263. + 8,
  16264. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  16265. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  16266. + msg_context);
  16267. +
  16268. + vchi_service_release(instance->handle);
  16269. +
  16270. + if (ret != 0) {
  16271. + /* callback will not be clearing the mutex */
  16272. + mutex_unlock(&instance->bulk_mutex);
  16273. + }
  16274. +
  16275. + return ret;
  16276. +}
  16277. +
  16278. +/* data in message, memcpy from packet into output buffer */
  16279. +static int inline_receive(struct vchiq_mmal_instance *instance,
  16280. + struct mmal_msg *msg,
  16281. + struct mmal_msg_context *msg_context)
  16282. +{
  16283. + unsigned long flags = 0;
  16284. +
  16285. + /* take buffer from queue */
  16286. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  16287. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  16288. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  16289. + pr_err("buffer list empty trying to receive inline\n");
  16290. +
  16291. + /* todo: this is a serious error, we should never have
  16292. + * commited a buffer_to_host operation to the mmal
  16293. + * port without the buffer to back it up (with
  16294. + * underflow handling) and there is no obvious way to
  16295. + * deal with this. Less bad than the bulk case as we
  16296. + * can just drop this on the floor but...unhelpful
  16297. + */
  16298. + return -EINVAL;
  16299. + }
  16300. +
  16301. + msg_context->u.bulk.buffer =
  16302. + list_entry(msg_context->u.bulk.port->buffers.next,
  16303. + struct mmal_buffer, list);
  16304. + list_del(&msg_context->u.bulk.buffer->list);
  16305. +
  16306. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  16307. +
  16308. + memcpy(msg_context->u.bulk.buffer->buffer,
  16309. + msg->u.buffer_from_host.short_data,
  16310. + msg->u.buffer_from_host.payload_in_message);
  16311. +
  16312. + msg_context->u.bulk.buffer_used =
  16313. + msg->u.buffer_from_host.payload_in_message;
  16314. +
  16315. + return 0;
  16316. +}
  16317. +
  16318. +/* queue the buffer availability with MMAL_MSG_TYPE_BUFFER_FROM_HOST */
  16319. +static int
  16320. +buffer_from_host(struct vchiq_mmal_instance *instance,
  16321. + struct vchiq_mmal_port *port, struct mmal_buffer *buf)
  16322. +{
  16323. + struct mmal_msg_context *msg_context;
  16324. + struct mmal_msg m;
  16325. + int ret;
  16326. +
  16327. + pr_debug("instance:%p buffer:%p\n", instance->handle, buf);
  16328. +
  16329. + /* bulk mutex stops other bulk operations while we
  16330. + * have a receive in progress
  16331. + */
  16332. + if (mutex_lock_interruptible(&instance->bulk_mutex))
  16333. + return -EINTR;
  16334. +
  16335. + /* get context */
  16336. + msg_context = get_msg_context(instance);
  16337. + if (msg_context == NULL)
  16338. + return -ENOMEM;
  16339. +
  16340. + /* store bulk message context for when data arrives */
  16341. + msg_context->u.bulk.instance = instance;
  16342. + msg_context->u.bulk.port = port;
  16343. + msg_context->u.bulk.buffer = NULL; /* not valid until bulk xfer */
  16344. + msg_context->u.bulk.buffer_used = 0;
  16345. +
  16346. + /* initialise work structure ready to schedule callback */
  16347. + INIT_WORK(&msg_context->u.bulk.work, buffer_work_cb);
  16348. +
  16349. + /* prep the buffer from host message */
  16350. + memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
  16351. +
  16352. + m.h.type = MMAL_MSG_TYPE_BUFFER_FROM_HOST;
  16353. + m.h.magic = MMAL_MAGIC;
  16354. + m.h.context = msg_context;
  16355. + m.h.status = 0;
  16356. +
  16357. + /* drvbuf is our private data passed back */
  16358. + m.u.buffer_from_host.drvbuf.magic = MMAL_MAGIC;
  16359. + m.u.buffer_from_host.drvbuf.component_handle = port->component->handle;
  16360. + m.u.buffer_from_host.drvbuf.port_handle = port->handle;
  16361. + m.u.buffer_from_host.drvbuf.client_context = msg_context;
  16362. +
  16363. + /* buffer header */
  16364. + m.u.buffer_from_host.buffer_header.cmd = 0;
  16365. + m.u.buffer_from_host.buffer_header.data = buf->buffer;
  16366. + m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size;
  16367. + m.u.buffer_from_host.buffer_header.length = 0; /* nothing used yet */
  16368. + m.u.buffer_from_host.buffer_header.offset = 0; /* no offset */
  16369. + m.u.buffer_from_host.buffer_header.flags = 0; /* no flags */
  16370. + m.u.buffer_from_host.buffer_header.pts = MMAL_TIME_UNKNOWN;
  16371. + m.u.buffer_from_host.buffer_header.dts = MMAL_TIME_UNKNOWN;
  16372. +
  16373. + /* clear buffer type sepecific data */
  16374. + memset(&m.u.buffer_from_host.buffer_header_type_specific, 0,
  16375. + sizeof(m.u.buffer_from_host.buffer_header_type_specific));
  16376. +
  16377. + /* no payload in message */
  16378. + m.u.buffer_from_host.payload_in_message = 0;
  16379. +
  16380. + vchi_service_use(instance->handle);
  16381. +
  16382. + ret = vchi_msg_queue(instance->handle, &m,
  16383. + sizeof(struct mmal_msg_header) +
  16384. + sizeof(m.u.buffer_from_host),
  16385. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  16386. +
  16387. + if (ret != 0) {
  16388. + release_msg_context(msg_context);
  16389. + /* todo: is this correct error value? */
  16390. + }
  16391. +
  16392. + vchi_service_release(instance->handle);
  16393. +
  16394. + mutex_unlock(&instance->bulk_mutex);
  16395. +
  16396. + return ret;
  16397. +}
  16398. +
  16399. +/* submit a buffer to the mmal sevice
  16400. + *
  16401. + * the buffer_from_host uses size data from the ports next available
  16402. + * mmal_buffer and deals with there being no buffer available by
  16403. + * incrementing the underflow for later
  16404. + */
  16405. +static int port_buffer_from_host(struct vchiq_mmal_instance *instance,
  16406. + struct vchiq_mmal_port *port)
  16407. +{
  16408. + int ret;
  16409. + struct mmal_buffer *buf;
  16410. + unsigned long flags = 0;
  16411. +
  16412. + if (!port->enabled)
  16413. + return -EINVAL;
  16414. +
  16415. + /* peek buffer from queue */
  16416. + spin_lock_irqsave(&port->slock, flags);
  16417. + if (list_empty(&port->buffers)) {
  16418. + port->buffer_underflow++;
  16419. + spin_unlock_irqrestore(&port->slock, flags);
  16420. + return -ENOSPC;
  16421. + }
  16422. +
  16423. + buf = list_entry(port->buffers.next, struct mmal_buffer, list);
  16424. +
  16425. + spin_unlock_irqrestore(&port->slock, flags);
  16426. +
  16427. + /* issue buffer to mmal service */
  16428. + ret = buffer_from_host(instance, port, buf);
  16429. + if (ret) {
  16430. + pr_err("adding buffer header failed\n");
  16431. + /* todo: how should this be dealt with */
  16432. + }
  16433. +
  16434. + return ret;
  16435. +}
  16436. +
  16437. +/* deals with receipt of buffer to host message */
  16438. +static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
  16439. + struct mmal_msg *msg, u32 msg_len)
  16440. +{
  16441. + struct mmal_msg_context *msg_context;
  16442. +
  16443. + pr_debug("buffer_to_host_cb: instance:%p msg:%p msg_len:%d\n",
  16444. + instance, msg, msg_len);
  16445. +
  16446. + if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
  16447. + msg_context = msg->u.buffer_from_host.drvbuf.client_context;
  16448. + } else {
  16449. + pr_err("MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n");
  16450. + return;
  16451. + }
  16452. +
  16453. + if (msg->h.status != MMAL_MSG_STATUS_SUCCESS) {
  16454. + /* message reception had an error */
  16455. + pr_warn("error %d in reply\n", msg->h.status);
  16456. +
  16457. + msg_context->u.bulk.status = msg->h.status;
  16458. +
  16459. + } else if (msg->u.buffer_from_host.buffer_header.length == 0) {
  16460. + /* empty buffer */
  16461. + if (msg->u.buffer_from_host.buffer_header.flags &
  16462. + MMAL_BUFFER_HEADER_FLAG_EOS) {
  16463. + msg_context->u.bulk.status =
  16464. + dummy_bulk_receive(instance, msg_context);
  16465. + if (msg_context->u.bulk.status == 0)
  16466. + return; /* successful bulk submission, bulk
  16467. + * completion will trigger callback
  16468. + */
  16469. + } else {
  16470. + /* do callback with empty buffer - not EOS though */
  16471. + msg_context->u.bulk.status = 0;
  16472. + msg_context->u.bulk.buffer_used = 0;
  16473. + }
  16474. + } else if (msg->u.buffer_from_host.payload_in_message == 0) {
  16475. + /* data is not in message, queue a bulk receive */
  16476. + msg_context->u.bulk.status =
  16477. + bulk_receive(instance, msg, msg_context);
  16478. + if (msg_context->u.bulk.status == 0)
  16479. + return; /* successful bulk submission, bulk
  16480. + * completion will trigger callback
  16481. + */
  16482. +
  16483. + /* failed to submit buffer, this will end badly */
  16484. + pr_err("error %d on bulk submission\n",
  16485. + msg_context->u.bulk.status);
  16486. +
  16487. + } else if (msg->u.buffer_from_host.payload_in_message <=
  16488. + MMAL_VC_SHORT_DATA) {
  16489. + /* data payload within message */
  16490. + msg_context->u.bulk.status = inline_receive(instance, msg,
  16491. + msg_context);
  16492. + } else {
  16493. + pr_err("message with invalid short payload\n");
  16494. +
  16495. + /* signal error */
  16496. + msg_context->u.bulk.status = -EINVAL;
  16497. + msg_context->u.bulk.buffer_used =
  16498. + msg->u.buffer_from_host.payload_in_message;
  16499. + }
  16500. +
  16501. + /* replace the buffer header */
  16502. + port_buffer_from_host(instance, msg_context->u.bulk.port);
  16503. +
  16504. + /* schedule the port callback */
  16505. + schedule_work(&msg_context->u.bulk.work);
  16506. +}
  16507. +
  16508. +static void bulk_receive_cb(struct vchiq_mmal_instance *instance,
  16509. + struct mmal_msg_context *msg_context)
  16510. +{
  16511. + /* bulk receive operation complete */
  16512. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  16513. +
  16514. + /* replace the buffer header */
  16515. + port_buffer_from_host(msg_context->u.bulk.instance,
  16516. + msg_context->u.bulk.port);
  16517. +
  16518. + msg_context->u.bulk.status = 0;
  16519. +
  16520. + /* schedule the port callback */
  16521. + schedule_work(&msg_context->u.bulk.work);
  16522. +}
  16523. +
  16524. +static void bulk_abort_cb(struct vchiq_mmal_instance *instance,
  16525. + struct mmal_msg_context *msg_context)
  16526. +{
  16527. + pr_err("%s: bulk ABORTED msg_context:%p\n", __func__, msg_context);
  16528. +
  16529. + /* bulk receive operation complete */
  16530. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  16531. +
  16532. + /* replace the buffer header */
  16533. + port_buffer_from_host(msg_context->u.bulk.instance,
  16534. + msg_context->u.bulk.port);
  16535. +
  16536. + msg_context->u.bulk.status = -EINTR;
  16537. +
  16538. + schedule_work(&msg_context->u.bulk.work);
  16539. +}
  16540. +
  16541. +/* incoming event service callback */
  16542. +static void service_callback(void *param,
  16543. + const VCHI_CALLBACK_REASON_T reason,
  16544. + void *bulk_ctx)
  16545. +{
  16546. + struct vchiq_mmal_instance *instance = param;
  16547. + int status;
  16548. + u32 msg_len;
  16549. + struct mmal_msg *msg;
  16550. + VCHI_HELD_MSG_T msg_handle;
  16551. +
  16552. + if (!instance) {
  16553. + pr_err("Message callback passed NULL instance\n");
  16554. + return;
  16555. + }
  16556. +
  16557. + switch (reason) {
  16558. + case VCHI_CALLBACK_MSG_AVAILABLE:
  16559. + status = vchi_msg_hold(instance->handle, (void **)&msg,
  16560. + &msg_len, VCHI_FLAGS_NONE, &msg_handle);
  16561. + if (status) {
  16562. + pr_err("Unable to dequeue a message (%d)\n", status);
  16563. + break;
  16564. + }
  16565. +
  16566. + DBG_DUMP_MSG(msg, msg_len, "<<< reply message");
  16567. +
  16568. + /* handling is different for buffer messages */
  16569. + switch (msg->h.type) {
  16570. +
  16571. + case MMAL_MSG_TYPE_BUFFER_FROM_HOST:
  16572. + vchi_held_msg_release(&msg_handle);
  16573. + break;
  16574. +
  16575. + case MMAL_MSG_TYPE_EVENT_TO_HOST:
  16576. + event_to_host_cb(instance, msg, msg_len);
  16577. + vchi_held_msg_release(&msg_handle);
  16578. +
  16579. + break;
  16580. +
  16581. + case MMAL_MSG_TYPE_BUFFER_TO_HOST:
  16582. + buffer_to_host_cb(instance, msg, msg_len);
  16583. + vchi_held_msg_release(&msg_handle);
  16584. + break;
  16585. +
  16586. + default:
  16587. + /* messages dependant on header context to complete */
  16588. +
  16589. + /* todo: the msg.context really ought to be sanity
  16590. + * checked before we just use it, afaict it comes back
  16591. + * and is used raw from the videocore. Perhaps it
  16592. + * should be verified the address lies in the kernel
  16593. + * address space.
  16594. + */
  16595. + if (msg->h.context == NULL) {
  16596. + pr_err("received message context was null!\n");
  16597. + vchi_held_msg_release(&msg_handle);
  16598. + break;
  16599. + }
  16600. +
  16601. + /* fill in context values */
  16602. + msg->h.context->u.sync.msg_handle = msg_handle;
  16603. + msg->h.context->u.sync.msg = msg;
  16604. + msg->h.context->u.sync.msg_len = msg_len;
  16605. +
  16606. + /* todo: should this check (completion_done()
  16607. + * == 1) for no one waiting? or do we need a
  16608. + * flag to tell us the completion has been
  16609. + * interrupted so we can free the message and
  16610. + * its context. This probably also solves the
  16611. + * message arriving after interruption todo
  16612. + * below
  16613. + */
  16614. +
  16615. + /* complete message so caller knows it happened */
  16616. + complete(&msg->h.context->u.sync.cmplt);
  16617. + break;
  16618. + }
  16619. +
  16620. + break;
  16621. +
  16622. + case VCHI_CALLBACK_BULK_RECEIVED:
  16623. + bulk_receive_cb(instance, bulk_ctx);
  16624. + break;
  16625. +
  16626. + case VCHI_CALLBACK_BULK_RECEIVE_ABORTED:
  16627. + bulk_abort_cb(instance, bulk_ctx);
  16628. + break;
  16629. +
  16630. + case VCHI_CALLBACK_SERVICE_CLOSED:
  16631. + /* TODO: consider if this requires action if received when
  16632. + * driver is not explicitly closing the service
  16633. + */
  16634. + break;
  16635. +
  16636. + default:
  16637. + pr_err("Received unhandled message reason %d\n", reason);
  16638. + break;
  16639. + }
  16640. +}
  16641. +
  16642. +static int send_synchronous_mmal_msg(struct vchiq_mmal_instance *instance,
  16643. + struct mmal_msg *msg,
  16644. + unsigned int payload_len,
  16645. + struct mmal_msg **msg_out,
  16646. + VCHI_HELD_MSG_T *msg_handle_out)
  16647. +{
  16648. + struct mmal_msg_context msg_context;
  16649. + int ret;
  16650. +
  16651. + /* payload size must not cause message to exceed max size */
  16652. + if (payload_len >
  16653. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header))) {
  16654. + pr_err("payload length %d exceeds max:%d\n", payload_len,
  16655. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header)));
  16656. + return -EINVAL;
  16657. + }
  16658. +
  16659. + init_completion(&msg_context.u.sync.cmplt);
  16660. +
  16661. + msg->h.magic = MMAL_MAGIC;
  16662. + msg->h.context = &msg_context;
  16663. + msg->h.status = 0;
  16664. +
  16665. + DBG_DUMP_MSG(msg, (sizeof(struct mmal_msg_header) + payload_len),
  16666. + ">>> sync message");
  16667. +
  16668. + vchi_service_use(instance->handle);
  16669. +
  16670. + ret = vchi_msg_queue(instance->handle,
  16671. + msg,
  16672. + sizeof(struct mmal_msg_header) + payload_len,
  16673. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  16674. +
  16675. + vchi_service_release(instance->handle);
  16676. +
  16677. + if (ret) {
  16678. + pr_err("error %d queuing message\n", ret);
  16679. + return ret;
  16680. + }
  16681. +
  16682. + ret = wait_for_completion_timeout(&msg_context.u.sync.cmplt, HZ);
  16683. + if (ret <= 0) {
  16684. + pr_err("error %d waiting for sync completion\n", ret);
  16685. + if (ret == 0)
  16686. + ret = -ETIME;
  16687. + /* todo: what happens if the message arrives after aborting */
  16688. + return ret;
  16689. + }
  16690. +
  16691. + *msg_out = msg_context.u.sync.msg;
  16692. + *msg_handle_out = msg_context.u.sync.msg_handle;
  16693. +
  16694. + return 0;
  16695. +}
  16696. +
  16697. +static void dump_port_info(struct vchiq_mmal_port *port)
  16698. +{
  16699. + pr_debug("port handle:0x%x enabled:%d\n", port->handle, port->enabled);
  16700. +
  16701. + pr_debug("buffer minimum num:%d size:%d align:%d\n",
  16702. + port->minimum_buffer.num,
  16703. + port->minimum_buffer.size, port->minimum_buffer.alignment);
  16704. +
  16705. + pr_debug("buffer recommended num:%d size:%d align:%d\n",
  16706. + port->recommended_buffer.num,
  16707. + port->recommended_buffer.size,
  16708. + port->recommended_buffer.alignment);
  16709. +
  16710. + pr_debug("buffer current values num:%d size:%d align:%d\n",
  16711. + port->current_buffer.num,
  16712. + port->current_buffer.size, port->current_buffer.alignment);
  16713. +
  16714. + pr_debug("elementry stream: type:%d encoding:0x%x varient:0x%x\n",
  16715. + port->format.type,
  16716. + port->format.encoding, port->format.encoding_variant);
  16717. +
  16718. + pr_debug(" bitrate:%d flags:0x%x\n",
  16719. + port->format.bitrate, port->format.flags);
  16720. +
  16721. + if (port->format.type == MMAL_ES_TYPE_VIDEO) {
  16722. + pr_debug
  16723. + ("es video format: width:%d height:%d colourspace:0x%x\n",
  16724. + port->es.video.width, port->es.video.height,
  16725. + port->es.video.color_space);
  16726. +
  16727. + pr_debug(" : crop xywh %d,%d,%d,%d\n",
  16728. + port->es.video.crop.x,
  16729. + port->es.video.crop.y,
  16730. + port->es.video.crop.width, port->es.video.crop.height);
  16731. + pr_debug(" : framerate %d/%d aspect %d/%d\n",
  16732. + port->es.video.frame_rate.num,
  16733. + port->es.video.frame_rate.den,
  16734. + port->es.video.par.num, port->es.video.par.den);
  16735. + }
  16736. +}
  16737. +
  16738. +static void port_to_mmal_msg(struct vchiq_mmal_port *port, struct mmal_port *p)
  16739. +{
  16740. +
  16741. + /* todo do readonly fields need setting at all? */
  16742. + p->type = port->type;
  16743. + p->index = port->index;
  16744. + p->index_all = 0;
  16745. + p->is_enabled = port->enabled;
  16746. + p->buffer_num_min = port->minimum_buffer.num;
  16747. + p->buffer_size_min = port->minimum_buffer.size;
  16748. + p->buffer_alignment_min = port->minimum_buffer.alignment;
  16749. + p->buffer_num_recommended = port->recommended_buffer.num;
  16750. + p->buffer_size_recommended = port->recommended_buffer.size;
  16751. +
  16752. + /* only three writable fields in a port */
  16753. + p->buffer_num = port->current_buffer.num;
  16754. + p->buffer_size = port->current_buffer.size;
  16755. + p->userdata = port;
  16756. +}
  16757. +
  16758. +static int port_info_set(struct vchiq_mmal_instance *instance,
  16759. + struct vchiq_mmal_port *port)
  16760. +{
  16761. + int ret;
  16762. + struct mmal_msg m;
  16763. + struct mmal_msg *rmsg;
  16764. + VCHI_HELD_MSG_T rmsg_handle;
  16765. +
  16766. + pr_debug("setting port info port %p\n", port);
  16767. + if (!port)
  16768. + return -1;
  16769. + dump_port_info(port);
  16770. +
  16771. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_SET;
  16772. +
  16773. + m.u.port_info_set.component_handle = port->component->handle;
  16774. + m.u.port_info_set.port_type = port->type;
  16775. + m.u.port_info_set.port_index = port->index;
  16776. +
  16777. + port_to_mmal_msg(port, &m.u.port_info_set.port);
  16778. +
  16779. + /* elementry stream format setup */
  16780. + m.u.port_info_set.format.type = port->format.type;
  16781. + m.u.port_info_set.format.encoding = port->format.encoding;
  16782. + m.u.port_info_set.format.encoding_variant =
  16783. + port->format.encoding_variant;
  16784. + m.u.port_info_set.format.bitrate = port->format.bitrate;
  16785. + m.u.port_info_set.format.flags = port->format.flags;
  16786. +
  16787. + memcpy(&m.u.port_info_set.es, &port->es,
  16788. + sizeof(union mmal_es_specific_format));
  16789. +
  16790. + m.u.port_info_set.format.extradata_size = port->format.extradata_size;
  16791. + memcpy(rmsg->u.port_info_set.extradata, port->format.extradata,
  16792. + port->format.extradata_size);
  16793. +
  16794. + ret = send_synchronous_mmal_msg(instance, &m,
  16795. + sizeof(m.u.port_info_set),
  16796. + &rmsg, &rmsg_handle);
  16797. + if (ret)
  16798. + return ret;
  16799. +
  16800. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_SET) {
  16801. + /* got an unexpected message type in reply */
  16802. + ret = -EINVAL;
  16803. + goto release_msg;
  16804. + }
  16805. +
  16806. + /* return operation status */
  16807. + ret = -rmsg->u.port_info_get_reply.status;
  16808. +
  16809. + pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret,
  16810. + port->component->handle, port->handle);
  16811. +
  16812. +release_msg:
  16813. + vchi_held_msg_release(&rmsg_handle);
  16814. +
  16815. + return ret;
  16816. +
  16817. +}
  16818. +
  16819. +/* use port info get message to retrive port information */
  16820. +static int port_info_get(struct vchiq_mmal_instance *instance,
  16821. + struct vchiq_mmal_port *port)
  16822. +{
  16823. + int ret;
  16824. + struct mmal_msg m;
  16825. + struct mmal_msg *rmsg;
  16826. + VCHI_HELD_MSG_T rmsg_handle;
  16827. +
  16828. + /* port info time */
  16829. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_GET;
  16830. + m.u.port_info_get.component_handle = port->component->handle;
  16831. + m.u.port_info_get.port_type = port->type;
  16832. + m.u.port_info_get.index = port->index;
  16833. +
  16834. + ret = send_synchronous_mmal_msg(instance, &m,
  16835. + sizeof(m.u.port_info_get),
  16836. + &rmsg, &rmsg_handle);
  16837. + if (ret)
  16838. + return ret;
  16839. +
  16840. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_GET) {
  16841. + /* got an unexpected message type in reply */
  16842. + ret = -EINVAL;
  16843. + goto release_msg;
  16844. + }
  16845. +
  16846. + /* return operation status */
  16847. + ret = -rmsg->u.port_info_get_reply.status;
  16848. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  16849. + goto release_msg;
  16850. +
  16851. + if (rmsg->u.port_info_get_reply.port.is_enabled == 0)
  16852. + port->enabled = false;
  16853. + else
  16854. + port->enabled = true;
  16855. +
  16856. + /* copy the values out of the message */
  16857. + port->handle = rmsg->u.port_info_get_reply.port_handle;
  16858. +
  16859. + /* port type and index cached to use on port info set becuase
  16860. + * it does not use a port handle
  16861. + */
  16862. + port->type = rmsg->u.port_info_get_reply.port_type;
  16863. + port->index = rmsg->u.port_info_get_reply.port_index;
  16864. +
  16865. + port->minimum_buffer.num =
  16866. + rmsg->u.port_info_get_reply.port.buffer_num_min;
  16867. + port->minimum_buffer.size =
  16868. + rmsg->u.port_info_get_reply.port.buffer_size_min;
  16869. + port->minimum_buffer.alignment =
  16870. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  16871. +
  16872. + port->recommended_buffer.alignment =
  16873. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  16874. + port->recommended_buffer.num =
  16875. + rmsg->u.port_info_get_reply.port.buffer_num_recommended;
  16876. +
  16877. + port->current_buffer.num = rmsg->u.port_info_get_reply.port.buffer_num;
  16878. + port->current_buffer.size =
  16879. + rmsg->u.port_info_get_reply.port.buffer_size;
  16880. +
  16881. + /* stream format */
  16882. + port->format.type = rmsg->u.port_info_get_reply.format.type;
  16883. + port->format.encoding = rmsg->u.port_info_get_reply.format.encoding;
  16884. + port->format.encoding_variant =
  16885. + rmsg->u.port_info_get_reply.format.encoding_variant;
  16886. + port->format.bitrate = rmsg->u.port_info_get_reply.format.bitrate;
  16887. + port->format.flags = rmsg->u.port_info_get_reply.format.flags;
  16888. +
  16889. + /* elementry stream format */
  16890. + memcpy(&port->es,
  16891. + &rmsg->u.port_info_get_reply.es,
  16892. + sizeof(union mmal_es_specific_format));
  16893. + port->format.es = &port->es;
  16894. +
  16895. + port->format.extradata_size =
  16896. + rmsg->u.port_info_get_reply.format.extradata_size;
  16897. + memcpy(port->format.extradata,
  16898. + rmsg->u.port_info_get_reply.extradata,
  16899. + port->format.extradata_size);
  16900. +
  16901. + pr_debug("received port info\n");
  16902. + dump_port_info(port);
  16903. +
  16904. +release_msg:
  16905. +
  16906. + pr_debug("%s:result:%d component:0x%x port:%d\n",
  16907. + __func__, ret, port->component->handle, port->handle);
  16908. +
  16909. + vchi_held_msg_release(&rmsg_handle);
  16910. +
  16911. + return ret;
  16912. +}
  16913. +
  16914. +/* create comonent on vc */
  16915. +static int create_component(struct vchiq_mmal_instance *instance,
  16916. + struct vchiq_mmal_component *component,
  16917. + const char *name)
  16918. +{
  16919. + int ret;
  16920. + struct mmal_msg m;
  16921. + struct mmal_msg *rmsg;
  16922. + VCHI_HELD_MSG_T rmsg_handle;
  16923. +
  16924. + /* build component create message */
  16925. + m.h.type = MMAL_MSG_TYPE_COMPONENT_CREATE;
  16926. + m.u.component_create.client_component = component;
  16927. + strncpy(m.u.component_create.name, name,
  16928. + sizeof(m.u.component_create.name));
  16929. +
  16930. + ret = send_synchronous_mmal_msg(instance, &m,
  16931. + sizeof(m.u.component_create),
  16932. + &rmsg, &rmsg_handle);
  16933. + if (ret)
  16934. + return ret;
  16935. +
  16936. + if (rmsg->h.type != m.h.type) {
  16937. + /* got an unexpected message type in reply */
  16938. + ret = -EINVAL;
  16939. + goto release_msg;
  16940. + }
  16941. +
  16942. + ret = -rmsg->u.component_create_reply.status;
  16943. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  16944. + goto release_msg;
  16945. +
  16946. + /* a valid component response received */
  16947. + component->handle = rmsg->u.component_create_reply.component_handle;
  16948. + component->inputs = rmsg->u.component_create_reply.input_num;
  16949. + component->outputs = rmsg->u.component_create_reply.output_num;
  16950. + component->clocks = rmsg->u.component_create_reply.clock_num;
  16951. +
  16952. + pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
  16953. + component->handle,
  16954. + component->inputs, component->outputs, component->clocks);
  16955. +
  16956. +release_msg:
  16957. + vchi_held_msg_release(&rmsg_handle);
  16958. +
  16959. + return ret;
  16960. +}
  16961. +
  16962. +/* destroys a component on vc */
  16963. +static int destroy_component(struct vchiq_mmal_instance *instance,
  16964. + struct vchiq_mmal_component *component)
  16965. +{
  16966. + int ret;
  16967. + struct mmal_msg m;
  16968. + struct mmal_msg *rmsg;
  16969. + VCHI_HELD_MSG_T rmsg_handle;
  16970. +
  16971. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DESTROY;
  16972. + m.u.component_destroy.component_handle = component->handle;
  16973. +
  16974. + ret = send_synchronous_mmal_msg(instance, &m,
  16975. + sizeof(m.u.component_destroy),
  16976. + &rmsg, &rmsg_handle);
  16977. + if (ret)
  16978. + return ret;
  16979. +
  16980. + if (rmsg->h.type != m.h.type) {
  16981. + /* got an unexpected message type in reply */
  16982. + ret = -EINVAL;
  16983. + goto release_msg;
  16984. + }
  16985. +
  16986. + ret = -rmsg->u.component_destroy_reply.status;
  16987. +
  16988. +release_msg:
  16989. +
  16990. + vchi_held_msg_release(&rmsg_handle);
  16991. +
  16992. + return ret;
  16993. +}
  16994. +
  16995. +/* enable a component on vc */
  16996. +static int enable_component(struct vchiq_mmal_instance *instance,
  16997. + struct vchiq_mmal_component *component)
  16998. +{
  16999. + int ret;
  17000. + struct mmal_msg m;
  17001. + struct mmal_msg *rmsg;
  17002. + VCHI_HELD_MSG_T rmsg_handle;
  17003. +
  17004. + m.h.type = MMAL_MSG_TYPE_COMPONENT_ENABLE;
  17005. + m.u.component_enable.component_handle = component->handle;
  17006. +
  17007. + ret = send_synchronous_mmal_msg(instance, &m,
  17008. + sizeof(m.u.component_enable),
  17009. + &rmsg, &rmsg_handle);
  17010. + if (ret)
  17011. + return ret;
  17012. +
  17013. + if (rmsg->h.type != m.h.type) {
  17014. + /* got an unexpected message type in reply */
  17015. + ret = -EINVAL;
  17016. + goto release_msg;
  17017. + }
  17018. +
  17019. + ret = -rmsg->u.component_enable_reply.status;
  17020. +
  17021. +release_msg:
  17022. + vchi_held_msg_release(&rmsg_handle);
  17023. +
  17024. + return ret;
  17025. +}
  17026. +
  17027. +/* disable a component on vc */
  17028. +static int disable_component(struct vchiq_mmal_instance *instance,
  17029. + struct vchiq_mmal_component *component)
  17030. +{
  17031. + int ret;
  17032. + struct mmal_msg m;
  17033. + struct mmal_msg *rmsg;
  17034. + VCHI_HELD_MSG_T rmsg_handle;
  17035. +
  17036. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DISABLE;
  17037. + m.u.component_disable.component_handle = component->handle;
  17038. +
  17039. + ret = send_synchronous_mmal_msg(instance, &m,
  17040. + sizeof(m.u.component_disable),
  17041. + &rmsg, &rmsg_handle);
  17042. + if (ret)
  17043. + return ret;
  17044. +
  17045. + if (rmsg->h.type != m.h.type) {
  17046. + /* got an unexpected message type in reply */
  17047. + ret = -EINVAL;
  17048. + goto release_msg;
  17049. + }
  17050. +
  17051. + ret = -rmsg->u.component_disable_reply.status;
  17052. +
  17053. +release_msg:
  17054. +
  17055. + vchi_held_msg_release(&rmsg_handle);
  17056. +
  17057. + return ret;
  17058. +}
  17059. +
  17060. +/* get version of mmal implementation */
  17061. +static int get_version(struct vchiq_mmal_instance *instance,
  17062. + u32 *major_out, u32 *minor_out)
  17063. +{
  17064. + int ret;
  17065. + struct mmal_msg m;
  17066. + struct mmal_msg *rmsg;
  17067. + VCHI_HELD_MSG_T rmsg_handle;
  17068. +
  17069. + m.h.type = MMAL_MSG_TYPE_GET_VERSION;
  17070. +
  17071. + ret = send_synchronous_mmal_msg(instance, &m,
  17072. + sizeof(m.u.version),
  17073. + &rmsg, &rmsg_handle);
  17074. + if (ret)
  17075. + return ret;
  17076. +
  17077. + if (rmsg->h.type != m.h.type) {
  17078. + /* got an unexpected message type in reply */
  17079. + ret = -EINVAL;
  17080. + goto release_msg;
  17081. + }
  17082. +
  17083. + *major_out = rmsg->u.version.major;
  17084. + *minor_out = rmsg->u.version.minor;
  17085. +
  17086. +release_msg:
  17087. + vchi_held_msg_release(&rmsg_handle);
  17088. +
  17089. + return ret;
  17090. +}
  17091. +
  17092. +/* do a port action with a port as a parameter */
  17093. +static int port_action_port(struct vchiq_mmal_instance *instance,
  17094. + struct vchiq_mmal_port *port,
  17095. + enum mmal_msg_port_action_type action_type)
  17096. +{
  17097. + int ret;
  17098. + struct mmal_msg m;
  17099. + struct mmal_msg *rmsg;
  17100. + VCHI_HELD_MSG_T rmsg_handle;
  17101. +
  17102. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  17103. + m.u.port_action_port.component_handle = port->component->handle;
  17104. + m.u.port_action_port.port_handle = port->handle;
  17105. + m.u.port_action_port.action = action_type;
  17106. +
  17107. + port_to_mmal_msg(port, &m.u.port_action_port.port);
  17108. +
  17109. + ret = send_synchronous_mmal_msg(instance, &m,
  17110. + sizeof(m.u.port_action_port),
  17111. + &rmsg, &rmsg_handle);
  17112. + if (ret)
  17113. + return ret;
  17114. +
  17115. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  17116. + /* got an unexpected message type in reply */
  17117. + ret = -EINVAL;
  17118. + goto release_msg;
  17119. + }
  17120. +
  17121. + ret = -rmsg->u.port_action_reply.status;
  17122. +
  17123. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
  17124. + __func__,
  17125. + ret, port->component->handle, port->handle,
  17126. + port_action_type_names[action_type], action_type);
  17127. +
  17128. +release_msg:
  17129. + vchi_held_msg_release(&rmsg_handle);
  17130. +
  17131. + return ret;
  17132. +}
  17133. +
  17134. +/* do a port action with handles as parameters */
  17135. +static int port_action_handle(struct vchiq_mmal_instance *instance,
  17136. + struct vchiq_mmal_port *port,
  17137. + enum mmal_msg_port_action_type action_type,
  17138. + u32 connect_component_handle,
  17139. + u32 connect_port_handle)
  17140. +{
  17141. + int ret;
  17142. + struct mmal_msg m;
  17143. + struct mmal_msg *rmsg;
  17144. + VCHI_HELD_MSG_T rmsg_handle;
  17145. +
  17146. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  17147. +
  17148. + m.u.port_action_handle.component_handle = port->component->handle;
  17149. + m.u.port_action_handle.port_handle = port->handle;
  17150. + m.u.port_action_handle.action = action_type;
  17151. +
  17152. + m.u.port_action_handle.connect_component_handle =
  17153. + connect_component_handle;
  17154. + m.u.port_action_handle.connect_port_handle = connect_port_handle;
  17155. +
  17156. + ret = send_synchronous_mmal_msg(instance, &m,
  17157. + sizeof(m.u.port_action_handle),
  17158. + &rmsg, &rmsg_handle);
  17159. + if (ret)
  17160. + return ret;
  17161. +
  17162. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  17163. + /* got an unexpected message type in reply */
  17164. + ret = -EINVAL;
  17165. + goto release_msg;
  17166. + }
  17167. +
  17168. + ret = -rmsg->u.port_action_reply.status;
  17169. +
  17170. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)" \
  17171. + " connect component:0x%x connect port:%d\n",
  17172. + __func__,
  17173. + ret, port->component->handle, port->handle,
  17174. + port_action_type_names[action_type],
  17175. + action_type, connect_component_handle, connect_port_handle);
  17176. +
  17177. +release_msg:
  17178. + vchi_held_msg_release(&rmsg_handle);
  17179. +
  17180. + return ret;
  17181. +}
  17182. +
  17183. +static int port_parameter_set(struct vchiq_mmal_instance *instance,
  17184. + struct vchiq_mmal_port *port,
  17185. + u32 parameter_id, void *value, u32 value_size)
  17186. +{
  17187. + int ret;
  17188. + struct mmal_msg m;
  17189. + struct mmal_msg *rmsg;
  17190. + VCHI_HELD_MSG_T rmsg_handle;
  17191. +
  17192. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_SET;
  17193. +
  17194. + m.u.port_parameter_set.component_handle = port->component->handle;
  17195. + m.u.port_parameter_set.port_handle = port->handle;
  17196. + m.u.port_parameter_set.id = parameter_id;
  17197. + m.u.port_parameter_set.size = (2 * sizeof(u32)) + value_size;
  17198. + memcpy(&m.u.port_parameter_set.value, value, value_size);
  17199. +
  17200. + ret = send_synchronous_mmal_msg(instance, &m,
  17201. + (4 * sizeof(u32)) + value_size,
  17202. + &rmsg, &rmsg_handle);
  17203. + if (ret)
  17204. + return ret;
  17205. +
  17206. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_SET) {
  17207. + /* got an unexpected message type in reply */
  17208. + ret = -EINVAL;
  17209. + goto release_msg;
  17210. + }
  17211. +
  17212. + ret = -rmsg->u.port_parameter_set_reply.status;
  17213. +
  17214. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
  17215. + __func__,
  17216. + ret, port->component->handle, port->handle, parameter_id);
  17217. +
  17218. +release_msg:
  17219. + vchi_held_msg_release(&rmsg_handle);
  17220. +
  17221. + return ret;
  17222. +}
  17223. +
  17224. +static int port_parameter_get(struct vchiq_mmal_instance *instance,
  17225. + struct vchiq_mmal_port *port,
  17226. + u32 parameter_id, void *value, u32 *value_size)
  17227. +{
  17228. + int ret;
  17229. + struct mmal_msg m;
  17230. + struct mmal_msg *rmsg;
  17231. + VCHI_HELD_MSG_T rmsg_handle;
  17232. +
  17233. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_GET;
  17234. +
  17235. + m.u.port_parameter_get.component_handle = port->component->handle;
  17236. + m.u.port_parameter_get.port_handle = port->handle;
  17237. + m.u.port_parameter_get.id = parameter_id;
  17238. + m.u.port_parameter_get.size = (2 * sizeof(u32)) + *value_size;
  17239. +
  17240. + ret = send_synchronous_mmal_msg(instance, &m,
  17241. + sizeof(struct
  17242. + mmal_msg_port_parameter_get),
  17243. + &rmsg, &rmsg_handle);
  17244. + if (ret)
  17245. + return ret;
  17246. +
  17247. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_GET) {
  17248. + /* got an unexpected message type in reply */
  17249. + pr_err("Incorrect reply type %d\n", rmsg->h.type);
  17250. + ret = -EINVAL;
  17251. + goto release_msg;
  17252. + }
  17253. +
  17254. + ret = -rmsg->u.port_parameter_get_reply.status;
  17255. + if (ret) {
  17256. + /* Copy only as much as we have space for
  17257. + * but report true size of parameter
  17258. + */
  17259. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  17260. + *value_size);
  17261. + *value_size = rmsg->u.port_parameter_get_reply.size;
  17262. + } else
  17263. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  17264. + rmsg->u.port_parameter_get_reply.size);
  17265. +
  17266. + pr_info("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
  17267. + ret, port->component->handle, port->handle, parameter_id);
  17268. +
  17269. +release_msg:
  17270. + vchi_held_msg_release(&rmsg_handle);
  17271. +
  17272. + return ret;
  17273. +}
  17274. +
  17275. +/* disables a port and drains buffers from it */
  17276. +static int port_disable(struct vchiq_mmal_instance *instance,
  17277. + struct vchiq_mmal_port *port)
  17278. +{
  17279. + int ret;
  17280. + struct list_head *q, *buf_head;
  17281. + unsigned long flags = 0;
  17282. +
  17283. + if (!port->enabled)
  17284. + return 0;
  17285. +
  17286. + port->enabled = false;
  17287. +
  17288. + ret = port_action_port(instance, port,
  17289. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE);
  17290. + if (ret == 0) {
  17291. +
  17292. + /* drain all queued buffers on port */
  17293. + spin_lock_irqsave(&port->slock, flags);
  17294. +
  17295. + list_for_each_safe(buf_head, q, &port->buffers) {
  17296. + struct mmal_buffer *mmalbuf;
  17297. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  17298. + list);
  17299. + list_del(buf_head);
  17300. + if (port->buffer_cb)
  17301. + port->buffer_cb(instance,
  17302. + port, 0, mmalbuf, 0, 0,
  17303. + MMAL_TIME_UNKNOWN,
  17304. + MMAL_TIME_UNKNOWN);
  17305. + }
  17306. +
  17307. + spin_unlock_irqrestore(&port->slock, flags);
  17308. +
  17309. + ret = port_info_get(instance, port);
  17310. + }
  17311. +
  17312. + return ret;
  17313. +}
  17314. +
  17315. +/* enable a port */
  17316. +static int port_enable(struct vchiq_mmal_instance *instance,
  17317. + struct vchiq_mmal_port *port)
  17318. +{
  17319. + unsigned int hdr_count;
  17320. + struct list_head *buf_head;
  17321. + int ret;
  17322. +
  17323. + if (port->enabled)
  17324. + return 0;
  17325. +
  17326. + /* ensure there are enough buffers queued to cover the buffer headers */
  17327. + if (port->buffer_cb != NULL) {
  17328. + hdr_count = 0;
  17329. + list_for_each(buf_head, &port->buffers) {
  17330. + hdr_count++;
  17331. + }
  17332. + if (hdr_count < port->current_buffer.num)
  17333. + return -ENOSPC;
  17334. + }
  17335. +
  17336. + ret = port_action_port(instance, port,
  17337. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE);
  17338. + if (ret)
  17339. + goto done;
  17340. +
  17341. + port->enabled = true;
  17342. +
  17343. + if (port->buffer_cb) {
  17344. + /* send buffer headers to videocore */
  17345. + hdr_count = 1;
  17346. + list_for_each(buf_head, &port->buffers) {
  17347. + struct mmal_buffer *mmalbuf;
  17348. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  17349. + list);
  17350. + ret = buffer_from_host(instance, port, mmalbuf);
  17351. + if (ret)
  17352. + goto done;
  17353. +
  17354. + hdr_count++;
  17355. + if (hdr_count > port->current_buffer.num)
  17356. + break;
  17357. + }
  17358. + }
  17359. +
  17360. + ret = port_info_get(instance, port);
  17361. +
  17362. +done:
  17363. + return ret;
  17364. +}
  17365. +
  17366. +/* ------------------------------------------------------------------
  17367. + * Exported API
  17368. + *------------------------------------------------------------------*/
  17369. +
  17370. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  17371. + struct vchiq_mmal_port *port)
  17372. +{
  17373. + int ret;
  17374. +
  17375. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17376. + return -EINTR;
  17377. +
  17378. + ret = port_info_set(instance, port);
  17379. + if (ret)
  17380. + goto release_unlock;
  17381. +
  17382. + /* read what has actually been set */
  17383. + ret = port_info_get(instance, port);
  17384. +
  17385. +release_unlock:
  17386. + mutex_unlock(&instance->vchiq_mutex);
  17387. +
  17388. + return ret;
  17389. +
  17390. +}
  17391. +
  17392. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  17393. + struct vchiq_mmal_port *port,
  17394. + u32 parameter, void *value, u32 value_size)
  17395. +{
  17396. + int ret;
  17397. +
  17398. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17399. + return -EINTR;
  17400. +
  17401. + ret = port_parameter_set(instance, port, parameter, value, value_size);
  17402. +
  17403. + mutex_unlock(&instance->vchiq_mutex);
  17404. +
  17405. + return ret;
  17406. +}
  17407. +
  17408. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  17409. + struct vchiq_mmal_port *port,
  17410. + u32 parameter, void *value, u32 *value_size)
  17411. +{
  17412. + int ret;
  17413. +
  17414. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17415. + return -EINTR;
  17416. +
  17417. + ret = port_parameter_get(instance, port, parameter, value, value_size);
  17418. +
  17419. + mutex_unlock(&instance->vchiq_mutex);
  17420. +
  17421. + return ret;
  17422. +}
  17423. +
  17424. +/* enable a port
  17425. + *
  17426. + * enables a port and queues buffers for satisfying callbacks if we
  17427. + * provide a callback handler
  17428. + */
  17429. +int vchiq_mmal_port_enable(struct vchiq_mmal_instance *instance,
  17430. + struct vchiq_mmal_port *port,
  17431. + vchiq_mmal_buffer_cb buffer_cb)
  17432. +{
  17433. + int ret;
  17434. +
  17435. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17436. + return -EINTR;
  17437. +
  17438. + /* already enabled - noop */
  17439. + if (port->enabled) {
  17440. + ret = 0;
  17441. + goto unlock;
  17442. + }
  17443. +
  17444. + port->buffer_cb = buffer_cb;
  17445. +
  17446. + ret = port_enable(instance, port);
  17447. +
  17448. +unlock:
  17449. + mutex_unlock(&instance->vchiq_mutex);
  17450. +
  17451. + return ret;
  17452. +}
  17453. +
  17454. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  17455. + struct vchiq_mmal_port *port)
  17456. +{
  17457. + int ret;
  17458. +
  17459. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17460. + return -EINTR;
  17461. +
  17462. + if (!port->enabled) {
  17463. + mutex_unlock(&instance->vchiq_mutex);
  17464. + return 0;
  17465. + }
  17466. +
  17467. + ret = port_disable(instance, port);
  17468. +
  17469. + mutex_unlock(&instance->vchiq_mutex);
  17470. +
  17471. + return ret;
  17472. +}
  17473. +
  17474. +/* ports will be connected in a tunneled manner so data buffers
  17475. + * are not handled by client.
  17476. + */
  17477. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  17478. + struct vchiq_mmal_port *src,
  17479. + struct vchiq_mmal_port *dst)
  17480. +{
  17481. + int ret;
  17482. +
  17483. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17484. + return -EINTR;
  17485. +
  17486. + /* disconnect ports if connected */
  17487. + if (src->connected != NULL) {
  17488. + ret = port_disable(instance, src);
  17489. + if (ret) {
  17490. + pr_err("failed disabling src port(%d)\n", ret);
  17491. + goto release_unlock;
  17492. + }
  17493. +
  17494. + /* do not need to disable the destination port as they
  17495. + * are connected and it is done automatically
  17496. + */
  17497. +
  17498. + ret = port_action_handle(instance, src,
  17499. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT,
  17500. + src->connected->component->handle,
  17501. + src->connected->handle);
  17502. + if (ret < 0) {
  17503. + pr_err("failed disconnecting src port\n");
  17504. + goto release_unlock;
  17505. + }
  17506. + src->connected->enabled = false;
  17507. + src->connected = NULL;
  17508. + }
  17509. +
  17510. + if (dst == NULL) {
  17511. + /* do not make new connection */
  17512. + ret = 0;
  17513. + pr_debug("not making new connection\n");
  17514. + goto release_unlock;
  17515. + }
  17516. +
  17517. + /* copy src port format to dst */
  17518. + dst->format.encoding = src->format.encoding;
  17519. + dst->es.video.width = src->es.video.width;
  17520. + dst->es.video.height = src->es.video.height;
  17521. + dst->es.video.crop.x = src->es.video.crop.x;
  17522. + dst->es.video.crop.y = src->es.video.crop.y;
  17523. + dst->es.video.crop.width = src->es.video.crop.width;
  17524. + dst->es.video.crop.height = src->es.video.crop.height;
  17525. + dst->es.video.frame_rate.num = src->es.video.frame_rate.num;
  17526. + dst->es.video.frame_rate.den = src->es.video.frame_rate.den;
  17527. +
  17528. + /* set new format */
  17529. + ret = port_info_set(instance, dst);
  17530. + if (ret) {
  17531. + pr_debug("setting port info failed\n");
  17532. + goto release_unlock;
  17533. + }
  17534. +
  17535. + /* read what has actually been set */
  17536. + ret = port_info_get(instance, dst);
  17537. + if (ret) {
  17538. + pr_debug("read back port info failed\n");
  17539. + goto release_unlock;
  17540. + }
  17541. +
  17542. + /* connect two ports together */
  17543. + ret = port_action_handle(instance, src,
  17544. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
  17545. + dst->component->handle, dst->handle);
  17546. + if (ret < 0) {
  17547. + pr_debug("connecting port %d:%d to %d:%d failed\n",
  17548. + src->component->handle, src->handle,
  17549. + dst->component->handle, dst->handle);
  17550. + goto release_unlock;
  17551. + }
  17552. + src->connected = dst;
  17553. +
  17554. +release_unlock:
  17555. +
  17556. + mutex_unlock(&instance->vchiq_mutex);
  17557. +
  17558. + return ret;
  17559. +}
  17560. +
  17561. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  17562. + struct vchiq_mmal_port *port,
  17563. + struct mmal_buffer *buffer)
  17564. +{
  17565. + unsigned long flags = 0;
  17566. +
  17567. + spin_lock_irqsave(&port->slock, flags);
  17568. + list_add_tail(&buffer->list, &port->buffers);
  17569. + spin_unlock_irqrestore(&port->slock, flags);
  17570. +
  17571. + /* the port previously underflowed because it was missing a
  17572. + * mmal_buffer which has just been added, submit that buffer
  17573. + * to the mmal service.
  17574. + */
  17575. + if (port->buffer_underflow) {
  17576. + port_buffer_from_host(instance, port);
  17577. + port->buffer_underflow--;
  17578. + }
  17579. +
  17580. + return 0;
  17581. +}
  17582. +
  17583. +/* Initialise a mmal component and its ports
  17584. + *
  17585. + */
  17586. +int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
  17587. + const char *name,
  17588. + struct vchiq_mmal_component **component_out)
  17589. +{
  17590. + int ret;
  17591. + int idx; /* port index */
  17592. + struct vchiq_mmal_component *component;
  17593. +
  17594. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17595. + return -EINTR;
  17596. +
  17597. + if (instance->component_idx == VCHIQ_MMAL_MAX_COMPONENTS) {
  17598. + ret = -EINVAL; /* todo is this correct error? */
  17599. + goto unlock;
  17600. + }
  17601. +
  17602. + component = &instance->component[instance->component_idx];
  17603. +
  17604. + ret = create_component(instance, component, name);
  17605. + if (ret < 0)
  17606. + goto unlock;
  17607. +
  17608. + /* ports info needs gathering */
  17609. + component->control.type = MMAL_PORT_TYPE_CONTROL;
  17610. + component->control.index = 0;
  17611. + component->control.component = component;
  17612. + spin_lock_init(&component->control.slock);
  17613. + INIT_LIST_HEAD(&component->control.buffers);
  17614. + ret = port_info_get(instance, &component->control);
  17615. + if (ret < 0)
  17616. + goto release_component;
  17617. +
  17618. + for (idx = 0; idx < component->inputs; idx++) {
  17619. + component->input[idx].type = MMAL_PORT_TYPE_INPUT;
  17620. + component->input[idx].index = idx;
  17621. + component->input[idx].component = component;
  17622. + spin_lock_init(&component->input[idx].slock);
  17623. + INIT_LIST_HEAD(&component->input[idx].buffers);
  17624. + ret = port_info_get(instance, &component->input[idx]);
  17625. + if (ret < 0)
  17626. + goto release_component;
  17627. + }
  17628. +
  17629. + for (idx = 0; idx < component->outputs; idx++) {
  17630. + component->output[idx].type = MMAL_PORT_TYPE_OUTPUT;
  17631. + component->output[idx].index = idx;
  17632. + component->output[idx].component = component;
  17633. + spin_lock_init(&component->output[idx].slock);
  17634. + INIT_LIST_HEAD(&component->output[idx].buffers);
  17635. + ret = port_info_get(instance, &component->output[idx]);
  17636. + if (ret < 0)
  17637. + goto release_component;
  17638. + }
  17639. +
  17640. + for (idx = 0; idx < component->clocks; idx++) {
  17641. + component->clock[idx].type = MMAL_PORT_TYPE_CLOCK;
  17642. + component->clock[idx].index = idx;
  17643. + component->clock[idx].component = component;
  17644. + spin_lock_init(&component->clock[idx].slock);
  17645. + INIT_LIST_HEAD(&component->clock[idx].buffers);
  17646. + ret = port_info_get(instance, &component->clock[idx]);
  17647. + if (ret < 0)
  17648. + goto release_component;
  17649. + }
  17650. +
  17651. + instance->component_idx++;
  17652. +
  17653. + *component_out = component;
  17654. +
  17655. + mutex_unlock(&instance->vchiq_mutex);
  17656. +
  17657. + return 0;
  17658. +
  17659. +release_component:
  17660. + destroy_component(instance, component);
  17661. +unlock:
  17662. + mutex_unlock(&instance->vchiq_mutex);
  17663. +
  17664. + return ret;
  17665. +}
  17666. +
  17667. +/*
  17668. + * cause a mmal component to be destroyed
  17669. + */
  17670. +int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
  17671. + struct vchiq_mmal_component *component)
  17672. +{
  17673. + int ret;
  17674. +
  17675. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17676. + return -EINTR;
  17677. +
  17678. + if (component->enabled)
  17679. + ret = disable_component(instance, component);
  17680. +
  17681. + ret = destroy_component(instance, component);
  17682. +
  17683. + mutex_unlock(&instance->vchiq_mutex);
  17684. +
  17685. + return ret;
  17686. +}
  17687. +
  17688. +/*
  17689. + * cause a mmal component to be enabled
  17690. + */
  17691. +int vchiq_mmal_component_enable(struct vchiq_mmal_instance *instance,
  17692. + struct vchiq_mmal_component *component)
  17693. +{
  17694. + int ret;
  17695. +
  17696. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17697. + return -EINTR;
  17698. +
  17699. + if (component->enabled) {
  17700. + mutex_unlock(&instance->vchiq_mutex);
  17701. + return 0;
  17702. + }
  17703. +
  17704. + ret = enable_component(instance, component);
  17705. + if (ret == 0)
  17706. + component->enabled = true;
  17707. +
  17708. + mutex_unlock(&instance->vchiq_mutex);
  17709. +
  17710. + return ret;
  17711. +}
  17712. +
  17713. +/*
  17714. + * cause a mmal component to be enabled
  17715. + */
  17716. +int vchiq_mmal_component_disable(struct vchiq_mmal_instance *instance,
  17717. + struct vchiq_mmal_component *component)
  17718. +{
  17719. + int ret;
  17720. +
  17721. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17722. + return -EINTR;
  17723. +
  17724. + if (!component->enabled) {
  17725. + mutex_unlock(&instance->vchiq_mutex);
  17726. + return 0;
  17727. + }
  17728. +
  17729. + ret = disable_component(instance, component);
  17730. + if (ret == 0)
  17731. + component->enabled = false;
  17732. +
  17733. + mutex_unlock(&instance->vchiq_mutex);
  17734. +
  17735. + return ret;
  17736. +}
  17737. +
  17738. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  17739. + u32 *major_out, u32 *minor_out)
  17740. +{
  17741. + int ret;
  17742. +
  17743. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17744. + return -EINTR;
  17745. +
  17746. + ret = get_version(instance, major_out, minor_out);
  17747. +
  17748. + mutex_unlock(&instance->vchiq_mutex);
  17749. +
  17750. + return ret;
  17751. +}
  17752. +
  17753. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
  17754. +{
  17755. + int status = 0;
  17756. +
  17757. + if (instance == NULL)
  17758. + return -EINVAL;
  17759. +
  17760. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17761. + return -EINTR;
  17762. +
  17763. + vchi_service_use(instance->handle);
  17764. +
  17765. + status = vchi_service_close(instance->handle);
  17766. + if (status != 0)
  17767. + pr_err("mmal-vchiq: VCHIQ close failed");
  17768. +
  17769. + mutex_unlock(&instance->vchiq_mutex);
  17770. +
  17771. + vfree(instance->bulk_scratch);
  17772. +
  17773. + kfree(instance);
  17774. +
  17775. + return status;
  17776. +}
  17777. +
  17778. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
  17779. +{
  17780. + int status;
  17781. + struct vchiq_mmal_instance *instance;
  17782. + static VCHI_CONNECTION_T *vchi_connection;
  17783. + static VCHI_INSTANCE_T vchi_instance;
  17784. + SERVICE_CREATION_T params = {
  17785. + VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER),
  17786. + VC_MMAL_SERVER_NAME,
  17787. + vchi_connection,
  17788. + 0, /* rx fifo size (unused) */
  17789. + 0, /* tx fifo size (unused) */
  17790. + service_callback,
  17791. + NULL, /* service callback parameter */
  17792. + 1, /* unaligned bulk receives */
  17793. + 1, /* unaligned bulk transmits */
  17794. + 0 /* want crc check on bulk transfers */
  17795. + };
  17796. +
  17797. + /* compile time checks to ensure structure size as they are
  17798. + * directly (de)serialised from memory.
  17799. + */
  17800. +
  17801. + /* ensure the header structure has packed to the correct size */
  17802. + BUILD_BUG_ON(sizeof(struct mmal_msg_header) != 24);
  17803. +
  17804. + /* ensure message structure does not exceed maximum length */
  17805. + BUILD_BUG_ON(sizeof(struct mmal_msg) > MMAL_MSG_MAX_SIZE);
  17806. +
  17807. + /* mmal port struct is correct size */
  17808. + BUILD_BUG_ON(sizeof(struct mmal_port) != 64);
  17809. +
  17810. + /* create a vchi instance */
  17811. + status = vchi_initialise(&vchi_instance);
  17812. + if (status) {
  17813. + pr_err("Failed to initialise VCHI instance (status=%d)\n",
  17814. + status);
  17815. + return -EIO;
  17816. + }
  17817. +
  17818. + status = vchi_connect(NULL, 0, vchi_instance);
  17819. + if (status) {
  17820. + pr_err("Failed to connect VCHI instance (status=%d)\n", status);
  17821. + return -EIO;
  17822. + }
  17823. +
  17824. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  17825. + memset(instance, 0, sizeof(*instance));
  17826. +
  17827. + mutex_init(&instance->vchiq_mutex);
  17828. + mutex_init(&instance->bulk_mutex);
  17829. +
  17830. + instance->bulk_scratch = vmalloc(PAGE_SIZE);
  17831. +
  17832. + params.callback_param = instance;
  17833. +
  17834. + status = vchi_service_open(vchi_instance, &params, &instance->handle);
  17835. + if (status) {
  17836. + pr_err("Failed to open VCHI service connection (status=%d)\n",
  17837. + status);
  17838. + goto err_close_services;
  17839. + }
  17840. +
  17841. + vchi_service_release(instance->handle);
  17842. +
  17843. + *out_instance = instance;
  17844. +
  17845. + return 0;
  17846. +
  17847. +err_close_services:
  17848. +
  17849. + vchi_service_close(instance->handle);
  17850. + vfree(instance->bulk_scratch);
  17851. + kfree(instance);
  17852. + return -ENODEV;
  17853. +}
  17854. diff -Nur linux-3.12.11.orig/drivers/media/platform/bcm2835/mmal-vchiq.h linux-3.12.11/drivers/media/platform/bcm2835/mmal-vchiq.h
  17855. --- linux-3.12.11.orig/drivers/media/platform/bcm2835/mmal-vchiq.h 1970-01-01 01:00:00.000000000 +0100
  17856. +++ linux-3.12.11/drivers/media/platform/bcm2835/mmal-vchiq.h 2014-02-18 11:52:14.000000000 +0100
  17857. @@ -0,0 +1,178 @@
  17858. +/*
  17859. + * Broadcom BM2835 V4L2 driver
  17860. + *
  17861. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  17862. + *
  17863. + * This file is subject to the terms and conditions of the GNU General Public
  17864. + * License. See the file COPYING in the main directory of this archive
  17865. + * for more details.
  17866. + *
  17867. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  17868. + * Dave Stevenson <dsteve@broadcom.com>
  17869. + * Simon Mellor <simellor@broadcom.com>
  17870. + * Luke Diamand <luked@broadcom.com>
  17871. + *
  17872. + * MMAL interface to VCHIQ message passing
  17873. + */
  17874. +
  17875. +#ifndef MMAL_VCHIQ_H
  17876. +#define MMAL_VCHIQ_H
  17877. +
  17878. +#include "mmal-msg-format.h"
  17879. +
  17880. +#define MAX_PORT_COUNT 4
  17881. +
  17882. +/* Maximum size of the format extradata. */
  17883. +#define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
  17884. +
  17885. +struct vchiq_mmal_instance;
  17886. +
  17887. +enum vchiq_mmal_es_type {
  17888. + MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
  17889. + MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
  17890. + MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
  17891. + MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
  17892. + MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
  17893. +};
  17894. +
  17895. +/* rectangle, used lots so it gets its own struct */
  17896. +struct vchiq_mmal_rect {
  17897. + s32 x;
  17898. + s32 y;
  17899. + s32 width;
  17900. + s32 height;
  17901. +};
  17902. +
  17903. +struct vchiq_mmal_port_buffer {
  17904. + unsigned int num; /* number of buffers */
  17905. + u32 size; /* size of buffers */
  17906. + u32 alignment; /* alignment of buffers */
  17907. +};
  17908. +
  17909. +struct vchiq_mmal_port;
  17910. +
  17911. +typedef void (*vchiq_mmal_buffer_cb)(
  17912. + struct vchiq_mmal_instance *instance,
  17913. + struct vchiq_mmal_port *port,
  17914. + int status, struct mmal_buffer *buffer,
  17915. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
  17916. +
  17917. +struct vchiq_mmal_port {
  17918. + bool enabled;
  17919. + u32 handle;
  17920. + u32 type; /* port type, cached to use on port info set */
  17921. + u32 index; /* port index, cached to use on port info set */
  17922. +
  17923. + /* component port belongs to, allows simple deref */
  17924. + struct vchiq_mmal_component *component;
  17925. +
  17926. + struct vchiq_mmal_port *connected; /* port conencted to */
  17927. +
  17928. + /* buffer info */
  17929. + struct vchiq_mmal_port_buffer minimum_buffer;
  17930. + struct vchiq_mmal_port_buffer recommended_buffer;
  17931. + struct vchiq_mmal_port_buffer current_buffer;
  17932. +
  17933. + /* stream format */
  17934. + struct mmal_es_format format;
  17935. + /* elementry stream format */
  17936. + union mmal_es_specific_format es;
  17937. +
  17938. + /* data buffers to fill */
  17939. + struct list_head buffers;
  17940. + /* lock to serialise adding and removing buffers from list */
  17941. + spinlock_t slock;
  17942. + /* count of how many buffer header refils have failed because
  17943. + * there was no buffer to satisfy them
  17944. + */
  17945. + int buffer_underflow;
  17946. + /* callback on buffer completion */
  17947. + vchiq_mmal_buffer_cb buffer_cb;
  17948. + /* callback context */
  17949. + void *cb_ctx;
  17950. +};
  17951. +
  17952. +struct vchiq_mmal_component {
  17953. + bool enabled;
  17954. + u32 handle; /* VideoCore handle for component */
  17955. + u32 inputs; /* Number of input ports */
  17956. + u32 outputs; /* Number of output ports */
  17957. + u32 clocks; /* Number of clock ports */
  17958. + struct vchiq_mmal_port control; /* control port */
  17959. + struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
  17960. + struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
  17961. + struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
  17962. +};
  17963. +
  17964. +
  17965. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
  17966. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
  17967. +
  17968. +/* Initialise a mmal component and its ports
  17969. +*
  17970. +*/
  17971. +int vchiq_mmal_component_init(
  17972. + struct vchiq_mmal_instance *instance,
  17973. + const char *name,
  17974. + struct vchiq_mmal_component **component_out);
  17975. +
  17976. +int vchiq_mmal_component_finalise(
  17977. + struct vchiq_mmal_instance *instance,
  17978. + struct vchiq_mmal_component *component);
  17979. +
  17980. +int vchiq_mmal_component_enable(
  17981. + struct vchiq_mmal_instance *instance,
  17982. + struct vchiq_mmal_component *component);
  17983. +
  17984. +int vchiq_mmal_component_disable(
  17985. + struct vchiq_mmal_instance *instance,
  17986. + struct vchiq_mmal_component *component);
  17987. +
  17988. +
  17989. +
  17990. +/* enable a mmal port
  17991. + *
  17992. + * enables a port and if a buffer callback provided enque buffer
  17993. + * headers as apropriate for the port.
  17994. + */
  17995. +int vchiq_mmal_port_enable(
  17996. + struct vchiq_mmal_instance *instance,
  17997. + struct vchiq_mmal_port *port,
  17998. + vchiq_mmal_buffer_cb buffer_cb);
  17999. +
  18000. +/* disable a port
  18001. + *
  18002. + * disable a port will dequeue any pending buffers
  18003. + */
  18004. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  18005. + struct vchiq_mmal_port *port);
  18006. +
  18007. +
  18008. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  18009. + struct vchiq_mmal_port *port,
  18010. + u32 parameter,
  18011. + void *value,
  18012. + u32 value_size);
  18013. +
  18014. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  18015. + struct vchiq_mmal_port *port,
  18016. + u32 parameter,
  18017. + void *value,
  18018. + u32 *value_size);
  18019. +
  18020. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  18021. + struct vchiq_mmal_port *port);
  18022. +
  18023. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  18024. + struct vchiq_mmal_port *src,
  18025. + struct vchiq_mmal_port *dst);
  18026. +
  18027. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  18028. + u32 *major_out,
  18029. + u32 *minor_out);
  18030. +
  18031. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  18032. + struct vchiq_mmal_port *port,
  18033. + struct mmal_buffer *buf);
  18034. +
  18035. +#endif /* MMAL_VCHIQ_H */
  18036. diff -Nur linux-3.12.11.orig/drivers/media/platform/Kconfig linux-3.12.11/drivers/media/platform/Kconfig
  18037. --- linux-3.12.11.orig/drivers/media/platform/Kconfig 2014-02-13 22:51:06.000000000 +0100
  18038. +++ linux-3.12.11/drivers/media/platform/Kconfig 2014-02-18 11:52:14.000000000 +0100
  18039. @@ -124,6 +124,7 @@
  18040. source "drivers/media/platform/soc_camera/Kconfig"
  18041. source "drivers/media/platform/exynos4-is/Kconfig"
  18042. source "drivers/media/platform/s5p-tv/Kconfig"
  18043. +source "drivers/media/platform/bcm2835/Kconfig"
  18044. endif # V4L_PLATFORM_DRIVERS
  18045. diff -Nur linux-3.12.11.orig/drivers/media/platform/Makefile linux-3.12.11/drivers/media/platform/Makefile
  18046. --- linux-3.12.11.orig/drivers/media/platform/Makefile 2014-02-13 22:51:06.000000000 +0100
  18047. +++ linux-3.12.11/drivers/media/platform/Makefile 2014-02-18 11:52:14.000000000 +0100
  18048. @@ -52,4 +52,6 @@
  18049. obj-$(CONFIG_ARCH_OMAP) += omap/
  18050. +obj-$(CONFIG_VIDEO_BCM2835) += bcm2835/
  18051. +
  18052. ccflags-y += -I$(srctree)/drivers/media/i2c
  18053. diff -Nur linux-3.12.11.orig/drivers/media/usb/dvb-usb-v2/az6007.c linux-3.12.11/drivers/media/usb/dvb-usb-v2/az6007.c
  18054. --- linux-3.12.11.orig/drivers/media/usb/dvb-usb-v2/az6007.c 2014-02-13 22:51:06.000000000 +0100
  18055. +++ linux-3.12.11/drivers/media/usb/dvb-usb-v2/az6007.c 2014-02-18 11:52:14.000000000 +0100
  18056. @@ -68,6 +68,19 @@
  18057. .microcode_name = "dvb-usb-terratec-h7-drxk.fw",
  18058. };
  18059. +static struct drxk_config cablestar_hdci_drxk = {
  18060. + .adr = 0x29,
  18061. + .parallel_ts = true,
  18062. + .dynamic_clk = true,
  18063. + .single_master = true,
  18064. + .enable_merr_cfg = true,
  18065. + .no_i2c_bridge = false,
  18066. + .chunk_size = 64,
  18067. + .mpeg_out_clk_strength = 0x02,
  18068. + .qam_demod_parameter_count = 2,
  18069. + .microcode_name = "dvb-usb-technisat-cablestar-hdci-drxk.fw",
  18070. +};
  18071. +
  18072. static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
  18073. {
  18074. struct az6007_device_state *st = fe_to_priv(fe);
  18075. @@ -630,6 +643,27 @@
  18076. return 0;
  18077. }
  18078. +static int az6007_cablestar_hdci_frontend_attach(struct dvb_usb_adapter *adap)
  18079. +{
  18080. + struct az6007_device_state *st = adap_to_priv(adap);
  18081. + struct dvb_usb_device *d = adap_to_d(adap);
  18082. +
  18083. + pr_debug("attaching demod drxk\n");
  18084. +
  18085. + adap->fe[0] = dvb_attach(drxk_attach, &cablestar_hdci_drxk,
  18086. + &d->i2c_adap);
  18087. + if (!adap->fe[0])
  18088. + return -EINVAL;
  18089. +
  18090. + adap->fe[0]->sec_priv = adap;
  18091. + st->gate_ctrl = adap->fe[0]->ops.i2c_gate_ctrl;
  18092. + adap->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
  18093. +
  18094. + az6007_ci_init(adap);
  18095. +
  18096. + return 0;
  18097. +}
  18098. +
  18099. static int az6007_tuner_attach(struct dvb_usb_adapter *adap)
  18100. {
  18101. struct dvb_usb_device *d = adap_to_d(adap);
  18102. @@ -868,6 +902,29 @@
  18103. }
  18104. };
  18105. +static struct dvb_usb_device_properties az6007_cablestar_hdci_props = {
  18106. + .driver_name = KBUILD_MODNAME,
  18107. + .owner = THIS_MODULE,
  18108. + .firmware = AZ6007_FIRMWARE,
  18109. +
  18110. + .adapter_nr = adapter_nr,
  18111. + .size_of_priv = sizeof(struct az6007_device_state),
  18112. + .i2c_algo = &az6007_i2c_algo,
  18113. + .tuner_attach = az6007_tuner_attach,
  18114. + .frontend_attach = az6007_cablestar_hdci_frontend_attach,
  18115. + .streaming_ctrl = az6007_streaming_ctrl,
  18116. +/* ditch get_rc_config as it can't work (TS35 remote, I believe it's rc5) */
  18117. + .get_rc_config = NULL,
  18118. + .read_mac_address = az6007_read_mac_addr,
  18119. + .download_firmware = az6007_download_firmware,
  18120. + .identify_state = az6007_identify_state,
  18121. + .power_ctrl = az6007_power_ctrl,
  18122. + .num_adapters = 1,
  18123. + .adapter = {
  18124. + { .stream = DVB_USB_STREAM_BULK(0x02, 10, 4096), }
  18125. + }
  18126. +};
  18127. +
  18128. static struct usb_device_id az6007_usb_table[] = {
  18129. {DVB_USB_DEVICE(USB_VID_AZUREWAVE, USB_PID_AZUREWAVE_6007,
  18130. &az6007_props, "Azurewave 6007", RC_MAP_EMPTY)},
  18131. @@ -875,6 +932,8 @@
  18132. &az6007_props, "Terratec H7", RC_MAP_NEC_TERRATEC_CINERGY_XS)},
  18133. {DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_H7_2,
  18134. &az6007_props, "Terratec H7", RC_MAP_NEC_TERRATEC_CINERGY_XS)},
  18135. + {DVB_USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_CABLESTAR_HDCI,
  18136. + &az6007_cablestar_hdci_props, "Technisat CableStar Combo HD CI", RC_MAP_EMPTY)},
  18137. {0},
  18138. };
  18139. diff -Nur linux-3.12.11.orig/drivers/media/usb/dvb-usb-v2/rtl28xxu.c linux-3.12.11/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
  18140. --- linux-3.12.11.orig/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2014-02-13 22:51:06.000000000 +0100
  18141. +++ linux-3.12.11/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2014-02-18 11:52:14.000000000 +0100
  18142. @@ -1384,6 +1384,10 @@
  18143. &rtl2832u_props, "Compro VideoMate U620F", NULL) },
  18144. { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
  18145. &rtl2832u_props, "MaxMedia HU394-T", NULL) },
  18146. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xb803 /*USB_PID_AUGUST_DVBT205*/,
  18147. + &rtl2832u_props, "August DVB-T 205", NULL) },
  18148. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xa803 /*USB_PID_AUGUST_DVBT205*/,
  18149. + &rtl2832u_props, "August DVB-T 205", NULL) },
  18150. { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03,
  18151. &rtl2832u_props, "Leadtek WinFast DTV Dongle mini", NULL) },
  18152. { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
  18153. diff -Nur linux-3.12.11.orig/drivers/misc/Kconfig linux-3.12.11/drivers/misc/Kconfig
  18154. --- linux-3.12.11.orig/drivers/misc/Kconfig 2014-02-13 22:51:06.000000000 +0100
  18155. +++ linux-3.12.11/drivers/misc/Kconfig 2014-02-18 11:52:14.000000000 +0100
  18156. @@ -537,4 +537,5 @@
  18157. source "drivers/misc/altera-stapl/Kconfig"
  18158. source "drivers/misc/mei/Kconfig"
  18159. source "drivers/misc/vmw_vmci/Kconfig"
  18160. +source "drivers/misc/vc04_services/Kconfig"
  18161. endmenu
  18162. diff -Nur linux-3.12.11.orig/drivers/misc/Makefile linux-3.12.11/drivers/misc/Makefile
  18163. --- linux-3.12.11.orig/drivers/misc/Makefile 2014-02-13 22:51:06.000000000 +0100
  18164. +++ linux-3.12.11/drivers/misc/Makefile 2014-02-18 11:52:14.000000000 +0100
  18165. @@ -53,3 +53,4 @@
  18166. obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/
  18167. obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o
  18168. obj-$(CONFIG_SRAM) += sram.o
  18169. +obj-$(CONFIG_BCM2708_VCHIQ) += vc04_services/
  18170. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchi/connections/connection.h linux-3.12.11/drivers/misc/vc04_services/interface/vchi/connections/connection.h
  18171. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchi/connections/connection.h 1970-01-01 01:00:00.000000000 +0100
  18172. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchi/connections/connection.h 2014-02-18 11:52:14.000000000 +0100
  18173. @@ -0,0 +1,328 @@
  18174. +/**
  18175. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18176. + *
  18177. + * Redistribution and use in source and binary forms, with or without
  18178. + * modification, are permitted provided that the following conditions
  18179. + * are met:
  18180. + * 1. Redistributions of source code must retain the above copyright
  18181. + * notice, this list of conditions, and the following disclaimer,
  18182. + * without modification.
  18183. + * 2. Redistributions in binary form must reproduce the above copyright
  18184. + * notice, this list of conditions and the following disclaimer in the
  18185. + * documentation and/or other materials provided with the distribution.
  18186. + * 3. The names of the above-listed copyright holders may not be used
  18187. + * to endorse or promote products derived from this software without
  18188. + * specific prior written permission.
  18189. + *
  18190. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18191. + * GNU General Public License ("GPL") version 2, as published by the Free
  18192. + * Software Foundation.
  18193. + *
  18194. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18195. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18196. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18197. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18198. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18199. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18200. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18201. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18202. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18203. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18204. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18205. + */
  18206. +
  18207. +#ifndef CONNECTION_H_
  18208. +#define CONNECTION_H_
  18209. +
  18210. +#include <linux/kernel.h>
  18211. +#include <linux/types.h>
  18212. +#include <linux/semaphore.h>
  18213. +
  18214. +#include "interface/vchi/vchi_cfg_internal.h"
  18215. +#include "interface/vchi/vchi_common.h"
  18216. +#include "interface/vchi/message_drivers/message.h"
  18217. +
  18218. +/******************************************************************************
  18219. + Global defs
  18220. + *****************************************************************************/
  18221. +
  18222. +// Opaque handle for a connection / service pair
  18223. +typedef struct opaque_vchi_connection_connected_service_handle_t *VCHI_CONNECTION_SERVICE_HANDLE_T;
  18224. +
  18225. +// opaque handle to the connection state information
  18226. +typedef struct opaque_vchi_connection_info_t VCHI_CONNECTION_STATE_T;
  18227. +
  18228. +typedef struct vchi_connection_t VCHI_CONNECTION_T;
  18229. +
  18230. +
  18231. +/******************************************************************************
  18232. + API
  18233. + *****************************************************************************/
  18234. +
  18235. +// Routine to init a connection with a particular low level driver
  18236. +typedef VCHI_CONNECTION_STATE_T * (*VCHI_CONNECTION_INIT_T)( struct vchi_connection_t * connection,
  18237. + const VCHI_MESSAGE_DRIVER_T * driver );
  18238. +
  18239. +// Routine to control CRC enabling at a connection level
  18240. +typedef int32_t (*VCHI_CONNECTION_CRC_CONTROL_T)( VCHI_CONNECTION_STATE_T *state_handle,
  18241. + VCHI_CRC_CONTROL_T control );
  18242. +
  18243. +// Routine to create a service
  18244. +typedef int32_t (*VCHI_CONNECTION_SERVICE_CONNECT_T)( VCHI_CONNECTION_STATE_T *state_handle,
  18245. + int32_t service_id,
  18246. + uint32_t rx_fifo_size,
  18247. + uint32_t tx_fifo_size,
  18248. + int server,
  18249. + VCHI_CALLBACK_T callback,
  18250. + void *callback_param,
  18251. + int32_t want_crc,
  18252. + int32_t want_unaligned_bulk_rx,
  18253. + int32_t want_unaligned_bulk_tx,
  18254. + VCHI_CONNECTION_SERVICE_HANDLE_T *service_handle );
  18255. +
  18256. +// Routine to close a service
  18257. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DISCONNECT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle );
  18258. +
  18259. +// Routine to queue a message
  18260. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18261. + const void *data,
  18262. + uint32_t data_size,
  18263. + VCHI_FLAGS_T flags,
  18264. + void *msg_handle );
  18265. +
  18266. +// scatter-gather (vector) message queueing
  18267. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18268. + VCHI_MSG_VECTOR_T *vector,
  18269. + uint32_t count,
  18270. + VCHI_FLAGS_T flags,
  18271. + void *msg_handle );
  18272. +
  18273. +// Routine to dequeue a message
  18274. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18275. + void *data,
  18276. + uint32_t max_data_size_to_read,
  18277. + uint32_t *actual_msg_size,
  18278. + VCHI_FLAGS_T flags );
  18279. +
  18280. +// Routine to peek at a message
  18281. +typedef int32_t (*VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18282. + void **data,
  18283. + uint32_t *msg_size,
  18284. + VCHI_FLAGS_T flags );
  18285. +
  18286. +// Routine to hold a message
  18287. +typedef int32_t (*VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18288. + void **data,
  18289. + uint32_t *msg_size,
  18290. + VCHI_FLAGS_T flags,
  18291. + void **message_handle );
  18292. +
  18293. +// Routine to initialise a received message iterator
  18294. +typedef int32_t (*VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18295. + VCHI_MSG_ITER_T *iter,
  18296. + VCHI_FLAGS_T flags );
  18297. +
  18298. +// Routine to release a held message
  18299. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_RELEASE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18300. + void *message_handle );
  18301. +
  18302. +// Routine to get info on a held message
  18303. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_INFO_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18304. + void *message_handle,
  18305. + void **data,
  18306. + int32_t *msg_size,
  18307. + uint32_t *tx_timestamp,
  18308. + uint32_t *rx_timestamp );
  18309. +
  18310. +// Routine to check whether the iterator has a next message
  18311. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  18312. + const VCHI_MSG_ITER_T *iter );
  18313. +
  18314. +// Routine to advance the iterator
  18315. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  18316. + VCHI_MSG_ITER_T *iter,
  18317. + void **data,
  18318. + uint32_t *msg_size );
  18319. +
  18320. +// Routine to remove the last message returned by the iterator
  18321. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_REMOVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  18322. + VCHI_MSG_ITER_T *iter );
  18323. +
  18324. +// Routine to hold the last message returned by the iterator
  18325. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HOLD_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  18326. + VCHI_MSG_ITER_T *iter,
  18327. + void **msg_handle );
  18328. +
  18329. +// Routine to transmit bulk data
  18330. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18331. + const void *data_src,
  18332. + uint32_t data_size,
  18333. + VCHI_FLAGS_T flags,
  18334. + void *bulk_handle );
  18335. +
  18336. +// Routine to receive data
  18337. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  18338. + void *data_dst,
  18339. + uint32_t data_size,
  18340. + VCHI_FLAGS_T flags,
  18341. + void *bulk_handle );
  18342. +
  18343. +// Routine to report if a server is available
  18344. +typedef int32_t (*VCHI_CONNECTION_SERVER_PRESENT)( VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t peer_flags );
  18345. +
  18346. +// Routine to report the number of RX slots available
  18347. +typedef int (*VCHI_CONNECTION_RX_SLOTS_AVAILABLE)( const VCHI_CONNECTION_STATE_T *state );
  18348. +
  18349. +// Routine to report the RX slot size
  18350. +typedef uint32_t (*VCHI_CONNECTION_RX_SLOT_SIZE)( const VCHI_CONNECTION_STATE_T *state );
  18351. +
  18352. +// Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  18353. +typedef void (*VCHI_CONNECTION_RX_BULK_BUFFER_ADDED)(VCHI_CONNECTION_STATE_T *state,
  18354. + int32_t service,
  18355. + uint32_t length,
  18356. + MESSAGE_TX_CHANNEL_T channel,
  18357. + uint32_t channel_params,
  18358. + uint32_t data_length,
  18359. + uint32_t data_offset);
  18360. +
  18361. +// Callback to inform a service that a Xon or Xoff message has been received
  18362. +typedef void (*VCHI_CONNECTION_FLOW_CONTROL)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t xoff);
  18363. +
  18364. +// Callback to inform a service that a server available reply message has been received
  18365. +typedef void (*VCHI_CONNECTION_SERVER_AVAILABLE_REPLY)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, uint32_t flags);
  18366. +
  18367. +// Callback to indicate that bulk auxiliary messages have arrived
  18368. +typedef void (*VCHI_CONNECTION_BULK_AUX_RECEIVED)(VCHI_CONNECTION_STATE_T *state);
  18369. +
  18370. +// Callback to indicate that bulk auxiliary messages have arrived
  18371. +typedef void (*VCHI_CONNECTION_BULK_AUX_TRANSMITTED)(VCHI_CONNECTION_STATE_T *state, void *handle);
  18372. +
  18373. +// Callback with all the connection info you require
  18374. +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);
  18375. +
  18376. +// Callback to inform of a disconnect
  18377. +typedef void (*VCHI_CONNECTION_DISCONNECT)(VCHI_CONNECTION_STATE_T *state, uint32_t flags);
  18378. +
  18379. +// Callback to inform of a power control request
  18380. +typedef void (*VCHI_CONNECTION_POWER_CONTROL)(VCHI_CONNECTION_STATE_T *state, MESSAGE_TX_CHANNEL_T channel, int32_t enable);
  18381. +
  18382. +// allocate memory suitably aligned for this connection
  18383. +typedef void * (*VCHI_BUFFER_ALLOCATE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, uint32_t * length);
  18384. +
  18385. +// free memory allocated by buffer_allocate
  18386. +typedef void (*VCHI_BUFFER_FREE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, void * address);
  18387. +
  18388. +
  18389. +/******************************************************************************
  18390. + System driver struct
  18391. + *****************************************************************************/
  18392. +
  18393. +struct opaque_vchi_connection_api_t
  18394. +{
  18395. + // Routine to init the connection
  18396. + VCHI_CONNECTION_INIT_T init;
  18397. +
  18398. + // Connection-level CRC control
  18399. + VCHI_CONNECTION_CRC_CONTROL_T crc_control;
  18400. +
  18401. + // Routine to connect to or create service
  18402. + VCHI_CONNECTION_SERVICE_CONNECT_T service_connect;
  18403. +
  18404. + // Routine to disconnect from a service
  18405. + VCHI_CONNECTION_SERVICE_DISCONNECT_T service_disconnect;
  18406. +
  18407. + // Routine to queue a message
  18408. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T service_queue_msg;
  18409. +
  18410. + // scatter-gather (vector) message queue
  18411. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T service_queue_msgv;
  18412. +
  18413. + // Routine to dequeue a message
  18414. + VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T service_dequeue_msg;
  18415. +
  18416. + // Routine to peek at a message
  18417. + VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T service_peek_msg;
  18418. +
  18419. + // Routine to hold a message
  18420. + VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T service_hold_msg;
  18421. +
  18422. + // Routine to initialise a received message iterator
  18423. + VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T service_look_ahead_msg;
  18424. +
  18425. + // Routine to release a message
  18426. + VCHI_CONNECTION_HELD_MSG_RELEASE_T held_msg_release;
  18427. +
  18428. + // Routine to get information on a held message
  18429. + VCHI_CONNECTION_HELD_MSG_INFO_T held_msg_info;
  18430. +
  18431. + // Routine to check for next message on iterator
  18432. + VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T msg_iter_has_next;
  18433. +
  18434. + // Routine to get next message on iterator
  18435. + VCHI_CONNECTION_MSG_ITER_NEXT_T msg_iter_next;
  18436. +
  18437. + // Routine to remove the last message returned by iterator
  18438. + VCHI_CONNECTION_MSG_ITER_REMOVE_T msg_iter_remove;
  18439. +
  18440. + // Routine to hold the last message returned by iterator
  18441. + VCHI_CONNECTION_MSG_ITER_HOLD_T msg_iter_hold;
  18442. +
  18443. + // Routine to transmit bulk data
  18444. + VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T bulk_queue_transmit;
  18445. +
  18446. + // Routine to receive data
  18447. + VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T bulk_queue_receive;
  18448. +
  18449. + // Routine to report the available servers
  18450. + VCHI_CONNECTION_SERVER_PRESENT server_present;
  18451. +
  18452. + // Routine to report the number of RX slots available
  18453. + VCHI_CONNECTION_RX_SLOTS_AVAILABLE connection_rx_slots_available;
  18454. +
  18455. + // Routine to report the RX slot size
  18456. + VCHI_CONNECTION_RX_SLOT_SIZE connection_rx_slot_size;
  18457. +
  18458. + // Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  18459. + VCHI_CONNECTION_RX_BULK_BUFFER_ADDED rx_bulk_buffer_added;
  18460. +
  18461. + // Callback to inform a service that a Xon or Xoff message has been received
  18462. + VCHI_CONNECTION_FLOW_CONTROL flow_control;
  18463. +
  18464. + // Callback to inform a service that a server available reply message has been received
  18465. + VCHI_CONNECTION_SERVER_AVAILABLE_REPLY server_available_reply;
  18466. +
  18467. + // Callback to indicate that bulk auxiliary messages have arrived
  18468. + VCHI_CONNECTION_BULK_AUX_RECEIVED bulk_aux_received;
  18469. +
  18470. + // Callback to indicate that a bulk auxiliary message has been transmitted
  18471. + VCHI_CONNECTION_BULK_AUX_TRANSMITTED bulk_aux_transmitted;
  18472. +
  18473. + // Callback to provide information about the connection
  18474. + VCHI_CONNECTION_INFO connection_info;
  18475. +
  18476. + // Callback to notify that peer has requested disconnect
  18477. + VCHI_CONNECTION_DISCONNECT disconnect;
  18478. +
  18479. + // Callback to notify that peer has requested power change
  18480. + VCHI_CONNECTION_POWER_CONTROL power_control;
  18481. +
  18482. + // allocate memory suitably aligned for this connection
  18483. + VCHI_BUFFER_ALLOCATE buffer_allocate;
  18484. +
  18485. + // free memory allocated by buffer_allocate
  18486. + VCHI_BUFFER_FREE buffer_free;
  18487. +
  18488. +};
  18489. +
  18490. +struct vchi_connection_t {
  18491. + const VCHI_CONNECTION_API_T *api;
  18492. + VCHI_CONNECTION_STATE_T *state;
  18493. +#ifdef VCHI_COARSE_LOCKING
  18494. + struct semaphore sem;
  18495. +#endif
  18496. +};
  18497. +
  18498. +
  18499. +#endif /* CONNECTION_H_ */
  18500. +
  18501. +/****************************** End of file **********************************/
  18502. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h linux-3.12.11/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h
  18503. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 1970-01-01 01:00:00.000000000 +0100
  18504. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 2014-02-18 11:52:14.000000000 +0100
  18505. @@ -0,0 +1,204 @@
  18506. +/**
  18507. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18508. + *
  18509. + * Redistribution and use in source and binary forms, with or without
  18510. + * modification, are permitted provided that the following conditions
  18511. + * are met:
  18512. + * 1. Redistributions of source code must retain the above copyright
  18513. + * notice, this list of conditions, and the following disclaimer,
  18514. + * without modification.
  18515. + * 2. Redistributions in binary form must reproduce the above copyright
  18516. + * notice, this list of conditions and the following disclaimer in the
  18517. + * documentation and/or other materials provided with the distribution.
  18518. + * 3. The names of the above-listed copyright holders may not be used
  18519. + * to endorse or promote products derived from this software without
  18520. + * specific prior written permission.
  18521. + *
  18522. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18523. + * GNU General Public License ("GPL") version 2, as published by the Free
  18524. + * Software Foundation.
  18525. + *
  18526. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18527. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18528. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18529. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18530. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18531. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18532. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18533. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18534. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18535. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18536. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18537. + */
  18538. +
  18539. +#ifndef _VCHI_MESSAGE_H_
  18540. +#define _VCHI_MESSAGE_H_
  18541. +
  18542. +#include <linux/kernel.h>
  18543. +#include <linux/types.h>
  18544. +#include <linux/semaphore.h>
  18545. +
  18546. +#include "interface/vchi/vchi_cfg_internal.h"
  18547. +#include "interface/vchi/vchi_common.h"
  18548. +
  18549. +
  18550. +typedef enum message_event_type {
  18551. + MESSAGE_EVENT_NONE,
  18552. + MESSAGE_EVENT_NOP,
  18553. + MESSAGE_EVENT_MESSAGE,
  18554. + MESSAGE_EVENT_SLOT_COMPLETE,
  18555. + MESSAGE_EVENT_RX_BULK_PAUSED,
  18556. + MESSAGE_EVENT_RX_BULK_COMPLETE,
  18557. + MESSAGE_EVENT_TX_COMPLETE,
  18558. + MESSAGE_EVENT_MSG_DISCARDED
  18559. +} MESSAGE_EVENT_TYPE_T;
  18560. +
  18561. +typedef enum vchi_msg_flags
  18562. +{
  18563. + VCHI_MSG_FLAGS_NONE = 0x0,
  18564. + VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1
  18565. +} VCHI_MSG_FLAGS_T;
  18566. +
  18567. +typedef enum message_tx_channel
  18568. +{
  18569. + MESSAGE_TX_CHANNEL_MESSAGE = 0,
  18570. + MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  18571. +} MESSAGE_TX_CHANNEL_T;
  18572. +
  18573. +// Macros used for cycling through bulk channels
  18574. +#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)
  18575. +#define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
  18576. +
  18577. +typedef enum message_rx_channel
  18578. +{
  18579. + MESSAGE_RX_CHANNEL_MESSAGE = 0,
  18580. + MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  18581. +} MESSAGE_RX_CHANNEL_T;
  18582. +
  18583. +// Message receive slot information
  18584. +typedef struct rx_msg_slot_info {
  18585. +
  18586. + struct rx_msg_slot_info *next;
  18587. + //struct slot_info *prev;
  18588. +#if !defined VCHI_COARSE_LOCKING
  18589. + struct semaphore sem;
  18590. +#endif
  18591. +
  18592. + uint8_t *addr; // base address of slot
  18593. + uint32_t len; // length of slot in bytes
  18594. +
  18595. + uint32_t write_ptr; // hardware causes this to advance
  18596. + uint32_t read_ptr; // this module does the reading
  18597. + int active; // is this slot in the hardware dma fifo?
  18598. + uint32_t msgs_parsed; // count how many messages are in this slot
  18599. + uint32_t msgs_released; // how many messages have been released
  18600. + void *state; // connection state information
  18601. + uint8_t ref_count[VCHI_MAX_SERVICES_PER_CONNECTION]; // reference count for slots held by services
  18602. +} RX_MSG_SLOTINFO_T;
  18603. +
  18604. +// The message driver no longer needs to know about the fields of RX_BULK_SLOTINFO_T - sort this out.
  18605. +// In particular, it mustn't use addr and len - they're the client buffer, but the message
  18606. +// driver will be tasked with sending the aligned core section.
  18607. +typedef struct rx_bulk_slotinfo_t {
  18608. + struct rx_bulk_slotinfo_t *next;
  18609. +
  18610. + struct semaphore *blocking;
  18611. +
  18612. + // needed by DMA
  18613. + void *addr;
  18614. + uint32_t len;
  18615. +
  18616. + // needed for the callback
  18617. + void *service;
  18618. + void *handle;
  18619. + VCHI_FLAGS_T flags;
  18620. +} RX_BULK_SLOTINFO_T;
  18621. +
  18622. +
  18623. +/* ----------------------------------------------------------------------
  18624. + * each connection driver will have a pool of the following struct.
  18625. + *
  18626. + * the pool will be managed by vchi_qman_*
  18627. + * this means there will be multiple queues (single linked lists)
  18628. + * a given struct message_info will be on exactly one of these queues
  18629. + * at any one time
  18630. + * -------------------------------------------------------------------- */
  18631. +typedef struct rx_message_info {
  18632. +
  18633. + struct message_info *next;
  18634. + //struct message_info *prev;
  18635. +
  18636. + uint8_t *addr;
  18637. + uint32_t len;
  18638. + RX_MSG_SLOTINFO_T *slot; // points to whichever slot contains this message
  18639. + uint32_t tx_timestamp;
  18640. + uint32_t rx_timestamp;
  18641. +
  18642. +} RX_MESSAGE_INFO_T;
  18643. +
  18644. +typedef struct {
  18645. + MESSAGE_EVENT_TYPE_T type;
  18646. +
  18647. + struct {
  18648. + // for messages
  18649. + void *addr; // address of message
  18650. + uint16_t slot_delta; // whether this message indicated slot delta
  18651. + uint32_t len; // length of message
  18652. + RX_MSG_SLOTINFO_T *slot; // slot this message is in
  18653. + int32_t service; // service id this message is destined for
  18654. + uint32_t tx_timestamp; // timestamp from the header
  18655. + uint32_t rx_timestamp; // timestamp when we parsed it
  18656. + } message;
  18657. +
  18658. + // FIXME: cleanup slot reporting...
  18659. + RX_MSG_SLOTINFO_T *rx_msg;
  18660. + RX_BULK_SLOTINFO_T *rx_bulk;
  18661. + void *tx_handle;
  18662. + MESSAGE_TX_CHANNEL_T tx_channel;
  18663. +
  18664. +} MESSAGE_EVENT_T;
  18665. +
  18666. +
  18667. +// callbacks
  18668. +typedef void VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T( void *state );
  18669. +
  18670. +typedef struct {
  18671. + VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T *event_callback;
  18672. +} VCHI_MESSAGE_DRIVER_OPEN_T;
  18673. +
  18674. +
  18675. +// handle to this instance of message driver (as returned by ->open)
  18676. +typedef struct opaque_mhandle_t *VCHI_MDRIVER_HANDLE_T;
  18677. +
  18678. +struct opaque_vchi_message_driver_t {
  18679. + VCHI_MDRIVER_HANDLE_T *(*open)( VCHI_MESSAGE_DRIVER_OPEN_T *params, void *state );
  18680. + int32_t (*suspending)( VCHI_MDRIVER_HANDLE_T *handle );
  18681. + int32_t (*resumed)( VCHI_MDRIVER_HANDLE_T *handle );
  18682. + int32_t (*power_control)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T, int32_t enable );
  18683. + int32_t (*add_msg_rx_slot)( VCHI_MDRIVER_HANDLE_T *handle, RX_MSG_SLOTINFO_T *slot ); // rx message
  18684. + int32_t (*add_bulk_rx)( VCHI_MDRIVER_HANDLE_T *handle, void *data, uint32_t len, RX_BULK_SLOTINFO_T *slot ); // rx data (bulk)
  18685. + 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)
  18686. + void (*next_event)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_EVENT_T *event ); // get the next event from message_driver
  18687. + int32_t (*enable)( VCHI_MDRIVER_HANDLE_T *handle );
  18688. + int32_t (*form_message)( VCHI_MDRIVER_HANDLE_T *handle, int32_t service_id, VCHI_MSG_VECTOR_T *vector, uint32_t count, void
  18689. + *address, uint32_t length_avail, uint32_t max_total_length, int32_t pad_to_fill, int32_t allow_partial );
  18690. +
  18691. + int32_t (*update_message)( VCHI_MDRIVER_HANDLE_T *handle, void *dest, int16_t *slot_count );
  18692. + int32_t (*buffer_aligned)( VCHI_MDRIVER_HANDLE_T *handle, int tx, int uncached, const void *address, const uint32_t length );
  18693. + void * (*allocate_buffer)( VCHI_MDRIVER_HANDLE_T *handle, uint32_t *length );
  18694. + void (*free_buffer)( VCHI_MDRIVER_HANDLE_T *handle, void *address );
  18695. + int (*rx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  18696. + int (*tx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  18697. +
  18698. + int32_t (*tx_supports_terminate)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  18699. + uint32_t (*tx_bulk_chunk_size)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  18700. + int (*tx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  18701. + int (*rx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_RX_CHANNEL_T channel );
  18702. + 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 );
  18703. + void (*debug)( VCHI_MDRIVER_HANDLE_T *handle );
  18704. +};
  18705. +
  18706. +
  18707. +#endif // _VCHI_MESSAGE_H_
  18708. +
  18709. +/****************************** End of file ***********************************/
  18710. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h linux-3.12.11/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h
  18711. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 1970-01-01 01:00:00.000000000 +0100
  18712. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 2014-02-18 11:52:14.000000000 +0100
  18713. @@ -0,0 +1,224 @@
  18714. +/**
  18715. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18716. + *
  18717. + * Redistribution and use in source and binary forms, with or without
  18718. + * modification, are permitted provided that the following conditions
  18719. + * are met:
  18720. + * 1. Redistributions of source code must retain the above copyright
  18721. + * notice, this list of conditions, and the following disclaimer,
  18722. + * without modification.
  18723. + * 2. Redistributions in binary form must reproduce the above copyright
  18724. + * notice, this list of conditions and the following disclaimer in the
  18725. + * documentation and/or other materials provided with the distribution.
  18726. + * 3. The names of the above-listed copyright holders may not be used
  18727. + * to endorse or promote products derived from this software without
  18728. + * specific prior written permission.
  18729. + *
  18730. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18731. + * GNU General Public License ("GPL") version 2, as published by the Free
  18732. + * Software Foundation.
  18733. + *
  18734. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18735. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18736. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18737. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18738. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18739. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18740. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18741. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18742. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18743. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18744. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18745. + */
  18746. +
  18747. +#ifndef VCHI_CFG_H_
  18748. +#define VCHI_CFG_H_
  18749. +
  18750. +/****************************************************************************************
  18751. + * Defines in this first section are part of the VCHI API and may be examined by VCHI
  18752. + * services.
  18753. + ***************************************************************************************/
  18754. +
  18755. +/* Required alignment of base addresses for bulk transfer, if unaligned transfers are not enabled */
  18756. +/* Really determined by the message driver, and should be available from a run-time call. */
  18757. +#ifndef VCHI_BULK_ALIGN
  18758. +# if __VCCOREVER__ >= 0x04000000
  18759. +# define VCHI_BULK_ALIGN 32 // Allows for the need to do cache cleans
  18760. +# else
  18761. +# define VCHI_BULK_ALIGN 16
  18762. +# endif
  18763. +#endif
  18764. +
  18765. +/* Required length multiple for bulk transfers, if unaligned transfers are not enabled */
  18766. +/* May be less than or greater than VCHI_BULK_ALIGN */
  18767. +/* Really determined by the message driver, and should be available from a run-time call. */
  18768. +#ifndef VCHI_BULK_GRANULARITY
  18769. +# if __VCCOREVER__ >= 0x04000000
  18770. +# define VCHI_BULK_GRANULARITY 32 // Allows for the need to do cache cleans
  18771. +# else
  18772. +# define VCHI_BULK_GRANULARITY 16
  18773. +# endif
  18774. +#endif
  18775. +
  18776. +/* The largest possible message to be queued with vchi_msg_queue. */
  18777. +#ifndef VCHI_MAX_MSG_SIZE
  18778. +# if defined VCHI_LOCAL_HOST_PORT
  18779. +# define VCHI_MAX_MSG_SIZE 16384 // makes file transfers fast, but should they be using bulk?
  18780. +# else
  18781. +# define VCHI_MAX_MSG_SIZE 4096 // NOTE: THIS MUST BE LARGER THAN OR EQUAL TO THE SIZE OF THE KHRONOS MERGE BUFFER!!
  18782. +# endif
  18783. +#endif
  18784. +
  18785. +/******************************************************************************************
  18786. + * Defines below are system configuration options, and should not be used by VCHI services.
  18787. + *****************************************************************************************/
  18788. +
  18789. +/* How many connections can we support? A localhost implementation uses 2 connections,
  18790. + * 1 for host-app, 1 for VMCS, and these are hooked together by a loopback MPHI VCFW
  18791. + * driver. */
  18792. +#ifndef VCHI_MAX_NUM_CONNECTIONS
  18793. +# define VCHI_MAX_NUM_CONNECTIONS 3
  18794. +#endif
  18795. +
  18796. +/* How many services can we open per connection? Extending this doesn't cost processing time, just a small
  18797. + * amount of static memory. */
  18798. +#ifndef VCHI_MAX_SERVICES_PER_CONNECTION
  18799. +# define VCHI_MAX_SERVICES_PER_CONNECTION 36
  18800. +#endif
  18801. +
  18802. +/* Adjust if using a message driver that supports more logical TX channels */
  18803. +#ifndef VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION
  18804. +# define VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION 9 // 1 MPHI + 8 CCP2 logical channels
  18805. +#endif
  18806. +
  18807. +/* Adjust if using a message driver that supports more logical RX channels */
  18808. +#ifndef VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION
  18809. +# define VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION 1 // 1 MPHI
  18810. +#endif
  18811. +
  18812. +/* How many receive slots do we use. This times VCHI_MAX_MSG_SIZE gives the effective
  18813. + * receive queue space, less message headers. */
  18814. +#ifndef VCHI_NUM_READ_SLOTS
  18815. +# if defined(VCHI_LOCAL_HOST_PORT)
  18816. +# define VCHI_NUM_READ_SLOTS 4
  18817. +# else
  18818. +# define VCHI_NUM_READ_SLOTS 48
  18819. +# endif
  18820. +#endif
  18821. +
  18822. +/* Do we utilise overrun facility for receive message slots? Can aid peer transmit
  18823. + * performance. Only define on VideoCore end, talking to host.
  18824. + */
  18825. +//#define VCHI_MSG_RX_OVERRUN
  18826. +
  18827. +/* How many transmit slots do we use. Generally don't need many, as the hardware driver
  18828. + * underneath VCHI will usually have its own buffering. */
  18829. +#ifndef VCHI_NUM_WRITE_SLOTS
  18830. +# define VCHI_NUM_WRITE_SLOTS 4
  18831. +#endif
  18832. +
  18833. +/* If a service has held or queued received messages in VCHI_XOFF_THRESHOLD or more slots,
  18834. + * then it's taking up too much buffer space, and the peer service will be told to stop
  18835. + * transmitting with an XOFF message. For this to be effective, the VCHI_NUM_READ_SLOTS
  18836. + * needs to be considerably bigger than VCHI_NUM_WRITE_SLOTS, or the transmit latency
  18837. + * is too high. */
  18838. +#ifndef VCHI_XOFF_THRESHOLD
  18839. +# define VCHI_XOFF_THRESHOLD (VCHI_NUM_READ_SLOTS / 2)
  18840. +#endif
  18841. +
  18842. +/* After we've sent an XOFF, the peer will be told to resume transmission once the local
  18843. + * service has dequeued/released enough messages that it's now occupying
  18844. + * VCHI_XON_THRESHOLD slots or fewer. */
  18845. +#ifndef VCHI_XON_THRESHOLD
  18846. +# define VCHI_XON_THRESHOLD (VCHI_NUM_READ_SLOTS / 4)
  18847. +#endif
  18848. +
  18849. +/* A size below which a bulk transfer omits the handshake completely and always goes
  18850. + * via the message channel, if bulk auxiliary is being sent on that service. (The user
  18851. + * can guarantee this by enabling unaligned transmits).
  18852. + * Not API. */
  18853. +#ifndef VCHI_MIN_BULK_SIZE
  18854. +# define VCHI_MIN_BULK_SIZE ( VCHI_MAX_MSG_SIZE / 2 < 4096 ? VCHI_MAX_MSG_SIZE / 2 : 4096 )
  18855. +#endif
  18856. +
  18857. +/* Maximum size of bulk transmission chunks, for each interface type. A trade-off between
  18858. + * speed and latency; the smaller the chunk size the better change of messages and other
  18859. + * bulk transmissions getting in when big bulk transfers are happening. Set to 0 to not
  18860. + * break transmissions into chunks.
  18861. + */
  18862. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_MPHI
  18863. +# define VCHI_MAX_BULK_CHUNK_SIZE_MPHI (16 * 1024)
  18864. +#endif
  18865. +
  18866. +/* NB Chunked CCP2 transmissions violate the letter of the CCP2 spec by using "JPEG8" mode
  18867. + * with multiple-line frames. Only use if the receiver can cope. */
  18868. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_CCP2
  18869. +# define VCHI_MAX_BULK_CHUNK_SIZE_CCP2 0
  18870. +#endif
  18871. +
  18872. +/* How many TX messages can we have pending in our transmit slots. Once exhausted,
  18873. + * vchi_msg_queue will be blocked. */
  18874. +#ifndef VCHI_TX_MSG_QUEUE_SIZE
  18875. +# define VCHI_TX_MSG_QUEUE_SIZE 256
  18876. +#endif
  18877. +
  18878. +/* How many RX messages can we have parsed in the receive slots. Once exhausted, parsing
  18879. + * will be suspended until older messages are dequeued/released. */
  18880. +#ifndef VCHI_RX_MSG_QUEUE_SIZE
  18881. +# define VCHI_RX_MSG_QUEUE_SIZE 256
  18882. +#endif
  18883. +
  18884. +/* Really should be able to cope if we run out of received message descriptors, by
  18885. + * suspending parsing as the comment above says, but we don't. This sweeps the issue
  18886. + * under the carpet. */
  18887. +#if VCHI_RX_MSG_QUEUE_SIZE < (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  18888. +# undef VCHI_RX_MSG_QUEUE_SIZE
  18889. +# define VCHI_RX_MSG_QUEUE_SIZE (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  18890. +#endif
  18891. +
  18892. +/* How many bulk transmits can we have pending. Once exhausted, vchi_bulk_queue_transmit
  18893. + * will be blocked. */
  18894. +#ifndef VCHI_TX_BULK_QUEUE_SIZE
  18895. +# define VCHI_TX_BULK_QUEUE_SIZE 64
  18896. +#endif
  18897. +
  18898. +/* How many bulk receives can we have pending. Once exhausted, vchi_bulk_queue_receive
  18899. + * will be blocked. */
  18900. +#ifndef VCHI_RX_BULK_QUEUE_SIZE
  18901. +# define VCHI_RX_BULK_QUEUE_SIZE 64
  18902. +#endif
  18903. +
  18904. +/* A limit on how many outstanding bulk requests we expect the peer to give us. If
  18905. + * the peer asks for more than this, VCHI will fail and assert. The number is determined
  18906. + * by the peer's hardware - it's the number of outstanding requests that can be queued
  18907. + * on all bulk channels. VC3's MPHI peripheral allows 16. */
  18908. +#ifndef VCHI_MAX_PEER_BULK_REQUESTS
  18909. +# define VCHI_MAX_PEER_BULK_REQUESTS 32
  18910. +#endif
  18911. +
  18912. +/* Define VCHI_CCP2TX_MANUAL_POWER if the host tells us when to turn the CCP2
  18913. + * transmitter on and off.
  18914. + */
  18915. +/*#define VCHI_CCP2TX_MANUAL_POWER*/
  18916. +
  18917. +#ifndef VCHI_CCP2TX_MANUAL_POWER
  18918. +
  18919. +/* Timeout (in milliseconds) for putting the CCP2TX interface into IDLE state. Set
  18920. + * negative for no IDLE.
  18921. + */
  18922. +# ifndef VCHI_CCP2TX_IDLE_TIMEOUT
  18923. +# define VCHI_CCP2TX_IDLE_TIMEOUT 5
  18924. +# endif
  18925. +
  18926. +/* Timeout (in milliseconds) for putting the CCP2TX interface into OFF state. Set
  18927. + * negative for no OFF.
  18928. + */
  18929. +# ifndef VCHI_CCP2TX_OFF_TIMEOUT
  18930. +# define VCHI_CCP2TX_OFF_TIMEOUT 1000
  18931. +# endif
  18932. +
  18933. +#endif /* VCHI_CCP2TX_MANUAL_POWER */
  18934. +
  18935. +#endif /* VCHI_CFG_H_ */
  18936. +
  18937. +/****************************** End of file **********************************/
  18938. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h linux-3.12.11/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h
  18939. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 1970-01-01 01:00:00.000000000 +0100
  18940. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 2014-02-18 11:52:14.000000000 +0100
  18941. @@ -0,0 +1,71 @@
  18942. +/**
  18943. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18944. + *
  18945. + * Redistribution and use in source and binary forms, with or without
  18946. + * modification, are permitted provided that the following conditions
  18947. + * are met:
  18948. + * 1. Redistributions of source code must retain the above copyright
  18949. + * notice, this list of conditions, and the following disclaimer,
  18950. + * without modification.
  18951. + * 2. Redistributions in binary form must reproduce the above copyright
  18952. + * notice, this list of conditions and the following disclaimer in the
  18953. + * documentation and/or other materials provided with the distribution.
  18954. + * 3. The names of the above-listed copyright holders may not be used
  18955. + * to endorse or promote products derived from this software without
  18956. + * specific prior written permission.
  18957. + *
  18958. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18959. + * GNU General Public License ("GPL") version 2, as published by the Free
  18960. + * Software Foundation.
  18961. + *
  18962. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18963. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18964. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18965. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18966. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18967. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18968. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18969. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18970. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18971. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18972. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18973. + */
  18974. +
  18975. +#ifndef VCHI_CFG_INTERNAL_H_
  18976. +#define VCHI_CFG_INTERNAL_H_
  18977. +
  18978. +/****************************************************************************************
  18979. + * Control optimisation attempts.
  18980. + ***************************************************************************************/
  18981. +
  18982. +// Don't use lots of short-term locks - use great long ones, reducing the overall locks-per-second
  18983. +#define VCHI_COARSE_LOCKING
  18984. +
  18985. +// Avoid lock then unlock on exit from blocking queue operations (msg tx, bulk rx/tx)
  18986. +// (only relevant if VCHI_COARSE_LOCKING)
  18987. +#define VCHI_ELIDE_BLOCK_EXIT_LOCK
  18988. +
  18989. +// Avoid lock on non-blocking peek
  18990. +// (only relevant if VCHI_COARSE_LOCKING)
  18991. +#define VCHI_AVOID_PEEK_LOCK
  18992. +
  18993. +// Use one slot-handler thread per connection, rather than 1 thread dealing with all connections in rotation.
  18994. +#define VCHI_MULTIPLE_HANDLER_THREADS
  18995. +
  18996. +// Put free descriptors onto the head of the free queue, rather than the tail, so that we don't thrash
  18997. +// our way through the pool of descriptors.
  18998. +#define VCHI_PUSH_FREE_DESCRIPTORS_ONTO_HEAD
  18999. +
  19000. +// Don't issue a MSG_AVAILABLE callback for every single message. Possibly only safe if VCHI_COARSE_LOCKING.
  19001. +#define VCHI_FEWER_MSG_AVAILABLE_CALLBACKS
  19002. +
  19003. +// Don't use message descriptors for TX messages that don't need them
  19004. +#define VCHI_MINIMISE_TX_MSG_DESCRIPTORS
  19005. +
  19006. +// Nano-locks for multiqueue
  19007. +//#define VCHI_MQUEUE_NANOLOCKS
  19008. +
  19009. +// Lock-free(er) dequeuing
  19010. +//#define VCHI_RX_NANOLOCKS
  19011. +
  19012. +#endif /*VCHI_CFG_INTERNAL_H_*/
  19013. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchi/vchi_common.h linux-3.12.11/drivers/misc/vc04_services/interface/vchi/vchi_common.h
  19014. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchi/vchi_common.h 1970-01-01 01:00:00.000000000 +0100
  19015. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchi/vchi_common.h 2014-02-18 11:52:14.000000000 +0100
  19016. @@ -0,0 +1,163 @@
  19017. +/**
  19018. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19019. + *
  19020. + * Redistribution and use in source and binary forms, with or without
  19021. + * modification, are permitted provided that the following conditions
  19022. + * are met:
  19023. + * 1. Redistributions of source code must retain the above copyright
  19024. + * notice, this list of conditions, and the following disclaimer,
  19025. + * without modification.
  19026. + * 2. Redistributions in binary form must reproduce the above copyright
  19027. + * notice, this list of conditions and the following disclaimer in the
  19028. + * documentation and/or other materials provided with the distribution.
  19029. + * 3. The names of the above-listed copyright holders may not be used
  19030. + * to endorse or promote products derived from this software without
  19031. + * specific prior written permission.
  19032. + *
  19033. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19034. + * GNU General Public License ("GPL") version 2, as published by the Free
  19035. + * Software Foundation.
  19036. + *
  19037. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19038. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19039. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19040. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19041. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19042. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19043. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19044. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19045. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19046. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19047. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19048. + */
  19049. +
  19050. +#ifndef VCHI_COMMON_H_
  19051. +#define VCHI_COMMON_H_
  19052. +
  19053. +
  19054. +//flags used when sending messages (must be bitmapped)
  19055. +typedef enum
  19056. +{
  19057. + VCHI_FLAGS_NONE = 0x0,
  19058. + 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)
  19059. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE = 0x2, // run a callback when message sent
  19060. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED = 0x4, // return once the transfer is in a queue ready to go
  19061. + VCHI_FLAGS_ALLOW_PARTIAL = 0x8,
  19062. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ = 0x10,
  19063. + VCHI_FLAGS_CALLBACK_WHEN_DATA_READ = 0x20,
  19064. +
  19065. + VCHI_FLAGS_ALIGN_SLOT = 0x000080, // internal use only
  19066. + VCHI_FLAGS_BULK_AUX_QUEUED = 0x010000, // internal use only
  19067. + VCHI_FLAGS_BULK_AUX_COMPLETE = 0x020000, // internal use only
  19068. + VCHI_FLAGS_BULK_DATA_QUEUED = 0x040000, // internal use only
  19069. + VCHI_FLAGS_BULK_DATA_COMPLETE = 0x080000, // internal use only
  19070. + VCHI_FLAGS_INTERNAL = 0xFF0000
  19071. +} VCHI_FLAGS_T;
  19072. +
  19073. +// constants for vchi_crc_control()
  19074. +typedef enum {
  19075. + VCHI_CRC_NOTHING = -1,
  19076. + VCHI_CRC_PER_SERVICE = 0,
  19077. + VCHI_CRC_EVERYTHING = 1,
  19078. +} VCHI_CRC_CONTROL_T;
  19079. +
  19080. +//callback reasons when an event occurs on a service
  19081. +typedef enum
  19082. +{
  19083. + VCHI_CALLBACK_REASON_MIN,
  19084. +
  19085. + //This indicates that there is data available
  19086. + //handle is the msg id that was transmitted with the data
  19087. + // When a message is received and there was no FULL message available previously, send callback
  19088. + // Tasks get kicked by the callback, reset their event and try and read from the fifo until it fails
  19089. + VCHI_CALLBACK_MSG_AVAILABLE,
  19090. + VCHI_CALLBACK_MSG_SENT,
  19091. + VCHI_CALLBACK_MSG_SPACE_AVAILABLE, // XXX not yet implemented
  19092. +
  19093. + // This indicates that a transfer from the other side has completed
  19094. + VCHI_CALLBACK_BULK_RECEIVED,
  19095. + //This indicates that data queued up to be sent has now gone
  19096. + //handle is the msg id that was used when sending the data
  19097. + VCHI_CALLBACK_BULK_SENT,
  19098. + VCHI_CALLBACK_BULK_RX_SPACE_AVAILABLE, // XXX not yet implemented
  19099. + VCHI_CALLBACK_BULK_TX_SPACE_AVAILABLE, // XXX not yet implemented
  19100. +
  19101. + VCHI_CALLBACK_SERVICE_CLOSED,
  19102. +
  19103. + // this side has sent XOFF to peer due to lack of data consumption by service
  19104. + // (suggests the service may need to take some recovery action if it has
  19105. + // been deliberately holding off consuming data)
  19106. + VCHI_CALLBACK_SENT_XOFF,
  19107. + VCHI_CALLBACK_SENT_XON,
  19108. +
  19109. + // indicates that a bulk transfer has finished reading the source buffer
  19110. + VCHI_CALLBACK_BULK_DATA_READ,
  19111. +
  19112. + // power notification events (currently host side only)
  19113. + VCHI_CALLBACK_PEER_OFF,
  19114. + VCHI_CALLBACK_PEER_SUSPENDED,
  19115. + VCHI_CALLBACK_PEER_ON,
  19116. + VCHI_CALLBACK_PEER_RESUMED,
  19117. + VCHI_CALLBACK_FORCED_POWER_OFF,
  19118. +
  19119. +#ifdef USE_VCHIQ_ARM
  19120. + // some extra notifications provided by vchiq_arm
  19121. + VCHI_CALLBACK_SERVICE_OPENED,
  19122. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  19123. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  19124. +#endif
  19125. +
  19126. + VCHI_CALLBACK_REASON_MAX
  19127. +} VCHI_CALLBACK_REASON_T;
  19128. +
  19129. +//Calback used by all services / bulk transfers
  19130. +typedef void (*VCHI_CALLBACK_T)( void *callback_param, //my service local param
  19131. + VCHI_CALLBACK_REASON_T reason,
  19132. + void *handle ); //for transmitting msg's only
  19133. +
  19134. +
  19135. +
  19136. +/*
  19137. + * Define vector struct for scatter-gather (vector) operations
  19138. + * Vectors can be nested - if a vector element has negative length, then
  19139. + * the data pointer is treated as pointing to another vector array, with
  19140. + * '-vec_len' elements. Thus to append a header onto an existing vector,
  19141. + * you can do this:
  19142. + *
  19143. + * void foo(const VCHI_MSG_VECTOR_T *v, int n)
  19144. + * {
  19145. + * VCHI_MSG_VECTOR_T nv[2];
  19146. + * nv[0].vec_base = my_header;
  19147. + * nv[0].vec_len = sizeof my_header;
  19148. + * nv[1].vec_base = v;
  19149. + * nv[1].vec_len = -n;
  19150. + * ...
  19151. + *
  19152. + */
  19153. +typedef struct vchi_msg_vector {
  19154. + const void *vec_base;
  19155. + int32_t vec_len;
  19156. +} VCHI_MSG_VECTOR_T;
  19157. +
  19158. +// Opaque type for a connection API
  19159. +typedef struct opaque_vchi_connection_api_t VCHI_CONNECTION_API_T;
  19160. +
  19161. +// Opaque type for a message driver
  19162. +typedef struct opaque_vchi_message_driver_t VCHI_MESSAGE_DRIVER_T;
  19163. +
  19164. +
  19165. +// Iterator structure for reading ahead through received message queue. Allocated by client,
  19166. +// initialised by vchi_msg_look_ahead. Fields are for internal VCHI use only.
  19167. +// Iterates over messages in queue at the instant of the call to vchi_msg_lookahead -
  19168. +// will not proceed to messages received since. Behaviour is undefined if an iterator
  19169. +// is used again after messages for that service are removed/dequeued by any
  19170. +// means other than vchi_msg_iter_... calls on the iterator itself.
  19171. +typedef struct {
  19172. + struct opaque_vchi_service_t *service;
  19173. + void *last;
  19174. + void *next;
  19175. + void *remove;
  19176. +} VCHI_MSG_ITER_T;
  19177. +
  19178. +
  19179. +#endif // VCHI_COMMON_H_
  19180. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchi/vchi.h linux-3.12.11/drivers/misc/vc04_services/interface/vchi/vchi.h
  19181. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchi/vchi.h 1970-01-01 01:00:00.000000000 +0100
  19182. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchi/vchi.h 2014-02-18 11:52:14.000000000 +0100
  19183. @@ -0,0 +1,373 @@
  19184. +/**
  19185. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19186. + *
  19187. + * Redistribution and use in source and binary forms, with or without
  19188. + * modification, are permitted provided that the following conditions
  19189. + * are met:
  19190. + * 1. Redistributions of source code must retain the above copyright
  19191. + * notice, this list of conditions, and the following disclaimer,
  19192. + * without modification.
  19193. + * 2. Redistributions in binary form must reproduce the above copyright
  19194. + * notice, this list of conditions and the following disclaimer in the
  19195. + * documentation and/or other materials provided with the distribution.
  19196. + * 3. The names of the above-listed copyright holders may not be used
  19197. + * to endorse or promote products derived from this software without
  19198. + * specific prior written permission.
  19199. + *
  19200. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19201. + * GNU General Public License ("GPL") version 2, as published by the Free
  19202. + * Software Foundation.
  19203. + *
  19204. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19205. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19206. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19207. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19208. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19209. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19210. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19211. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19212. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19213. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19214. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19215. + */
  19216. +
  19217. +#ifndef VCHI_H_
  19218. +#define VCHI_H_
  19219. +
  19220. +#include "interface/vchi/vchi_cfg.h"
  19221. +#include "interface/vchi/vchi_common.h"
  19222. +#include "interface/vchi/connections/connection.h"
  19223. +#include "vchi_mh.h"
  19224. +
  19225. +
  19226. +/******************************************************************************
  19227. + Global defs
  19228. + *****************************************************************************/
  19229. +
  19230. +#define VCHI_BULK_ROUND_UP(x) ((((unsigned long)(x))+VCHI_BULK_ALIGN-1) & ~(VCHI_BULK_ALIGN-1))
  19231. +#define VCHI_BULK_ROUND_DOWN(x) (((unsigned long)(x)) & ~(VCHI_BULK_ALIGN-1))
  19232. +#define VCHI_BULK_ALIGN_NBYTES(x) (VCHI_BULK_ALIGNED(x) ? 0 : (VCHI_BULK_ALIGN - ((unsigned long)(x) & (VCHI_BULK_ALIGN-1))))
  19233. +
  19234. +#ifdef USE_VCHIQ_ARM
  19235. +#define VCHI_BULK_ALIGNED(x) 1
  19236. +#else
  19237. +#define VCHI_BULK_ALIGNED(x) (((unsigned long)(x) & (VCHI_BULK_ALIGN-1)) == 0)
  19238. +#endif
  19239. +
  19240. +struct vchi_version {
  19241. + uint32_t version;
  19242. + uint32_t version_min;
  19243. +};
  19244. +#define VCHI_VERSION(v_) { v_, v_ }
  19245. +#define VCHI_VERSION_EX(v_, m_) { v_, m_ }
  19246. +
  19247. +typedef enum
  19248. +{
  19249. + VCHI_VEC_POINTER,
  19250. + VCHI_VEC_HANDLE,
  19251. + VCHI_VEC_LIST
  19252. +} VCHI_MSG_VECTOR_TYPE_T;
  19253. +
  19254. +typedef struct vchi_msg_vector_ex {
  19255. +
  19256. + VCHI_MSG_VECTOR_TYPE_T type;
  19257. + union
  19258. + {
  19259. + // a memory handle
  19260. + struct
  19261. + {
  19262. + VCHI_MEM_HANDLE_T handle;
  19263. + uint32_t offset;
  19264. + int32_t vec_len;
  19265. + } handle;
  19266. +
  19267. + // an ordinary data pointer
  19268. + struct
  19269. + {
  19270. + const void *vec_base;
  19271. + int32_t vec_len;
  19272. + } ptr;
  19273. +
  19274. + // a nested vector list
  19275. + struct
  19276. + {
  19277. + struct vchi_msg_vector_ex *vec;
  19278. + uint32_t vec_len;
  19279. + } list;
  19280. + } u;
  19281. +} VCHI_MSG_VECTOR_EX_T;
  19282. +
  19283. +
  19284. +// Construct an entry in a msg vector for a pointer (p) of length (l)
  19285. +#define VCHI_VEC_POINTER(p,l) VCHI_VEC_POINTER, { { (VCHI_MEM_HANDLE_T)(p), (l) } }
  19286. +
  19287. +// Construct an entry in a msg vector for a message handle (h), starting at offset (o) of length (l)
  19288. +#define VCHI_VEC_HANDLE(h,o,l) VCHI_VEC_HANDLE, { { (h), (o), (l) } }
  19289. +
  19290. +// Macros to manipulate 'FOURCC' values
  19291. +#define MAKE_FOURCC(x) ((int32_t)( (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3] ))
  19292. +#define FOURCC_TO_CHAR(x) (x >> 24) & 0xFF,(x >> 16) & 0xFF,(x >> 8) & 0xFF, x & 0xFF
  19293. +
  19294. +
  19295. +// Opaque service information
  19296. +struct opaque_vchi_service_t;
  19297. +
  19298. +// Descriptor for a held message. Allocated by client, initialised by vchi_msg_hold,
  19299. +// vchi_msg_iter_hold or vchi_msg_iter_hold_next. Fields are for internal VCHI use only.
  19300. +typedef struct
  19301. +{
  19302. + struct opaque_vchi_service_t *service;
  19303. + void *message;
  19304. +} VCHI_HELD_MSG_T;
  19305. +
  19306. +
  19307. +
  19308. +// structure used to provide the information needed to open a server or a client
  19309. +typedef struct {
  19310. + struct vchi_version version;
  19311. + int32_t service_id;
  19312. + VCHI_CONNECTION_T *connection;
  19313. + uint32_t rx_fifo_size;
  19314. + uint32_t tx_fifo_size;
  19315. + VCHI_CALLBACK_T callback;
  19316. + void *callback_param;
  19317. + /* client intends to receive bulk transfers of
  19318. + odd lengths or into unaligned buffers */
  19319. + int32_t want_unaligned_bulk_rx;
  19320. + /* client intends to transmit bulk transfers of
  19321. + odd lengths or out of unaligned buffers */
  19322. + int32_t want_unaligned_bulk_tx;
  19323. + /* client wants to check CRCs on (bulk) xfers.
  19324. + Only needs to be set at 1 end - will do both directions. */
  19325. + int32_t want_crc;
  19326. +} SERVICE_CREATION_T;
  19327. +
  19328. +// Opaque handle for a VCHI instance
  19329. +typedef struct opaque_vchi_instance_handle_t *VCHI_INSTANCE_T;
  19330. +
  19331. +// Opaque handle for a server or client
  19332. +typedef struct opaque_vchi_service_handle_t *VCHI_SERVICE_HANDLE_T;
  19333. +
  19334. +// Service registration & startup
  19335. +typedef void (*VCHI_SERVICE_INIT)(VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections);
  19336. +
  19337. +typedef struct service_info_tag {
  19338. + const char * const vll_filename; /* VLL to load to start this service. This is an empty string if VLL is "static" */
  19339. + VCHI_SERVICE_INIT init; /* Service initialisation function */
  19340. + void *vll_handle; /* VLL handle; NULL when unloaded or a "static VLL" in build */
  19341. +} SERVICE_INFO_T;
  19342. +
  19343. +/******************************************************************************
  19344. + Global funcs - implementation is specific to which side you are on (local / remote)
  19345. + *****************************************************************************/
  19346. +
  19347. +#ifdef __cplusplus
  19348. +extern "C" {
  19349. +#endif
  19350. +
  19351. +extern /*@observer@*/ VCHI_CONNECTION_T * vchi_create_connection( const VCHI_CONNECTION_API_T * function_table,
  19352. + const VCHI_MESSAGE_DRIVER_T * low_level);
  19353. +
  19354. +
  19355. +// Routine used to initialise the vchi on both local + remote connections
  19356. +extern int32_t vchi_initialise( VCHI_INSTANCE_T *instance_handle );
  19357. +
  19358. +extern int32_t vchi_exit( void );
  19359. +
  19360. +extern int32_t vchi_connect( VCHI_CONNECTION_T **connections,
  19361. + const uint32_t num_connections,
  19362. + VCHI_INSTANCE_T instance_handle );
  19363. +
  19364. +//When this is called, ensure that all services have no data pending.
  19365. +//Bulk transfers can remain 'queued'
  19366. +extern int32_t vchi_disconnect( VCHI_INSTANCE_T instance_handle );
  19367. +
  19368. +// Global control over bulk CRC checking
  19369. +extern int32_t vchi_crc_control( VCHI_CONNECTION_T *connection,
  19370. + VCHI_CRC_CONTROL_T control );
  19371. +
  19372. +// helper functions
  19373. +extern void * vchi_allocate_buffer(VCHI_SERVICE_HANDLE_T handle, uint32_t *length);
  19374. +extern void vchi_free_buffer(VCHI_SERVICE_HANDLE_T handle, void *address);
  19375. +extern uint32_t vchi_current_time(VCHI_INSTANCE_T instance_handle);
  19376. +
  19377. +
  19378. +/******************************************************************************
  19379. + Global service API
  19380. + *****************************************************************************/
  19381. +// Routine to create a named service
  19382. +extern int32_t vchi_service_create( VCHI_INSTANCE_T instance_handle,
  19383. + SERVICE_CREATION_T *setup,
  19384. + VCHI_SERVICE_HANDLE_T *handle );
  19385. +
  19386. +// Routine to destory a service
  19387. +extern int32_t vchi_service_destroy( const VCHI_SERVICE_HANDLE_T handle );
  19388. +
  19389. +// Routine to open a named service
  19390. +extern int32_t vchi_service_open( VCHI_INSTANCE_T instance_handle,
  19391. + SERVICE_CREATION_T *setup,
  19392. + VCHI_SERVICE_HANDLE_T *handle);
  19393. +
  19394. +extern int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle,
  19395. + short *peer_version );
  19396. +
  19397. +// Routine to close a named service
  19398. +extern int32_t vchi_service_close( const VCHI_SERVICE_HANDLE_T handle );
  19399. +
  19400. +// Routine to increment ref count on a named service
  19401. +extern int32_t vchi_service_use( const VCHI_SERVICE_HANDLE_T handle );
  19402. +
  19403. +// Routine to decrement ref count on a named service
  19404. +extern int32_t vchi_service_release( const VCHI_SERVICE_HANDLE_T handle );
  19405. +
  19406. +// Routine to send a message accross a service
  19407. +extern int32_t vchi_msg_queue( VCHI_SERVICE_HANDLE_T handle,
  19408. + const void *data,
  19409. + uint32_t data_size,
  19410. + VCHI_FLAGS_T flags,
  19411. + void *msg_handle );
  19412. +
  19413. +// scatter-gather (vector) and send message
  19414. +int32_t vchi_msg_queuev_ex( VCHI_SERVICE_HANDLE_T handle,
  19415. + VCHI_MSG_VECTOR_EX_T *vector,
  19416. + uint32_t count,
  19417. + VCHI_FLAGS_T flags,
  19418. + void *msg_handle );
  19419. +
  19420. +// legacy scatter-gather (vector) and send message, only handles pointers
  19421. +int32_t vchi_msg_queuev( VCHI_SERVICE_HANDLE_T handle,
  19422. + VCHI_MSG_VECTOR_T *vector,
  19423. + uint32_t count,
  19424. + VCHI_FLAGS_T flags,
  19425. + void *msg_handle );
  19426. +
  19427. +// Routine to receive a msg from a service
  19428. +// Dequeue is equivalent to hold, copy into client buffer, release
  19429. +extern int32_t vchi_msg_dequeue( VCHI_SERVICE_HANDLE_T handle,
  19430. + void *data,
  19431. + uint32_t max_data_size_to_read,
  19432. + uint32_t *actual_msg_size,
  19433. + VCHI_FLAGS_T flags );
  19434. +
  19435. +// Routine to look at a message in place.
  19436. +// The message is not dequeued, so a subsequent call to peek or dequeue
  19437. +// will return the same message.
  19438. +extern int32_t vchi_msg_peek( VCHI_SERVICE_HANDLE_T handle,
  19439. + void **data,
  19440. + uint32_t *msg_size,
  19441. + VCHI_FLAGS_T flags );
  19442. +
  19443. +// Routine to remove a message after it has been read in place with peek
  19444. +// The first message on the queue is dequeued.
  19445. +extern int32_t vchi_msg_remove( VCHI_SERVICE_HANDLE_T handle );
  19446. +
  19447. +// Routine to look at a message in place.
  19448. +// The message is dequeued, so the caller is left holding it; the descriptor is
  19449. +// filled in and must be released when the user has finished with the message.
  19450. +extern int32_t vchi_msg_hold( VCHI_SERVICE_HANDLE_T handle,
  19451. + void **data, // } may be NULL, as info can be
  19452. + uint32_t *msg_size, // } obtained from HELD_MSG_T
  19453. + VCHI_FLAGS_T flags,
  19454. + VCHI_HELD_MSG_T *message_descriptor );
  19455. +
  19456. +// Initialise an iterator to look through messages in place
  19457. +extern int32_t vchi_msg_look_ahead( VCHI_SERVICE_HANDLE_T handle,
  19458. + VCHI_MSG_ITER_T *iter,
  19459. + VCHI_FLAGS_T flags );
  19460. +
  19461. +/******************************************************************************
  19462. + Global service support API - operations on held messages and message iterators
  19463. + *****************************************************************************/
  19464. +
  19465. +// Routine to get the address of a held message
  19466. +extern void *vchi_held_msg_ptr( const VCHI_HELD_MSG_T *message );
  19467. +
  19468. +// Routine to get the size of a held message
  19469. +extern int32_t vchi_held_msg_size( const VCHI_HELD_MSG_T *message );
  19470. +
  19471. +// Routine to get the transmit timestamp as written into the header by the peer
  19472. +extern uint32_t vchi_held_msg_tx_timestamp( const VCHI_HELD_MSG_T *message );
  19473. +
  19474. +// Routine to get the reception timestamp, written as we parsed the header
  19475. +extern uint32_t vchi_held_msg_rx_timestamp( const VCHI_HELD_MSG_T *message );
  19476. +
  19477. +// Routine to release a held message after it has been processed
  19478. +extern int32_t vchi_held_msg_release( VCHI_HELD_MSG_T *message );
  19479. +
  19480. +// Indicates whether the iterator has a next message.
  19481. +extern int32_t vchi_msg_iter_has_next( const VCHI_MSG_ITER_T *iter );
  19482. +
  19483. +// Return the pointer and length for the next message and advance the iterator.
  19484. +extern int32_t vchi_msg_iter_next( VCHI_MSG_ITER_T *iter,
  19485. + void **data,
  19486. + uint32_t *msg_size );
  19487. +
  19488. +// Remove the last message returned by vchi_msg_iter_next.
  19489. +// Can only be called once after each call to vchi_msg_iter_next.
  19490. +extern int32_t vchi_msg_iter_remove( VCHI_MSG_ITER_T *iter );
  19491. +
  19492. +// Hold the last message returned by vchi_msg_iter_next.
  19493. +// Can only be called once after each call to vchi_msg_iter_next.
  19494. +extern int32_t vchi_msg_iter_hold( VCHI_MSG_ITER_T *iter,
  19495. + VCHI_HELD_MSG_T *message );
  19496. +
  19497. +// Return information for the next message, and hold it, advancing the iterator.
  19498. +extern int32_t vchi_msg_iter_hold_next( VCHI_MSG_ITER_T *iter,
  19499. + void **data, // } may be NULL
  19500. + uint32_t *msg_size, // }
  19501. + VCHI_HELD_MSG_T *message );
  19502. +
  19503. +
  19504. +/******************************************************************************
  19505. + Global bulk API
  19506. + *****************************************************************************/
  19507. +
  19508. +// Routine to prepare interface for a transfer from the other side
  19509. +extern int32_t vchi_bulk_queue_receive( VCHI_SERVICE_HANDLE_T handle,
  19510. + void *data_dst,
  19511. + uint32_t data_size,
  19512. + VCHI_FLAGS_T flags,
  19513. + void *transfer_handle );
  19514. +
  19515. +
  19516. +// Prepare interface for a transfer from the other side into relocatable memory.
  19517. +int32_t vchi_bulk_queue_receive_reloc( const VCHI_SERVICE_HANDLE_T handle,
  19518. + VCHI_MEM_HANDLE_T h_dst,
  19519. + uint32_t offset,
  19520. + uint32_t data_size,
  19521. + const VCHI_FLAGS_T flags,
  19522. + void * const bulk_handle );
  19523. +
  19524. +// Routine to queue up data ready for transfer to the other (once they have signalled they are ready)
  19525. +extern int32_t vchi_bulk_queue_transmit( VCHI_SERVICE_HANDLE_T handle,
  19526. + const void *data_src,
  19527. + uint32_t data_size,
  19528. + VCHI_FLAGS_T flags,
  19529. + void *transfer_handle );
  19530. +
  19531. +
  19532. +/******************************************************************************
  19533. + Configuration plumbing
  19534. + *****************************************************************************/
  19535. +
  19536. +// function prototypes for the different mid layers (the state info gives the different physical connections)
  19537. +extern const VCHI_CONNECTION_API_T *single_get_func_table( void );
  19538. +//extern const VCHI_CONNECTION_API_T *local_server_get_func_table( void );
  19539. +//extern const VCHI_CONNECTION_API_T *local_client_get_func_table( void );
  19540. +
  19541. +// declare all message drivers here
  19542. +const VCHI_MESSAGE_DRIVER_T *vchi_mphi_message_driver_func_table( void );
  19543. +
  19544. +#ifdef __cplusplus
  19545. +}
  19546. +#endif
  19547. +
  19548. +extern int32_t vchi_bulk_queue_transmit_reloc( VCHI_SERVICE_HANDLE_T handle,
  19549. + VCHI_MEM_HANDLE_T h_src,
  19550. + uint32_t offset,
  19551. + uint32_t data_size,
  19552. + VCHI_FLAGS_T flags,
  19553. + void *transfer_handle );
  19554. +#endif /* VCHI_H_ */
  19555. +
  19556. +/****************************** End of file **********************************/
  19557. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchi/vchi_mh.h linux-3.12.11/drivers/misc/vc04_services/interface/vchi/vchi_mh.h
  19558. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 1970-01-01 01:00:00.000000000 +0100
  19559. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 2014-02-18 11:52:14.000000000 +0100
  19560. @@ -0,0 +1,42 @@
  19561. +/**
  19562. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19563. + *
  19564. + * Redistribution and use in source and binary forms, with or without
  19565. + * modification, are permitted provided that the following conditions
  19566. + * are met:
  19567. + * 1. Redistributions of source code must retain the above copyright
  19568. + * notice, this list of conditions, and the following disclaimer,
  19569. + * without modification.
  19570. + * 2. Redistributions in binary form must reproduce the above copyright
  19571. + * notice, this list of conditions and the following disclaimer in the
  19572. + * documentation and/or other materials provided with the distribution.
  19573. + * 3. The names of the above-listed copyright holders may not be used
  19574. + * to endorse or promote products derived from this software without
  19575. + * specific prior written permission.
  19576. + *
  19577. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19578. + * GNU General Public License ("GPL") version 2, as published by the Free
  19579. + * Software Foundation.
  19580. + *
  19581. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19582. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19583. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19584. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19585. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19586. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19587. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19588. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19589. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19590. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19591. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19592. + */
  19593. +
  19594. +#ifndef VCHI_MH_H_
  19595. +#define VCHI_MH_H_
  19596. +
  19597. +#include <linux/types.h>
  19598. +
  19599. +typedef int32_t VCHI_MEM_HANDLE_T;
  19600. +#define VCHI_MEM_HANDLE_INVALID 0
  19601. +
  19602. +#endif
  19603. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
  19604. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 1970-01-01 01:00:00.000000000 +0100
  19605. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 2014-02-18 11:52:14.000000000 +0100
  19606. @@ -0,0 +1,561 @@
  19607. +/**
  19608. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19609. + *
  19610. + * Redistribution and use in source and binary forms, with or without
  19611. + * modification, are permitted provided that the following conditions
  19612. + * are met:
  19613. + * 1. Redistributions of source code must retain the above copyright
  19614. + * notice, this list of conditions, and the following disclaimer,
  19615. + * without modification.
  19616. + * 2. Redistributions in binary form must reproduce the above copyright
  19617. + * notice, this list of conditions and the following disclaimer in the
  19618. + * documentation and/or other materials provided with the distribution.
  19619. + * 3. The names of the above-listed copyright holders may not be used
  19620. + * to endorse or promote products derived from this software without
  19621. + * specific prior written permission.
  19622. + *
  19623. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19624. + * GNU General Public License ("GPL") version 2, as published by the Free
  19625. + * Software Foundation.
  19626. + *
  19627. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19628. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19629. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19630. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19631. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19632. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19633. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19634. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19635. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19636. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19637. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19638. + */
  19639. +
  19640. +#include <linux/kernel.h>
  19641. +#include <linux/types.h>
  19642. +#include <linux/errno.h>
  19643. +#include <linux/interrupt.h>
  19644. +#include <linux/irq.h>
  19645. +#include <linux/pagemap.h>
  19646. +#include <linux/dma-mapping.h>
  19647. +#include <linux/version.h>
  19648. +#include <linux/io.h>
  19649. +#include <linux/uaccess.h>
  19650. +#include <asm/pgtable.h>
  19651. +
  19652. +#include <mach/irqs.h>
  19653. +
  19654. +#include <mach/platform.h>
  19655. +#include <mach/vcio.h>
  19656. +
  19657. +#define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
  19658. +
  19659. +#define VCHIQ_DOORBELL_IRQ IRQ_ARM_DOORBELL_0
  19660. +#define VCHIQ_ARM_ADDRESS(x) ((void *)__virt_to_bus((unsigned)x))
  19661. +
  19662. +#include "vchiq_arm.h"
  19663. +#include "vchiq_2835.h"
  19664. +#include "vchiq_connected.h"
  19665. +
  19666. +#define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
  19667. +
  19668. +typedef struct vchiq_2835_state_struct {
  19669. + int inited;
  19670. + VCHIQ_ARM_STATE_T arm_state;
  19671. +} VCHIQ_2835_ARM_STATE_T;
  19672. +
  19673. +static char *g_slot_mem;
  19674. +static int g_slot_mem_size;
  19675. +dma_addr_t g_slot_phys;
  19676. +static FRAGMENTS_T *g_fragments_base;
  19677. +static FRAGMENTS_T *g_free_fragments;
  19678. +struct semaphore g_free_fragments_sema;
  19679. +
  19680. +extern int vchiq_arm_log_level;
  19681. +
  19682. +static DEFINE_SEMAPHORE(g_free_fragments_mutex);
  19683. +
  19684. +static irqreturn_t
  19685. +vchiq_doorbell_irq(int irq, void *dev_id);
  19686. +
  19687. +static int
  19688. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  19689. + struct task_struct *task, PAGELIST_T ** ppagelist);
  19690. +
  19691. +static void
  19692. +free_pagelist(PAGELIST_T *pagelist, int actual);
  19693. +
  19694. +int __init
  19695. +vchiq_platform_init(VCHIQ_STATE_T *state)
  19696. +{
  19697. + VCHIQ_SLOT_ZERO_T *vchiq_slot_zero;
  19698. + int frag_mem_size;
  19699. + int err;
  19700. + int i;
  19701. +
  19702. + /* Allocate space for the channels in coherent memory */
  19703. + g_slot_mem_size = PAGE_ALIGN(TOTAL_SLOTS * VCHIQ_SLOT_SIZE);
  19704. + frag_mem_size = PAGE_ALIGN(sizeof(FRAGMENTS_T) * MAX_FRAGMENTS);
  19705. +
  19706. + g_slot_mem = dma_alloc_coherent(NULL, g_slot_mem_size + frag_mem_size,
  19707. + &g_slot_phys, GFP_ATOMIC);
  19708. +
  19709. + if (!g_slot_mem) {
  19710. + vchiq_log_error(vchiq_arm_log_level,
  19711. + "Unable to allocate channel memory");
  19712. + err = -ENOMEM;
  19713. + goto failed_alloc;
  19714. + }
  19715. +
  19716. + WARN_ON(((int)g_slot_mem & (PAGE_SIZE - 1)) != 0);
  19717. +
  19718. + vchiq_slot_zero = vchiq_init_slots(g_slot_mem, g_slot_mem_size);
  19719. + if (!vchiq_slot_zero) {
  19720. + err = -EINVAL;
  19721. + goto failed_init_slots;
  19722. + }
  19723. +
  19724. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX] =
  19725. + (int)g_slot_phys + g_slot_mem_size;
  19726. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX] =
  19727. + MAX_FRAGMENTS;
  19728. +
  19729. + g_fragments_base = (FRAGMENTS_T *)(g_slot_mem + g_slot_mem_size);
  19730. + g_slot_mem_size += frag_mem_size;
  19731. +
  19732. + g_free_fragments = g_fragments_base;
  19733. + for (i = 0; i < (MAX_FRAGMENTS - 1); i++) {
  19734. + *(FRAGMENTS_T **)&g_fragments_base[i] =
  19735. + &g_fragments_base[i + 1];
  19736. + }
  19737. + *(FRAGMENTS_T **)&g_fragments_base[i] = NULL;
  19738. + sema_init(&g_free_fragments_sema, MAX_FRAGMENTS);
  19739. +
  19740. + if (vchiq_init_state(state, vchiq_slot_zero, 0/*slave*/) !=
  19741. + VCHIQ_SUCCESS) {
  19742. + err = -EINVAL;
  19743. + goto failed_vchiq_init;
  19744. + }
  19745. +
  19746. + err = request_irq(VCHIQ_DOORBELL_IRQ, vchiq_doorbell_irq,
  19747. + IRQF_IRQPOLL, "VCHIQ doorbell",
  19748. + state);
  19749. + if (err < 0) {
  19750. + vchiq_log_error(vchiq_arm_log_level, "%s: failed to register "
  19751. + "irq=%d err=%d", __func__,
  19752. + VCHIQ_DOORBELL_IRQ, err);
  19753. + goto failed_request_irq;
  19754. + }
  19755. +
  19756. + /* Send the base address of the slots to VideoCore */
  19757. +
  19758. + dsb(); /* Ensure all writes have completed */
  19759. +
  19760. + bcm_mailbox_write(MBOX_CHAN_VCHIQ, (unsigned int)g_slot_phys);
  19761. +
  19762. + vchiq_log_info(vchiq_arm_log_level,
  19763. + "vchiq_init - done (slots %x, phys %x)",
  19764. + (unsigned int)vchiq_slot_zero, g_slot_phys);
  19765. +
  19766. + vchiq_call_connected_callbacks();
  19767. +
  19768. + return 0;
  19769. +
  19770. +failed_request_irq:
  19771. +failed_vchiq_init:
  19772. +failed_init_slots:
  19773. + dma_free_coherent(NULL, g_slot_mem_size, g_slot_mem, g_slot_phys);
  19774. +
  19775. +failed_alloc:
  19776. + return err;
  19777. +}
  19778. +
  19779. +void __exit
  19780. +vchiq_platform_exit(VCHIQ_STATE_T *state)
  19781. +{
  19782. + free_irq(VCHIQ_DOORBELL_IRQ, state);
  19783. + dma_free_coherent(NULL, g_slot_mem_size,
  19784. + g_slot_mem, g_slot_phys);
  19785. +}
  19786. +
  19787. +
  19788. +VCHIQ_STATUS_T
  19789. +vchiq_platform_init_state(VCHIQ_STATE_T *state)
  19790. +{
  19791. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  19792. + state->platform_state = kzalloc(sizeof(VCHIQ_2835_ARM_STATE_T), GFP_KERNEL);
  19793. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 1;
  19794. + status = vchiq_arm_init_state(state, &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state);
  19795. + if(status != VCHIQ_SUCCESS)
  19796. + {
  19797. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 0;
  19798. + }
  19799. + return status;
  19800. +}
  19801. +
  19802. +VCHIQ_ARM_STATE_T*
  19803. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state)
  19804. +{
  19805. + if(!((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited)
  19806. + {
  19807. + BUG();
  19808. + }
  19809. + return &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state;
  19810. +}
  19811. +
  19812. +void
  19813. +remote_event_signal(REMOTE_EVENT_T *event)
  19814. +{
  19815. + wmb();
  19816. +
  19817. + event->fired = 1;
  19818. +
  19819. + dsb(); /* data barrier operation */
  19820. +
  19821. + if (event->armed) {
  19822. + /* trigger vc interrupt */
  19823. +
  19824. + writel(0, __io_address(ARM_0_BELL2));
  19825. + }
  19826. +}
  19827. +
  19828. +int
  19829. +vchiq_copy_from_user(void *dst, const void *src, int size)
  19830. +{
  19831. + if ((uint32_t)src < TASK_SIZE) {
  19832. + return copy_from_user(dst, src, size);
  19833. + } else {
  19834. + memcpy(dst, src, size);
  19835. + return 0;
  19836. + }
  19837. +}
  19838. +
  19839. +VCHIQ_STATUS_T
  19840. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk, VCHI_MEM_HANDLE_T memhandle,
  19841. + void *offset, int size, int dir)
  19842. +{
  19843. + PAGELIST_T *pagelist;
  19844. + int ret;
  19845. +
  19846. + WARN_ON(memhandle != VCHI_MEM_HANDLE_INVALID);
  19847. +
  19848. + ret = create_pagelist((char __user *)offset, size,
  19849. + (dir == VCHIQ_BULK_RECEIVE)
  19850. + ? PAGELIST_READ
  19851. + : PAGELIST_WRITE,
  19852. + current,
  19853. + &pagelist);
  19854. + if (ret != 0)
  19855. + return VCHIQ_ERROR;
  19856. +
  19857. + bulk->handle = memhandle;
  19858. + bulk->data = VCHIQ_ARM_ADDRESS(pagelist);
  19859. +
  19860. + /* Store the pagelist address in remote_data, which isn't used by the
  19861. + slave. */
  19862. + bulk->remote_data = pagelist;
  19863. +
  19864. + return VCHIQ_SUCCESS;
  19865. +}
  19866. +
  19867. +void
  19868. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk)
  19869. +{
  19870. + if (bulk && bulk->remote_data && bulk->actual)
  19871. + free_pagelist((PAGELIST_T *)bulk->remote_data, bulk->actual);
  19872. +}
  19873. +
  19874. +void
  19875. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk)
  19876. +{
  19877. + /*
  19878. + * This should only be called on the master (VideoCore) side, but
  19879. + * provide an implementation to avoid the need for ifdefery.
  19880. + */
  19881. + BUG();
  19882. +}
  19883. +
  19884. +void
  19885. +vchiq_dump_platform_state(void *dump_context)
  19886. +{
  19887. + char buf[80];
  19888. + int len;
  19889. + len = snprintf(buf, sizeof(buf),
  19890. + " Platform: 2835 (VC master)");
  19891. + vchiq_dump(dump_context, buf, len + 1);
  19892. +}
  19893. +
  19894. +VCHIQ_STATUS_T
  19895. +vchiq_platform_suspend(VCHIQ_STATE_T *state)
  19896. +{
  19897. + return VCHIQ_ERROR;
  19898. +}
  19899. +
  19900. +VCHIQ_STATUS_T
  19901. +vchiq_platform_resume(VCHIQ_STATE_T *state)
  19902. +{
  19903. + return VCHIQ_SUCCESS;
  19904. +}
  19905. +
  19906. +void
  19907. +vchiq_platform_paused(VCHIQ_STATE_T *state)
  19908. +{
  19909. +}
  19910. +
  19911. +void
  19912. +vchiq_platform_resumed(VCHIQ_STATE_T *state)
  19913. +{
  19914. +}
  19915. +
  19916. +int
  19917. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T* state)
  19918. +{
  19919. + return 1; // autosuspend not supported - videocore always wanted
  19920. +}
  19921. +
  19922. +int
  19923. +vchiq_platform_use_suspend_timer(void)
  19924. +{
  19925. + return 0;
  19926. +}
  19927. +void
  19928. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state)
  19929. +{
  19930. + vchiq_log_info((vchiq_arm_log_level>=VCHIQ_LOG_INFO),"Suspend timer not in use");
  19931. +}
  19932. +void
  19933. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state)
  19934. +{
  19935. + (void)state;
  19936. +}
  19937. +/*
  19938. + * Local functions
  19939. + */
  19940. +
  19941. +static irqreturn_t
  19942. +vchiq_doorbell_irq(int irq, void *dev_id)
  19943. +{
  19944. + VCHIQ_STATE_T *state = dev_id;
  19945. + irqreturn_t ret = IRQ_NONE;
  19946. + unsigned int status;
  19947. +
  19948. + /* Read (and clear) the doorbell */
  19949. + status = readl(__io_address(ARM_0_BELL0));
  19950. +
  19951. + if (status & 0x4) { /* Was the doorbell rung? */
  19952. + remote_event_pollall(state);
  19953. + ret = IRQ_HANDLED;
  19954. + }
  19955. +
  19956. + return ret;
  19957. +}
  19958. +
  19959. +/* There is a potential problem with partial cache lines (pages?)
  19960. +** at the ends of the block when reading. If the CPU accessed anything in
  19961. +** the same line (page?) then it may have pulled old data into the cache,
  19962. +** obscuring the new data underneath. We can solve this by transferring the
  19963. +** partial cache lines separately, and allowing the ARM to copy into the
  19964. +** cached area.
  19965. +
  19966. +** N.B. This implementation plays slightly fast and loose with the Linux
  19967. +** driver programming rules, e.g. its use of __virt_to_bus instead of
  19968. +** dma_map_single, but it isn't a multi-platform driver and it benefits
  19969. +** from increased speed as a result.
  19970. +*/
  19971. +
  19972. +static int
  19973. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  19974. + struct task_struct *task, PAGELIST_T ** ppagelist)
  19975. +{
  19976. + PAGELIST_T *pagelist;
  19977. + struct page **pages;
  19978. + struct page *page;
  19979. + unsigned long *addrs;
  19980. + unsigned int num_pages, offset, i;
  19981. + char *addr, *base_addr, *next_addr;
  19982. + int run, addridx, actual_pages;
  19983. + unsigned long *need_release;
  19984. +
  19985. + offset = (unsigned int)buf & (PAGE_SIZE - 1);
  19986. + num_pages = (count + offset + PAGE_SIZE - 1) / PAGE_SIZE;
  19987. +
  19988. + *ppagelist = NULL;
  19989. +
  19990. + /* Allocate enough storage to hold the page pointers and the page
  19991. + ** list
  19992. + */
  19993. + pagelist = kmalloc(sizeof(PAGELIST_T) +
  19994. + (num_pages * sizeof(unsigned long)) +
  19995. + sizeof(unsigned long) +
  19996. + (num_pages * sizeof(pages[0])),
  19997. + GFP_KERNEL);
  19998. +
  19999. + vchiq_log_trace(vchiq_arm_log_level,
  20000. + "create_pagelist - %x", (unsigned int)pagelist);
  20001. + if (!pagelist)
  20002. + return -ENOMEM;
  20003. +
  20004. + addrs = pagelist->addrs;
  20005. + need_release = (unsigned long *)(addrs + num_pages);
  20006. + pages = (struct page **)(addrs + num_pages + 1);
  20007. +
  20008. + if (is_vmalloc_addr(buf)) {
  20009. + for (actual_pages = 0; actual_pages < num_pages; actual_pages++) {
  20010. + pages[actual_pages] = vmalloc_to_page(buf + (actual_pages * PAGE_SIZE));
  20011. + }
  20012. + *need_release = 0; /* do not try and release vmalloc pages */
  20013. + } else {
  20014. + down_read(&task->mm->mmap_sem);
  20015. + actual_pages = get_user_pages(task, task->mm,
  20016. + (unsigned long)buf & ~(PAGE_SIZE - 1),
  20017. + num_pages,
  20018. + (type == PAGELIST_READ) /*Write */ ,
  20019. + 0 /*Force */ ,
  20020. + pages,
  20021. + NULL /*vmas */);
  20022. + up_read(&task->mm->mmap_sem);
  20023. +
  20024. + if (actual_pages != num_pages) {
  20025. + vchiq_log_info(vchiq_arm_log_level,
  20026. + "create_pagelist - only %d/%d pages locked",
  20027. + actual_pages,
  20028. + num_pages);
  20029. +
  20030. + /* This is probably due to the process being killed */
  20031. + while (actual_pages > 0)
  20032. + {
  20033. + actual_pages--;
  20034. + page_cache_release(pages[actual_pages]);
  20035. + }
  20036. + kfree(pagelist);
  20037. + if (actual_pages == 0)
  20038. + actual_pages = -ENOMEM;
  20039. + return actual_pages;
  20040. + }
  20041. + *need_release = 1; /* release user pages */
  20042. + }
  20043. +
  20044. + pagelist->length = count;
  20045. + pagelist->type = type;
  20046. + pagelist->offset = offset;
  20047. +
  20048. + /* Group the pages into runs of contiguous pages */
  20049. +
  20050. + base_addr = VCHIQ_ARM_ADDRESS(page_address(pages[0]));
  20051. + next_addr = base_addr + PAGE_SIZE;
  20052. + addridx = 0;
  20053. + run = 0;
  20054. +
  20055. + for (i = 1; i < num_pages; i++) {
  20056. + addr = VCHIQ_ARM_ADDRESS(page_address(pages[i]));
  20057. + if ((addr == next_addr) && (run < (PAGE_SIZE - 1))) {
  20058. + next_addr += PAGE_SIZE;
  20059. + run++;
  20060. + } else {
  20061. + addrs[addridx] = (unsigned long)base_addr + run;
  20062. + addridx++;
  20063. + base_addr = addr;
  20064. + next_addr = addr + PAGE_SIZE;
  20065. + run = 0;
  20066. + }
  20067. + }
  20068. +
  20069. + addrs[addridx] = (unsigned long)base_addr + run;
  20070. + addridx++;
  20071. +
  20072. + /* Partial cache lines (fragments) require special measures */
  20073. + if ((type == PAGELIST_READ) &&
  20074. + ((pagelist->offset & (CACHE_LINE_SIZE - 1)) ||
  20075. + ((pagelist->offset + pagelist->length) &
  20076. + (CACHE_LINE_SIZE - 1)))) {
  20077. + FRAGMENTS_T *fragments;
  20078. +
  20079. + if (down_interruptible(&g_free_fragments_sema) != 0) {
  20080. + kfree(pagelist);
  20081. + return -EINTR;
  20082. + }
  20083. +
  20084. + WARN_ON(g_free_fragments == NULL);
  20085. +
  20086. + down(&g_free_fragments_mutex);
  20087. + fragments = (FRAGMENTS_T *) g_free_fragments;
  20088. + WARN_ON(fragments == NULL);
  20089. + g_free_fragments = *(FRAGMENTS_T **) g_free_fragments;
  20090. + up(&g_free_fragments_mutex);
  20091. + pagelist->type =
  20092. + PAGELIST_READ_WITH_FRAGMENTS + (fragments -
  20093. + g_fragments_base);
  20094. + }
  20095. +
  20096. + for (page = virt_to_page(pagelist);
  20097. + page <= virt_to_page(addrs + num_pages - 1); page++) {
  20098. + flush_dcache_page(page);
  20099. + }
  20100. +
  20101. + *ppagelist = pagelist;
  20102. +
  20103. + return 0;
  20104. +}
  20105. +
  20106. +static void
  20107. +free_pagelist(PAGELIST_T *pagelist, int actual)
  20108. +{
  20109. + unsigned long *need_release;
  20110. + struct page **pages;
  20111. + unsigned int num_pages, i;
  20112. +
  20113. + vchiq_log_trace(vchiq_arm_log_level,
  20114. + "free_pagelist - %x, %d", (unsigned int)pagelist, actual);
  20115. +
  20116. + num_pages =
  20117. + (pagelist->length + pagelist->offset + PAGE_SIZE - 1) /
  20118. + PAGE_SIZE;
  20119. +
  20120. + need_release = (unsigned long *)(pagelist->addrs + num_pages);
  20121. + pages = (struct page **)(pagelist->addrs + num_pages + 1);
  20122. +
  20123. + /* Deal with any partial cache lines (fragments) */
  20124. + if (pagelist->type >= PAGELIST_READ_WITH_FRAGMENTS) {
  20125. + FRAGMENTS_T *fragments = g_fragments_base +
  20126. + (pagelist->type - PAGELIST_READ_WITH_FRAGMENTS);
  20127. + int head_bytes, tail_bytes;
  20128. + head_bytes = (CACHE_LINE_SIZE - pagelist->offset) &
  20129. + (CACHE_LINE_SIZE - 1);
  20130. + tail_bytes = (pagelist->offset + actual) &
  20131. + (CACHE_LINE_SIZE - 1);
  20132. +
  20133. + if ((actual >= 0) && (head_bytes != 0)) {
  20134. + if (head_bytes > actual)
  20135. + head_bytes = actual;
  20136. +
  20137. + memcpy((char *)page_address(pages[0]) +
  20138. + pagelist->offset,
  20139. + fragments->headbuf,
  20140. + head_bytes);
  20141. + }
  20142. + if ((actual >= 0) && (head_bytes < actual) &&
  20143. + (tail_bytes != 0)) {
  20144. + memcpy((char *)page_address(pages[num_pages - 1]) +
  20145. + ((pagelist->offset + actual) &
  20146. + (PAGE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1)),
  20147. + fragments->tailbuf, tail_bytes);
  20148. + }
  20149. +
  20150. + down(&g_free_fragments_mutex);
  20151. + *(FRAGMENTS_T **) fragments = g_free_fragments;
  20152. + g_free_fragments = fragments;
  20153. + up(&g_free_fragments_mutex);
  20154. + up(&g_free_fragments_sema);
  20155. + }
  20156. +
  20157. + if (*need_release) {
  20158. + for (i = 0; i < num_pages; i++) {
  20159. + if (pagelist->type != PAGELIST_WRITE)
  20160. + set_page_dirty(pages[i]);
  20161. +
  20162. + page_cache_release(pages[i]);
  20163. + }
  20164. + }
  20165. +
  20166. + kfree(pagelist);
  20167. +}
  20168. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h
  20169. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 1970-01-01 01:00:00.000000000 +0100
  20170. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 2014-02-18 11:52:14.000000000 +0100
  20171. @@ -0,0 +1,42 @@
  20172. +/**
  20173. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  20174. + *
  20175. + * Redistribution and use in source and binary forms, with or without
  20176. + * modification, are permitted provided that the following conditions
  20177. + * are met:
  20178. + * 1. Redistributions of source code must retain the above copyright
  20179. + * notice, this list of conditions, and the following disclaimer,
  20180. + * without modification.
  20181. + * 2. Redistributions in binary form must reproduce the above copyright
  20182. + * notice, this list of conditions and the following disclaimer in the
  20183. + * documentation and/or other materials provided with the distribution.
  20184. + * 3. The names of the above-listed copyright holders may not be used
  20185. + * to endorse or promote products derived from this software without
  20186. + * specific prior written permission.
  20187. + *
  20188. + * ALTERNATIVELY, this software may be distributed under the terms of the
  20189. + * GNU General Public License ("GPL") version 2, as published by the Free
  20190. + * Software Foundation.
  20191. + *
  20192. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20193. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20194. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20195. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20196. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20197. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20198. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20199. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20200. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20201. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20202. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20203. + */
  20204. +
  20205. +#ifndef VCHIQ_2835_H
  20206. +#define VCHIQ_2835_H
  20207. +
  20208. +#include "vchiq_pagelist.h"
  20209. +
  20210. +#define VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX 0
  20211. +#define VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX 1
  20212. +
  20213. +#endif /* VCHIQ_2835_H */
  20214. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
  20215. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 1970-01-01 01:00:00.000000000 +0100
  20216. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 2014-02-18 11:52:14.000000000 +0100
  20217. @@ -0,0 +1,2813 @@
  20218. +/**
  20219. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  20220. + *
  20221. + * Redistribution and use in source and binary forms, with or without
  20222. + * modification, are permitted provided that the following conditions
  20223. + * are met:
  20224. + * 1. Redistributions of source code must retain the above copyright
  20225. + * notice, this list of conditions, and the following disclaimer,
  20226. + * without modification.
  20227. + * 2. Redistributions in binary form must reproduce the above copyright
  20228. + * notice, this list of conditions and the following disclaimer in the
  20229. + * documentation and/or other materials provided with the distribution.
  20230. + * 3. The names of the above-listed copyright holders may not be used
  20231. + * to endorse or promote products derived from this software without
  20232. + * specific prior written permission.
  20233. + *
  20234. + * ALTERNATIVELY, this software may be distributed under the terms of the
  20235. + * GNU General Public License ("GPL") version 2, as published by the Free
  20236. + * Software Foundation.
  20237. + *
  20238. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20239. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20240. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20241. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20242. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20243. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20244. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20245. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20246. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20247. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20248. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20249. + */
  20250. +
  20251. +#include <linux/kernel.h>
  20252. +#include <linux/module.h>
  20253. +#include <linux/types.h>
  20254. +#include <linux/errno.h>
  20255. +#include <linux/cdev.h>
  20256. +#include <linux/fs.h>
  20257. +#include <linux/device.h>
  20258. +#include <linux/mm.h>
  20259. +#include <linux/highmem.h>
  20260. +#include <linux/pagemap.h>
  20261. +#include <linux/bug.h>
  20262. +#include <linux/semaphore.h>
  20263. +#include <linux/list.h>
  20264. +#include <linux/proc_fs.h>
  20265. +
  20266. +#include "vchiq_core.h"
  20267. +#include "vchiq_ioctl.h"
  20268. +#include "vchiq_arm.h"
  20269. +
  20270. +#define DEVICE_NAME "vchiq"
  20271. +
  20272. +/* Override the default prefix, which would be vchiq_arm (from the filename) */
  20273. +#undef MODULE_PARAM_PREFIX
  20274. +#define MODULE_PARAM_PREFIX DEVICE_NAME "."
  20275. +
  20276. +#define VCHIQ_MINOR 0
  20277. +
  20278. +/* Some per-instance constants */
  20279. +#define MAX_COMPLETIONS 16
  20280. +#define MAX_SERVICES 64
  20281. +#define MAX_ELEMENTS 8
  20282. +#define MSG_QUEUE_SIZE 64
  20283. +
  20284. +#define KEEPALIVE_VER 1
  20285. +#define KEEPALIVE_VER_MIN KEEPALIVE_VER
  20286. +
  20287. +/* Run time control of log level, based on KERN_XXX level. */
  20288. +int vchiq_arm_log_level = VCHIQ_LOG_DEFAULT;
  20289. +int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
  20290. +
  20291. +#define SUSPEND_TIMER_TIMEOUT_MS 100
  20292. +#define SUSPEND_RETRY_TIMER_TIMEOUT_MS 1000
  20293. +
  20294. +#define VC_SUSPEND_NUM_OFFSET 3 /* number of values before idle which are -ve */
  20295. +static const char *const suspend_state_names[] = {
  20296. + "VC_SUSPEND_FORCE_CANCELED",
  20297. + "VC_SUSPEND_REJECTED",
  20298. + "VC_SUSPEND_FAILED",
  20299. + "VC_SUSPEND_IDLE",
  20300. + "VC_SUSPEND_REQUESTED",
  20301. + "VC_SUSPEND_IN_PROGRESS",
  20302. + "VC_SUSPEND_SUSPENDED"
  20303. +};
  20304. +#define VC_RESUME_NUM_OFFSET 1 /* number of values before idle which are -ve */
  20305. +static const char *const resume_state_names[] = {
  20306. + "VC_RESUME_FAILED",
  20307. + "VC_RESUME_IDLE",
  20308. + "VC_RESUME_REQUESTED",
  20309. + "VC_RESUME_IN_PROGRESS",
  20310. + "VC_RESUME_RESUMED"
  20311. +};
  20312. +/* The number of times we allow force suspend to timeout before actually
  20313. +** _forcing_ suspend. This is to cater for SW which fails to release vchiq
  20314. +** correctly - we don't want to prevent ARM suspend indefinitely in this case.
  20315. +*/
  20316. +#define FORCE_SUSPEND_FAIL_MAX 8
  20317. +
  20318. +/* The time in ms allowed for videocore to go idle when force suspend has been
  20319. + * requested */
  20320. +#define FORCE_SUSPEND_TIMEOUT_MS 200
  20321. +
  20322. +
  20323. +static void suspend_timer_callback(unsigned long context);
  20324. +static int vchiq_proc_add_instance(VCHIQ_INSTANCE_T instance);
  20325. +static void vchiq_proc_remove_instance(VCHIQ_INSTANCE_T instance);
  20326. +
  20327. +
  20328. +typedef struct user_service_struct {
  20329. + VCHIQ_SERVICE_T *service;
  20330. + void *userdata;
  20331. + VCHIQ_INSTANCE_T instance;
  20332. + int is_vchi;
  20333. + int dequeue_pending;
  20334. + int message_available_pos;
  20335. + int msg_insert;
  20336. + int msg_remove;
  20337. + struct semaphore insert_event;
  20338. + struct semaphore remove_event;
  20339. + VCHIQ_HEADER_T * msg_queue[MSG_QUEUE_SIZE];
  20340. +} USER_SERVICE_T;
  20341. +
  20342. +struct bulk_waiter_node {
  20343. + struct bulk_waiter bulk_waiter;
  20344. + int pid;
  20345. + struct list_head list;
  20346. +};
  20347. +
  20348. +struct vchiq_instance_struct {
  20349. + VCHIQ_STATE_T *state;
  20350. + VCHIQ_COMPLETION_DATA_T completions[MAX_COMPLETIONS];
  20351. + int completion_insert;
  20352. + int completion_remove;
  20353. + struct semaphore insert_event;
  20354. + struct semaphore remove_event;
  20355. + struct mutex completion_mutex;
  20356. +
  20357. + int connected;
  20358. + int closing;
  20359. + int pid;
  20360. + int mark;
  20361. +
  20362. + struct list_head bulk_waiter_list;
  20363. + struct mutex bulk_waiter_list_mutex;
  20364. +
  20365. + struct proc_dir_entry *proc_entry;
  20366. +};
  20367. +
  20368. +typedef struct dump_context_struct {
  20369. + char __user *buf;
  20370. + size_t actual;
  20371. + size_t space;
  20372. + loff_t offset;
  20373. +} DUMP_CONTEXT_T;
  20374. +
  20375. +static struct cdev vchiq_cdev;
  20376. +static dev_t vchiq_devid;
  20377. +static VCHIQ_STATE_T g_state;
  20378. +static struct class *vchiq_class;
  20379. +static struct device *vchiq_dev;
  20380. +static DEFINE_SPINLOCK(msg_queue_spinlock);
  20381. +
  20382. +static const char *const ioctl_names[] = {
  20383. + "CONNECT",
  20384. + "SHUTDOWN",
  20385. + "CREATE_SERVICE",
  20386. + "REMOVE_SERVICE",
  20387. + "QUEUE_MESSAGE",
  20388. + "QUEUE_BULK_TRANSMIT",
  20389. + "QUEUE_BULK_RECEIVE",
  20390. + "AWAIT_COMPLETION",
  20391. + "DEQUEUE_MESSAGE",
  20392. + "GET_CLIENT_ID",
  20393. + "GET_CONFIG",
  20394. + "CLOSE_SERVICE",
  20395. + "USE_SERVICE",
  20396. + "RELEASE_SERVICE",
  20397. + "SET_SERVICE_OPTION",
  20398. + "DUMP_PHYS_MEM"
  20399. +};
  20400. +
  20401. +vchiq_static_assert((sizeof(ioctl_names)/sizeof(ioctl_names[0])) ==
  20402. + (VCHIQ_IOC_MAX + 1));
  20403. +
  20404. +static void
  20405. +dump_phys_mem(void *virt_addr, uint32_t num_bytes);
  20406. +
  20407. +/****************************************************************************
  20408. +*
  20409. +* add_completion
  20410. +*
  20411. +***************************************************************************/
  20412. +
  20413. +static VCHIQ_STATUS_T
  20414. +add_completion(VCHIQ_INSTANCE_T instance, VCHIQ_REASON_T reason,
  20415. + VCHIQ_HEADER_T *header, USER_SERVICE_T *user_service,
  20416. + void *bulk_userdata)
  20417. +{
  20418. + VCHIQ_COMPLETION_DATA_T *completion;
  20419. + DEBUG_INITIALISE(g_state.local)
  20420. +
  20421. + while (instance->completion_insert ==
  20422. + (instance->completion_remove + MAX_COMPLETIONS)) {
  20423. + /* Out of space - wait for the client */
  20424. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20425. + vchiq_log_trace(vchiq_arm_log_level,
  20426. + "add_completion - completion queue full");
  20427. + DEBUG_COUNT(COMPLETION_QUEUE_FULL_COUNT);
  20428. + if (down_interruptible(&instance->remove_event) != 0) {
  20429. + vchiq_log_info(vchiq_arm_log_level,
  20430. + "service_callback interrupted");
  20431. + return VCHIQ_RETRY;
  20432. + } else if (instance->closing) {
  20433. + vchiq_log_info(vchiq_arm_log_level,
  20434. + "service_callback closing");
  20435. + return VCHIQ_ERROR;
  20436. + }
  20437. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20438. + }
  20439. +
  20440. + completion =
  20441. + &instance->completions[instance->completion_insert &
  20442. + (MAX_COMPLETIONS - 1)];
  20443. +
  20444. + completion->header = header;
  20445. + completion->reason = reason;
  20446. + /* N.B. service_userdata is updated while processing AWAIT_COMPLETION */
  20447. + completion->service_userdata = user_service->service;
  20448. + completion->bulk_userdata = bulk_userdata;
  20449. +
  20450. + if (reason == VCHIQ_SERVICE_CLOSED)
  20451. + /* Take an extra reference, to be held until
  20452. + this CLOSED notification is delivered. */
  20453. + lock_service(user_service->service);
  20454. +
  20455. + /* A write barrier is needed here to ensure that the entire completion
  20456. + record is written out before the insert point. */
  20457. + wmb();
  20458. +
  20459. + if (reason == VCHIQ_MESSAGE_AVAILABLE)
  20460. + user_service->message_available_pos =
  20461. + instance->completion_insert;
  20462. + instance->completion_insert++;
  20463. +
  20464. + up(&instance->insert_event);
  20465. +
  20466. + return VCHIQ_SUCCESS;
  20467. +}
  20468. +
  20469. +/****************************************************************************
  20470. +*
  20471. +* service_callback
  20472. +*
  20473. +***************************************************************************/
  20474. +
  20475. +static VCHIQ_STATUS_T
  20476. +service_callback(VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header,
  20477. + VCHIQ_SERVICE_HANDLE_T handle, void *bulk_userdata)
  20478. +{
  20479. + /* How do we ensure the callback goes to the right client?
  20480. + ** The service_user data points to a USER_SERVICE_T record containing
  20481. + ** the original callback and the user state structure, which contains a
  20482. + ** circular buffer for completion records.
  20483. + */
  20484. + USER_SERVICE_T *user_service;
  20485. + VCHIQ_SERVICE_T *service;
  20486. + VCHIQ_INSTANCE_T instance;
  20487. + DEBUG_INITIALISE(g_state.local)
  20488. +
  20489. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20490. +
  20491. + service = handle_to_service(handle);
  20492. + BUG_ON(!service);
  20493. + user_service = (USER_SERVICE_T *)service->base.userdata;
  20494. + instance = user_service->instance;
  20495. +
  20496. + if (!instance || instance->closing)
  20497. + return VCHIQ_SUCCESS;
  20498. +
  20499. + vchiq_log_trace(vchiq_arm_log_level,
  20500. + "service_callback - service %lx(%d), reason %d, header %lx, "
  20501. + "instance %lx, bulk_userdata %lx",
  20502. + (unsigned long)user_service,
  20503. + service->localport,
  20504. + reason, (unsigned long)header,
  20505. + (unsigned long)instance, (unsigned long)bulk_userdata);
  20506. +
  20507. + if (header && user_service->is_vchi) {
  20508. + spin_lock(&msg_queue_spinlock);
  20509. + while (user_service->msg_insert ==
  20510. + (user_service->msg_remove + MSG_QUEUE_SIZE)) {
  20511. + spin_unlock(&msg_queue_spinlock);
  20512. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20513. + DEBUG_COUNT(MSG_QUEUE_FULL_COUNT);
  20514. + vchiq_log_trace(vchiq_arm_log_level,
  20515. + "service_callback - msg queue full");
  20516. + /* If there is no MESSAGE_AVAILABLE in the completion
  20517. + ** queue, add one
  20518. + */
  20519. + if ((user_service->message_available_pos -
  20520. + instance->completion_remove) < 0) {
  20521. + VCHIQ_STATUS_T status;
  20522. + vchiq_log_info(vchiq_arm_log_level,
  20523. + "Inserting extra MESSAGE_AVAILABLE");
  20524. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20525. + status = add_completion(instance, reason,
  20526. + NULL, user_service, bulk_userdata);
  20527. + if (status != VCHIQ_SUCCESS) {
  20528. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20529. + return status;
  20530. + }
  20531. + }
  20532. +
  20533. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20534. + if (down_interruptible(&user_service->remove_event)
  20535. + != 0) {
  20536. + vchiq_log_info(vchiq_arm_log_level,
  20537. + "service_callback interrupted");
  20538. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20539. + return VCHIQ_RETRY;
  20540. + } else if (instance->closing) {
  20541. + vchiq_log_info(vchiq_arm_log_level,
  20542. + "service_callback closing");
  20543. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20544. + return VCHIQ_ERROR;
  20545. + }
  20546. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20547. + spin_lock(&msg_queue_spinlock);
  20548. + }
  20549. +
  20550. + user_service->msg_queue[user_service->msg_insert &
  20551. + (MSG_QUEUE_SIZE - 1)] = header;
  20552. + user_service->msg_insert++;
  20553. + spin_unlock(&msg_queue_spinlock);
  20554. +
  20555. + up(&user_service->insert_event);
  20556. +
  20557. + /* If there is a thread waiting in DEQUEUE_MESSAGE, or if
  20558. + ** there is a MESSAGE_AVAILABLE in the completion queue then
  20559. + ** bypass the completion queue.
  20560. + */
  20561. + if (((user_service->message_available_pos -
  20562. + instance->completion_remove) >= 0) ||
  20563. + user_service->dequeue_pending) {
  20564. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20565. + user_service->dequeue_pending = 0;
  20566. + return VCHIQ_SUCCESS;
  20567. + }
  20568. +
  20569. + header = NULL;
  20570. + }
  20571. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20572. +
  20573. + return add_completion(instance, reason, header, user_service,
  20574. + bulk_userdata);
  20575. +}
  20576. +
  20577. +/****************************************************************************
  20578. +*
  20579. +* user_service_free
  20580. +*
  20581. +***************************************************************************/
  20582. +static void
  20583. +user_service_free(void *userdata)
  20584. +{
  20585. + kfree(userdata);
  20586. +}
  20587. +
  20588. +/****************************************************************************
  20589. +*
  20590. +* vchiq_ioctl
  20591. +*
  20592. +***************************************************************************/
  20593. +
  20594. +static long
  20595. +vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  20596. +{
  20597. + VCHIQ_INSTANCE_T instance = file->private_data;
  20598. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  20599. + VCHIQ_SERVICE_T *service = NULL;
  20600. + long ret = 0;
  20601. + int i, rc;
  20602. + DEBUG_INITIALISE(g_state.local)
  20603. +
  20604. + vchiq_log_trace(vchiq_arm_log_level,
  20605. + "vchiq_ioctl - instance %x, cmd %s, arg %lx",
  20606. + (unsigned int)instance,
  20607. + ((_IOC_TYPE(cmd) == VCHIQ_IOC_MAGIC) &&
  20608. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX)) ?
  20609. + ioctl_names[_IOC_NR(cmd)] : "<invalid>", arg);
  20610. +
  20611. + switch (cmd) {
  20612. + case VCHIQ_IOC_SHUTDOWN:
  20613. + if (!instance->connected)
  20614. + break;
  20615. +
  20616. + /* Remove all services */
  20617. + i = 0;
  20618. + while ((service = next_service_by_instance(instance->state,
  20619. + instance, &i)) != NULL) {
  20620. + status = vchiq_remove_service(service->handle);
  20621. + unlock_service(service);
  20622. + if (status != VCHIQ_SUCCESS)
  20623. + break;
  20624. + }
  20625. + service = NULL;
  20626. +
  20627. + if (status == VCHIQ_SUCCESS) {
  20628. + /* Wake the completion thread and ask it to exit */
  20629. + instance->closing = 1;
  20630. + up(&instance->insert_event);
  20631. + }
  20632. +
  20633. + break;
  20634. +
  20635. + case VCHIQ_IOC_CONNECT:
  20636. + if (instance->connected) {
  20637. + ret = -EINVAL;
  20638. + break;
  20639. + }
  20640. + rc = mutex_lock_interruptible(&instance->state->mutex);
  20641. + if (rc != 0) {
  20642. + vchiq_log_error(vchiq_arm_log_level,
  20643. + "vchiq: connect: could not lock mutex for "
  20644. + "state %d: %d",
  20645. + instance->state->id, rc);
  20646. + ret = -EINTR;
  20647. + break;
  20648. + }
  20649. + status = vchiq_connect_internal(instance->state, instance);
  20650. + mutex_unlock(&instance->state->mutex);
  20651. +
  20652. + if (status == VCHIQ_SUCCESS)
  20653. + instance->connected = 1;
  20654. + else
  20655. + vchiq_log_error(vchiq_arm_log_level,
  20656. + "vchiq: could not connect: %d", status);
  20657. + break;
  20658. +
  20659. + case VCHIQ_IOC_CREATE_SERVICE: {
  20660. + VCHIQ_CREATE_SERVICE_T args;
  20661. + USER_SERVICE_T *user_service = NULL;
  20662. + void *userdata;
  20663. + int srvstate;
  20664. +
  20665. + if (copy_from_user
  20666. + (&args, (const void __user *)arg,
  20667. + sizeof(args)) != 0) {
  20668. + ret = -EFAULT;
  20669. + break;
  20670. + }
  20671. +
  20672. + user_service = kmalloc(sizeof(USER_SERVICE_T), GFP_KERNEL);
  20673. + if (!user_service) {
  20674. + ret = -ENOMEM;
  20675. + break;
  20676. + }
  20677. +
  20678. + if (args.is_open) {
  20679. + if (!instance->connected) {
  20680. + ret = -ENOTCONN;
  20681. + kfree(user_service);
  20682. + break;
  20683. + }
  20684. + srvstate = VCHIQ_SRVSTATE_OPENING;
  20685. + } else {
  20686. + srvstate =
  20687. + instance->connected ?
  20688. + VCHIQ_SRVSTATE_LISTENING :
  20689. + VCHIQ_SRVSTATE_HIDDEN;
  20690. + }
  20691. +
  20692. + userdata = args.params.userdata;
  20693. + args.params.callback = service_callback;
  20694. + args.params.userdata = user_service;
  20695. + service = vchiq_add_service_internal(
  20696. + instance->state,
  20697. + &args.params, srvstate,
  20698. + instance, user_service_free);
  20699. +
  20700. + if (service != NULL) {
  20701. + user_service->service = service;
  20702. + user_service->userdata = userdata;
  20703. + user_service->instance = instance;
  20704. + user_service->is_vchi = args.is_vchi;
  20705. + user_service->dequeue_pending = 0;
  20706. + user_service->message_available_pos =
  20707. + instance->completion_remove - 1;
  20708. + user_service->msg_insert = 0;
  20709. + user_service->msg_remove = 0;
  20710. + sema_init(&user_service->insert_event, 0);
  20711. + sema_init(&user_service->remove_event, 0);
  20712. +
  20713. + if (args.is_open) {
  20714. + status = vchiq_open_service_internal
  20715. + (service, instance->pid);
  20716. + if (status != VCHIQ_SUCCESS) {
  20717. + vchiq_remove_service(service->handle);
  20718. + service = NULL;
  20719. + ret = (status == VCHIQ_RETRY) ?
  20720. + -EINTR : -EIO;
  20721. + break;
  20722. + }
  20723. + }
  20724. +
  20725. + if (copy_to_user((void __user *)
  20726. + &(((VCHIQ_CREATE_SERVICE_T __user *)
  20727. + arg)->handle),
  20728. + (const void *)&service->handle,
  20729. + sizeof(service->handle)) != 0) {
  20730. + ret = -EFAULT;
  20731. + vchiq_remove_service(service->handle);
  20732. + }
  20733. +
  20734. + service = NULL;
  20735. + } else {
  20736. + ret = -EEXIST;
  20737. + kfree(user_service);
  20738. + }
  20739. + } break;
  20740. +
  20741. + case VCHIQ_IOC_CLOSE_SERVICE: {
  20742. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  20743. +
  20744. + service = find_service_for_instance(instance, handle);
  20745. + if (service != NULL)
  20746. + status = vchiq_close_service(service->handle);
  20747. + else
  20748. + ret = -EINVAL;
  20749. + } break;
  20750. +
  20751. + case VCHIQ_IOC_REMOVE_SERVICE: {
  20752. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  20753. +
  20754. + service = find_service_for_instance(instance, handle);
  20755. + if (service != NULL)
  20756. + status = vchiq_remove_service(service->handle);
  20757. + else
  20758. + ret = -EINVAL;
  20759. + } break;
  20760. +
  20761. + case VCHIQ_IOC_USE_SERVICE:
  20762. + case VCHIQ_IOC_RELEASE_SERVICE: {
  20763. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  20764. +
  20765. + service = find_service_for_instance(instance, handle);
  20766. + if (service != NULL) {
  20767. + status = (cmd == VCHIQ_IOC_USE_SERVICE) ?
  20768. + vchiq_use_service_internal(service) :
  20769. + vchiq_release_service_internal(service);
  20770. + if (status != VCHIQ_SUCCESS) {
  20771. + vchiq_log_error(vchiq_susp_log_level,
  20772. + "%s: cmd %s returned error %d for "
  20773. + "service %c%c%c%c:%03d",
  20774. + __func__,
  20775. + (cmd == VCHIQ_IOC_USE_SERVICE) ?
  20776. + "VCHIQ_IOC_USE_SERVICE" :
  20777. + "VCHIQ_IOC_RELEASE_SERVICE",
  20778. + status,
  20779. + VCHIQ_FOURCC_AS_4CHARS(
  20780. + service->base.fourcc),
  20781. + service->client_id);
  20782. + ret = -EINVAL;
  20783. + }
  20784. + } else
  20785. + ret = -EINVAL;
  20786. + } break;
  20787. +
  20788. + case VCHIQ_IOC_QUEUE_MESSAGE: {
  20789. + VCHIQ_QUEUE_MESSAGE_T args;
  20790. + if (copy_from_user
  20791. + (&args, (const void __user *)arg,
  20792. + sizeof(args)) != 0) {
  20793. + ret = -EFAULT;
  20794. + break;
  20795. + }
  20796. +
  20797. + service = find_service_for_instance(instance, args.handle);
  20798. +
  20799. + if ((service != NULL) && (args.count <= MAX_ELEMENTS)) {
  20800. + /* Copy elements into kernel space */
  20801. + VCHIQ_ELEMENT_T elements[MAX_ELEMENTS];
  20802. + if (copy_from_user(elements, args.elements,
  20803. + args.count * sizeof(VCHIQ_ELEMENT_T)) == 0)
  20804. + status = vchiq_queue_message
  20805. + (args.handle,
  20806. + elements, args.count);
  20807. + else
  20808. + ret = -EFAULT;
  20809. + } else {
  20810. + ret = -EINVAL;
  20811. + }
  20812. + } break;
  20813. +
  20814. + case VCHIQ_IOC_QUEUE_BULK_TRANSMIT:
  20815. + case VCHIQ_IOC_QUEUE_BULK_RECEIVE: {
  20816. + VCHIQ_QUEUE_BULK_TRANSFER_T args;
  20817. + struct bulk_waiter_node *waiter = NULL;
  20818. + VCHIQ_BULK_DIR_T dir =
  20819. + (cmd == VCHIQ_IOC_QUEUE_BULK_TRANSMIT) ?
  20820. + VCHIQ_BULK_TRANSMIT : VCHIQ_BULK_RECEIVE;
  20821. +
  20822. + if (copy_from_user
  20823. + (&args, (const void __user *)arg,
  20824. + sizeof(args)) != 0) {
  20825. + ret = -EFAULT;
  20826. + break;
  20827. + }
  20828. +
  20829. + service = find_service_for_instance(instance, args.handle);
  20830. + if (!service) {
  20831. + ret = -EINVAL;
  20832. + break;
  20833. + }
  20834. +
  20835. + if (args.mode == VCHIQ_BULK_MODE_BLOCKING) {
  20836. + waiter = kzalloc(sizeof(struct bulk_waiter_node),
  20837. + GFP_KERNEL);
  20838. + if (!waiter) {
  20839. + ret = -ENOMEM;
  20840. + break;
  20841. + }
  20842. + args.userdata = &waiter->bulk_waiter;
  20843. + } else if (args.mode == VCHIQ_BULK_MODE_WAITING) {
  20844. + struct list_head *pos;
  20845. + mutex_lock(&instance->bulk_waiter_list_mutex);
  20846. + list_for_each(pos, &instance->bulk_waiter_list) {
  20847. + if (list_entry(pos, struct bulk_waiter_node,
  20848. + list)->pid == current->pid) {
  20849. + waiter = list_entry(pos,
  20850. + struct bulk_waiter_node,
  20851. + list);
  20852. + list_del(pos);
  20853. + break;
  20854. + }
  20855. +
  20856. + }
  20857. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  20858. + if (!waiter) {
  20859. + vchiq_log_error(vchiq_arm_log_level,
  20860. + "no bulk_waiter found for pid %d",
  20861. + current->pid);
  20862. + ret = -ESRCH;
  20863. + break;
  20864. + }
  20865. + vchiq_log_info(vchiq_arm_log_level,
  20866. + "found bulk_waiter %x for pid %d",
  20867. + (unsigned int)waiter, current->pid);
  20868. + args.userdata = &waiter->bulk_waiter;
  20869. + }
  20870. + status = vchiq_bulk_transfer
  20871. + (args.handle,
  20872. + VCHI_MEM_HANDLE_INVALID,
  20873. + args.data, args.size,
  20874. + args.userdata, args.mode,
  20875. + dir);
  20876. + if (!waiter)
  20877. + break;
  20878. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  20879. + !waiter->bulk_waiter.bulk) {
  20880. + if (waiter->bulk_waiter.bulk) {
  20881. + /* Cancel the signal when the transfer
  20882. + ** completes. */
  20883. + spin_lock(&bulk_waiter_spinlock);
  20884. + waiter->bulk_waiter.bulk->userdata = NULL;
  20885. + spin_unlock(&bulk_waiter_spinlock);
  20886. + }
  20887. + kfree(waiter);
  20888. + } else {
  20889. + const VCHIQ_BULK_MODE_T mode_waiting =
  20890. + VCHIQ_BULK_MODE_WAITING;
  20891. + waiter->pid = current->pid;
  20892. + mutex_lock(&instance->bulk_waiter_list_mutex);
  20893. + list_add(&waiter->list, &instance->bulk_waiter_list);
  20894. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  20895. + vchiq_log_info(vchiq_arm_log_level,
  20896. + "saved bulk_waiter %x for pid %d",
  20897. + (unsigned int)waiter, current->pid);
  20898. +
  20899. + if (copy_to_user((void __user *)
  20900. + &(((VCHIQ_QUEUE_BULK_TRANSFER_T __user *)
  20901. + arg)->mode),
  20902. + (const void *)&mode_waiting,
  20903. + sizeof(mode_waiting)) != 0)
  20904. + ret = -EFAULT;
  20905. + }
  20906. + } break;
  20907. +
  20908. + case VCHIQ_IOC_AWAIT_COMPLETION: {
  20909. + VCHIQ_AWAIT_COMPLETION_T args;
  20910. +
  20911. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20912. + if (!instance->connected) {
  20913. + ret = -ENOTCONN;
  20914. + break;
  20915. + }
  20916. +
  20917. + if (copy_from_user(&args, (const void __user *)arg,
  20918. + sizeof(args)) != 0) {
  20919. + ret = -EFAULT;
  20920. + break;
  20921. + }
  20922. +
  20923. + mutex_lock(&instance->completion_mutex);
  20924. +
  20925. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20926. + while ((instance->completion_remove ==
  20927. + instance->completion_insert)
  20928. + && !instance->closing) {
  20929. + int rc;
  20930. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20931. + mutex_unlock(&instance->completion_mutex);
  20932. + rc = down_interruptible(&instance->insert_event);
  20933. + mutex_lock(&instance->completion_mutex);
  20934. + if (rc != 0) {
  20935. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20936. + vchiq_log_info(vchiq_arm_log_level,
  20937. + "AWAIT_COMPLETION interrupted");
  20938. + ret = -EINTR;
  20939. + break;
  20940. + }
  20941. + }
  20942. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20943. +
  20944. + /* A read memory barrier is needed to stop prefetch of a stale
  20945. + ** completion record
  20946. + */
  20947. + rmb();
  20948. +
  20949. + if (ret == 0) {
  20950. + int msgbufcount = args.msgbufcount;
  20951. + for (ret = 0; ret < args.count; ret++) {
  20952. + VCHIQ_COMPLETION_DATA_T *completion;
  20953. + VCHIQ_SERVICE_T *service;
  20954. + USER_SERVICE_T *user_service;
  20955. + VCHIQ_HEADER_T *header;
  20956. + if (instance->completion_remove ==
  20957. + instance->completion_insert)
  20958. + break;
  20959. + completion = &instance->completions[
  20960. + instance->completion_remove &
  20961. + (MAX_COMPLETIONS - 1)];
  20962. +
  20963. + service = completion->service_userdata;
  20964. + user_service = service->base.userdata;
  20965. + completion->service_userdata =
  20966. + user_service->userdata;
  20967. +
  20968. + header = completion->header;
  20969. + if (header) {
  20970. + void __user *msgbuf;
  20971. + int msglen;
  20972. +
  20973. + msglen = header->size +
  20974. + sizeof(VCHIQ_HEADER_T);
  20975. + /* This must be a VCHIQ-style service */
  20976. + if (args.msgbufsize < msglen) {
  20977. + vchiq_log_error(
  20978. + vchiq_arm_log_level,
  20979. + "header %x: msgbufsize"
  20980. + " %x < msglen %x",
  20981. + (unsigned int)header,
  20982. + args.msgbufsize,
  20983. + msglen);
  20984. + WARN(1, "invalid message "
  20985. + "size\n");
  20986. + if (ret == 0)
  20987. + ret = -EMSGSIZE;
  20988. + break;
  20989. + }
  20990. + if (msgbufcount <= 0)
  20991. + /* Stall here for lack of a
  20992. + ** buffer for the message. */
  20993. + break;
  20994. + /* Get the pointer from user space */
  20995. + msgbufcount--;
  20996. + if (copy_from_user(&msgbuf,
  20997. + (const void __user *)
  20998. + &args.msgbufs[msgbufcount],
  20999. + sizeof(msgbuf)) != 0) {
  21000. + if (ret == 0)
  21001. + ret = -EFAULT;
  21002. + break;
  21003. + }
  21004. +
  21005. + /* Copy the message to user space */
  21006. + if (copy_to_user(msgbuf, header,
  21007. + msglen) != 0) {
  21008. + if (ret == 0)
  21009. + ret = -EFAULT;
  21010. + break;
  21011. + }
  21012. +
  21013. + /* Now it has been copied, the message
  21014. + ** can be released. */
  21015. + vchiq_release_message(service->handle,
  21016. + header);
  21017. +
  21018. + /* The completion must point to the
  21019. + ** msgbuf. */
  21020. + completion->header = msgbuf;
  21021. + }
  21022. +
  21023. + if (completion->reason ==
  21024. + VCHIQ_SERVICE_CLOSED)
  21025. + unlock_service(service);
  21026. +
  21027. + if (copy_to_user((void __user *)(
  21028. + (size_t)args.buf +
  21029. + ret * sizeof(VCHIQ_COMPLETION_DATA_T)),
  21030. + completion,
  21031. + sizeof(VCHIQ_COMPLETION_DATA_T)) != 0) {
  21032. + if (ret == 0)
  21033. + ret = -EFAULT;
  21034. + break;
  21035. + }
  21036. +
  21037. + instance->completion_remove++;
  21038. + }
  21039. +
  21040. + if (msgbufcount != args.msgbufcount) {
  21041. + if (copy_to_user((void __user *)
  21042. + &((VCHIQ_AWAIT_COMPLETION_T *)arg)->
  21043. + msgbufcount,
  21044. + &msgbufcount,
  21045. + sizeof(msgbufcount)) != 0) {
  21046. + ret = -EFAULT;
  21047. + }
  21048. + }
  21049. + }
  21050. +
  21051. + if (ret != 0)
  21052. + up(&instance->remove_event);
  21053. + mutex_unlock(&instance->completion_mutex);
  21054. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  21055. + } break;
  21056. +
  21057. + case VCHIQ_IOC_DEQUEUE_MESSAGE: {
  21058. + VCHIQ_DEQUEUE_MESSAGE_T args;
  21059. + USER_SERVICE_T *user_service;
  21060. + VCHIQ_HEADER_T *header;
  21061. +
  21062. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  21063. + if (copy_from_user
  21064. + (&args, (const void __user *)arg,
  21065. + sizeof(args)) != 0) {
  21066. + ret = -EFAULT;
  21067. + break;
  21068. + }
  21069. + service = find_service_for_instance(instance, args.handle);
  21070. + if (!service) {
  21071. + ret = -EINVAL;
  21072. + break;
  21073. + }
  21074. + user_service = (USER_SERVICE_T *)service->base.userdata;
  21075. + if (user_service->is_vchi == 0) {
  21076. + ret = -EINVAL;
  21077. + break;
  21078. + }
  21079. +
  21080. + spin_lock(&msg_queue_spinlock);
  21081. + if (user_service->msg_remove == user_service->msg_insert) {
  21082. + if (!args.blocking) {
  21083. + spin_unlock(&msg_queue_spinlock);
  21084. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  21085. + ret = -EWOULDBLOCK;
  21086. + break;
  21087. + }
  21088. + user_service->dequeue_pending = 1;
  21089. + do {
  21090. + spin_unlock(&msg_queue_spinlock);
  21091. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  21092. + if (down_interruptible(
  21093. + &user_service->insert_event) != 0) {
  21094. + vchiq_log_info(vchiq_arm_log_level,
  21095. + "DEQUEUE_MESSAGE interrupted");
  21096. + ret = -EINTR;
  21097. + break;
  21098. + }
  21099. + spin_lock(&msg_queue_spinlock);
  21100. + } while (user_service->msg_remove ==
  21101. + user_service->msg_insert);
  21102. +
  21103. + if (ret)
  21104. + break;
  21105. + }
  21106. +
  21107. + BUG_ON((int)(user_service->msg_insert -
  21108. + user_service->msg_remove) < 0);
  21109. +
  21110. + header = user_service->msg_queue[user_service->msg_remove &
  21111. + (MSG_QUEUE_SIZE - 1)];
  21112. + user_service->msg_remove++;
  21113. + spin_unlock(&msg_queue_spinlock);
  21114. +
  21115. + up(&user_service->remove_event);
  21116. + if (header == NULL)
  21117. + ret = -ENOTCONN;
  21118. + else if (header->size <= args.bufsize) {
  21119. + /* Copy to user space if msgbuf is not NULL */
  21120. + if ((args.buf == NULL) ||
  21121. + (copy_to_user((void __user *)args.buf,
  21122. + header->data,
  21123. + header->size) == 0)) {
  21124. + ret = header->size;
  21125. + vchiq_release_message(
  21126. + service->handle,
  21127. + header);
  21128. + } else
  21129. + ret = -EFAULT;
  21130. + } else {
  21131. + vchiq_log_error(vchiq_arm_log_level,
  21132. + "header %x: bufsize %x < size %x",
  21133. + (unsigned int)header, args.bufsize,
  21134. + header->size);
  21135. + WARN(1, "invalid size\n");
  21136. + ret = -EMSGSIZE;
  21137. + }
  21138. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  21139. + } break;
  21140. +
  21141. + case VCHIQ_IOC_GET_CLIENT_ID: {
  21142. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  21143. +
  21144. + ret = vchiq_get_client_id(handle);
  21145. + } break;
  21146. +
  21147. + case VCHIQ_IOC_GET_CONFIG: {
  21148. + VCHIQ_GET_CONFIG_T args;
  21149. + VCHIQ_CONFIG_T config;
  21150. +
  21151. + if (copy_from_user(&args, (const void __user *)arg,
  21152. + sizeof(args)) != 0) {
  21153. + ret = -EFAULT;
  21154. + break;
  21155. + }
  21156. + if (args.config_size > sizeof(config)) {
  21157. + ret = -EINVAL;
  21158. + break;
  21159. + }
  21160. + status = vchiq_get_config(instance, args.config_size, &config);
  21161. + if (status == VCHIQ_SUCCESS) {
  21162. + if (copy_to_user((void __user *)args.pconfig,
  21163. + &config, args.config_size) != 0) {
  21164. + ret = -EFAULT;
  21165. + break;
  21166. + }
  21167. + }
  21168. + } break;
  21169. +
  21170. + case VCHIQ_IOC_SET_SERVICE_OPTION: {
  21171. + VCHIQ_SET_SERVICE_OPTION_T args;
  21172. +
  21173. + if (copy_from_user(
  21174. + &args, (const void __user *)arg,
  21175. + sizeof(args)) != 0) {
  21176. + ret = -EFAULT;
  21177. + break;
  21178. + }
  21179. +
  21180. + service = find_service_for_instance(instance, args.handle);
  21181. + if (!service) {
  21182. + ret = -EINVAL;
  21183. + break;
  21184. + }
  21185. +
  21186. + status = vchiq_set_service_option(
  21187. + args.handle, args.option, args.value);
  21188. + } break;
  21189. +
  21190. + case VCHIQ_IOC_DUMP_PHYS_MEM: {
  21191. + VCHIQ_DUMP_MEM_T args;
  21192. +
  21193. + if (copy_from_user
  21194. + (&args, (const void __user *)arg,
  21195. + sizeof(args)) != 0) {
  21196. + ret = -EFAULT;
  21197. + break;
  21198. + }
  21199. + dump_phys_mem(args.virt_addr, args.num_bytes);
  21200. + } break;
  21201. +
  21202. + default:
  21203. + ret = -ENOTTY;
  21204. + break;
  21205. + }
  21206. +
  21207. + if (service)
  21208. + unlock_service(service);
  21209. +
  21210. + if (ret == 0) {
  21211. + if (status == VCHIQ_ERROR)
  21212. + ret = -EIO;
  21213. + else if (status == VCHIQ_RETRY)
  21214. + ret = -EINTR;
  21215. + }
  21216. +
  21217. + if ((status == VCHIQ_SUCCESS) && (ret < 0) && (ret != -EINTR) &&
  21218. + (ret != -EWOULDBLOCK))
  21219. + vchiq_log_info(vchiq_arm_log_level,
  21220. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  21221. + (unsigned long)instance,
  21222. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  21223. + ioctl_names[_IOC_NR(cmd)] :
  21224. + "<invalid>",
  21225. + status, ret);
  21226. + else
  21227. + vchiq_log_trace(vchiq_arm_log_level,
  21228. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  21229. + (unsigned long)instance,
  21230. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  21231. + ioctl_names[_IOC_NR(cmd)] :
  21232. + "<invalid>",
  21233. + status, ret);
  21234. +
  21235. + return ret;
  21236. +}
  21237. +
  21238. +/****************************************************************************
  21239. +*
  21240. +* vchiq_open
  21241. +*
  21242. +***************************************************************************/
  21243. +
  21244. +static int
  21245. +vchiq_open(struct inode *inode, struct file *file)
  21246. +{
  21247. + int dev = iminor(inode) & 0x0f;
  21248. + vchiq_log_info(vchiq_arm_log_level, "vchiq_open");
  21249. + switch (dev) {
  21250. + case VCHIQ_MINOR: {
  21251. + int ret;
  21252. + VCHIQ_STATE_T *state = vchiq_get_state();
  21253. + VCHIQ_INSTANCE_T instance;
  21254. +
  21255. + if (!state) {
  21256. + vchiq_log_error(vchiq_arm_log_level,
  21257. + "vchiq has no connection to VideoCore");
  21258. + return -ENOTCONN;
  21259. + }
  21260. +
  21261. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  21262. + if (!instance)
  21263. + return -ENOMEM;
  21264. +
  21265. + instance->state = state;
  21266. + instance->pid = current->tgid;
  21267. +
  21268. + ret = vchiq_proc_add_instance(instance);
  21269. + if (ret != 0) {
  21270. + kfree(instance);
  21271. + return ret;
  21272. + }
  21273. +
  21274. + sema_init(&instance->insert_event, 0);
  21275. + sema_init(&instance->remove_event, 0);
  21276. + mutex_init(&instance->completion_mutex);
  21277. + mutex_init(&instance->bulk_waiter_list_mutex);
  21278. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  21279. +
  21280. + file->private_data = instance;
  21281. + } break;
  21282. +
  21283. + default:
  21284. + vchiq_log_error(vchiq_arm_log_level,
  21285. + "Unknown minor device: %d", dev);
  21286. + return -ENXIO;
  21287. + }
  21288. +
  21289. + return 0;
  21290. +}
  21291. +
  21292. +/****************************************************************************
  21293. +*
  21294. +* vchiq_release
  21295. +*
  21296. +***************************************************************************/
  21297. +
  21298. +static int
  21299. +vchiq_release(struct inode *inode, struct file *file)
  21300. +{
  21301. + int dev = iminor(inode) & 0x0f;
  21302. + int ret = 0;
  21303. + switch (dev) {
  21304. + case VCHIQ_MINOR: {
  21305. + VCHIQ_INSTANCE_T instance = file->private_data;
  21306. + VCHIQ_STATE_T *state = vchiq_get_state();
  21307. + VCHIQ_SERVICE_T *service;
  21308. + int i;
  21309. +
  21310. + vchiq_log_info(vchiq_arm_log_level,
  21311. + "vchiq_release: instance=%lx",
  21312. + (unsigned long)instance);
  21313. +
  21314. + if (!state) {
  21315. + ret = -EPERM;
  21316. + goto out;
  21317. + }
  21318. +
  21319. + /* Ensure videocore is awake to allow termination. */
  21320. + vchiq_use_internal(instance->state, NULL,
  21321. + USE_TYPE_VCHIQ);
  21322. +
  21323. + mutex_lock(&instance->completion_mutex);
  21324. +
  21325. + /* Wake the completion thread and ask it to exit */
  21326. + instance->closing = 1;
  21327. + up(&instance->insert_event);
  21328. +
  21329. + mutex_unlock(&instance->completion_mutex);
  21330. +
  21331. + /* Wake the slot handler if the completion queue is full. */
  21332. + up(&instance->remove_event);
  21333. +
  21334. + /* Mark all services for termination... */
  21335. + i = 0;
  21336. + while ((service = next_service_by_instance(state, instance,
  21337. + &i)) != NULL) {
  21338. + USER_SERVICE_T *user_service = service->base.userdata;
  21339. +
  21340. + /* Wake the slot handler if the msg queue is full. */
  21341. + up(&user_service->remove_event);
  21342. +
  21343. + vchiq_terminate_service_internal(service);
  21344. + unlock_service(service);
  21345. + }
  21346. +
  21347. + /* ...and wait for them to die */
  21348. + i = 0;
  21349. + while ((service = next_service_by_instance(state, instance, &i))
  21350. + != NULL) {
  21351. + USER_SERVICE_T *user_service = service->base.userdata;
  21352. +
  21353. + down(&service->remove_event);
  21354. +
  21355. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  21356. +
  21357. + spin_lock(&msg_queue_spinlock);
  21358. +
  21359. + while (user_service->msg_remove !=
  21360. + user_service->msg_insert) {
  21361. + VCHIQ_HEADER_T *header = user_service->
  21362. + msg_queue[user_service->msg_remove &
  21363. + (MSG_QUEUE_SIZE - 1)];
  21364. + user_service->msg_remove++;
  21365. + spin_unlock(&msg_queue_spinlock);
  21366. +
  21367. + if (header)
  21368. + vchiq_release_message(
  21369. + service->handle,
  21370. + header);
  21371. + spin_lock(&msg_queue_spinlock);
  21372. + }
  21373. +
  21374. + spin_unlock(&msg_queue_spinlock);
  21375. +
  21376. + unlock_service(service);
  21377. + }
  21378. +
  21379. + /* Release any closed services */
  21380. + while (instance->completion_remove !=
  21381. + instance->completion_insert) {
  21382. + VCHIQ_COMPLETION_DATA_T *completion;
  21383. + VCHIQ_SERVICE_T *service;
  21384. + completion = &instance->completions[
  21385. + instance->completion_remove &
  21386. + (MAX_COMPLETIONS - 1)];
  21387. + service = completion->service_userdata;
  21388. + if (completion->reason == VCHIQ_SERVICE_CLOSED)
  21389. + unlock_service(service);
  21390. + instance->completion_remove++;
  21391. + }
  21392. +
  21393. + /* Release the PEER service count. */
  21394. + vchiq_release_internal(instance->state, NULL);
  21395. +
  21396. + {
  21397. + struct list_head *pos, *next;
  21398. + list_for_each_safe(pos, next,
  21399. + &instance->bulk_waiter_list) {
  21400. + struct bulk_waiter_node *waiter;
  21401. + waiter = list_entry(pos,
  21402. + struct bulk_waiter_node,
  21403. + list);
  21404. + list_del(pos);
  21405. + vchiq_log_info(vchiq_arm_log_level,
  21406. + "bulk_waiter - cleaned up %x "
  21407. + "for pid %d",
  21408. + (unsigned int)waiter, waiter->pid);
  21409. + kfree(waiter);
  21410. + }
  21411. + }
  21412. +
  21413. + vchiq_proc_remove_instance(instance);
  21414. +
  21415. + kfree(instance);
  21416. + file->private_data = NULL;
  21417. + } break;
  21418. +
  21419. + default:
  21420. + vchiq_log_error(vchiq_arm_log_level,
  21421. + "Unknown minor device: %d", dev);
  21422. + ret = -ENXIO;
  21423. + }
  21424. +
  21425. +out:
  21426. + return ret;
  21427. +}
  21428. +
  21429. +/****************************************************************************
  21430. +*
  21431. +* vchiq_dump
  21432. +*
  21433. +***************************************************************************/
  21434. +
  21435. +void
  21436. +vchiq_dump(void *dump_context, const char *str, int len)
  21437. +{
  21438. + DUMP_CONTEXT_T *context = (DUMP_CONTEXT_T *)dump_context;
  21439. +
  21440. + if (context->actual < context->space) {
  21441. + int copy_bytes;
  21442. + if (context->offset > 0) {
  21443. + int skip_bytes = min(len, (int)context->offset);
  21444. + str += skip_bytes;
  21445. + len -= skip_bytes;
  21446. + context->offset -= skip_bytes;
  21447. + if (context->offset > 0)
  21448. + return;
  21449. + }
  21450. + copy_bytes = min(len, (int)(context->space - context->actual));
  21451. + if (copy_bytes == 0)
  21452. + return;
  21453. + if (copy_to_user(context->buf + context->actual, str,
  21454. + copy_bytes))
  21455. + context->actual = -EFAULT;
  21456. + context->actual += copy_bytes;
  21457. + len -= copy_bytes;
  21458. +
  21459. + /* If tne terminating NUL is included in the length, then it
  21460. + ** marks the end of a line and should be replaced with a
  21461. + ** carriage return. */
  21462. + if ((len == 0) && (str[copy_bytes - 1] == '\0')) {
  21463. + char cr = '\n';
  21464. + if (copy_to_user(context->buf + context->actual - 1,
  21465. + &cr, 1))
  21466. + context->actual = -EFAULT;
  21467. + }
  21468. + }
  21469. +}
  21470. +
  21471. +/****************************************************************************
  21472. +*
  21473. +* vchiq_dump_platform_instance_state
  21474. +*
  21475. +***************************************************************************/
  21476. +
  21477. +void
  21478. +vchiq_dump_platform_instances(void *dump_context)
  21479. +{
  21480. + VCHIQ_STATE_T *state = vchiq_get_state();
  21481. + char buf[80];
  21482. + int len;
  21483. + int i;
  21484. +
  21485. + /* There is no list of instances, so instead scan all services,
  21486. + marking those that have been dumped. */
  21487. +
  21488. + for (i = 0; i < state->unused_service; i++) {
  21489. + VCHIQ_SERVICE_T *service = state->services[i];
  21490. + VCHIQ_INSTANCE_T instance;
  21491. +
  21492. + if (service && (service->base.callback == service_callback)) {
  21493. + instance = service->instance;
  21494. + if (instance)
  21495. + instance->mark = 0;
  21496. + }
  21497. + }
  21498. +
  21499. + for (i = 0; i < state->unused_service; i++) {
  21500. + VCHIQ_SERVICE_T *service = state->services[i];
  21501. + VCHIQ_INSTANCE_T instance;
  21502. +
  21503. + if (service && (service->base.callback == service_callback)) {
  21504. + instance = service->instance;
  21505. + if (instance && !instance->mark) {
  21506. + len = snprintf(buf, sizeof(buf),
  21507. + "Instance %x: pid %d,%s completions "
  21508. + "%d/%d",
  21509. + (unsigned int)instance, instance->pid,
  21510. + instance->connected ? " connected, " :
  21511. + "",
  21512. + instance->completion_insert -
  21513. + instance->completion_remove,
  21514. + MAX_COMPLETIONS);
  21515. +
  21516. + vchiq_dump(dump_context, buf, len + 1);
  21517. +
  21518. + instance->mark = 1;
  21519. + }
  21520. + }
  21521. + }
  21522. +}
  21523. +
  21524. +/****************************************************************************
  21525. +*
  21526. +* vchiq_dump_platform_service_state
  21527. +*
  21528. +***************************************************************************/
  21529. +
  21530. +void
  21531. +vchiq_dump_platform_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  21532. +{
  21533. + USER_SERVICE_T *user_service = (USER_SERVICE_T *)service->base.userdata;
  21534. + char buf[80];
  21535. + int len;
  21536. +
  21537. + len = snprintf(buf, sizeof(buf), " instance %x",
  21538. + (unsigned int)service->instance);
  21539. +
  21540. + if ((service->base.callback == service_callback) &&
  21541. + user_service->is_vchi) {
  21542. + len += snprintf(buf + len, sizeof(buf) - len,
  21543. + ", %d/%d messages",
  21544. + user_service->msg_insert - user_service->msg_remove,
  21545. + MSG_QUEUE_SIZE);
  21546. +
  21547. + if (user_service->dequeue_pending)
  21548. + len += snprintf(buf + len, sizeof(buf) - len,
  21549. + " (dequeue pending)");
  21550. + }
  21551. +
  21552. + vchiq_dump(dump_context, buf, len + 1);
  21553. +}
  21554. +
  21555. +/****************************************************************************
  21556. +*
  21557. +* dump_user_mem
  21558. +*
  21559. +***************************************************************************/
  21560. +
  21561. +static void
  21562. +dump_phys_mem(void *virt_addr, uint32_t num_bytes)
  21563. +{
  21564. + int rc;
  21565. + uint8_t *end_virt_addr = virt_addr + num_bytes;
  21566. + int num_pages;
  21567. + int offset;
  21568. + int end_offset;
  21569. + int page_idx;
  21570. + int prev_idx;
  21571. + struct page *page;
  21572. + struct page **pages;
  21573. + uint8_t *kmapped_virt_ptr;
  21574. +
  21575. + /* Align virtAddr and endVirtAddr to 16 byte boundaries. */
  21576. +
  21577. + virt_addr = (void *)((unsigned long)virt_addr & ~0x0fuL);
  21578. + end_virt_addr = (void *)(((unsigned long)end_virt_addr + 15uL) &
  21579. + ~0x0fuL);
  21580. +
  21581. + offset = (int)(long)virt_addr & (PAGE_SIZE - 1);
  21582. + end_offset = (int)(long)end_virt_addr & (PAGE_SIZE - 1);
  21583. +
  21584. + num_pages = (offset + num_bytes + PAGE_SIZE - 1) / PAGE_SIZE;
  21585. +
  21586. + pages = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL);
  21587. + if (pages == NULL) {
  21588. + vchiq_log_error(vchiq_arm_log_level,
  21589. + "Unable to allocation memory for %d pages\n",
  21590. + num_pages);
  21591. + return;
  21592. + }
  21593. +
  21594. + down_read(&current->mm->mmap_sem);
  21595. + rc = get_user_pages(current, /* task */
  21596. + current->mm, /* mm */
  21597. + (unsigned long)virt_addr, /* start */
  21598. + num_pages, /* len */
  21599. + 0, /* write */
  21600. + 0, /* force */
  21601. + pages, /* pages (array of page pointers) */
  21602. + NULL); /* vmas */
  21603. + up_read(&current->mm->mmap_sem);
  21604. +
  21605. + prev_idx = -1;
  21606. + page = NULL;
  21607. +
  21608. + while (offset < end_offset) {
  21609. +
  21610. + int page_offset = offset % PAGE_SIZE;
  21611. + page_idx = offset / PAGE_SIZE;
  21612. +
  21613. + if (page_idx != prev_idx) {
  21614. +
  21615. + if (page != NULL)
  21616. + kunmap(page);
  21617. + page = pages[page_idx];
  21618. + kmapped_virt_ptr = kmap(page);
  21619. +
  21620. + prev_idx = page_idx;
  21621. + }
  21622. +
  21623. + if (vchiq_arm_log_level >= VCHIQ_LOG_TRACE)
  21624. + vchiq_log_dump_mem("ph",
  21625. + (uint32_t)(unsigned long)&kmapped_virt_ptr[
  21626. + page_offset],
  21627. + &kmapped_virt_ptr[page_offset], 16);
  21628. +
  21629. + offset += 16;
  21630. + }
  21631. + if (page != NULL)
  21632. + kunmap(page);
  21633. +
  21634. + for (page_idx = 0; page_idx < num_pages; page_idx++)
  21635. + page_cache_release(pages[page_idx]);
  21636. +
  21637. + kfree(pages);
  21638. +}
  21639. +
  21640. +/****************************************************************************
  21641. +*
  21642. +* vchiq_read
  21643. +*
  21644. +***************************************************************************/
  21645. +
  21646. +static ssize_t
  21647. +vchiq_read(struct file *file, char __user *buf,
  21648. + size_t count, loff_t *ppos)
  21649. +{
  21650. + DUMP_CONTEXT_T context;
  21651. + context.buf = buf;
  21652. + context.actual = 0;
  21653. + context.space = count;
  21654. + context.offset = *ppos;
  21655. +
  21656. + vchiq_dump_state(&context, &g_state);
  21657. +
  21658. + *ppos += context.actual;
  21659. +
  21660. + return context.actual;
  21661. +}
  21662. +
  21663. +VCHIQ_STATE_T *
  21664. +vchiq_get_state(void)
  21665. +{
  21666. +
  21667. + if (g_state.remote == NULL)
  21668. + printk(KERN_ERR "%s: g_state.remote == NULL\n", __func__);
  21669. + else if (g_state.remote->initialised != 1)
  21670. + printk(KERN_NOTICE "%s: g_state.remote->initialised != 1 (%d)\n",
  21671. + __func__, g_state.remote->initialised);
  21672. +
  21673. + return ((g_state.remote != NULL) &&
  21674. + (g_state.remote->initialised == 1)) ? &g_state : NULL;
  21675. +}
  21676. +
  21677. +static const struct file_operations
  21678. +vchiq_fops = {
  21679. + .owner = THIS_MODULE,
  21680. + .unlocked_ioctl = vchiq_ioctl,
  21681. + .open = vchiq_open,
  21682. + .release = vchiq_release,
  21683. + .read = vchiq_read
  21684. +};
  21685. +
  21686. +/*
  21687. + * Autosuspend related functionality
  21688. + */
  21689. +
  21690. +int
  21691. +vchiq_videocore_wanted(VCHIQ_STATE_T *state)
  21692. +{
  21693. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21694. + if (!arm_state)
  21695. + /* autosuspend not supported - always return wanted */
  21696. + return 1;
  21697. + else if (arm_state->blocked_count)
  21698. + return 1;
  21699. + else if (!arm_state->videocore_use_count)
  21700. + /* usage count zero - check for override unless we're forcing */
  21701. + if (arm_state->resume_blocked)
  21702. + return 0;
  21703. + else
  21704. + return vchiq_platform_videocore_wanted(state);
  21705. + else
  21706. + /* non-zero usage count - videocore still required */
  21707. + return 1;
  21708. +}
  21709. +
  21710. +static VCHIQ_STATUS_T
  21711. +vchiq_keepalive_vchiq_callback(VCHIQ_REASON_T reason,
  21712. + VCHIQ_HEADER_T *header,
  21713. + VCHIQ_SERVICE_HANDLE_T service_user,
  21714. + void *bulk_user)
  21715. +{
  21716. + vchiq_log_error(vchiq_susp_log_level,
  21717. + "%s callback reason %d", __func__, reason);
  21718. + return 0;
  21719. +}
  21720. +
  21721. +static int
  21722. +vchiq_keepalive_thread_func(void *v)
  21723. +{
  21724. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  21725. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21726. +
  21727. + VCHIQ_STATUS_T status;
  21728. + VCHIQ_INSTANCE_T instance;
  21729. + VCHIQ_SERVICE_HANDLE_T ka_handle;
  21730. +
  21731. + VCHIQ_SERVICE_PARAMS_T params = {
  21732. + .fourcc = VCHIQ_MAKE_FOURCC('K', 'E', 'E', 'P'),
  21733. + .callback = vchiq_keepalive_vchiq_callback,
  21734. + .version = KEEPALIVE_VER,
  21735. + .version_min = KEEPALIVE_VER_MIN
  21736. + };
  21737. +
  21738. + status = vchiq_initialise(&instance);
  21739. + if (status != VCHIQ_SUCCESS) {
  21740. + vchiq_log_error(vchiq_susp_log_level,
  21741. + "%s vchiq_initialise failed %d", __func__, status);
  21742. + goto exit;
  21743. + }
  21744. +
  21745. + status = vchiq_connect(instance);
  21746. + if (status != VCHIQ_SUCCESS) {
  21747. + vchiq_log_error(vchiq_susp_log_level,
  21748. + "%s vchiq_connect failed %d", __func__, status);
  21749. + goto shutdown;
  21750. + }
  21751. +
  21752. + status = vchiq_add_service(instance, &params, &ka_handle);
  21753. + if (status != VCHIQ_SUCCESS) {
  21754. + vchiq_log_error(vchiq_susp_log_level,
  21755. + "%s vchiq_open_service failed %d", __func__, status);
  21756. + goto shutdown;
  21757. + }
  21758. +
  21759. + while (1) {
  21760. + long rc = 0, uc = 0;
  21761. + if (wait_for_completion_interruptible(&arm_state->ka_evt)
  21762. + != 0) {
  21763. + vchiq_log_error(vchiq_susp_log_level,
  21764. + "%s interrupted", __func__);
  21765. + flush_signals(current);
  21766. + continue;
  21767. + }
  21768. +
  21769. + /* read and clear counters. Do release_count then use_count to
  21770. + * prevent getting more releases than uses */
  21771. + rc = atomic_xchg(&arm_state->ka_release_count, 0);
  21772. + uc = atomic_xchg(&arm_state->ka_use_count, 0);
  21773. +
  21774. + /* Call use/release service the requisite number of times.
  21775. + * Process use before release so use counts don't go negative */
  21776. + while (uc--) {
  21777. + atomic_inc(&arm_state->ka_use_ack_count);
  21778. + status = vchiq_use_service(ka_handle);
  21779. + if (status != VCHIQ_SUCCESS) {
  21780. + vchiq_log_error(vchiq_susp_log_level,
  21781. + "%s vchiq_use_service error %d",
  21782. + __func__, status);
  21783. + }
  21784. + }
  21785. + while (rc--) {
  21786. + status = vchiq_release_service(ka_handle);
  21787. + if (status != VCHIQ_SUCCESS) {
  21788. + vchiq_log_error(vchiq_susp_log_level,
  21789. + "%s vchiq_release_service error %d",
  21790. + __func__, status);
  21791. + }
  21792. + }
  21793. + }
  21794. +
  21795. +shutdown:
  21796. + vchiq_shutdown(instance);
  21797. +exit:
  21798. + return 0;
  21799. +}
  21800. +
  21801. +
  21802. +
  21803. +VCHIQ_STATUS_T
  21804. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state)
  21805. +{
  21806. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  21807. +
  21808. + if (arm_state) {
  21809. + rwlock_init(&arm_state->susp_res_lock);
  21810. +
  21811. + init_completion(&arm_state->ka_evt);
  21812. + atomic_set(&arm_state->ka_use_count, 0);
  21813. + atomic_set(&arm_state->ka_use_ack_count, 0);
  21814. + atomic_set(&arm_state->ka_release_count, 0);
  21815. +
  21816. + init_completion(&arm_state->vc_suspend_complete);
  21817. +
  21818. + init_completion(&arm_state->vc_resume_complete);
  21819. + /* Initialise to 'done' state. We only want to block on resume
  21820. + * completion while videocore is suspended. */
  21821. + set_resume_state(arm_state, VC_RESUME_RESUMED);
  21822. +
  21823. + init_completion(&arm_state->resume_blocker);
  21824. + /* Initialise to 'done' state. We only want to block on this
  21825. + * completion while resume is blocked */
  21826. + complete_all(&arm_state->resume_blocker);
  21827. +
  21828. + init_completion(&arm_state->blocked_blocker);
  21829. + /* Initialise to 'done' state. We only want to block on this
  21830. + * completion while things are waiting on the resume blocker */
  21831. + complete_all(&arm_state->blocked_blocker);
  21832. +
  21833. + arm_state->suspend_timer_timeout = SUSPEND_TIMER_TIMEOUT_MS;
  21834. + arm_state->suspend_timer_running = 0;
  21835. + init_timer(&arm_state->suspend_timer);
  21836. + arm_state->suspend_timer.data = (unsigned long)(state);
  21837. + arm_state->suspend_timer.function = suspend_timer_callback;
  21838. +
  21839. + arm_state->first_connect = 0;
  21840. +
  21841. + }
  21842. + return status;
  21843. +}
  21844. +
  21845. +/*
  21846. +** Functions to modify the state variables;
  21847. +** set_suspend_state
  21848. +** set_resume_state
  21849. +**
  21850. +** There are more state variables than we might like, so ensure they remain in
  21851. +** step. Suspend and resume state are maintained separately, since most of
  21852. +** these state machines can operate independently. However, there are a few
  21853. +** states where state transitions in one state machine cause a reset to the
  21854. +** other state machine. In addition, there are some completion events which
  21855. +** need to occur on state machine reset and end-state(s), so these are also
  21856. +** dealt with in these functions.
  21857. +**
  21858. +** In all states we set the state variable according to the input, but in some
  21859. +** cases we perform additional steps outlined below;
  21860. +**
  21861. +** VC_SUSPEND_IDLE - Initialise the suspend completion at the same time.
  21862. +** The suspend completion is completed after any suspend
  21863. +** attempt. When we reset the state machine we also reset
  21864. +** the completion. This reset occurs when videocore is
  21865. +** resumed, and also if we initiate suspend after a suspend
  21866. +** failure.
  21867. +**
  21868. +** VC_SUSPEND_IN_PROGRESS - This state is considered the point of no return for
  21869. +** suspend - ie from this point on we must try to suspend
  21870. +** before resuming can occur. We therefore also reset the
  21871. +** resume state machine to VC_RESUME_IDLE in this state.
  21872. +**
  21873. +** VC_SUSPEND_SUSPENDED - Suspend has completed successfully. Also call
  21874. +** complete_all on the suspend completion to notify
  21875. +** anything waiting for suspend to happen.
  21876. +**
  21877. +** VC_SUSPEND_REJECTED - Videocore rejected suspend. Videocore will also
  21878. +** initiate resume, so no need to alter resume state.
  21879. +** We call complete_all on the suspend completion to notify
  21880. +** of suspend rejection.
  21881. +**
  21882. +** VC_SUSPEND_FAILED - We failed to initiate videocore suspend. We notify the
  21883. +** suspend completion and reset the resume state machine.
  21884. +**
  21885. +** VC_RESUME_IDLE - Initialise the resume completion at the same time. The
  21886. +** resume completion is in it's 'done' state whenever
  21887. +** videcore is running. Therfore, the VC_RESUME_IDLE state
  21888. +** implies that videocore is suspended.
  21889. +** Hence, any thread which needs to wait until videocore is
  21890. +** running can wait on this completion - it will only block
  21891. +** if videocore is suspended.
  21892. +**
  21893. +** VC_RESUME_RESUMED - Resume has completed successfully. Videocore is running.
  21894. +** Call complete_all on the resume completion to unblock
  21895. +** any threads waiting for resume. Also reset the suspend
  21896. +** state machine to it's idle state.
  21897. +**
  21898. +** VC_RESUME_FAILED - Currently unused - no mechanism to fail resume exists.
  21899. +*/
  21900. +
  21901. +inline void
  21902. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  21903. + enum vc_suspend_status new_state)
  21904. +{
  21905. + /* set the state in all cases */
  21906. + arm_state->vc_suspend_state = new_state;
  21907. +
  21908. + /* state specific additional actions */
  21909. + switch (new_state) {
  21910. + case VC_SUSPEND_FORCE_CANCELED:
  21911. + complete_all(&arm_state->vc_suspend_complete);
  21912. + break;
  21913. + case VC_SUSPEND_REJECTED:
  21914. + complete_all(&arm_state->vc_suspend_complete);
  21915. + break;
  21916. + case VC_SUSPEND_FAILED:
  21917. + complete_all(&arm_state->vc_suspend_complete);
  21918. + arm_state->vc_resume_state = VC_RESUME_RESUMED;
  21919. + complete_all(&arm_state->vc_resume_complete);
  21920. + break;
  21921. + case VC_SUSPEND_IDLE:
  21922. + INIT_COMPLETION(arm_state->vc_suspend_complete);
  21923. + break;
  21924. + case VC_SUSPEND_REQUESTED:
  21925. + break;
  21926. + case VC_SUSPEND_IN_PROGRESS:
  21927. + set_resume_state(arm_state, VC_RESUME_IDLE);
  21928. + break;
  21929. + case VC_SUSPEND_SUSPENDED:
  21930. + complete_all(&arm_state->vc_suspend_complete);
  21931. + break;
  21932. + default:
  21933. + BUG();
  21934. + break;
  21935. + }
  21936. +}
  21937. +
  21938. +inline void
  21939. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  21940. + enum vc_resume_status new_state)
  21941. +{
  21942. + /* set the state in all cases */
  21943. + arm_state->vc_resume_state = new_state;
  21944. +
  21945. + /* state specific additional actions */
  21946. + switch (new_state) {
  21947. + case VC_RESUME_FAILED:
  21948. + break;
  21949. + case VC_RESUME_IDLE:
  21950. + INIT_COMPLETION(arm_state->vc_resume_complete);
  21951. + break;
  21952. + case VC_RESUME_REQUESTED:
  21953. + break;
  21954. + case VC_RESUME_IN_PROGRESS:
  21955. + break;
  21956. + case VC_RESUME_RESUMED:
  21957. + complete_all(&arm_state->vc_resume_complete);
  21958. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  21959. + break;
  21960. + default:
  21961. + BUG();
  21962. + break;
  21963. + }
  21964. +}
  21965. +
  21966. +
  21967. +/* should be called with the write lock held */
  21968. +inline void
  21969. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  21970. +{
  21971. + del_timer(&arm_state->suspend_timer);
  21972. + arm_state->suspend_timer.expires = jiffies +
  21973. + msecs_to_jiffies(arm_state->
  21974. + suspend_timer_timeout);
  21975. + add_timer(&arm_state->suspend_timer);
  21976. + arm_state->suspend_timer_running = 1;
  21977. +}
  21978. +
  21979. +/* should be called with the write lock held */
  21980. +static inline void
  21981. +stop_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  21982. +{
  21983. + if (arm_state->suspend_timer_running) {
  21984. + del_timer(&arm_state->suspend_timer);
  21985. + arm_state->suspend_timer_running = 0;
  21986. + }
  21987. +}
  21988. +
  21989. +static inline int
  21990. +need_resume(VCHIQ_STATE_T *state)
  21991. +{
  21992. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21993. + return (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) &&
  21994. + (arm_state->vc_resume_state < VC_RESUME_REQUESTED) &&
  21995. + vchiq_videocore_wanted(state);
  21996. +}
  21997. +
  21998. +static int
  21999. +block_resume(VCHIQ_ARM_STATE_T *arm_state)
  22000. +{
  22001. + int status = VCHIQ_SUCCESS;
  22002. + const unsigned long timeout_val =
  22003. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS);
  22004. + int resume_count = 0;
  22005. +
  22006. + /* Allow any threads which were blocked by the last force suspend to
  22007. + * complete if they haven't already. Only give this one shot; if
  22008. + * blocked_count is incremented after blocked_blocker is completed
  22009. + * (which only happens when blocked_count hits 0) then those threads
  22010. + * will have to wait until next time around */
  22011. + if (arm_state->blocked_count) {
  22012. + INIT_COMPLETION(arm_state->blocked_blocker);
  22013. + write_unlock_bh(&arm_state->susp_res_lock);
  22014. + vchiq_log_info(vchiq_susp_log_level, "%s wait for previously "
  22015. + "blocked clients", __func__);
  22016. + if (wait_for_completion_interruptible_timeout(
  22017. + &arm_state->blocked_blocker, timeout_val)
  22018. + <= 0) {
  22019. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  22020. + "previously blocked clients failed" , __func__);
  22021. + status = VCHIQ_ERROR;
  22022. + write_lock_bh(&arm_state->susp_res_lock);
  22023. + goto out;
  22024. + }
  22025. + vchiq_log_info(vchiq_susp_log_level, "%s previously blocked "
  22026. + "clients resumed", __func__);
  22027. + write_lock_bh(&arm_state->susp_res_lock);
  22028. + }
  22029. +
  22030. + /* We need to wait for resume to complete if it's in process */
  22031. + while (arm_state->vc_resume_state != VC_RESUME_RESUMED &&
  22032. + arm_state->vc_resume_state > VC_RESUME_IDLE) {
  22033. + if (resume_count > 1) {
  22034. + status = VCHIQ_ERROR;
  22035. + vchiq_log_error(vchiq_susp_log_level, "%s waited too "
  22036. + "many times for resume" , __func__);
  22037. + goto out;
  22038. + }
  22039. + write_unlock_bh(&arm_state->susp_res_lock);
  22040. + vchiq_log_info(vchiq_susp_log_level, "%s wait for resume",
  22041. + __func__);
  22042. + if (wait_for_completion_interruptible_timeout(
  22043. + &arm_state->vc_resume_complete, timeout_val)
  22044. + <= 0) {
  22045. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  22046. + "resume failed (%s)", __func__,
  22047. + resume_state_names[arm_state->vc_resume_state +
  22048. + VC_RESUME_NUM_OFFSET]);
  22049. + status = VCHIQ_ERROR;
  22050. + write_lock_bh(&arm_state->susp_res_lock);
  22051. + goto out;
  22052. + }
  22053. + vchiq_log_info(vchiq_susp_log_level, "%s resumed", __func__);
  22054. + write_lock_bh(&arm_state->susp_res_lock);
  22055. + resume_count++;
  22056. + }
  22057. + INIT_COMPLETION(arm_state->resume_blocker);
  22058. + arm_state->resume_blocked = 1;
  22059. +
  22060. +out:
  22061. + return status;
  22062. +}
  22063. +
  22064. +static inline void
  22065. +unblock_resume(VCHIQ_ARM_STATE_T *arm_state)
  22066. +{
  22067. + complete_all(&arm_state->resume_blocker);
  22068. + arm_state->resume_blocked = 0;
  22069. +}
  22070. +
  22071. +/* Initiate suspend via slot handler. Should be called with the write lock
  22072. + * held */
  22073. +VCHIQ_STATUS_T
  22074. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state)
  22075. +{
  22076. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  22077. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22078. +
  22079. + if (!arm_state)
  22080. + goto out;
  22081. +
  22082. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22083. + status = VCHIQ_SUCCESS;
  22084. +
  22085. +
  22086. + switch (arm_state->vc_suspend_state) {
  22087. + case VC_SUSPEND_REQUESTED:
  22088. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already "
  22089. + "requested", __func__);
  22090. + break;
  22091. + case VC_SUSPEND_IN_PROGRESS:
  22092. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already in "
  22093. + "progress", __func__);
  22094. + break;
  22095. +
  22096. + default:
  22097. + /* We don't expect to be in other states, so log but continue
  22098. + * anyway */
  22099. + vchiq_log_error(vchiq_susp_log_level,
  22100. + "%s unexpected suspend state %s", __func__,
  22101. + suspend_state_names[arm_state->vc_suspend_state +
  22102. + VC_SUSPEND_NUM_OFFSET]);
  22103. + /* fall through */
  22104. + case VC_SUSPEND_REJECTED:
  22105. + case VC_SUSPEND_FAILED:
  22106. + /* Ensure any idle state actions have been run */
  22107. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  22108. + /* fall through */
  22109. + case VC_SUSPEND_IDLE:
  22110. + vchiq_log_info(vchiq_susp_log_level,
  22111. + "%s: suspending", __func__);
  22112. + set_suspend_state(arm_state, VC_SUSPEND_REQUESTED);
  22113. + /* kick the slot handler thread to initiate suspend */
  22114. + request_poll(state, NULL, 0);
  22115. + break;
  22116. + }
  22117. +
  22118. +out:
  22119. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  22120. + return status;
  22121. +}
  22122. +
  22123. +void
  22124. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state)
  22125. +{
  22126. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22127. + int susp = 0;
  22128. +
  22129. + if (!arm_state)
  22130. + goto out;
  22131. +
  22132. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22133. +
  22134. + write_lock_bh(&arm_state->susp_res_lock);
  22135. + if (arm_state->vc_suspend_state == VC_SUSPEND_REQUESTED &&
  22136. + arm_state->vc_resume_state == VC_RESUME_RESUMED) {
  22137. + set_suspend_state(arm_state, VC_SUSPEND_IN_PROGRESS);
  22138. + susp = 1;
  22139. + }
  22140. + write_unlock_bh(&arm_state->susp_res_lock);
  22141. +
  22142. + if (susp)
  22143. + vchiq_platform_suspend(state);
  22144. +
  22145. +out:
  22146. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  22147. + return;
  22148. +}
  22149. +
  22150. +
  22151. +static void
  22152. +output_timeout_error(VCHIQ_STATE_T *state)
  22153. +{
  22154. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22155. + char service_err[50] = "";
  22156. + int vc_use_count = arm_state->videocore_use_count;
  22157. + int active_services = state->unused_service;
  22158. + int i;
  22159. +
  22160. + if (!arm_state->videocore_use_count) {
  22161. + snprintf(service_err, 50, " Videocore usecount is 0");
  22162. + goto output_msg;
  22163. + }
  22164. + for (i = 0; i < active_services; i++) {
  22165. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  22166. + if (service_ptr && service_ptr->service_use_count &&
  22167. + (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE)) {
  22168. + snprintf(service_err, 50, " %c%c%c%c(%d) service has "
  22169. + "use count %d%s", VCHIQ_FOURCC_AS_4CHARS(
  22170. + service_ptr->base.fourcc),
  22171. + service_ptr->client_id,
  22172. + service_ptr->service_use_count,
  22173. + service_ptr->service_use_count ==
  22174. + vc_use_count ? "" : " (+ more)");
  22175. + break;
  22176. + }
  22177. + }
  22178. +
  22179. +output_msg:
  22180. + vchiq_log_error(vchiq_susp_log_level,
  22181. + "timed out waiting for vc suspend (%d).%s",
  22182. + arm_state->autosuspend_override, service_err);
  22183. +
  22184. +}
  22185. +
  22186. +/* Try to get videocore into suspended state, regardless of autosuspend state.
  22187. +** We don't actually force suspend, since videocore may get into a bad state
  22188. +** if we force suspend at a bad time. Instead, we wait for autosuspend to
  22189. +** determine a good point to suspend. If this doesn't happen within 100ms we
  22190. +** report failure.
  22191. +**
  22192. +** Returns VCHIQ_SUCCESS if videocore suspended successfully, VCHIQ_RETRY if
  22193. +** videocore failed to suspend in time or VCHIQ_ERROR if interrupted.
  22194. +*/
  22195. +VCHIQ_STATUS_T
  22196. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state)
  22197. +{
  22198. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22199. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  22200. + long rc = 0;
  22201. + int repeat = -1;
  22202. +
  22203. + if (!arm_state)
  22204. + goto out;
  22205. +
  22206. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22207. +
  22208. + write_lock_bh(&arm_state->susp_res_lock);
  22209. +
  22210. + status = block_resume(arm_state);
  22211. + if (status != VCHIQ_SUCCESS)
  22212. + goto unlock;
  22213. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  22214. + /* Already suspended - just block resume and exit */
  22215. + vchiq_log_info(vchiq_susp_log_level, "%s already suspended",
  22216. + __func__);
  22217. + status = VCHIQ_SUCCESS;
  22218. + goto unlock;
  22219. + } else if (arm_state->vc_suspend_state <= VC_SUSPEND_IDLE) {
  22220. + /* initiate suspend immediately in the case that we're waiting
  22221. + * for the timeout */
  22222. + stop_suspend_timer(arm_state);
  22223. + if (!vchiq_videocore_wanted(state)) {
  22224. + vchiq_log_info(vchiq_susp_log_level, "%s videocore "
  22225. + "idle, initiating suspend", __func__);
  22226. + status = vchiq_arm_vcsuspend(state);
  22227. + } else if (arm_state->autosuspend_override <
  22228. + FORCE_SUSPEND_FAIL_MAX) {
  22229. + vchiq_log_info(vchiq_susp_log_level, "%s letting "
  22230. + "videocore go idle", __func__);
  22231. + status = VCHIQ_SUCCESS;
  22232. + } else {
  22233. + vchiq_log_warning(vchiq_susp_log_level, "%s failed too "
  22234. + "many times - attempting suspend", __func__);
  22235. + status = vchiq_arm_vcsuspend(state);
  22236. + }
  22237. + } else {
  22238. + vchiq_log_info(vchiq_susp_log_level, "%s videocore suspend "
  22239. + "in progress - wait for completion", __func__);
  22240. + status = VCHIQ_SUCCESS;
  22241. + }
  22242. +
  22243. + /* Wait for suspend to happen due to system idle (not forced..) */
  22244. + if (status != VCHIQ_SUCCESS)
  22245. + goto unblock_resume;
  22246. +
  22247. + do {
  22248. + write_unlock_bh(&arm_state->susp_res_lock);
  22249. +
  22250. + rc = wait_for_completion_interruptible_timeout(
  22251. + &arm_state->vc_suspend_complete,
  22252. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS));
  22253. +
  22254. + write_lock_bh(&arm_state->susp_res_lock);
  22255. + if (rc < 0) {
  22256. + vchiq_log_warning(vchiq_susp_log_level, "%s "
  22257. + "interrupted waiting for suspend", __func__);
  22258. + status = VCHIQ_ERROR;
  22259. + goto unblock_resume;
  22260. + } else if (rc == 0) {
  22261. + if (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) {
  22262. + /* Repeat timeout once if in progress */
  22263. + if (repeat < 0) {
  22264. + repeat = 1;
  22265. + continue;
  22266. + }
  22267. + }
  22268. + arm_state->autosuspend_override++;
  22269. + output_timeout_error(state);
  22270. +
  22271. + status = VCHIQ_RETRY;
  22272. + goto unblock_resume;
  22273. + }
  22274. + } while (0 < (repeat--));
  22275. +
  22276. + /* Check and report state in case we need to abort ARM suspend */
  22277. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED) {
  22278. + status = VCHIQ_RETRY;
  22279. + vchiq_log_error(vchiq_susp_log_level,
  22280. + "%s videocore suspend failed (state %s)", __func__,
  22281. + suspend_state_names[arm_state->vc_suspend_state +
  22282. + VC_SUSPEND_NUM_OFFSET]);
  22283. + /* Reset the state only if it's still in an error state.
  22284. + * Something could have already initiated another suspend. */
  22285. + if (arm_state->vc_suspend_state < VC_SUSPEND_IDLE)
  22286. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  22287. +
  22288. + goto unblock_resume;
  22289. + }
  22290. +
  22291. + /* successfully suspended - unlock and exit */
  22292. + goto unlock;
  22293. +
  22294. +unblock_resume:
  22295. + /* all error states need to unblock resume before exit */
  22296. + unblock_resume(arm_state);
  22297. +
  22298. +unlock:
  22299. + write_unlock_bh(&arm_state->susp_res_lock);
  22300. +
  22301. +out:
  22302. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  22303. + return status;
  22304. +}
  22305. +
  22306. +void
  22307. +vchiq_check_suspend(VCHIQ_STATE_T *state)
  22308. +{
  22309. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22310. +
  22311. + if (!arm_state)
  22312. + goto out;
  22313. +
  22314. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22315. +
  22316. + write_lock_bh(&arm_state->susp_res_lock);
  22317. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED &&
  22318. + arm_state->first_connect &&
  22319. + !vchiq_videocore_wanted(state)) {
  22320. + vchiq_arm_vcsuspend(state);
  22321. + }
  22322. + write_unlock_bh(&arm_state->susp_res_lock);
  22323. +
  22324. +out:
  22325. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  22326. + return;
  22327. +}
  22328. +
  22329. +
  22330. +int
  22331. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state)
  22332. +{
  22333. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22334. + int resume = 0;
  22335. + int ret = -1;
  22336. +
  22337. + if (!arm_state)
  22338. + goto out;
  22339. +
  22340. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22341. +
  22342. + write_lock_bh(&arm_state->susp_res_lock);
  22343. + unblock_resume(arm_state);
  22344. + resume = vchiq_check_resume(state);
  22345. + write_unlock_bh(&arm_state->susp_res_lock);
  22346. +
  22347. + if (resume) {
  22348. + if (wait_for_completion_interruptible(
  22349. + &arm_state->vc_resume_complete) < 0) {
  22350. + vchiq_log_error(vchiq_susp_log_level,
  22351. + "%s interrupted", __func__);
  22352. + /* failed, cannot accurately derive suspend
  22353. + * state, so exit early. */
  22354. + goto out;
  22355. + }
  22356. + }
  22357. +
  22358. + read_lock_bh(&arm_state->susp_res_lock);
  22359. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  22360. + vchiq_log_info(vchiq_susp_log_level,
  22361. + "%s: Videocore remains suspended", __func__);
  22362. + } else {
  22363. + vchiq_log_info(vchiq_susp_log_level,
  22364. + "%s: Videocore resumed", __func__);
  22365. + ret = 0;
  22366. + }
  22367. + read_unlock_bh(&arm_state->susp_res_lock);
  22368. +out:
  22369. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  22370. + return ret;
  22371. +}
  22372. +
  22373. +/* This function should be called with the write lock held */
  22374. +int
  22375. +vchiq_check_resume(VCHIQ_STATE_T *state)
  22376. +{
  22377. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22378. + int resume = 0;
  22379. +
  22380. + if (!arm_state)
  22381. + goto out;
  22382. +
  22383. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22384. +
  22385. + if (need_resume(state)) {
  22386. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  22387. + request_poll(state, NULL, 0);
  22388. + resume = 1;
  22389. + }
  22390. +
  22391. +out:
  22392. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  22393. + return resume;
  22394. +}
  22395. +
  22396. +void
  22397. +vchiq_platform_check_resume(VCHIQ_STATE_T *state)
  22398. +{
  22399. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22400. + int res = 0;
  22401. +
  22402. + if (!arm_state)
  22403. + goto out;
  22404. +
  22405. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22406. +
  22407. + write_lock_bh(&arm_state->susp_res_lock);
  22408. + if (arm_state->wake_address == 0) {
  22409. + vchiq_log_info(vchiq_susp_log_level,
  22410. + "%s: already awake", __func__);
  22411. + goto unlock;
  22412. + }
  22413. + if (arm_state->vc_resume_state == VC_RESUME_IN_PROGRESS) {
  22414. + vchiq_log_info(vchiq_susp_log_level,
  22415. + "%s: already resuming", __func__);
  22416. + goto unlock;
  22417. + }
  22418. +
  22419. + if (arm_state->vc_resume_state == VC_RESUME_REQUESTED) {
  22420. + set_resume_state(arm_state, VC_RESUME_IN_PROGRESS);
  22421. + res = 1;
  22422. + } else
  22423. + vchiq_log_trace(vchiq_susp_log_level,
  22424. + "%s: not resuming (resume state %s)", __func__,
  22425. + resume_state_names[arm_state->vc_resume_state +
  22426. + VC_RESUME_NUM_OFFSET]);
  22427. +
  22428. +unlock:
  22429. + write_unlock_bh(&arm_state->susp_res_lock);
  22430. +
  22431. + if (res)
  22432. + vchiq_platform_resume(state);
  22433. +
  22434. +out:
  22435. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  22436. + return;
  22437. +
  22438. +}
  22439. +
  22440. +
  22441. +
  22442. +VCHIQ_STATUS_T
  22443. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  22444. + enum USE_TYPE_E use_type)
  22445. +{
  22446. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22447. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  22448. + char entity[16];
  22449. + int *entity_uc;
  22450. + int local_uc, local_entity_uc;
  22451. +
  22452. + if (!arm_state)
  22453. + goto out;
  22454. +
  22455. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22456. +
  22457. + if (use_type == USE_TYPE_VCHIQ) {
  22458. + sprintf(entity, "VCHIQ: ");
  22459. + entity_uc = &arm_state->peer_use_count;
  22460. + } else if (service) {
  22461. + sprintf(entity, "%c%c%c%c:%03d",
  22462. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  22463. + service->client_id);
  22464. + entity_uc = &service->service_use_count;
  22465. + } else {
  22466. + vchiq_log_error(vchiq_susp_log_level, "%s null service "
  22467. + "ptr", __func__);
  22468. + ret = VCHIQ_ERROR;
  22469. + goto out;
  22470. + }
  22471. +
  22472. + write_lock_bh(&arm_state->susp_res_lock);
  22473. + while (arm_state->resume_blocked) {
  22474. + /* If we call 'use' while force suspend is waiting for suspend,
  22475. + * then we're about to block the thread which the force is
  22476. + * waiting to complete, so we're bound to just time out. In this
  22477. + * case, set the suspend state such that the wait will be
  22478. + * canceled, so we can complete as quickly as possible. */
  22479. + if (arm_state->resume_blocked && arm_state->vc_suspend_state ==
  22480. + VC_SUSPEND_IDLE) {
  22481. + set_suspend_state(arm_state, VC_SUSPEND_FORCE_CANCELED);
  22482. + break;
  22483. + }
  22484. + /* If suspend is already in progress then we need to block */
  22485. + if (!try_wait_for_completion(&arm_state->resume_blocker)) {
  22486. + /* Indicate that there are threads waiting on the resume
  22487. + * blocker. These need to be allowed to complete before
  22488. + * a _second_ call to force suspend can complete,
  22489. + * otherwise low priority threads might never actually
  22490. + * continue */
  22491. + arm_state->blocked_count++;
  22492. + write_unlock_bh(&arm_state->susp_res_lock);
  22493. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  22494. + "blocked - waiting...", __func__, entity);
  22495. + if (wait_for_completion_killable(
  22496. + &arm_state->resume_blocker) != 0) {
  22497. + vchiq_log_error(vchiq_susp_log_level, "%s %s "
  22498. + "wait for resume blocker interrupted",
  22499. + __func__, entity);
  22500. + ret = VCHIQ_ERROR;
  22501. + write_lock_bh(&arm_state->susp_res_lock);
  22502. + arm_state->blocked_count--;
  22503. + write_unlock_bh(&arm_state->susp_res_lock);
  22504. + goto out;
  22505. + }
  22506. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  22507. + "unblocked", __func__, entity);
  22508. + write_lock_bh(&arm_state->susp_res_lock);
  22509. + if (--arm_state->blocked_count == 0)
  22510. + complete_all(&arm_state->blocked_blocker);
  22511. + }
  22512. + }
  22513. +
  22514. + stop_suspend_timer(arm_state);
  22515. +
  22516. + local_uc = ++arm_state->videocore_use_count;
  22517. + local_entity_uc = ++(*entity_uc);
  22518. +
  22519. + /* If there's a pending request which hasn't yet been serviced then
  22520. + * just clear it. If we're past VC_SUSPEND_REQUESTED state then
  22521. + * vc_resume_complete will block until we either resume or fail to
  22522. + * suspend */
  22523. + if (arm_state->vc_suspend_state <= VC_SUSPEND_REQUESTED)
  22524. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  22525. +
  22526. + if ((use_type != USE_TYPE_SERVICE_NO_RESUME) && need_resume(state)) {
  22527. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  22528. + vchiq_log_info(vchiq_susp_log_level,
  22529. + "%s %s count %d, state count %d",
  22530. + __func__, entity, local_entity_uc, local_uc);
  22531. + request_poll(state, NULL, 0);
  22532. + } else
  22533. + vchiq_log_trace(vchiq_susp_log_level,
  22534. + "%s %s count %d, state count %d",
  22535. + __func__, entity, *entity_uc, local_uc);
  22536. +
  22537. +
  22538. + write_unlock_bh(&arm_state->susp_res_lock);
  22539. +
  22540. + /* Completion is in a done state when we're not suspended, so this won't
  22541. + * block for the non-suspended case. */
  22542. + if (!try_wait_for_completion(&arm_state->vc_resume_complete)) {
  22543. + vchiq_log_info(vchiq_susp_log_level, "%s %s wait for resume",
  22544. + __func__, entity);
  22545. + if (wait_for_completion_killable(
  22546. + &arm_state->vc_resume_complete) != 0) {
  22547. + vchiq_log_error(vchiq_susp_log_level, "%s %s wait for "
  22548. + "resume interrupted", __func__, entity);
  22549. + ret = VCHIQ_ERROR;
  22550. + goto out;
  22551. + }
  22552. + vchiq_log_info(vchiq_susp_log_level, "%s %s resumed", __func__,
  22553. + entity);
  22554. + }
  22555. +
  22556. + if (ret == VCHIQ_SUCCESS) {
  22557. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  22558. + long ack_cnt = atomic_xchg(&arm_state->ka_use_ack_count, 0);
  22559. + while (ack_cnt && (status == VCHIQ_SUCCESS)) {
  22560. + /* Send the use notify to videocore */
  22561. + status = vchiq_send_remote_use_active(state);
  22562. + if (status == VCHIQ_SUCCESS)
  22563. + ack_cnt--;
  22564. + else
  22565. + atomic_add(ack_cnt,
  22566. + &arm_state->ka_use_ack_count);
  22567. + }
  22568. + }
  22569. +
  22570. +out:
  22571. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  22572. + return ret;
  22573. +}
  22574. +
  22575. +VCHIQ_STATUS_T
  22576. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service)
  22577. +{
  22578. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22579. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  22580. + char entity[16];
  22581. + int *entity_uc;
  22582. + int local_uc, local_entity_uc;
  22583. +
  22584. + if (!arm_state)
  22585. + goto out;
  22586. +
  22587. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22588. +
  22589. + if (service) {
  22590. + sprintf(entity, "%c%c%c%c:%03d",
  22591. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  22592. + service->client_id);
  22593. + entity_uc = &service->service_use_count;
  22594. + } else {
  22595. + sprintf(entity, "PEER: ");
  22596. + entity_uc = &arm_state->peer_use_count;
  22597. + }
  22598. +
  22599. + write_lock_bh(&arm_state->susp_res_lock);
  22600. + if (!arm_state->videocore_use_count || !(*entity_uc)) {
  22601. + /* Don't use BUG_ON - don't allow user thread to crash kernel */
  22602. + WARN_ON(!arm_state->videocore_use_count);
  22603. + WARN_ON(!(*entity_uc));
  22604. + ret = VCHIQ_ERROR;
  22605. + goto unlock;
  22606. + }
  22607. + local_uc = --arm_state->videocore_use_count;
  22608. + local_entity_uc = --(*entity_uc);
  22609. +
  22610. + if (!vchiq_videocore_wanted(state)) {
  22611. + if (vchiq_platform_use_suspend_timer() &&
  22612. + !arm_state->resume_blocked) {
  22613. + /* Only use the timer if we're not trying to force
  22614. + * suspend (=> resume_blocked) */
  22615. + start_suspend_timer(arm_state);
  22616. + } else {
  22617. + vchiq_log_info(vchiq_susp_log_level,
  22618. + "%s %s count %d, state count %d - suspending",
  22619. + __func__, entity, *entity_uc,
  22620. + arm_state->videocore_use_count);
  22621. + vchiq_arm_vcsuspend(state);
  22622. + }
  22623. + } else
  22624. + vchiq_log_trace(vchiq_susp_log_level,
  22625. + "%s %s count %d, state count %d",
  22626. + __func__, entity, *entity_uc,
  22627. + arm_state->videocore_use_count);
  22628. +
  22629. +unlock:
  22630. + write_unlock_bh(&arm_state->susp_res_lock);
  22631. +
  22632. +out:
  22633. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  22634. + return ret;
  22635. +}
  22636. +
  22637. +void
  22638. +vchiq_on_remote_use(VCHIQ_STATE_T *state)
  22639. +{
  22640. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22641. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22642. + atomic_inc(&arm_state->ka_use_count);
  22643. + complete(&arm_state->ka_evt);
  22644. +}
  22645. +
  22646. +void
  22647. +vchiq_on_remote_release(VCHIQ_STATE_T *state)
  22648. +{
  22649. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22650. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22651. + atomic_inc(&arm_state->ka_release_count);
  22652. + complete(&arm_state->ka_evt);
  22653. +}
  22654. +
  22655. +VCHIQ_STATUS_T
  22656. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service)
  22657. +{
  22658. + return vchiq_use_internal(service->state, service, USE_TYPE_SERVICE);
  22659. +}
  22660. +
  22661. +VCHIQ_STATUS_T
  22662. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service)
  22663. +{
  22664. + return vchiq_release_internal(service->state, service);
  22665. +}
  22666. +
  22667. +static void suspend_timer_callback(unsigned long context)
  22668. +{
  22669. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *)context;
  22670. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22671. + if (!arm_state)
  22672. + goto out;
  22673. + vchiq_log_info(vchiq_susp_log_level,
  22674. + "%s - suspend timer expired - check suspend", __func__);
  22675. + vchiq_check_suspend(state);
  22676. +out:
  22677. + return;
  22678. +}
  22679. +
  22680. +VCHIQ_STATUS_T
  22681. +vchiq_use_service_no_resume(VCHIQ_SERVICE_HANDLE_T handle)
  22682. +{
  22683. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22684. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  22685. + if (service) {
  22686. + ret = vchiq_use_internal(service->state, service,
  22687. + USE_TYPE_SERVICE_NO_RESUME);
  22688. + unlock_service(service);
  22689. + }
  22690. + return ret;
  22691. +}
  22692. +
  22693. +VCHIQ_STATUS_T
  22694. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle)
  22695. +{
  22696. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22697. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  22698. + if (service) {
  22699. + ret = vchiq_use_internal(service->state, service,
  22700. + USE_TYPE_SERVICE);
  22701. + unlock_service(service);
  22702. + }
  22703. + return ret;
  22704. +}
  22705. +
  22706. +VCHIQ_STATUS_T
  22707. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle)
  22708. +{
  22709. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22710. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  22711. + if (service) {
  22712. + ret = vchiq_release_internal(service->state, service);
  22713. + unlock_service(service);
  22714. + }
  22715. + return ret;
  22716. +}
  22717. +
  22718. +void
  22719. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state)
  22720. +{
  22721. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22722. + int i, j = 0;
  22723. + /* Only dump 64 services */
  22724. + static const int local_max_services = 64;
  22725. + /* If there's more than 64 services, only dump ones with
  22726. + * non-zero counts */
  22727. + int only_nonzero = 0;
  22728. + static const char *nz = "<-- preventing suspend";
  22729. +
  22730. + enum vc_suspend_status vc_suspend_state;
  22731. + enum vc_resume_status vc_resume_state;
  22732. + int peer_count;
  22733. + int vc_use_count;
  22734. + int active_services;
  22735. + struct service_data_struct {
  22736. + int fourcc;
  22737. + int clientid;
  22738. + int use_count;
  22739. + } service_data[local_max_services];
  22740. +
  22741. + if (!arm_state)
  22742. + return;
  22743. +
  22744. + read_lock_bh(&arm_state->susp_res_lock);
  22745. + vc_suspend_state = arm_state->vc_suspend_state;
  22746. + vc_resume_state = arm_state->vc_resume_state;
  22747. + peer_count = arm_state->peer_use_count;
  22748. + vc_use_count = arm_state->videocore_use_count;
  22749. + active_services = state->unused_service;
  22750. + if (active_services > local_max_services)
  22751. + only_nonzero = 1;
  22752. +
  22753. + for (i = 0; (i < active_services) && (j < local_max_services); i++) {
  22754. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  22755. + if (!service_ptr)
  22756. + continue;
  22757. +
  22758. + if (only_nonzero && !service_ptr->service_use_count)
  22759. + continue;
  22760. +
  22761. + if (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE) {
  22762. + service_data[j].fourcc = service_ptr->base.fourcc;
  22763. + service_data[j].clientid = service_ptr->client_id;
  22764. + service_data[j++].use_count = service_ptr->
  22765. + service_use_count;
  22766. + }
  22767. + }
  22768. +
  22769. + read_unlock_bh(&arm_state->susp_res_lock);
  22770. +
  22771. + vchiq_log_warning(vchiq_susp_log_level,
  22772. + "-- Videcore suspend state: %s --",
  22773. + suspend_state_names[vc_suspend_state + VC_SUSPEND_NUM_OFFSET]);
  22774. + vchiq_log_warning(vchiq_susp_log_level,
  22775. + "-- Videcore resume state: %s --",
  22776. + resume_state_names[vc_resume_state + VC_RESUME_NUM_OFFSET]);
  22777. +
  22778. + if (only_nonzero)
  22779. + vchiq_log_warning(vchiq_susp_log_level, "Too many active "
  22780. + "services (%d). Only dumping up to first %d services "
  22781. + "with non-zero use-count", active_services,
  22782. + local_max_services);
  22783. +
  22784. + for (i = 0; i < j; i++) {
  22785. + vchiq_log_warning(vchiq_susp_log_level,
  22786. + "----- %c%c%c%c:%d service count %d %s",
  22787. + VCHIQ_FOURCC_AS_4CHARS(service_data[i].fourcc),
  22788. + service_data[i].clientid,
  22789. + service_data[i].use_count,
  22790. + service_data[i].use_count ? nz : "");
  22791. + }
  22792. + vchiq_log_warning(vchiq_susp_log_level,
  22793. + "----- VCHIQ use count count %d", peer_count);
  22794. + vchiq_log_warning(vchiq_susp_log_level,
  22795. + "--- Overall vchiq instance use count %d", vc_use_count);
  22796. +
  22797. + vchiq_dump_platform_use_state(state);
  22798. +}
  22799. +
  22800. +VCHIQ_STATUS_T
  22801. +vchiq_check_service(VCHIQ_SERVICE_T *service)
  22802. +{
  22803. + VCHIQ_ARM_STATE_T *arm_state;
  22804. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22805. +
  22806. + if (!service || !service->state)
  22807. + goto out;
  22808. +
  22809. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22810. +
  22811. + arm_state = vchiq_platform_get_arm_state(service->state);
  22812. +
  22813. + read_lock_bh(&arm_state->susp_res_lock);
  22814. + if (service->service_use_count)
  22815. + ret = VCHIQ_SUCCESS;
  22816. + read_unlock_bh(&arm_state->susp_res_lock);
  22817. +
  22818. + if (ret == VCHIQ_ERROR) {
  22819. + vchiq_log_error(vchiq_susp_log_level,
  22820. + "%s ERROR - %c%c%c%c:%d service count %d, "
  22821. + "state count %d, videocore suspend state %s", __func__,
  22822. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  22823. + service->client_id, service->service_use_count,
  22824. + arm_state->videocore_use_count,
  22825. + suspend_state_names[arm_state->vc_suspend_state +
  22826. + VC_SUSPEND_NUM_OFFSET]);
  22827. + vchiq_dump_service_use_state(service->state);
  22828. + }
  22829. +out:
  22830. + return ret;
  22831. +}
  22832. +
  22833. +/* stub functions */
  22834. +void vchiq_on_remote_use_active(VCHIQ_STATE_T *state)
  22835. +{
  22836. + (void)state;
  22837. +}
  22838. +
  22839. +void vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  22840. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate)
  22841. +{
  22842. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22843. + vchiq_log_info(vchiq_susp_log_level, "%d: %s->%s", state->id,
  22844. + get_conn_state_name(oldstate), get_conn_state_name(newstate));
  22845. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTED) {
  22846. + write_lock_bh(&arm_state->susp_res_lock);
  22847. + if (!arm_state->first_connect) {
  22848. + char threadname[10];
  22849. + arm_state->first_connect = 1;
  22850. + write_unlock_bh(&arm_state->susp_res_lock);
  22851. + snprintf(threadname, sizeof(threadname), "VCHIQka-%d",
  22852. + state->id);
  22853. + arm_state->ka_thread = kthread_create(
  22854. + &vchiq_keepalive_thread_func,
  22855. + (void *)state,
  22856. + threadname);
  22857. + if (arm_state->ka_thread == NULL) {
  22858. + vchiq_log_error(vchiq_susp_log_level,
  22859. + "vchiq: FATAL: couldn't create thread %s",
  22860. + threadname);
  22861. + } else {
  22862. + wake_up_process(arm_state->ka_thread);
  22863. + }
  22864. + } else
  22865. + write_unlock_bh(&arm_state->susp_res_lock);
  22866. + }
  22867. +}
  22868. +
  22869. +
  22870. +/****************************************************************************
  22871. +*
  22872. +* vchiq_init - called when the module is loaded.
  22873. +*
  22874. +***************************************************************************/
  22875. +
  22876. +static int __init
  22877. +vchiq_init(void)
  22878. +{
  22879. + int err;
  22880. + void *ptr_err;
  22881. +
  22882. + /* create proc entries */
  22883. + err = vchiq_proc_init();
  22884. + if (err != 0)
  22885. + goto failed_proc_init;
  22886. +
  22887. + err = alloc_chrdev_region(&vchiq_devid, VCHIQ_MINOR, 1, DEVICE_NAME);
  22888. + if (err != 0) {
  22889. + vchiq_log_error(vchiq_arm_log_level,
  22890. + "Unable to allocate device number");
  22891. + goto failed_alloc_chrdev;
  22892. + }
  22893. + cdev_init(&vchiq_cdev, &vchiq_fops);
  22894. + vchiq_cdev.owner = THIS_MODULE;
  22895. + err = cdev_add(&vchiq_cdev, vchiq_devid, 1);
  22896. + if (err != 0) {
  22897. + vchiq_log_error(vchiq_arm_log_level,
  22898. + "Unable to register device");
  22899. + goto failed_cdev_add;
  22900. + }
  22901. +
  22902. + /* create sysfs entries */
  22903. + vchiq_class = class_create(THIS_MODULE, DEVICE_NAME);
  22904. + ptr_err = vchiq_class;
  22905. + if (IS_ERR(ptr_err))
  22906. + goto failed_class_create;
  22907. +
  22908. + vchiq_dev = device_create(vchiq_class, NULL,
  22909. + vchiq_devid, NULL, "vchiq");
  22910. + ptr_err = vchiq_dev;
  22911. + if (IS_ERR(ptr_err))
  22912. + goto failed_device_create;
  22913. +
  22914. + err = vchiq_platform_init(&g_state);
  22915. + if (err != 0)
  22916. + goto failed_platform_init;
  22917. +
  22918. + vchiq_log_info(vchiq_arm_log_level,
  22919. + "vchiq: initialised - version %d (min %d), device %d.%d",
  22920. + VCHIQ_VERSION, VCHIQ_VERSION_MIN,
  22921. + MAJOR(vchiq_devid), MINOR(vchiq_devid));
  22922. +
  22923. + return 0;
  22924. +
  22925. +failed_platform_init:
  22926. + device_destroy(vchiq_class, vchiq_devid);
  22927. +failed_device_create:
  22928. + class_destroy(vchiq_class);
  22929. +failed_class_create:
  22930. + cdev_del(&vchiq_cdev);
  22931. + err = PTR_ERR(ptr_err);
  22932. +failed_cdev_add:
  22933. + unregister_chrdev_region(vchiq_devid, 1);
  22934. +failed_alloc_chrdev:
  22935. + vchiq_proc_deinit();
  22936. +failed_proc_init:
  22937. + vchiq_log_warning(vchiq_arm_log_level, "could not load vchiq");
  22938. + return err;
  22939. +}
  22940. +
  22941. +static int vchiq_instance_get_use_count(VCHIQ_INSTANCE_T instance)
  22942. +{
  22943. + VCHIQ_SERVICE_T *service;
  22944. + int use_count = 0, i;
  22945. + i = 0;
  22946. + while ((service = next_service_by_instance(instance->state,
  22947. + instance, &i)) != NULL) {
  22948. + use_count += service->service_use_count;
  22949. + unlock_service(service);
  22950. + }
  22951. + return use_count;
  22952. +}
  22953. +
  22954. +/* read the per-process use-count */
  22955. +static int proc_read_use_count(char *page, char **start,
  22956. + off_t off, int count,
  22957. + int *eof, void *data)
  22958. +{
  22959. + VCHIQ_INSTANCE_T instance = data;
  22960. + int len, use_count;
  22961. +
  22962. + use_count = vchiq_instance_get_use_count(instance);
  22963. + len = snprintf(page+off, count, "%d\n", use_count);
  22964. +
  22965. + return len;
  22966. +}
  22967. +
  22968. +/* add an instance (process) to the proc entries */
  22969. +static int vchiq_proc_add_instance(VCHIQ_INSTANCE_T instance)
  22970. +{
  22971. +#if 1
  22972. + return 0;
  22973. +#else
  22974. + char pidstr[32];
  22975. + struct proc_dir_entry *top, *use_count;
  22976. + struct proc_dir_entry *clients = vchiq_clients_top();
  22977. + int pid = instance->pid;
  22978. +
  22979. + snprintf(pidstr, sizeof(pidstr), "%d", pid);
  22980. + top = proc_mkdir(pidstr, clients);
  22981. + if (!top)
  22982. + goto fail_top;
  22983. +
  22984. + use_count = create_proc_read_entry("use_count",
  22985. + 0444, top,
  22986. + proc_read_use_count,
  22987. + instance);
  22988. + if (!use_count)
  22989. + goto fail_use_count;
  22990. +
  22991. + instance->proc_entry = top;
  22992. +
  22993. + return 0;
  22994. +
  22995. +fail_use_count:
  22996. + remove_proc_entry(top->name, clients);
  22997. +fail_top:
  22998. + return -ENOMEM;
  22999. +#endif
  23000. +}
  23001. +
  23002. +static void vchiq_proc_remove_instance(VCHIQ_INSTANCE_T instance)
  23003. +{
  23004. +#if 0
  23005. + struct proc_dir_entry *clients = vchiq_clients_top();
  23006. + remove_proc_entry("use_count", instance->proc_entry);
  23007. + remove_proc_entry(instance->proc_entry->name, clients);
  23008. +#endif
  23009. +}
  23010. +
  23011. +/****************************************************************************
  23012. +*
  23013. +* vchiq_exit - called when the module is unloaded.
  23014. +*
  23015. +***************************************************************************/
  23016. +
  23017. +static void __exit
  23018. +vchiq_exit(void)
  23019. +{
  23020. + vchiq_platform_exit(&g_state);
  23021. + device_destroy(vchiq_class, vchiq_devid);
  23022. + class_destroy(vchiq_class);
  23023. + cdev_del(&vchiq_cdev);
  23024. + unregister_chrdev_region(vchiq_devid, 1);
  23025. +}
  23026. +
  23027. +module_init(vchiq_init);
  23028. +module_exit(vchiq_exit);
  23029. +MODULE_LICENSE("GPL");
  23030. +MODULE_AUTHOR("Broadcom Corporation");
  23031. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h
  23032. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 1970-01-01 01:00:00.000000000 +0100
  23033. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 2014-02-18 11:52:14.000000000 +0100
  23034. @@ -0,0 +1,212 @@
  23035. +/**
  23036. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23037. + *
  23038. + * Redistribution and use in source and binary forms, with or without
  23039. + * modification, are permitted provided that the following conditions
  23040. + * are met:
  23041. + * 1. Redistributions of source code must retain the above copyright
  23042. + * notice, this list of conditions, and the following disclaimer,
  23043. + * without modification.
  23044. + * 2. Redistributions in binary form must reproduce the above copyright
  23045. + * notice, this list of conditions and the following disclaimer in the
  23046. + * documentation and/or other materials provided with the distribution.
  23047. + * 3. The names of the above-listed copyright holders may not be used
  23048. + * to endorse or promote products derived from this software without
  23049. + * specific prior written permission.
  23050. + *
  23051. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23052. + * GNU General Public License ("GPL") version 2, as published by the Free
  23053. + * Software Foundation.
  23054. + *
  23055. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23056. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23057. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23058. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23059. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23060. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23061. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23062. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23063. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23064. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23065. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23066. + */
  23067. +
  23068. +#ifndef VCHIQ_ARM_H
  23069. +#define VCHIQ_ARM_H
  23070. +
  23071. +#include <linux/mutex.h>
  23072. +#include <linux/semaphore.h>
  23073. +#include <linux/atomic.h>
  23074. +#include "vchiq_core.h"
  23075. +
  23076. +
  23077. +enum vc_suspend_status {
  23078. + VC_SUSPEND_FORCE_CANCELED = -3, /* Force suspend canceled, too busy */
  23079. + VC_SUSPEND_REJECTED = -2, /* Videocore rejected suspend request */
  23080. + VC_SUSPEND_FAILED = -1, /* Videocore suspend failed */
  23081. + VC_SUSPEND_IDLE = 0, /* VC active, no suspend actions */
  23082. + VC_SUSPEND_REQUESTED, /* User has requested suspend */
  23083. + VC_SUSPEND_IN_PROGRESS, /* Slot handler has recvd suspend request */
  23084. + VC_SUSPEND_SUSPENDED /* Videocore suspend succeeded */
  23085. +};
  23086. +
  23087. +enum vc_resume_status {
  23088. + VC_RESUME_FAILED = -1, /* Videocore resume failed */
  23089. + VC_RESUME_IDLE = 0, /* VC suspended, no resume actions */
  23090. + VC_RESUME_REQUESTED, /* User has requested resume */
  23091. + VC_RESUME_IN_PROGRESS, /* Slot handler has received resume request */
  23092. + VC_RESUME_RESUMED /* Videocore resumed successfully (active) */
  23093. +};
  23094. +
  23095. +
  23096. +enum USE_TYPE_E {
  23097. + USE_TYPE_SERVICE,
  23098. + USE_TYPE_SERVICE_NO_RESUME,
  23099. + USE_TYPE_VCHIQ
  23100. +};
  23101. +
  23102. +
  23103. +
  23104. +typedef struct vchiq_arm_state_struct {
  23105. + /* Keepalive-related data */
  23106. + struct task_struct *ka_thread;
  23107. + struct completion ka_evt;
  23108. + atomic_t ka_use_count;
  23109. + atomic_t ka_use_ack_count;
  23110. + atomic_t ka_release_count;
  23111. +
  23112. + struct completion vc_suspend_complete;
  23113. + struct completion vc_resume_complete;
  23114. +
  23115. + rwlock_t susp_res_lock;
  23116. + enum vc_suspend_status vc_suspend_state;
  23117. + enum vc_resume_status vc_resume_state;
  23118. +
  23119. + unsigned int wake_address;
  23120. +
  23121. + struct timer_list suspend_timer;
  23122. + int suspend_timer_timeout;
  23123. + int suspend_timer_running;
  23124. +
  23125. + /* Global use count for videocore.
  23126. + ** This is equal to the sum of the use counts for all services. When
  23127. + ** this hits zero the videocore suspend procedure will be initiated.
  23128. + */
  23129. + int videocore_use_count;
  23130. +
  23131. + /* Use count to track requests from videocore peer.
  23132. + ** This use count is not associated with a service, so needs to be
  23133. + ** tracked separately with the state.
  23134. + */
  23135. + int peer_use_count;
  23136. +
  23137. + /* Flag to indicate whether resume is blocked. This happens when the
  23138. + ** ARM is suspending
  23139. + */
  23140. + struct completion resume_blocker;
  23141. + int resume_blocked;
  23142. + struct completion blocked_blocker;
  23143. + int blocked_count;
  23144. +
  23145. + int autosuspend_override;
  23146. +
  23147. + /* Flag to indicate that the first vchiq connect has made it through.
  23148. + ** This means that both sides should be fully ready, and we should
  23149. + ** be able to suspend after this point.
  23150. + */
  23151. + int first_connect;
  23152. +
  23153. + unsigned long long suspend_start_time;
  23154. + unsigned long long sleep_start_time;
  23155. + unsigned long long resume_start_time;
  23156. + unsigned long long last_wake_time;
  23157. +
  23158. +} VCHIQ_ARM_STATE_T;
  23159. +
  23160. +extern int vchiq_arm_log_level;
  23161. +extern int vchiq_susp_log_level;
  23162. +
  23163. +extern int __init
  23164. +vchiq_platform_init(VCHIQ_STATE_T *state);
  23165. +
  23166. +extern void __exit
  23167. +vchiq_platform_exit(VCHIQ_STATE_T *state);
  23168. +
  23169. +extern VCHIQ_STATE_T *
  23170. +vchiq_get_state(void);
  23171. +
  23172. +extern VCHIQ_STATUS_T
  23173. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state);
  23174. +
  23175. +extern VCHIQ_STATUS_T
  23176. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state);
  23177. +
  23178. +extern int
  23179. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state);
  23180. +
  23181. +extern VCHIQ_STATUS_T
  23182. +vchiq_arm_vcresume(VCHIQ_STATE_T *state);
  23183. +
  23184. +extern VCHIQ_STATUS_T
  23185. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state);
  23186. +
  23187. +extern int
  23188. +vchiq_check_resume(VCHIQ_STATE_T *state);
  23189. +
  23190. +extern void
  23191. +vchiq_check_suspend(VCHIQ_STATE_T *state);
  23192. +
  23193. +extern VCHIQ_STATUS_T
  23194. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle);
  23195. +
  23196. +extern VCHIQ_STATUS_T
  23197. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle);
  23198. +
  23199. +extern VCHIQ_STATUS_T
  23200. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  23201. +
  23202. +extern VCHIQ_STATUS_T
  23203. +vchiq_platform_suspend(VCHIQ_STATE_T *state);
  23204. +
  23205. +extern int
  23206. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T *state);
  23207. +
  23208. +extern int
  23209. +vchiq_platform_use_suspend_timer(void);
  23210. +
  23211. +extern void
  23212. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state);
  23213. +
  23214. +extern void
  23215. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state);
  23216. +
  23217. +extern VCHIQ_ARM_STATE_T*
  23218. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state);
  23219. +
  23220. +extern int
  23221. +vchiq_videocore_wanted(VCHIQ_STATE_T *state);
  23222. +
  23223. +extern VCHIQ_STATUS_T
  23224. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  23225. + enum USE_TYPE_E use_type);
  23226. +extern VCHIQ_STATUS_T
  23227. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service);
  23228. +
  23229. +void
  23230. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  23231. + enum vc_suspend_status new_state);
  23232. +
  23233. +void
  23234. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  23235. + enum vc_resume_status new_state);
  23236. +
  23237. +void
  23238. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state);
  23239. +
  23240. +extern int vchiq_proc_init(void);
  23241. +extern void vchiq_proc_deinit(void);
  23242. +extern struct proc_dir_entry *vchiq_proc_top(void);
  23243. +extern struct proc_dir_entry *vchiq_clients_top(void);
  23244. +
  23245. +
  23246. +#endif /* VCHIQ_ARM_H */
  23247. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h
  23248. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 1970-01-01 01:00:00.000000000 +0100
  23249. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 2014-02-18 11:52:14.000000000 +0100
  23250. @@ -0,0 +1,37 @@
  23251. +/**
  23252. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23253. + *
  23254. + * Redistribution and use in source and binary forms, with or without
  23255. + * modification, are permitted provided that the following conditions
  23256. + * are met:
  23257. + * 1. Redistributions of source code must retain the above copyright
  23258. + * notice, this list of conditions, and the following disclaimer,
  23259. + * without modification.
  23260. + * 2. Redistributions in binary form must reproduce the above copyright
  23261. + * notice, this list of conditions and the following disclaimer in the
  23262. + * documentation and/or other materials provided with the distribution.
  23263. + * 3. The names of the above-listed copyright holders may not be used
  23264. + * to endorse or promote products derived from this software without
  23265. + * specific prior written permission.
  23266. + *
  23267. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23268. + * GNU General Public License ("GPL") version 2, as published by the Free
  23269. + * Software Foundation.
  23270. + *
  23271. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23272. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23273. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23274. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23275. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23276. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23277. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23278. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23279. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23280. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23281. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23282. + */
  23283. +
  23284. +const char *vchiq_get_build_hostname(void);
  23285. +const char *vchiq_get_build_version(void);
  23286. +const char *vchiq_get_build_time(void);
  23287. +const char *vchiq_get_build_date(void);
  23288. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h
  23289. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 1970-01-01 01:00:00.000000000 +0100
  23290. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 2014-02-18 11:52:14.000000000 +0100
  23291. @@ -0,0 +1,60 @@
  23292. +/**
  23293. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23294. + *
  23295. + * Redistribution and use in source and binary forms, with or without
  23296. + * modification, are permitted provided that the following conditions
  23297. + * are met:
  23298. + * 1. Redistributions of source code must retain the above copyright
  23299. + * notice, this list of conditions, and the following disclaimer,
  23300. + * without modification.
  23301. + * 2. Redistributions in binary form must reproduce the above copyright
  23302. + * notice, this list of conditions and the following disclaimer in the
  23303. + * documentation and/or other materials provided with the distribution.
  23304. + * 3. The names of the above-listed copyright holders may not be used
  23305. + * to endorse or promote products derived from this software without
  23306. + * specific prior written permission.
  23307. + *
  23308. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23309. + * GNU General Public License ("GPL") version 2, as published by the Free
  23310. + * Software Foundation.
  23311. + *
  23312. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23313. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23314. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23315. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23316. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23317. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23318. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23319. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23320. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23321. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23322. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23323. + */
  23324. +
  23325. +#ifndef VCHIQ_CFG_H
  23326. +#define VCHIQ_CFG_H
  23327. +
  23328. +#define VCHIQ_MAGIC VCHIQ_MAKE_FOURCC('V', 'C', 'H', 'I')
  23329. +/* The version of VCHIQ - change with any non-trivial change */
  23330. +#define VCHIQ_VERSION 6
  23331. +/* The minimum compatible version - update to match VCHIQ_VERSION with any
  23332. +** incompatible change */
  23333. +#define VCHIQ_VERSION_MIN 3
  23334. +
  23335. +#define VCHIQ_MAX_STATES 1
  23336. +#define VCHIQ_MAX_SERVICES 4096
  23337. +#define VCHIQ_MAX_SLOTS 128
  23338. +#define VCHIQ_MAX_SLOTS_PER_SIDE 64
  23339. +
  23340. +#define VCHIQ_NUM_CURRENT_BULKS 32
  23341. +#define VCHIQ_NUM_SERVICE_BULKS 4
  23342. +
  23343. +#ifndef VCHIQ_ENABLE_DEBUG
  23344. +#define VCHIQ_ENABLE_DEBUG 1
  23345. +#endif
  23346. +
  23347. +#ifndef VCHIQ_ENABLE_STATS
  23348. +#define VCHIQ_ENABLE_STATS 1
  23349. +#endif
  23350. +
  23351. +#endif /* VCHIQ_CFG_H */
  23352. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
  23353. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 1970-01-01 01:00:00.000000000 +0100
  23354. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 2014-02-18 11:52:14.000000000 +0100
  23355. @@ -0,0 +1,119 @@
  23356. +/**
  23357. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23358. + *
  23359. + * Redistribution and use in source and binary forms, with or without
  23360. + * modification, are permitted provided that the following conditions
  23361. + * are met:
  23362. + * 1. Redistributions of source code must retain the above copyright
  23363. + * notice, this list of conditions, and the following disclaimer,
  23364. + * without modification.
  23365. + * 2. Redistributions in binary form must reproduce the above copyright
  23366. + * notice, this list of conditions and the following disclaimer in the
  23367. + * documentation and/or other materials provided with the distribution.
  23368. + * 3. The names of the above-listed copyright holders may not be used
  23369. + * to endorse or promote products derived from this software without
  23370. + * specific prior written permission.
  23371. + *
  23372. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23373. + * GNU General Public License ("GPL") version 2, as published by the Free
  23374. + * Software Foundation.
  23375. + *
  23376. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23377. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23378. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23379. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23380. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23381. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23382. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23383. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23384. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23385. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23386. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23387. + */
  23388. +
  23389. +#include "vchiq_connected.h"
  23390. +#include "vchiq_core.h"
  23391. +#include <linux/module.h>
  23392. +#include <linux/mutex.h>
  23393. +
  23394. +#define MAX_CALLBACKS 10
  23395. +
  23396. +static int g_connected;
  23397. +static int g_num_deferred_callbacks;
  23398. +static VCHIQ_CONNECTED_CALLBACK_T g_deferred_callback[MAX_CALLBACKS];
  23399. +static int g_once_init;
  23400. +static struct mutex g_connected_mutex;
  23401. +
  23402. +/****************************************************************************
  23403. +*
  23404. +* Function to initialize our lock.
  23405. +*
  23406. +***************************************************************************/
  23407. +
  23408. +static void connected_init(void)
  23409. +{
  23410. + if (!g_once_init) {
  23411. + mutex_init(&g_connected_mutex);
  23412. + g_once_init = 1;
  23413. + }
  23414. +}
  23415. +
  23416. +/****************************************************************************
  23417. +*
  23418. +* This function is used to defer initialization until the vchiq stack is
  23419. +* initialized. If the stack is already initialized, then the callback will
  23420. +* be made immediately, otherwise it will be deferred until
  23421. +* vchiq_call_connected_callbacks is called.
  23422. +*
  23423. +***************************************************************************/
  23424. +
  23425. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback)
  23426. +{
  23427. + connected_init();
  23428. +
  23429. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  23430. + return;
  23431. +
  23432. + if (g_connected)
  23433. + /* We're already connected. Call the callback immediately. */
  23434. +
  23435. + callback();
  23436. + else {
  23437. + if (g_num_deferred_callbacks >= MAX_CALLBACKS)
  23438. + vchiq_log_error(vchiq_core_log_level,
  23439. + "There already %d callback registered - "
  23440. + "please increase MAX_CALLBACKS",
  23441. + g_num_deferred_callbacks);
  23442. + else {
  23443. + g_deferred_callback[g_num_deferred_callbacks] =
  23444. + callback;
  23445. + g_num_deferred_callbacks++;
  23446. + }
  23447. + }
  23448. + mutex_unlock(&g_connected_mutex);
  23449. +}
  23450. +
  23451. +/****************************************************************************
  23452. +*
  23453. +* This function is called by the vchiq stack once it has been connected to
  23454. +* the videocore and clients can start to use the stack.
  23455. +*
  23456. +***************************************************************************/
  23457. +
  23458. +void vchiq_call_connected_callbacks(void)
  23459. +{
  23460. + int i;
  23461. +
  23462. + connected_init();
  23463. +
  23464. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  23465. + return;
  23466. +
  23467. + for (i = 0; i < g_num_deferred_callbacks; i++)
  23468. + g_deferred_callback[i]();
  23469. +
  23470. + g_num_deferred_callbacks = 0;
  23471. + g_connected = 1;
  23472. + mutex_unlock(&g_connected_mutex);
  23473. +}
  23474. +EXPORT_SYMBOL(vchiq_add_connected_callback);
  23475. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h
  23476. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 1970-01-01 01:00:00.000000000 +0100
  23477. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 2014-02-18 11:52:14.000000000 +0100
  23478. @@ -0,0 +1,50 @@
  23479. +/**
  23480. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23481. + *
  23482. + * Redistribution and use in source and binary forms, with or without
  23483. + * modification, are permitted provided that the following conditions
  23484. + * are met:
  23485. + * 1. Redistributions of source code must retain the above copyright
  23486. + * notice, this list of conditions, and the following disclaimer,
  23487. + * without modification.
  23488. + * 2. Redistributions in binary form must reproduce the above copyright
  23489. + * notice, this list of conditions and the following disclaimer in the
  23490. + * documentation and/or other materials provided with the distribution.
  23491. + * 3. The names of the above-listed copyright holders may not be used
  23492. + * to endorse or promote products derived from this software without
  23493. + * specific prior written permission.
  23494. + *
  23495. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23496. + * GNU General Public License ("GPL") version 2, as published by the Free
  23497. + * Software Foundation.
  23498. + *
  23499. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23500. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23501. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23502. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23503. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23504. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23505. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23506. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23507. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23508. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23509. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23510. + */
  23511. +
  23512. +#ifndef VCHIQ_CONNECTED_H
  23513. +#define VCHIQ_CONNECTED_H
  23514. +
  23515. +/* ---- Include Files ----------------------------------------------------- */
  23516. +
  23517. +/* ---- Constants and Types ---------------------------------------------- */
  23518. +
  23519. +typedef void (*VCHIQ_CONNECTED_CALLBACK_T)(void);
  23520. +
  23521. +/* ---- Variable Externs ------------------------------------------------- */
  23522. +
  23523. +/* ---- Function Prototypes ---------------------------------------------- */
  23524. +
  23525. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback);
  23526. +void vchiq_call_connected_callbacks(void);
  23527. +
  23528. +#endif /* VCHIQ_CONNECTED_H */
  23529. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
  23530. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 1970-01-01 01:00:00.000000000 +0100
  23531. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 2014-02-18 11:52:14.000000000 +0100
  23532. @@ -0,0 +1,3824 @@
  23533. +/**
  23534. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23535. + *
  23536. + * Redistribution and use in source and binary forms, with or without
  23537. + * modification, are permitted provided that the following conditions
  23538. + * are met:
  23539. + * 1. Redistributions of source code must retain the above copyright
  23540. + * notice, this list of conditions, and the following disclaimer,
  23541. + * without modification.
  23542. + * 2. Redistributions in binary form must reproduce the above copyright
  23543. + * notice, this list of conditions and the following disclaimer in the
  23544. + * documentation and/or other materials provided with the distribution.
  23545. + * 3. The names of the above-listed copyright holders may not be used
  23546. + * to endorse or promote products derived from this software without
  23547. + * specific prior written permission.
  23548. + *
  23549. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23550. + * GNU General Public License ("GPL") version 2, as published by the Free
  23551. + * Software Foundation.
  23552. + *
  23553. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23554. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23555. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23556. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23557. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23558. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23559. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23560. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23561. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23562. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23563. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23564. + */
  23565. +
  23566. +#include "vchiq_core.h"
  23567. +
  23568. +#define VCHIQ_SLOT_HANDLER_STACK 8192
  23569. +
  23570. +#define HANDLE_STATE_SHIFT 12
  23571. +
  23572. +#define SLOT_INFO_FROM_INDEX(state, index) (state->slot_info + (index))
  23573. +#define SLOT_DATA_FROM_INDEX(state, index) (state->slot_data + (index))
  23574. +#define SLOT_INDEX_FROM_DATA(state, data) \
  23575. + (((unsigned int)((char *)data - (char *)state->slot_data)) / \
  23576. + VCHIQ_SLOT_SIZE)
  23577. +#define SLOT_INDEX_FROM_INFO(state, info) \
  23578. + ((unsigned int)(info - state->slot_info))
  23579. +#define SLOT_QUEUE_INDEX_FROM_POS(pos) \
  23580. + ((int)((unsigned int)(pos) / VCHIQ_SLOT_SIZE))
  23581. +
  23582. +
  23583. +#define BULK_INDEX(x) (x & (VCHIQ_NUM_SERVICE_BULKS - 1))
  23584. +
  23585. +
  23586. +struct vchiq_open_payload {
  23587. + int fourcc;
  23588. + int client_id;
  23589. + short version;
  23590. + short version_min;
  23591. +};
  23592. +
  23593. +struct vchiq_openack_payload {
  23594. + short version;
  23595. +};
  23596. +
  23597. +/* we require this for consistency between endpoints */
  23598. +vchiq_static_assert(sizeof(VCHIQ_HEADER_T) == 8);
  23599. +vchiq_static_assert(IS_POW2(sizeof(VCHIQ_HEADER_T)));
  23600. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_CURRENT_BULKS));
  23601. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_SERVICE_BULKS));
  23602. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SERVICES));
  23603. +vchiq_static_assert(VCHIQ_VERSION >= VCHIQ_VERSION_MIN);
  23604. +
  23605. +/* Run time control of log level, based on KERN_XXX level. */
  23606. +int vchiq_core_log_level = VCHIQ_LOG_DEFAULT;
  23607. +int vchiq_core_msg_log_level = VCHIQ_LOG_DEFAULT;
  23608. +int vchiq_sync_log_level = VCHIQ_LOG_DEFAULT;
  23609. +
  23610. +static atomic_t pause_bulks_count = ATOMIC_INIT(0);
  23611. +
  23612. +static DEFINE_SPINLOCK(service_spinlock);
  23613. +DEFINE_SPINLOCK(bulk_waiter_spinlock);
  23614. +DEFINE_SPINLOCK(quota_spinlock);
  23615. +
  23616. +VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  23617. +static unsigned int handle_seq;
  23618. +
  23619. +static const char *const srvstate_names[] = {
  23620. + "FREE",
  23621. + "HIDDEN",
  23622. + "LISTENING",
  23623. + "OPENING",
  23624. + "OPEN",
  23625. + "OPENSYNC",
  23626. + "CLOSESENT",
  23627. + "CLOSERECVD",
  23628. + "CLOSEWAIT",
  23629. + "CLOSED"
  23630. +};
  23631. +
  23632. +static const char *const reason_names[] = {
  23633. + "SERVICE_OPENED",
  23634. + "SERVICE_CLOSED",
  23635. + "MESSAGE_AVAILABLE",
  23636. + "BULK_TRANSMIT_DONE",
  23637. + "BULK_RECEIVE_DONE",
  23638. + "BULK_TRANSMIT_ABORTED",
  23639. + "BULK_RECEIVE_ABORTED"
  23640. +};
  23641. +
  23642. +static const char *const conn_state_names[] = {
  23643. + "DISCONNECTED",
  23644. + "CONNECTING",
  23645. + "CONNECTED",
  23646. + "PAUSING",
  23647. + "PAUSE_SENT",
  23648. + "PAUSED",
  23649. + "RESUMING",
  23650. + "PAUSE_TIMEOUT",
  23651. + "RESUME_TIMEOUT"
  23652. +};
  23653. +
  23654. +
  23655. +static void
  23656. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header);
  23657. +
  23658. +static const char *msg_type_str(unsigned int msg_type)
  23659. +{
  23660. + switch (msg_type) {
  23661. + case VCHIQ_MSG_PADDING: return "PADDING";
  23662. + case VCHIQ_MSG_CONNECT: return "CONNECT";
  23663. + case VCHIQ_MSG_OPEN: return "OPEN";
  23664. + case VCHIQ_MSG_OPENACK: return "OPENACK";
  23665. + case VCHIQ_MSG_CLOSE: return "CLOSE";
  23666. + case VCHIQ_MSG_DATA: return "DATA";
  23667. + case VCHIQ_MSG_BULK_RX: return "BULK_RX";
  23668. + case VCHIQ_MSG_BULK_TX: return "BULK_TX";
  23669. + case VCHIQ_MSG_BULK_RX_DONE: return "BULK_RX_DONE";
  23670. + case VCHIQ_MSG_BULK_TX_DONE: return "BULK_TX_DONE";
  23671. + case VCHIQ_MSG_PAUSE: return "PAUSE";
  23672. + case VCHIQ_MSG_RESUME: return "RESUME";
  23673. + case VCHIQ_MSG_REMOTE_USE: return "REMOTE_USE";
  23674. + case VCHIQ_MSG_REMOTE_RELEASE: return "REMOTE_RELEASE";
  23675. + case VCHIQ_MSG_REMOTE_USE_ACTIVE: return "REMOTE_USE_ACTIVE";
  23676. + }
  23677. + return "???";
  23678. +}
  23679. +
  23680. +static inline void
  23681. +vchiq_set_service_state(VCHIQ_SERVICE_T *service, int newstate)
  23682. +{
  23683. + vchiq_log_info(vchiq_core_log_level, "%d: srv:%d %s->%s",
  23684. + service->state->id, service->localport,
  23685. + srvstate_names[service->srvstate],
  23686. + srvstate_names[newstate]);
  23687. + service->srvstate = newstate;
  23688. +}
  23689. +
  23690. +VCHIQ_SERVICE_T *
  23691. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle)
  23692. +{
  23693. + VCHIQ_SERVICE_T *service;
  23694. +
  23695. + spin_lock(&service_spinlock);
  23696. + service = handle_to_service(handle);
  23697. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  23698. + (service->handle == handle)) {
  23699. + BUG_ON(service->ref_count == 0);
  23700. + service->ref_count++;
  23701. + } else
  23702. + service = NULL;
  23703. + spin_unlock(&service_spinlock);
  23704. +
  23705. + if (!service)
  23706. + vchiq_log_info(vchiq_core_log_level,
  23707. + "Invalid service handle 0x%x", handle);
  23708. +
  23709. + return service;
  23710. +}
  23711. +
  23712. +VCHIQ_SERVICE_T *
  23713. +find_service_by_port(VCHIQ_STATE_T *state, int localport)
  23714. +{
  23715. + VCHIQ_SERVICE_T *service = NULL;
  23716. + if ((unsigned int)localport <= VCHIQ_PORT_MAX) {
  23717. + spin_lock(&service_spinlock);
  23718. + service = state->services[localport];
  23719. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE)) {
  23720. + BUG_ON(service->ref_count == 0);
  23721. + service->ref_count++;
  23722. + } else
  23723. + service = NULL;
  23724. + spin_unlock(&service_spinlock);
  23725. + }
  23726. +
  23727. + if (!service)
  23728. + vchiq_log_info(vchiq_core_log_level,
  23729. + "Invalid port %d", localport);
  23730. +
  23731. + return service;
  23732. +}
  23733. +
  23734. +VCHIQ_SERVICE_T *
  23735. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  23736. + VCHIQ_SERVICE_HANDLE_T handle) {
  23737. + VCHIQ_SERVICE_T *service;
  23738. +
  23739. + spin_lock(&service_spinlock);
  23740. + service = handle_to_service(handle);
  23741. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  23742. + (service->handle == handle) &&
  23743. + (service->instance == instance)) {
  23744. + BUG_ON(service->ref_count == 0);
  23745. + service->ref_count++;
  23746. + } else
  23747. + service = NULL;
  23748. + spin_unlock(&service_spinlock);
  23749. +
  23750. + if (!service)
  23751. + vchiq_log_info(vchiq_core_log_level,
  23752. + "Invalid service handle 0x%x", handle);
  23753. +
  23754. + return service;
  23755. +}
  23756. +
  23757. +VCHIQ_SERVICE_T *
  23758. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  23759. + int *pidx)
  23760. +{
  23761. + VCHIQ_SERVICE_T *service = NULL;
  23762. + int idx = *pidx;
  23763. +
  23764. + spin_lock(&service_spinlock);
  23765. + while (idx < state->unused_service) {
  23766. + VCHIQ_SERVICE_T *srv = state->services[idx++];
  23767. + if (srv && (srv->srvstate != VCHIQ_SRVSTATE_FREE) &&
  23768. + (srv->instance == instance)) {
  23769. + service = srv;
  23770. + BUG_ON(service->ref_count == 0);
  23771. + service->ref_count++;
  23772. + break;
  23773. + }
  23774. + }
  23775. + spin_unlock(&service_spinlock);
  23776. +
  23777. + *pidx = idx;
  23778. +
  23779. + return service;
  23780. +}
  23781. +
  23782. +void
  23783. +lock_service(VCHIQ_SERVICE_T *service)
  23784. +{
  23785. + spin_lock(&service_spinlock);
  23786. + BUG_ON(!service || (service->ref_count == 0));
  23787. + if (service)
  23788. + service->ref_count++;
  23789. + spin_unlock(&service_spinlock);
  23790. +}
  23791. +
  23792. +void
  23793. +unlock_service(VCHIQ_SERVICE_T *service)
  23794. +{
  23795. + VCHIQ_STATE_T *state = service->state;
  23796. + spin_lock(&service_spinlock);
  23797. + BUG_ON(!service || (service->ref_count == 0));
  23798. + if (service && service->ref_count) {
  23799. + service->ref_count--;
  23800. + if (!service->ref_count) {
  23801. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  23802. + state->services[service->localport] = NULL;
  23803. + } else
  23804. + service = NULL;
  23805. + }
  23806. + spin_unlock(&service_spinlock);
  23807. +
  23808. + if (service && service->userdata_term)
  23809. + service->userdata_term(service->base.userdata);
  23810. +
  23811. + kfree(service);
  23812. +}
  23813. +
  23814. +int
  23815. +vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T handle)
  23816. +{
  23817. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  23818. + int id;
  23819. +
  23820. + id = service ? service->client_id : 0;
  23821. + if (service)
  23822. + unlock_service(service);
  23823. +
  23824. + return id;
  23825. +}
  23826. +
  23827. +void *
  23828. +vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T handle)
  23829. +{
  23830. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  23831. +
  23832. + return service ? service->base.userdata : NULL;
  23833. +}
  23834. +
  23835. +int
  23836. +vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T handle)
  23837. +{
  23838. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  23839. +
  23840. + return service ? service->base.fourcc : 0;
  23841. +}
  23842. +
  23843. +static void
  23844. +mark_service_closing_internal(VCHIQ_SERVICE_T *service, int sh_thread)
  23845. +{
  23846. + VCHIQ_STATE_T *state = service->state;
  23847. + VCHIQ_SERVICE_QUOTA_T *service_quota;
  23848. +
  23849. + service->closing = 1;
  23850. +
  23851. + /* Synchronise with other threads. */
  23852. + mutex_lock(&state->recycle_mutex);
  23853. + mutex_unlock(&state->recycle_mutex);
  23854. + if (!sh_thread || (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT)) {
  23855. + /* If we're pausing then the slot_mutex is held until resume
  23856. + * by the slot handler. Therefore don't try to acquire this
  23857. + * mutex if we're the slot handler and in the pause sent state.
  23858. + * We don't need to in this case anyway. */
  23859. + mutex_lock(&state->slot_mutex);
  23860. + mutex_unlock(&state->slot_mutex);
  23861. + }
  23862. +
  23863. + /* Unblock any sending thread. */
  23864. + service_quota = &state->service_quotas[service->localport];
  23865. + up(&service_quota->quota_event);
  23866. +}
  23867. +
  23868. +static void
  23869. +mark_service_closing(VCHIQ_SERVICE_T *service)
  23870. +{
  23871. + mark_service_closing_internal(service, 0);
  23872. +}
  23873. +
  23874. +static inline VCHIQ_STATUS_T
  23875. +make_service_callback(VCHIQ_SERVICE_T *service, VCHIQ_REASON_T reason,
  23876. + VCHIQ_HEADER_T *header, void *bulk_userdata)
  23877. +{
  23878. + VCHIQ_STATUS_T status;
  23879. + vchiq_log_trace(vchiq_core_log_level, "%d: callback:%d (%s, %x, %x)",
  23880. + service->state->id, service->localport, reason_names[reason],
  23881. + (unsigned int)header, (unsigned int)bulk_userdata);
  23882. + status = service->base.callback(reason, header, service->handle,
  23883. + bulk_userdata);
  23884. + if (status == VCHIQ_ERROR) {
  23885. + vchiq_log_warning(vchiq_core_log_level,
  23886. + "%d: ignoring ERROR from callback to service %x",
  23887. + service->state->id, service->handle);
  23888. + status = VCHIQ_SUCCESS;
  23889. + }
  23890. + return status;
  23891. +}
  23892. +
  23893. +inline void
  23894. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate)
  23895. +{
  23896. + VCHIQ_CONNSTATE_T oldstate = state->conn_state;
  23897. + vchiq_log_info(vchiq_core_log_level, "%d: %s->%s", state->id,
  23898. + conn_state_names[oldstate],
  23899. + conn_state_names[newstate]);
  23900. + state->conn_state = newstate;
  23901. + vchiq_platform_conn_state_changed(state, oldstate, newstate);
  23902. +}
  23903. +
  23904. +static inline void
  23905. +remote_event_create(REMOTE_EVENT_T *event)
  23906. +{
  23907. + event->armed = 0;
  23908. + /* Don't clear the 'fired' flag because it may already have been set
  23909. + ** by the other side. */
  23910. + sema_init(event->event, 0);
  23911. +}
  23912. +
  23913. +static inline void
  23914. +remote_event_destroy(REMOTE_EVENT_T *event)
  23915. +{
  23916. + (void)event;
  23917. +}
  23918. +
  23919. +static inline int
  23920. +remote_event_wait(REMOTE_EVENT_T *event)
  23921. +{
  23922. + if (!event->fired) {
  23923. + event->armed = 1;
  23924. + dsb();
  23925. + if (!event->fired) {
  23926. + if (down_interruptible(event->event) != 0) {
  23927. + event->armed = 0;
  23928. + return 0;
  23929. + }
  23930. + }
  23931. + event->armed = 0;
  23932. + wmb();
  23933. + }
  23934. +
  23935. + event->fired = 0;
  23936. + return 1;
  23937. +}
  23938. +
  23939. +static inline void
  23940. +remote_event_signal_local(REMOTE_EVENT_T *event)
  23941. +{
  23942. + event->armed = 0;
  23943. + up(event->event);
  23944. +}
  23945. +
  23946. +static inline void
  23947. +remote_event_poll(REMOTE_EVENT_T *event)
  23948. +{
  23949. + if (event->fired && event->armed)
  23950. + remote_event_signal_local(event);
  23951. +}
  23952. +
  23953. +void
  23954. +remote_event_pollall(VCHIQ_STATE_T *state)
  23955. +{
  23956. + remote_event_poll(&state->local->sync_trigger);
  23957. + remote_event_poll(&state->local->sync_release);
  23958. + remote_event_poll(&state->local->trigger);
  23959. + remote_event_poll(&state->local->recycle);
  23960. +}
  23961. +
  23962. +/* Round up message sizes so that any space at the end of a slot is always big
  23963. +** enough for a header. This relies on header size being a power of two, which
  23964. +** has been verified earlier by a static assertion. */
  23965. +
  23966. +static inline unsigned int
  23967. +calc_stride(unsigned int size)
  23968. +{
  23969. + /* Allow room for the header */
  23970. + size += sizeof(VCHIQ_HEADER_T);
  23971. +
  23972. + /* Round up */
  23973. + return (size + sizeof(VCHIQ_HEADER_T) - 1) & ~(sizeof(VCHIQ_HEADER_T)
  23974. + - 1);
  23975. +}
  23976. +
  23977. +/* Called by the slot handler thread */
  23978. +static VCHIQ_SERVICE_T *
  23979. +get_listening_service(VCHIQ_STATE_T *state, int fourcc)
  23980. +{
  23981. + int i;
  23982. +
  23983. + WARN_ON(fourcc == VCHIQ_FOURCC_INVALID);
  23984. +
  23985. + for (i = 0; i < state->unused_service; i++) {
  23986. + VCHIQ_SERVICE_T *service = state->services[i];
  23987. + if (service &&
  23988. + (service->public_fourcc == fourcc) &&
  23989. + ((service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  23990. + ((service->srvstate == VCHIQ_SRVSTATE_OPEN) &&
  23991. + (service->remoteport == VCHIQ_PORT_FREE)))) {
  23992. + lock_service(service);
  23993. + return service;
  23994. + }
  23995. + }
  23996. +
  23997. + return NULL;
  23998. +}
  23999. +
  24000. +/* Called by the slot handler thread */
  24001. +static VCHIQ_SERVICE_T *
  24002. +get_connected_service(VCHIQ_STATE_T *state, unsigned int port)
  24003. +{
  24004. + int i;
  24005. + for (i = 0; i < state->unused_service; i++) {
  24006. + VCHIQ_SERVICE_T *service = state->services[i];
  24007. + if (service && (service->srvstate == VCHIQ_SRVSTATE_OPEN)
  24008. + && (service->remoteport == port)) {
  24009. + lock_service(service);
  24010. + return service;
  24011. + }
  24012. + }
  24013. + return NULL;
  24014. +}
  24015. +
  24016. +inline void
  24017. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type)
  24018. +{
  24019. + uint32_t value;
  24020. +
  24021. + if (service) {
  24022. + do {
  24023. + value = atomic_read(&service->poll_flags);
  24024. + } while (atomic_cmpxchg(&service->poll_flags, value,
  24025. + value | (1 << poll_type)) != value);
  24026. +
  24027. + do {
  24028. + value = atomic_read(&state->poll_services[
  24029. + service->localport>>5]);
  24030. + } while (atomic_cmpxchg(
  24031. + &state->poll_services[service->localport>>5],
  24032. + value, value | (1 << (service->localport & 0x1f)))
  24033. + != value);
  24034. + }
  24035. +
  24036. + state->poll_needed = 1;
  24037. + wmb();
  24038. +
  24039. + /* ... and ensure the slot handler runs. */
  24040. + remote_event_signal_local(&state->local->trigger);
  24041. +}
  24042. +
  24043. +/* Called from queue_message, by the slot handler and application threads,
  24044. +** with slot_mutex held */
  24045. +static VCHIQ_HEADER_T *
  24046. +reserve_space(VCHIQ_STATE_T *state, int space, int is_blocking)
  24047. +{
  24048. + VCHIQ_SHARED_STATE_T *local = state->local;
  24049. + int tx_pos = state->local_tx_pos;
  24050. + int slot_space = VCHIQ_SLOT_SIZE - (tx_pos & VCHIQ_SLOT_MASK);
  24051. +
  24052. + if (space > slot_space) {
  24053. + VCHIQ_HEADER_T *header;
  24054. + /* Fill the remaining space with padding */
  24055. + WARN_ON(state->tx_data == NULL);
  24056. + header = (VCHIQ_HEADER_T *)
  24057. + (state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  24058. + header->msgid = VCHIQ_MSGID_PADDING;
  24059. + header->size = slot_space - sizeof(VCHIQ_HEADER_T);
  24060. +
  24061. + tx_pos += slot_space;
  24062. + }
  24063. +
  24064. + /* If necessary, get the next slot. */
  24065. + if ((tx_pos & VCHIQ_SLOT_MASK) == 0) {
  24066. + int slot_index;
  24067. +
  24068. + /* If there is no free slot... */
  24069. +
  24070. + if (down_trylock(&state->slot_available_event) != 0) {
  24071. + /* ...wait for one. */
  24072. +
  24073. + VCHIQ_STATS_INC(state, slot_stalls);
  24074. +
  24075. + /* But first, flush through the last slot. */
  24076. + state->local_tx_pos = tx_pos;
  24077. + local->tx_pos = tx_pos;
  24078. + remote_event_signal(&state->remote->trigger);
  24079. +
  24080. + if (!is_blocking ||
  24081. + (down_interruptible(
  24082. + &state->slot_available_event) != 0))
  24083. + return NULL; /* No space available */
  24084. + }
  24085. +
  24086. + BUG_ON(tx_pos ==
  24087. + (state->slot_queue_available * VCHIQ_SLOT_SIZE));
  24088. +
  24089. + slot_index = local->slot_queue[
  24090. + SLOT_QUEUE_INDEX_FROM_POS(tx_pos) &
  24091. + VCHIQ_SLOT_QUEUE_MASK];
  24092. + state->tx_data =
  24093. + (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  24094. + }
  24095. +
  24096. + state->local_tx_pos = tx_pos + space;
  24097. +
  24098. + return (VCHIQ_HEADER_T *)(state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  24099. +}
  24100. +
  24101. +/* Called by the recycle thread. */
  24102. +static void
  24103. +process_free_queue(VCHIQ_STATE_T *state)
  24104. +{
  24105. + VCHIQ_SHARED_STATE_T *local = state->local;
  24106. + BITSET_T service_found[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  24107. + int slot_queue_available;
  24108. +
  24109. + /* Use a read memory barrier to ensure that any state that may have
  24110. + ** been modified by another thread is not masked by stale prefetched
  24111. + ** values. */
  24112. + rmb();
  24113. +
  24114. + /* Find slots which have been freed by the other side, and return them
  24115. + ** to the available queue. */
  24116. + slot_queue_available = state->slot_queue_available;
  24117. +
  24118. + while (slot_queue_available != local->slot_queue_recycle) {
  24119. + unsigned int pos;
  24120. + int slot_index = local->slot_queue[slot_queue_available++ &
  24121. + VCHIQ_SLOT_QUEUE_MASK];
  24122. + char *data = (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  24123. + int data_found = 0;
  24124. +
  24125. + vchiq_log_trace(vchiq_core_log_level, "%d: pfq %d=%x %x %x",
  24126. + state->id, slot_index, (unsigned int)data,
  24127. + local->slot_queue_recycle, slot_queue_available);
  24128. +
  24129. + /* Initialise the bitmask for services which have used this
  24130. + ** slot */
  24131. + BITSET_ZERO(service_found);
  24132. +
  24133. + pos = 0;
  24134. +
  24135. + while (pos < VCHIQ_SLOT_SIZE) {
  24136. + VCHIQ_HEADER_T *header =
  24137. + (VCHIQ_HEADER_T *)(data + pos);
  24138. + int msgid = header->msgid;
  24139. + if (VCHIQ_MSG_TYPE(msgid) == VCHIQ_MSG_DATA) {
  24140. + int port = VCHIQ_MSG_SRCPORT(msgid);
  24141. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  24142. + &state->service_quotas[port];
  24143. + int count;
  24144. + spin_lock(&quota_spinlock);
  24145. + count = service_quota->message_use_count;
  24146. + if (count > 0)
  24147. + service_quota->message_use_count =
  24148. + count - 1;
  24149. + spin_unlock(&quota_spinlock);
  24150. +
  24151. + if (count == service_quota->message_quota)
  24152. + /* Signal the service that it
  24153. + ** has dropped below its quota
  24154. + */
  24155. + up(&service_quota->quota_event);
  24156. + else if (count == 0) {
  24157. + vchiq_log_error(vchiq_core_log_level,
  24158. + "service %d "
  24159. + "message_use_count=%d "
  24160. + "(header %x, msgid %x, "
  24161. + "header->msgid %x, "
  24162. + "header->size %x)",
  24163. + port,
  24164. + service_quota->
  24165. + message_use_count,
  24166. + (unsigned int)header, msgid,
  24167. + header->msgid,
  24168. + header->size);
  24169. + WARN(1, "invalid message use count\n");
  24170. + }
  24171. + if (!BITSET_IS_SET(service_found, port)) {
  24172. + /* Set the found bit for this service */
  24173. + BITSET_SET(service_found, port);
  24174. +
  24175. + spin_lock(&quota_spinlock);
  24176. + count = service_quota->slot_use_count;
  24177. + if (count > 0)
  24178. + service_quota->slot_use_count =
  24179. + count - 1;
  24180. + spin_unlock(&quota_spinlock);
  24181. +
  24182. + if (count > 0) {
  24183. + /* Signal the service in case
  24184. + ** it has dropped below its
  24185. + ** quota */
  24186. + up(&service_quota->quota_event);
  24187. + vchiq_log_trace(
  24188. + vchiq_core_log_level,
  24189. + "%d: pfq:%d %x@%x - "
  24190. + "slot_use->%d",
  24191. + state->id, port,
  24192. + header->size,
  24193. + (unsigned int)header,
  24194. + count - 1);
  24195. + } else {
  24196. + vchiq_log_error(
  24197. + vchiq_core_log_level,
  24198. + "service %d "
  24199. + "slot_use_count"
  24200. + "=%d (header %x"
  24201. + ", msgid %x, "
  24202. + "header->msgid"
  24203. + " %x, header->"
  24204. + "size %x)",
  24205. + port, count,
  24206. + (unsigned int)header,
  24207. + msgid,
  24208. + header->msgid,
  24209. + header->size);
  24210. + WARN(1, "bad slot use count\n");
  24211. + }
  24212. + }
  24213. +
  24214. + data_found = 1;
  24215. + }
  24216. +
  24217. + pos += calc_stride(header->size);
  24218. + if (pos > VCHIQ_SLOT_SIZE) {
  24219. + vchiq_log_error(vchiq_core_log_level,
  24220. + "pfq - pos %x: header %x, msgid %x, "
  24221. + "header->msgid %x, header->size %x",
  24222. + pos, (unsigned int)header, msgid,
  24223. + header->msgid, header->size);
  24224. + WARN(1, "invalid slot position\n");
  24225. + }
  24226. + }
  24227. +
  24228. + if (data_found) {
  24229. + int count;
  24230. + spin_lock(&quota_spinlock);
  24231. + count = state->data_use_count;
  24232. + if (count > 0)
  24233. + state->data_use_count =
  24234. + count - 1;
  24235. + spin_unlock(&quota_spinlock);
  24236. + if (count == state->data_quota)
  24237. + up(&state->data_quota_event);
  24238. + }
  24239. +
  24240. + state->slot_queue_available = slot_queue_available;
  24241. + up(&state->slot_available_event);
  24242. + }
  24243. +}
  24244. +
  24245. +/* Called by the slot handler and application threads */
  24246. +static VCHIQ_STATUS_T
  24247. +queue_message(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  24248. + int msgid, const VCHIQ_ELEMENT_T *elements,
  24249. + int count, int size, int is_blocking)
  24250. +{
  24251. + VCHIQ_SHARED_STATE_T *local;
  24252. + VCHIQ_SERVICE_QUOTA_T *service_quota = NULL;
  24253. + VCHIQ_HEADER_T *header;
  24254. + int type = VCHIQ_MSG_TYPE(msgid);
  24255. +
  24256. + unsigned int stride;
  24257. +
  24258. + local = state->local;
  24259. +
  24260. + stride = calc_stride(size);
  24261. +
  24262. + WARN_ON(!(stride <= VCHIQ_SLOT_SIZE));
  24263. +
  24264. + if ((type != VCHIQ_MSG_RESUME) &&
  24265. + (mutex_lock_interruptible(&state->slot_mutex) != 0))
  24266. + return VCHIQ_RETRY;
  24267. +
  24268. + if (type == VCHIQ_MSG_DATA) {
  24269. + int tx_end_index;
  24270. +
  24271. + BUG_ON(!service);
  24272. +
  24273. + if (service->closing) {
  24274. + /* The service has been closed */
  24275. + mutex_unlock(&state->slot_mutex);
  24276. + return VCHIQ_ERROR;
  24277. + }
  24278. +
  24279. + service_quota = &state->service_quotas[service->localport];
  24280. +
  24281. + spin_lock(&quota_spinlock);
  24282. +
  24283. + /* Ensure this service doesn't use more than its quota of
  24284. + ** messages or slots */
  24285. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  24286. + state->local_tx_pos + stride - 1);
  24287. +
  24288. + /* Ensure data messages don't use more than their quota of
  24289. + ** slots */
  24290. + while ((tx_end_index != state->previous_data_index) &&
  24291. + (state->data_use_count == state->data_quota)) {
  24292. + VCHIQ_STATS_INC(state, data_stalls);
  24293. + spin_unlock(&quota_spinlock);
  24294. + mutex_unlock(&state->slot_mutex);
  24295. +
  24296. + if (down_interruptible(&state->data_quota_event)
  24297. + != 0)
  24298. + return VCHIQ_RETRY;
  24299. +
  24300. + mutex_lock(&state->slot_mutex);
  24301. + spin_lock(&quota_spinlock);
  24302. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  24303. + state->local_tx_pos + stride - 1);
  24304. + if ((tx_end_index == state->previous_data_index) ||
  24305. + (state->data_use_count < state->data_quota)) {
  24306. + /* Pass the signal on to other waiters */
  24307. + up(&state->data_quota_event);
  24308. + break;
  24309. + }
  24310. + }
  24311. +
  24312. + while ((service_quota->message_use_count ==
  24313. + service_quota->message_quota) ||
  24314. + ((tx_end_index != service_quota->previous_tx_index) &&
  24315. + (service_quota->slot_use_count ==
  24316. + service_quota->slot_quota))) {
  24317. + spin_unlock(&quota_spinlock);
  24318. + vchiq_log_trace(vchiq_core_log_level,
  24319. + "%d: qm:%d %s,%x - quota stall "
  24320. + "(msg %d, slot %d)",
  24321. + state->id, service->localport,
  24322. + msg_type_str(type), size,
  24323. + service_quota->message_use_count,
  24324. + service_quota->slot_use_count);
  24325. + VCHIQ_SERVICE_STATS_INC(service, quota_stalls);
  24326. + mutex_unlock(&state->slot_mutex);
  24327. + if (down_interruptible(&service_quota->quota_event)
  24328. + != 0)
  24329. + return VCHIQ_RETRY;
  24330. + if (service->closing)
  24331. + return VCHIQ_ERROR;
  24332. + if (mutex_lock_interruptible(&state->slot_mutex) != 0)
  24333. + return VCHIQ_RETRY;
  24334. + if (service->srvstate != VCHIQ_SRVSTATE_OPEN) {
  24335. + /* The service has been closed */
  24336. + mutex_unlock(&state->slot_mutex);
  24337. + return VCHIQ_ERROR;
  24338. + }
  24339. + spin_lock(&quota_spinlock);
  24340. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  24341. + state->local_tx_pos + stride - 1);
  24342. + }
  24343. +
  24344. + spin_unlock(&quota_spinlock);
  24345. + }
  24346. +
  24347. + header = reserve_space(state, stride, is_blocking);
  24348. +
  24349. + if (!header) {
  24350. + if (service)
  24351. + VCHIQ_SERVICE_STATS_INC(service, slot_stalls);
  24352. + mutex_unlock(&state->slot_mutex);
  24353. + return VCHIQ_RETRY;
  24354. + }
  24355. +
  24356. + if (type == VCHIQ_MSG_DATA) {
  24357. + int i, pos;
  24358. + int tx_end_index;
  24359. + int slot_use_count;
  24360. +
  24361. + vchiq_log_info(vchiq_core_log_level,
  24362. + "%d: qm %s@%x,%x (%d->%d)",
  24363. + state->id,
  24364. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24365. + (unsigned int)header, size,
  24366. + VCHIQ_MSG_SRCPORT(msgid),
  24367. + VCHIQ_MSG_DSTPORT(msgid));
  24368. +
  24369. + BUG_ON(!service);
  24370. +
  24371. + for (i = 0, pos = 0; i < (unsigned int)count;
  24372. + pos += elements[i++].size)
  24373. + if (elements[i].size) {
  24374. + if (vchiq_copy_from_user
  24375. + (header->data + pos, elements[i].data,
  24376. + (size_t) elements[i].size) !=
  24377. + VCHIQ_SUCCESS) {
  24378. + mutex_unlock(&state->slot_mutex);
  24379. + VCHIQ_SERVICE_STATS_INC(service,
  24380. + error_count);
  24381. + return VCHIQ_ERROR;
  24382. + }
  24383. + if (i == 0) {
  24384. + if (vchiq_core_msg_log_level >=
  24385. + VCHIQ_LOG_INFO)
  24386. + vchiq_log_dump_mem("Sent", 0,
  24387. + header->data + pos,
  24388. + min(64u,
  24389. + elements[0].size));
  24390. + }
  24391. + }
  24392. +
  24393. + spin_lock(&quota_spinlock);
  24394. + service_quota->message_use_count++;
  24395. +
  24396. + tx_end_index =
  24397. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos - 1);
  24398. +
  24399. + /* If this transmission can't fit in the last slot used by any
  24400. + ** service, the data_use_count must be increased. */
  24401. + if (tx_end_index != state->previous_data_index) {
  24402. + state->previous_data_index = tx_end_index;
  24403. + state->data_use_count++;
  24404. + }
  24405. +
  24406. + /* If this isn't the same slot last used by this service,
  24407. + ** the service's slot_use_count must be increased. */
  24408. + if (tx_end_index != service_quota->previous_tx_index) {
  24409. + service_quota->previous_tx_index = tx_end_index;
  24410. + slot_use_count = ++service_quota->slot_use_count;
  24411. + } else {
  24412. + slot_use_count = 0;
  24413. + }
  24414. +
  24415. + spin_unlock(&quota_spinlock);
  24416. +
  24417. + if (slot_use_count)
  24418. + vchiq_log_trace(vchiq_core_log_level,
  24419. + "%d: qm:%d %s,%x - slot_use->%d (hdr %p)",
  24420. + state->id, service->localport,
  24421. + msg_type_str(VCHIQ_MSG_TYPE(msgid)), size,
  24422. + slot_use_count, header);
  24423. +
  24424. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  24425. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  24426. + } else {
  24427. + vchiq_log_info(vchiq_core_log_level,
  24428. + "%d: qm %s@%x,%x (%d->%d)", state->id,
  24429. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24430. + (unsigned int)header, size,
  24431. + VCHIQ_MSG_SRCPORT(msgid),
  24432. + VCHIQ_MSG_DSTPORT(msgid));
  24433. + if (size != 0) {
  24434. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  24435. + memcpy(header->data, elements[0].data,
  24436. + elements[0].size);
  24437. + }
  24438. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  24439. + }
  24440. +
  24441. + header->msgid = msgid;
  24442. + header->size = size;
  24443. +
  24444. + {
  24445. + int svc_fourcc;
  24446. +
  24447. + svc_fourcc = service
  24448. + ? service->base.fourcc
  24449. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  24450. +
  24451. + vchiq_log_info(vchiq_core_msg_log_level,
  24452. + "Sent Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  24453. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24454. + VCHIQ_MSG_TYPE(msgid),
  24455. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  24456. + VCHIQ_MSG_SRCPORT(msgid),
  24457. + VCHIQ_MSG_DSTPORT(msgid),
  24458. + size);
  24459. + }
  24460. +
  24461. + /* Make sure the new header is visible to the peer. */
  24462. + wmb();
  24463. +
  24464. + /* Make the new tx_pos visible to the peer. */
  24465. + local->tx_pos = state->local_tx_pos;
  24466. + wmb();
  24467. +
  24468. + if (service && (type == VCHIQ_MSG_CLOSE))
  24469. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_CLOSESENT);
  24470. +
  24471. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  24472. + mutex_unlock(&state->slot_mutex);
  24473. +
  24474. + remote_event_signal(&state->remote->trigger);
  24475. +
  24476. + return VCHIQ_SUCCESS;
  24477. +}
  24478. +
  24479. +/* Called by the slot handler and application threads */
  24480. +static VCHIQ_STATUS_T
  24481. +queue_message_sync(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  24482. + int msgid, const VCHIQ_ELEMENT_T *elements,
  24483. + int count, int size, int is_blocking)
  24484. +{
  24485. + VCHIQ_SHARED_STATE_T *local;
  24486. + VCHIQ_HEADER_T *header;
  24487. +
  24488. + local = state->local;
  24489. +
  24490. + if ((VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_RESUME) &&
  24491. + (mutex_lock_interruptible(&state->sync_mutex) != 0))
  24492. + return VCHIQ_RETRY;
  24493. +
  24494. + remote_event_wait(&local->sync_release);
  24495. +
  24496. + rmb();
  24497. +
  24498. + header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  24499. + local->slot_sync);
  24500. +
  24501. + {
  24502. + int oldmsgid = header->msgid;
  24503. + if (oldmsgid != VCHIQ_MSGID_PADDING)
  24504. + vchiq_log_error(vchiq_core_log_level,
  24505. + "%d: qms - msgid %x, not PADDING",
  24506. + state->id, oldmsgid);
  24507. + }
  24508. +
  24509. + if (service) {
  24510. + int i, pos;
  24511. +
  24512. + vchiq_log_info(vchiq_sync_log_level,
  24513. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  24514. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24515. + (unsigned int)header, size,
  24516. + VCHIQ_MSG_SRCPORT(msgid),
  24517. + VCHIQ_MSG_DSTPORT(msgid));
  24518. +
  24519. + for (i = 0, pos = 0; i < (unsigned int)count;
  24520. + pos += elements[i++].size)
  24521. + if (elements[i].size) {
  24522. + if (vchiq_copy_from_user
  24523. + (header->data + pos, elements[i].data,
  24524. + (size_t) elements[i].size) !=
  24525. + VCHIQ_SUCCESS) {
  24526. + mutex_unlock(&state->sync_mutex);
  24527. + VCHIQ_SERVICE_STATS_INC(service,
  24528. + error_count);
  24529. + return VCHIQ_ERROR;
  24530. + }
  24531. + if (i == 0) {
  24532. + if (vchiq_sync_log_level >=
  24533. + VCHIQ_LOG_TRACE)
  24534. + vchiq_log_dump_mem("Sent Sync",
  24535. + 0, header->data + pos,
  24536. + min(64u,
  24537. + elements[0].size));
  24538. + }
  24539. + }
  24540. +
  24541. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  24542. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  24543. + } else {
  24544. + vchiq_log_info(vchiq_sync_log_level,
  24545. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  24546. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24547. + (unsigned int)header, size,
  24548. + VCHIQ_MSG_SRCPORT(msgid),
  24549. + VCHIQ_MSG_DSTPORT(msgid));
  24550. + if (size != 0) {
  24551. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  24552. + memcpy(header->data, elements[0].data,
  24553. + elements[0].size);
  24554. + }
  24555. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  24556. + }
  24557. +
  24558. + header->size = size;
  24559. + header->msgid = msgid;
  24560. +
  24561. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  24562. + int svc_fourcc;
  24563. +
  24564. + svc_fourcc = service
  24565. + ? service->base.fourcc
  24566. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  24567. +
  24568. + vchiq_log_trace(vchiq_sync_log_level,
  24569. + "Sent Sync Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  24570. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24571. + VCHIQ_MSG_TYPE(msgid),
  24572. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  24573. + VCHIQ_MSG_SRCPORT(msgid),
  24574. + VCHIQ_MSG_DSTPORT(msgid),
  24575. + size);
  24576. + }
  24577. +
  24578. + /* Make sure the new header is visible to the peer. */
  24579. + wmb();
  24580. +
  24581. + remote_event_signal(&state->remote->sync_trigger);
  24582. +
  24583. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  24584. + mutex_unlock(&state->sync_mutex);
  24585. +
  24586. + return VCHIQ_SUCCESS;
  24587. +}
  24588. +
  24589. +static inline void
  24590. +claim_slot(VCHIQ_SLOT_INFO_T *slot)
  24591. +{
  24592. + slot->use_count++;
  24593. +}
  24594. +
  24595. +static void
  24596. +release_slot(VCHIQ_STATE_T *state, VCHIQ_SLOT_INFO_T *slot_info,
  24597. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_T *service)
  24598. +{
  24599. + int release_count;
  24600. +
  24601. + mutex_lock(&state->recycle_mutex);
  24602. +
  24603. + if (header) {
  24604. + int msgid = header->msgid;
  24605. + if (((msgid & VCHIQ_MSGID_CLAIMED) == 0) ||
  24606. + (service && service->closing)) {
  24607. + mutex_unlock(&state->recycle_mutex);
  24608. + return;
  24609. + }
  24610. +
  24611. + /* Rewrite the message header to prevent a double
  24612. + ** release */
  24613. + header->msgid = msgid & ~VCHIQ_MSGID_CLAIMED;
  24614. + }
  24615. +
  24616. + release_count = slot_info->release_count;
  24617. + slot_info->release_count = ++release_count;
  24618. +
  24619. + if (release_count == slot_info->use_count) {
  24620. + int slot_queue_recycle;
  24621. + /* Add to the freed queue */
  24622. +
  24623. + /* A read barrier is necessary here to prevent speculative
  24624. + ** fetches of remote->slot_queue_recycle from overtaking the
  24625. + ** mutex. */
  24626. + rmb();
  24627. +
  24628. + slot_queue_recycle = state->remote->slot_queue_recycle;
  24629. + state->remote->slot_queue[slot_queue_recycle &
  24630. + VCHIQ_SLOT_QUEUE_MASK] =
  24631. + SLOT_INDEX_FROM_INFO(state, slot_info);
  24632. + state->remote->slot_queue_recycle = slot_queue_recycle + 1;
  24633. + vchiq_log_info(vchiq_core_log_level,
  24634. + "%d: release_slot %d - recycle->%x",
  24635. + state->id, SLOT_INDEX_FROM_INFO(state, slot_info),
  24636. + state->remote->slot_queue_recycle);
  24637. +
  24638. + /* A write barrier is necessary, but remote_event_signal
  24639. + ** contains one. */
  24640. + remote_event_signal(&state->remote->recycle);
  24641. + }
  24642. +
  24643. + mutex_unlock(&state->recycle_mutex);
  24644. +}
  24645. +
  24646. +/* Called by the slot handler - don't hold the bulk mutex */
  24647. +static VCHIQ_STATUS_T
  24648. +notify_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue,
  24649. + int retry_poll)
  24650. +{
  24651. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  24652. +
  24653. + vchiq_log_trace(vchiq_core_log_level,
  24654. + "%d: nb:%d %cx - p=%x rn=%x r=%x",
  24655. + service->state->id, service->localport,
  24656. + (queue == &service->bulk_tx) ? 't' : 'r',
  24657. + queue->process, queue->remote_notify, queue->remove);
  24658. +
  24659. + if (service->state->is_master) {
  24660. + while (queue->remote_notify != queue->process) {
  24661. + VCHIQ_BULK_T *bulk =
  24662. + &queue->bulks[BULK_INDEX(queue->remote_notify)];
  24663. + int msgtype = (bulk->dir == VCHIQ_BULK_TRANSMIT) ?
  24664. + VCHIQ_MSG_BULK_RX_DONE : VCHIQ_MSG_BULK_TX_DONE;
  24665. + int msgid = VCHIQ_MAKE_MSG(msgtype, service->localport,
  24666. + service->remoteport);
  24667. + VCHIQ_ELEMENT_T element = { &bulk->actual, 4 };
  24668. + /* Only reply to non-dummy bulk requests */
  24669. + if (bulk->remote_data) {
  24670. + status = queue_message(service->state, NULL,
  24671. + msgid, &element, 1, 4, 0);
  24672. + if (status != VCHIQ_SUCCESS)
  24673. + break;
  24674. + }
  24675. + queue->remote_notify++;
  24676. + }
  24677. + } else {
  24678. + queue->remote_notify = queue->process;
  24679. + }
  24680. +
  24681. + if (status == VCHIQ_SUCCESS) {
  24682. + while (queue->remove != queue->remote_notify) {
  24683. + VCHIQ_BULK_T *bulk =
  24684. + &queue->bulks[BULK_INDEX(queue->remove)];
  24685. +
  24686. + /* Only generate callbacks for non-dummy bulk
  24687. + ** requests, and non-terminated services */
  24688. + if (bulk->data && service->instance) {
  24689. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED) {
  24690. + if (bulk->dir == VCHIQ_BULK_TRANSMIT) {
  24691. + VCHIQ_SERVICE_STATS_INC(service,
  24692. + bulk_tx_count);
  24693. + VCHIQ_SERVICE_STATS_ADD(service,
  24694. + bulk_tx_bytes,
  24695. + bulk->actual);
  24696. + } else {
  24697. + VCHIQ_SERVICE_STATS_INC(service,
  24698. + bulk_rx_count);
  24699. + VCHIQ_SERVICE_STATS_ADD(service,
  24700. + bulk_rx_bytes,
  24701. + bulk->actual);
  24702. + }
  24703. + } else {
  24704. + VCHIQ_SERVICE_STATS_INC(service,
  24705. + bulk_aborted_count);
  24706. + }
  24707. + if (bulk->mode == VCHIQ_BULK_MODE_BLOCKING) {
  24708. + struct bulk_waiter *waiter;
  24709. + spin_lock(&bulk_waiter_spinlock);
  24710. + waiter = bulk->userdata;
  24711. + if (waiter) {
  24712. + waiter->actual = bulk->actual;
  24713. + up(&waiter->event);
  24714. + }
  24715. + spin_unlock(&bulk_waiter_spinlock);
  24716. + } else if (bulk->mode ==
  24717. + VCHIQ_BULK_MODE_CALLBACK) {
  24718. + VCHIQ_REASON_T reason = (bulk->dir ==
  24719. + VCHIQ_BULK_TRANSMIT) ?
  24720. + ((bulk->actual ==
  24721. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  24722. + VCHIQ_BULK_TRANSMIT_ABORTED :
  24723. + VCHIQ_BULK_TRANSMIT_DONE) :
  24724. + ((bulk->actual ==
  24725. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  24726. + VCHIQ_BULK_RECEIVE_ABORTED :
  24727. + VCHIQ_BULK_RECEIVE_DONE);
  24728. + status = make_service_callback(service,
  24729. + reason, NULL, bulk->userdata);
  24730. + if (status == VCHIQ_RETRY)
  24731. + break;
  24732. + }
  24733. + }
  24734. +
  24735. + queue->remove++;
  24736. + up(&service->bulk_remove_event);
  24737. + }
  24738. + if (!retry_poll)
  24739. + status = VCHIQ_SUCCESS;
  24740. + }
  24741. +
  24742. + if (status == VCHIQ_RETRY)
  24743. + request_poll(service->state, service,
  24744. + (queue == &service->bulk_tx) ?
  24745. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  24746. +
  24747. + return status;
  24748. +}
  24749. +
  24750. +/* Called by the slot handler thread */
  24751. +static void
  24752. +poll_services(VCHIQ_STATE_T *state)
  24753. +{
  24754. + int group, i;
  24755. +
  24756. + for (group = 0; group < BITSET_SIZE(state->unused_service); group++) {
  24757. + uint32_t flags;
  24758. + flags = atomic_xchg(&state->poll_services[group], 0);
  24759. + for (i = 0; flags; i++) {
  24760. + if (flags & (1 << i)) {
  24761. + VCHIQ_SERVICE_T *service =
  24762. + find_service_by_port(state,
  24763. + (group<<5) + i);
  24764. + uint32_t service_flags;
  24765. + flags &= ~(1 << i);
  24766. + if (!service)
  24767. + continue;
  24768. + service_flags =
  24769. + atomic_xchg(&service->poll_flags, 0);
  24770. + if (service_flags &
  24771. + (1 << VCHIQ_POLL_REMOVE)) {
  24772. + vchiq_log_info(vchiq_core_log_level,
  24773. + "%d: ps - remove %d<->%d",
  24774. + state->id, service->localport,
  24775. + service->remoteport);
  24776. +
  24777. + /* Make it look like a client, because
  24778. + it must be removed and not left in
  24779. + the LISTENING state. */
  24780. + service->public_fourcc =
  24781. + VCHIQ_FOURCC_INVALID;
  24782. +
  24783. + if (vchiq_close_service_internal(
  24784. + service, 0/*!close_recvd*/) !=
  24785. + VCHIQ_SUCCESS)
  24786. + request_poll(state, service,
  24787. + VCHIQ_POLL_REMOVE);
  24788. + } else if (service_flags &
  24789. + (1 << VCHIQ_POLL_TERMINATE)) {
  24790. + vchiq_log_info(vchiq_core_log_level,
  24791. + "%d: ps - terminate %d<->%d",
  24792. + state->id, service->localport,
  24793. + service->remoteport);
  24794. + if (vchiq_close_service_internal(
  24795. + service, 0/*!close_recvd*/) !=
  24796. + VCHIQ_SUCCESS)
  24797. + request_poll(state, service,
  24798. + VCHIQ_POLL_TERMINATE);
  24799. + }
  24800. + if (service_flags & (1 << VCHIQ_POLL_TXNOTIFY))
  24801. + notify_bulks(service,
  24802. + &service->bulk_tx,
  24803. + 1/*retry_poll*/);
  24804. + if (service_flags & (1 << VCHIQ_POLL_RXNOTIFY))
  24805. + notify_bulks(service,
  24806. + &service->bulk_rx,
  24807. + 1/*retry_poll*/);
  24808. + unlock_service(service);
  24809. + }
  24810. + }
  24811. + }
  24812. +}
  24813. +
  24814. +/* Called by the slot handler or application threads, holding the bulk mutex. */
  24815. +static int
  24816. +resolve_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  24817. +{
  24818. + VCHIQ_STATE_T *state = service->state;
  24819. + int resolved = 0;
  24820. + int rc;
  24821. +
  24822. + while ((queue->process != queue->local_insert) &&
  24823. + (queue->process != queue->remote_insert)) {
  24824. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  24825. +
  24826. + vchiq_log_trace(vchiq_core_log_level,
  24827. + "%d: rb:%d %cx - li=%x ri=%x p=%x",
  24828. + state->id, service->localport,
  24829. + (queue == &service->bulk_tx) ? 't' : 'r',
  24830. + queue->local_insert, queue->remote_insert,
  24831. + queue->process);
  24832. +
  24833. + WARN_ON(!((int)(queue->local_insert - queue->process) > 0));
  24834. + WARN_ON(!((int)(queue->remote_insert - queue->process) > 0));
  24835. +
  24836. + rc = mutex_lock_interruptible(&state->bulk_transfer_mutex);
  24837. + if (rc != 0)
  24838. + break;
  24839. +
  24840. + vchiq_transfer_bulk(bulk);
  24841. + mutex_unlock(&state->bulk_transfer_mutex);
  24842. +
  24843. + if (vchiq_core_msg_log_level >= VCHIQ_LOG_INFO) {
  24844. + const char *header = (queue == &service->bulk_tx) ?
  24845. + "Send Bulk to" : "Recv Bulk from";
  24846. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED)
  24847. + vchiq_log_info(vchiq_core_msg_log_level,
  24848. + "%s %c%c%c%c d:%d len:%d %x<->%x",
  24849. + header,
  24850. + VCHIQ_FOURCC_AS_4CHARS(
  24851. + service->base.fourcc),
  24852. + service->remoteport,
  24853. + bulk->size,
  24854. + (unsigned int)bulk->data,
  24855. + (unsigned int)bulk->remote_data);
  24856. + else
  24857. + vchiq_log_info(vchiq_core_msg_log_level,
  24858. + "%s %c%c%c%c d:%d ABORTED - tx len:%d,"
  24859. + " rx len:%d %x<->%x",
  24860. + header,
  24861. + VCHIQ_FOURCC_AS_4CHARS(
  24862. + service->base.fourcc),
  24863. + service->remoteport,
  24864. + bulk->size,
  24865. + bulk->remote_size,
  24866. + (unsigned int)bulk->data,
  24867. + (unsigned int)bulk->remote_data);
  24868. + }
  24869. +
  24870. + vchiq_complete_bulk(bulk);
  24871. + queue->process++;
  24872. + resolved++;
  24873. + }
  24874. + return resolved;
  24875. +}
  24876. +
  24877. +/* Called with the bulk_mutex held */
  24878. +static void
  24879. +abort_outstanding_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  24880. +{
  24881. + int is_tx = (queue == &service->bulk_tx);
  24882. + vchiq_log_trace(vchiq_core_log_level,
  24883. + "%d: aob:%d %cx - li=%x ri=%x p=%x",
  24884. + service->state->id, service->localport, is_tx ? 't' : 'r',
  24885. + queue->local_insert, queue->remote_insert, queue->process);
  24886. +
  24887. + WARN_ON(!((int)(queue->local_insert - queue->process) >= 0));
  24888. + WARN_ON(!((int)(queue->remote_insert - queue->process) >= 0));
  24889. +
  24890. + while ((queue->process != queue->local_insert) ||
  24891. + (queue->process != queue->remote_insert)) {
  24892. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  24893. +
  24894. + if (queue->process == queue->remote_insert) {
  24895. + /* fabricate a matching dummy bulk */
  24896. + bulk->remote_data = NULL;
  24897. + bulk->remote_size = 0;
  24898. + queue->remote_insert++;
  24899. + }
  24900. +
  24901. + if (queue->process != queue->local_insert) {
  24902. + vchiq_complete_bulk(bulk);
  24903. +
  24904. + vchiq_log_info(vchiq_core_msg_log_level,
  24905. + "%s %c%c%c%c d:%d ABORTED - tx len:%d, "
  24906. + "rx len:%d",
  24907. + is_tx ? "Send Bulk to" : "Recv Bulk from",
  24908. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  24909. + service->remoteport,
  24910. + bulk->size,
  24911. + bulk->remote_size);
  24912. + } else {
  24913. + /* fabricate a matching dummy bulk */
  24914. + bulk->data = NULL;
  24915. + bulk->size = 0;
  24916. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  24917. + bulk->dir = is_tx ? VCHIQ_BULK_TRANSMIT :
  24918. + VCHIQ_BULK_RECEIVE;
  24919. + queue->local_insert++;
  24920. + }
  24921. +
  24922. + queue->process++;
  24923. + }
  24924. +}
  24925. +
  24926. +/* Called from the slot handler thread */
  24927. +static void
  24928. +pause_bulks(VCHIQ_STATE_T *state)
  24929. +{
  24930. + if (unlikely(atomic_inc_return(&pause_bulks_count) != 1)) {
  24931. + WARN_ON_ONCE(1);
  24932. + atomic_set(&pause_bulks_count, 1);
  24933. + return;
  24934. + }
  24935. +
  24936. + /* Block bulk transfers from all services */
  24937. + mutex_lock(&state->bulk_transfer_mutex);
  24938. +}
  24939. +
  24940. +/* Called from the slot handler thread */
  24941. +static void
  24942. +resume_bulks(VCHIQ_STATE_T *state)
  24943. +{
  24944. + int i;
  24945. + if (unlikely(atomic_dec_return(&pause_bulks_count) != 0)) {
  24946. + WARN_ON_ONCE(1);
  24947. + atomic_set(&pause_bulks_count, 0);
  24948. + return;
  24949. + }
  24950. +
  24951. + /* Allow bulk transfers from all services */
  24952. + mutex_unlock(&state->bulk_transfer_mutex);
  24953. +
  24954. + if (state->deferred_bulks == 0)
  24955. + return;
  24956. +
  24957. + /* Deal with any bulks which had to be deferred due to being in
  24958. + * paused state. Don't try to match up to number of deferred bulks
  24959. + * in case we've had something come and close the service in the
  24960. + * interim - just process all bulk queues for all services */
  24961. + vchiq_log_info(vchiq_core_log_level, "%s: processing %d deferred bulks",
  24962. + __func__, state->deferred_bulks);
  24963. +
  24964. + for (i = 0; i < state->unused_service; i++) {
  24965. + VCHIQ_SERVICE_T *service = state->services[i];
  24966. + int resolved_rx = 0;
  24967. + int resolved_tx = 0;
  24968. + if (!service || (service->srvstate != VCHIQ_SRVSTATE_OPEN))
  24969. + continue;
  24970. +
  24971. + mutex_lock(&service->bulk_mutex);
  24972. + resolved_rx = resolve_bulks(service, &service->bulk_rx);
  24973. + resolved_tx = resolve_bulks(service, &service->bulk_tx);
  24974. + mutex_unlock(&service->bulk_mutex);
  24975. + if (resolved_rx)
  24976. + notify_bulks(service, &service->bulk_rx, 1);
  24977. + if (resolved_tx)
  24978. + notify_bulks(service, &service->bulk_tx, 1);
  24979. + }
  24980. + state->deferred_bulks = 0;
  24981. +}
  24982. +
  24983. +static int
  24984. +parse_open(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  24985. +{
  24986. + VCHIQ_SERVICE_T *service = NULL;
  24987. + int msgid, size;
  24988. + int type;
  24989. + unsigned int localport, remoteport;
  24990. +
  24991. + msgid = header->msgid;
  24992. + size = header->size;
  24993. + type = VCHIQ_MSG_TYPE(msgid);
  24994. + localport = VCHIQ_MSG_DSTPORT(msgid);
  24995. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  24996. + if (size >= sizeof(struct vchiq_open_payload)) {
  24997. + const struct vchiq_open_payload *payload =
  24998. + (struct vchiq_open_payload *)header->data;
  24999. + unsigned int fourcc;
  25000. +
  25001. + fourcc = payload->fourcc;
  25002. + vchiq_log_info(vchiq_core_log_level,
  25003. + "%d: prs OPEN@%x (%d->'%c%c%c%c')",
  25004. + state->id, (unsigned int)header,
  25005. + localport,
  25006. + VCHIQ_FOURCC_AS_4CHARS(fourcc));
  25007. +
  25008. + service = get_listening_service(state, fourcc);
  25009. +
  25010. + if (service) {
  25011. + /* A matching service exists */
  25012. + short version = payload->version;
  25013. + short version_min = payload->version_min;
  25014. + if ((service->version < version_min) ||
  25015. + (version < service->version_min)) {
  25016. + /* Version mismatch */
  25017. + vchiq_loud_error_header();
  25018. + vchiq_loud_error("%d: service %d (%c%c%c%c) "
  25019. + "version mismatch - local (%d, min %d)"
  25020. + " vs. remote (%d, min %d)",
  25021. + state->id, service->localport,
  25022. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  25023. + service->version, service->version_min,
  25024. + version, version_min);
  25025. + vchiq_loud_error_footer();
  25026. + unlock_service(service);
  25027. + service = NULL;
  25028. + goto fail_open;
  25029. + }
  25030. + service->peer_version = version;
  25031. +
  25032. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  25033. + struct vchiq_openack_payload ack_payload = {
  25034. + service->version
  25035. + };
  25036. + VCHIQ_ELEMENT_T body = {
  25037. + &ack_payload,
  25038. + sizeof(ack_payload)
  25039. + };
  25040. +
  25041. + /* Acknowledge the OPEN */
  25042. + if (service->sync) {
  25043. + if (queue_message_sync(state, NULL,
  25044. + VCHIQ_MAKE_MSG(
  25045. + VCHIQ_MSG_OPENACK,
  25046. + service->localport,
  25047. + remoteport),
  25048. + &body, 1, sizeof(ack_payload),
  25049. + 0) == VCHIQ_RETRY)
  25050. + goto bail_not_ready;
  25051. + } else {
  25052. + if (queue_message(state, NULL,
  25053. + VCHIQ_MAKE_MSG(
  25054. + VCHIQ_MSG_OPENACK,
  25055. + service->localport,
  25056. + remoteport),
  25057. + &body, 1, sizeof(ack_payload),
  25058. + 0) == VCHIQ_RETRY)
  25059. + goto bail_not_ready;
  25060. + }
  25061. +
  25062. + /* The service is now open */
  25063. + vchiq_set_service_state(service,
  25064. + service->sync ? VCHIQ_SRVSTATE_OPENSYNC
  25065. + : VCHIQ_SRVSTATE_OPEN);
  25066. + }
  25067. +
  25068. + service->remoteport = remoteport;
  25069. + service->client_id = ((int *)header->data)[1];
  25070. + if (make_service_callback(service, VCHIQ_SERVICE_OPENED,
  25071. + NULL, NULL) == VCHIQ_RETRY) {
  25072. + /* Bail out if not ready */
  25073. + service->remoteport = VCHIQ_PORT_FREE;
  25074. + goto bail_not_ready;
  25075. + }
  25076. +
  25077. + /* Success - the message has been dealt with */
  25078. + unlock_service(service);
  25079. + return 1;
  25080. + }
  25081. + }
  25082. +
  25083. +fail_open:
  25084. + /* No available service, or an invalid request - send a CLOSE */
  25085. + if (queue_message(state, NULL,
  25086. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CLOSE, 0, VCHIQ_MSG_SRCPORT(msgid)),
  25087. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  25088. + goto bail_not_ready;
  25089. +
  25090. + return 1;
  25091. +
  25092. +bail_not_ready:
  25093. + if (service)
  25094. + unlock_service(service);
  25095. +
  25096. + return 0;
  25097. +}
  25098. +
  25099. +/* Called by the slot handler thread */
  25100. +static void
  25101. +parse_rx_slots(VCHIQ_STATE_T *state)
  25102. +{
  25103. + VCHIQ_SHARED_STATE_T *remote = state->remote;
  25104. + VCHIQ_SERVICE_T *service = NULL;
  25105. + int tx_pos;
  25106. + DEBUG_INITIALISE(state->local)
  25107. +
  25108. + tx_pos = remote->tx_pos;
  25109. +
  25110. + while (state->rx_pos != tx_pos) {
  25111. + VCHIQ_HEADER_T *header;
  25112. + int msgid, size;
  25113. + int type;
  25114. + unsigned int localport, remoteport;
  25115. +
  25116. + DEBUG_TRACE(PARSE_LINE);
  25117. + if (!state->rx_data) {
  25118. + int rx_index;
  25119. + WARN_ON(!((state->rx_pos & VCHIQ_SLOT_MASK) == 0));
  25120. + rx_index = remote->slot_queue[
  25121. + SLOT_QUEUE_INDEX_FROM_POS(state->rx_pos) &
  25122. + VCHIQ_SLOT_QUEUE_MASK];
  25123. + state->rx_data = (char *)SLOT_DATA_FROM_INDEX(state,
  25124. + rx_index);
  25125. + state->rx_info = SLOT_INFO_FROM_INDEX(state, rx_index);
  25126. +
  25127. + /* Initialise use_count to one, and increment
  25128. + ** release_count at the end of the slot to avoid
  25129. + ** releasing the slot prematurely. */
  25130. + state->rx_info->use_count = 1;
  25131. + state->rx_info->release_count = 0;
  25132. + }
  25133. +
  25134. + header = (VCHIQ_HEADER_T *)(state->rx_data +
  25135. + (state->rx_pos & VCHIQ_SLOT_MASK));
  25136. + DEBUG_VALUE(PARSE_HEADER, (int)header);
  25137. + msgid = header->msgid;
  25138. + DEBUG_VALUE(PARSE_MSGID, msgid);
  25139. + size = header->size;
  25140. + type = VCHIQ_MSG_TYPE(msgid);
  25141. + localport = VCHIQ_MSG_DSTPORT(msgid);
  25142. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  25143. +
  25144. + if (type != VCHIQ_MSG_DATA)
  25145. + VCHIQ_STATS_INC(state, ctrl_rx_count);
  25146. +
  25147. + switch (type) {
  25148. + case VCHIQ_MSG_OPENACK:
  25149. + case VCHIQ_MSG_CLOSE:
  25150. + case VCHIQ_MSG_DATA:
  25151. + case VCHIQ_MSG_BULK_RX:
  25152. + case VCHIQ_MSG_BULK_TX:
  25153. + case VCHIQ_MSG_BULK_RX_DONE:
  25154. + case VCHIQ_MSG_BULK_TX_DONE:
  25155. + service = find_service_by_port(state, localport);
  25156. + if ((!service || service->remoteport != remoteport) &&
  25157. + (localport == 0) &&
  25158. + (type == VCHIQ_MSG_CLOSE)) {
  25159. + /* This could be a CLOSE from a client which
  25160. + hadn't yet received the OPENACK - look for
  25161. + the connected service */
  25162. + if (service)
  25163. + unlock_service(service);
  25164. + service = get_connected_service(state,
  25165. + remoteport);
  25166. + if (service)
  25167. + vchiq_log_warning(vchiq_core_log_level,
  25168. + "%d: prs %s@%x (%d->%d) - "
  25169. + "found connected service %d",
  25170. + state->id, msg_type_str(type),
  25171. + (unsigned int)header,
  25172. + remoteport, localport,
  25173. + service->localport);
  25174. + }
  25175. +
  25176. + if (!service) {
  25177. + vchiq_log_error(vchiq_core_log_level,
  25178. + "%d: prs %s@%x (%d->%d) - "
  25179. + "invalid/closed service %d",
  25180. + state->id, msg_type_str(type),
  25181. + (unsigned int)header,
  25182. + remoteport, localport, localport);
  25183. + goto skip_message;
  25184. + }
  25185. + break;
  25186. + default:
  25187. + break;
  25188. + }
  25189. +
  25190. + if (vchiq_core_msg_log_level >= VCHIQ_LOG_INFO) {
  25191. + int svc_fourcc;
  25192. +
  25193. + svc_fourcc = service
  25194. + ? service->base.fourcc
  25195. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  25196. + vchiq_log_info(vchiq_core_msg_log_level,
  25197. + "Rcvd Msg %s(%u) from %c%c%c%c s:%d d:%d "
  25198. + "len:%d",
  25199. + msg_type_str(type), type,
  25200. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  25201. + remoteport, localport, size);
  25202. + if (size > 0)
  25203. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  25204. + min(64, size));
  25205. + }
  25206. +
  25207. + if (((unsigned int)header & VCHIQ_SLOT_MASK) + calc_stride(size)
  25208. + > VCHIQ_SLOT_SIZE) {
  25209. + vchiq_log_error(vchiq_core_log_level,
  25210. + "header %x (msgid %x) - size %x too big for "
  25211. + "slot",
  25212. + (unsigned int)header, (unsigned int)msgid,
  25213. + (unsigned int)size);
  25214. + WARN(1, "oversized for slot\n");
  25215. + }
  25216. +
  25217. + switch (type) {
  25218. + case VCHIQ_MSG_OPEN:
  25219. + WARN_ON(!(VCHIQ_MSG_DSTPORT(msgid) == 0));
  25220. + if (!parse_open(state, header))
  25221. + goto bail_not_ready;
  25222. + break;
  25223. + case VCHIQ_MSG_OPENACK:
  25224. + if (size >= sizeof(struct vchiq_openack_payload)) {
  25225. + const struct vchiq_openack_payload *payload =
  25226. + (struct vchiq_openack_payload *)
  25227. + header->data;
  25228. + service->peer_version = payload->version;
  25229. + }
  25230. + vchiq_log_info(vchiq_core_log_level,
  25231. + "%d: prs OPENACK@%x,%x (%d->%d) v:%d",
  25232. + state->id, (unsigned int)header, size,
  25233. + remoteport, localport, service->peer_version);
  25234. + if (service->srvstate ==
  25235. + VCHIQ_SRVSTATE_OPENING) {
  25236. + service->remoteport = remoteport;
  25237. + vchiq_set_service_state(service,
  25238. + VCHIQ_SRVSTATE_OPEN);
  25239. + up(&service->remove_event);
  25240. + } else
  25241. + vchiq_log_error(vchiq_core_log_level,
  25242. + "OPENACK received in state %s",
  25243. + srvstate_names[service->srvstate]);
  25244. + break;
  25245. + case VCHIQ_MSG_CLOSE:
  25246. + WARN_ON(size != 0); /* There should be no data */
  25247. +
  25248. + vchiq_log_info(vchiq_core_log_level,
  25249. + "%d: prs CLOSE@%x (%d->%d)",
  25250. + state->id, (unsigned int)header,
  25251. + remoteport, localport);
  25252. +
  25253. + mark_service_closing_internal(service, 1);
  25254. +
  25255. + if (vchiq_close_service_internal(service,
  25256. + 1/*close_recvd*/) == VCHIQ_RETRY)
  25257. + goto bail_not_ready;
  25258. +
  25259. + vchiq_log_info(vchiq_core_log_level,
  25260. + "Close Service %c%c%c%c s:%u d:%d",
  25261. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  25262. + service->localport,
  25263. + service->remoteport);
  25264. + break;
  25265. + case VCHIQ_MSG_DATA:
  25266. + vchiq_log_trace(vchiq_core_log_level,
  25267. + "%d: prs DATA@%x,%x (%d->%d)",
  25268. + state->id, (unsigned int)header, size,
  25269. + remoteport, localport);
  25270. +
  25271. + if ((service->remoteport == remoteport)
  25272. + && (service->srvstate ==
  25273. + VCHIQ_SRVSTATE_OPEN)) {
  25274. + header->msgid = msgid | VCHIQ_MSGID_CLAIMED;
  25275. + claim_slot(state->rx_info);
  25276. + DEBUG_TRACE(PARSE_LINE);
  25277. + if (make_service_callback(service,
  25278. + VCHIQ_MESSAGE_AVAILABLE, header,
  25279. + NULL) == VCHIQ_RETRY) {
  25280. + DEBUG_TRACE(PARSE_LINE);
  25281. + goto bail_not_ready;
  25282. + }
  25283. + VCHIQ_SERVICE_STATS_INC(service, ctrl_rx_count);
  25284. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_rx_bytes,
  25285. + size);
  25286. + } else {
  25287. + VCHIQ_STATS_INC(state, error_count);
  25288. + }
  25289. + break;
  25290. + case VCHIQ_MSG_CONNECT:
  25291. + vchiq_log_info(vchiq_core_log_level,
  25292. + "%d: prs CONNECT@%x",
  25293. + state->id, (unsigned int)header);
  25294. + up(&state->connect);
  25295. + break;
  25296. + case VCHIQ_MSG_BULK_RX:
  25297. + case VCHIQ_MSG_BULK_TX: {
  25298. + VCHIQ_BULK_QUEUE_T *queue;
  25299. + WARN_ON(!state->is_master);
  25300. + queue = (type == VCHIQ_MSG_BULK_RX) ?
  25301. + &service->bulk_tx : &service->bulk_rx;
  25302. + if ((service->remoteport == remoteport)
  25303. + && (service->srvstate ==
  25304. + VCHIQ_SRVSTATE_OPEN)) {
  25305. + VCHIQ_BULK_T *bulk;
  25306. + int resolved = 0;
  25307. +
  25308. + DEBUG_TRACE(PARSE_LINE);
  25309. + if (mutex_lock_interruptible(
  25310. + &service->bulk_mutex) != 0) {
  25311. + DEBUG_TRACE(PARSE_LINE);
  25312. + goto bail_not_ready;
  25313. + }
  25314. +
  25315. + WARN_ON(!(queue->remote_insert < queue->remove +
  25316. + VCHIQ_NUM_SERVICE_BULKS));
  25317. + bulk = &queue->bulks[
  25318. + BULK_INDEX(queue->remote_insert)];
  25319. + bulk->remote_data =
  25320. + (void *)((int *)header->data)[0];
  25321. + bulk->remote_size = ((int *)header->data)[1];
  25322. + wmb();
  25323. +
  25324. + vchiq_log_info(vchiq_core_log_level,
  25325. + "%d: prs %s@%x (%d->%d) %x@%x",
  25326. + state->id, msg_type_str(type),
  25327. + (unsigned int)header,
  25328. + remoteport, localport,
  25329. + bulk->remote_size,
  25330. + (unsigned int)bulk->remote_data);
  25331. +
  25332. + queue->remote_insert++;
  25333. +
  25334. + if (atomic_read(&pause_bulks_count)) {
  25335. + state->deferred_bulks++;
  25336. + vchiq_log_info(vchiq_core_log_level,
  25337. + "%s: deferring bulk (%d)",
  25338. + __func__,
  25339. + state->deferred_bulks);
  25340. + if (state->conn_state !=
  25341. + VCHIQ_CONNSTATE_PAUSE_SENT)
  25342. + vchiq_log_error(
  25343. + vchiq_core_log_level,
  25344. + "%s: bulks paused in "
  25345. + "unexpected state %s",
  25346. + __func__,
  25347. + conn_state_names[
  25348. + state->conn_state]);
  25349. + } else if (state->conn_state ==
  25350. + VCHIQ_CONNSTATE_CONNECTED) {
  25351. + DEBUG_TRACE(PARSE_LINE);
  25352. + resolved = resolve_bulks(service,
  25353. + queue);
  25354. + }
  25355. +
  25356. + mutex_unlock(&service->bulk_mutex);
  25357. + if (resolved)
  25358. + notify_bulks(service, queue,
  25359. + 1/*retry_poll*/);
  25360. + }
  25361. + } break;
  25362. + case VCHIQ_MSG_BULK_RX_DONE:
  25363. + case VCHIQ_MSG_BULK_TX_DONE:
  25364. + WARN_ON(state->is_master);
  25365. + if ((service->remoteport == remoteport)
  25366. + && (service->srvstate !=
  25367. + VCHIQ_SRVSTATE_FREE)) {
  25368. + VCHIQ_BULK_QUEUE_T *queue;
  25369. + VCHIQ_BULK_T *bulk;
  25370. +
  25371. + queue = (type == VCHIQ_MSG_BULK_RX_DONE) ?
  25372. + &service->bulk_rx : &service->bulk_tx;
  25373. +
  25374. + DEBUG_TRACE(PARSE_LINE);
  25375. + if (mutex_lock_interruptible(
  25376. + &service->bulk_mutex) != 0) {
  25377. + DEBUG_TRACE(PARSE_LINE);
  25378. + goto bail_not_ready;
  25379. + }
  25380. + if ((int)(queue->remote_insert -
  25381. + queue->local_insert) >= 0) {
  25382. + vchiq_log_error(vchiq_core_log_level,
  25383. + "%d: prs %s@%x (%d->%d) "
  25384. + "unexpected (ri=%d,li=%d)",
  25385. + state->id, msg_type_str(type),
  25386. + (unsigned int)header,
  25387. + remoteport, localport,
  25388. + queue->remote_insert,
  25389. + queue->local_insert);
  25390. + mutex_unlock(&service->bulk_mutex);
  25391. + break;
  25392. + }
  25393. +
  25394. + BUG_ON(queue->process == queue->local_insert);
  25395. + BUG_ON(queue->process != queue->remote_insert);
  25396. +
  25397. + bulk = &queue->bulks[
  25398. + BULK_INDEX(queue->remote_insert)];
  25399. + bulk->actual = *(int *)header->data;
  25400. + queue->remote_insert++;
  25401. +
  25402. + vchiq_log_info(vchiq_core_log_level,
  25403. + "%d: prs %s@%x (%d->%d) %x@%x",
  25404. + state->id, msg_type_str(type),
  25405. + (unsigned int)header,
  25406. + remoteport, localport,
  25407. + bulk->actual, (unsigned int)bulk->data);
  25408. +
  25409. + vchiq_log_trace(vchiq_core_log_level,
  25410. + "%d: prs:%d %cx li=%x ri=%x p=%x",
  25411. + state->id, localport,
  25412. + (type == VCHIQ_MSG_BULK_RX_DONE) ?
  25413. + 'r' : 't',
  25414. + queue->local_insert,
  25415. + queue->remote_insert, queue->process);
  25416. +
  25417. + DEBUG_TRACE(PARSE_LINE);
  25418. + WARN_ON(queue->process == queue->local_insert);
  25419. + vchiq_complete_bulk(bulk);
  25420. + queue->process++;
  25421. + mutex_unlock(&service->bulk_mutex);
  25422. + DEBUG_TRACE(PARSE_LINE);
  25423. + notify_bulks(service, queue, 1/*retry_poll*/);
  25424. + DEBUG_TRACE(PARSE_LINE);
  25425. + }
  25426. + break;
  25427. + case VCHIQ_MSG_PADDING:
  25428. + vchiq_log_trace(vchiq_core_log_level,
  25429. + "%d: prs PADDING@%x,%x",
  25430. + state->id, (unsigned int)header, size);
  25431. + break;
  25432. + case VCHIQ_MSG_PAUSE:
  25433. + /* If initiated, signal the application thread */
  25434. + vchiq_log_trace(vchiq_core_log_level,
  25435. + "%d: prs PAUSE@%x,%x",
  25436. + state->id, (unsigned int)header, size);
  25437. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  25438. + vchiq_log_error(vchiq_core_log_level,
  25439. + "%d: PAUSE received in state PAUSED",
  25440. + state->id);
  25441. + break;
  25442. + }
  25443. + if (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT) {
  25444. + /* Send a PAUSE in response */
  25445. + if (queue_message(state, NULL,
  25446. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  25447. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  25448. + goto bail_not_ready;
  25449. + if (state->is_master)
  25450. + pause_bulks(state);
  25451. + }
  25452. + /* At this point slot_mutex is held */
  25453. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSED);
  25454. + vchiq_platform_paused(state);
  25455. + break;
  25456. + case VCHIQ_MSG_RESUME:
  25457. + vchiq_log_trace(vchiq_core_log_level,
  25458. + "%d: prs RESUME@%x,%x",
  25459. + state->id, (unsigned int)header, size);
  25460. + /* Release the slot mutex */
  25461. + mutex_unlock(&state->slot_mutex);
  25462. + if (state->is_master)
  25463. + resume_bulks(state);
  25464. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  25465. + vchiq_platform_resumed(state);
  25466. + break;
  25467. +
  25468. + case VCHIQ_MSG_REMOTE_USE:
  25469. + vchiq_on_remote_use(state);
  25470. + break;
  25471. + case VCHIQ_MSG_REMOTE_RELEASE:
  25472. + vchiq_on_remote_release(state);
  25473. + break;
  25474. + case VCHIQ_MSG_REMOTE_USE_ACTIVE:
  25475. + vchiq_on_remote_use_active(state);
  25476. + break;
  25477. +
  25478. + default:
  25479. + vchiq_log_error(vchiq_core_log_level,
  25480. + "%d: prs invalid msgid %x@%x,%x",
  25481. + state->id, msgid, (unsigned int)header, size);
  25482. + WARN(1, "invalid message\n");
  25483. + break;
  25484. + }
  25485. +
  25486. +skip_message:
  25487. + if (service) {
  25488. + unlock_service(service);
  25489. + service = NULL;
  25490. + }
  25491. +
  25492. + state->rx_pos += calc_stride(size);
  25493. +
  25494. + DEBUG_TRACE(PARSE_LINE);
  25495. + /* Perform some housekeeping when the end of the slot is
  25496. + ** reached. */
  25497. + if ((state->rx_pos & VCHIQ_SLOT_MASK) == 0) {
  25498. + /* Remove the extra reference count. */
  25499. + release_slot(state, state->rx_info, NULL, NULL);
  25500. + state->rx_data = NULL;
  25501. + }
  25502. + }
  25503. +
  25504. +bail_not_ready:
  25505. + if (service)
  25506. + unlock_service(service);
  25507. +}
  25508. +
  25509. +/* Called by the slot handler thread */
  25510. +static int
  25511. +slot_handler_func(void *v)
  25512. +{
  25513. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  25514. + VCHIQ_SHARED_STATE_T *local = state->local;
  25515. + DEBUG_INITIALISE(local)
  25516. +
  25517. + while (1) {
  25518. + DEBUG_COUNT(SLOT_HANDLER_COUNT);
  25519. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  25520. + remote_event_wait(&local->trigger);
  25521. +
  25522. + rmb();
  25523. +
  25524. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  25525. + if (state->poll_needed) {
  25526. + /* Check if we need to suspend - may change our
  25527. + * conn_state */
  25528. + vchiq_platform_check_suspend(state);
  25529. +
  25530. + state->poll_needed = 0;
  25531. +
  25532. + /* Handle service polling and other rare conditions here
  25533. + ** out of the mainline code */
  25534. + switch (state->conn_state) {
  25535. + case VCHIQ_CONNSTATE_CONNECTED:
  25536. + /* Poll the services as requested */
  25537. + poll_services(state);
  25538. + break;
  25539. +
  25540. + case VCHIQ_CONNSTATE_PAUSING:
  25541. + if (state->is_master)
  25542. + pause_bulks(state);
  25543. + if (queue_message(state, NULL,
  25544. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  25545. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  25546. + vchiq_set_conn_state(state,
  25547. + VCHIQ_CONNSTATE_PAUSE_SENT);
  25548. + } else {
  25549. + if (state->is_master)
  25550. + resume_bulks(state);
  25551. + /* Retry later */
  25552. + state->poll_needed = 1;
  25553. + }
  25554. + break;
  25555. +
  25556. + case VCHIQ_CONNSTATE_PAUSED:
  25557. + vchiq_platform_resume(state);
  25558. + break;
  25559. +
  25560. + case VCHIQ_CONNSTATE_RESUMING:
  25561. + if (queue_message(state, NULL,
  25562. + VCHIQ_MAKE_MSG(VCHIQ_MSG_RESUME, 0, 0),
  25563. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  25564. + if (state->is_master)
  25565. + resume_bulks(state);
  25566. + vchiq_set_conn_state(state,
  25567. + VCHIQ_CONNSTATE_CONNECTED);
  25568. + vchiq_platform_resumed(state);
  25569. + } else {
  25570. + /* This should really be impossible,
  25571. + ** since the PAUSE should have flushed
  25572. + ** through outstanding messages. */
  25573. + vchiq_log_error(vchiq_core_log_level,
  25574. + "Failed to send RESUME "
  25575. + "message");
  25576. + BUG();
  25577. + }
  25578. + break;
  25579. +
  25580. + case VCHIQ_CONNSTATE_PAUSE_TIMEOUT:
  25581. + case VCHIQ_CONNSTATE_RESUME_TIMEOUT:
  25582. + vchiq_platform_handle_timeout(state);
  25583. + break;
  25584. + default:
  25585. + break;
  25586. + }
  25587. +
  25588. +
  25589. + }
  25590. +
  25591. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  25592. + parse_rx_slots(state);
  25593. + }
  25594. + return 0;
  25595. +}
  25596. +
  25597. +
  25598. +/* Called by the recycle thread */
  25599. +static int
  25600. +recycle_func(void *v)
  25601. +{
  25602. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  25603. + VCHIQ_SHARED_STATE_T *local = state->local;
  25604. +
  25605. + while (1) {
  25606. + remote_event_wait(&local->recycle);
  25607. +
  25608. + process_free_queue(state);
  25609. + }
  25610. + return 0;
  25611. +}
  25612. +
  25613. +
  25614. +/* Called by the sync thread */
  25615. +static int
  25616. +sync_func(void *v)
  25617. +{
  25618. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  25619. + VCHIQ_SHARED_STATE_T *local = state->local;
  25620. + VCHIQ_HEADER_T *header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  25621. + state->remote->slot_sync);
  25622. +
  25623. + while (1) {
  25624. + VCHIQ_SERVICE_T *service;
  25625. + int msgid, size;
  25626. + int type;
  25627. + unsigned int localport, remoteport;
  25628. +
  25629. + remote_event_wait(&local->sync_trigger);
  25630. +
  25631. + rmb();
  25632. +
  25633. + msgid = header->msgid;
  25634. + size = header->size;
  25635. + type = VCHIQ_MSG_TYPE(msgid);
  25636. + localport = VCHIQ_MSG_DSTPORT(msgid);
  25637. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  25638. +
  25639. + service = find_service_by_port(state, localport);
  25640. +
  25641. + if (!service) {
  25642. + vchiq_log_error(vchiq_sync_log_level,
  25643. + "%d: sf %s@%x (%d->%d) - "
  25644. + "invalid/closed service %d",
  25645. + state->id, msg_type_str(type),
  25646. + (unsigned int)header,
  25647. + remoteport, localport, localport);
  25648. + release_message_sync(state, header);
  25649. + continue;
  25650. + }
  25651. +
  25652. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  25653. + int svc_fourcc;
  25654. +
  25655. + svc_fourcc = service
  25656. + ? service->base.fourcc
  25657. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  25658. + vchiq_log_trace(vchiq_sync_log_level,
  25659. + "Rcvd Msg %s from %c%c%c%c s:%d d:%d len:%d",
  25660. + msg_type_str(type),
  25661. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  25662. + remoteport, localport, size);
  25663. + if (size > 0)
  25664. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  25665. + min(64, size));
  25666. + }
  25667. +
  25668. + switch (type) {
  25669. + case VCHIQ_MSG_OPENACK:
  25670. + if (size >= sizeof(struct vchiq_openack_payload)) {
  25671. + const struct vchiq_openack_payload *payload =
  25672. + (struct vchiq_openack_payload *)
  25673. + header->data;
  25674. + service->peer_version = payload->version;
  25675. + }
  25676. + vchiq_log_info(vchiq_sync_log_level,
  25677. + "%d: sf OPENACK@%x,%x (%d->%d) v:%d",
  25678. + state->id, (unsigned int)header, size,
  25679. + remoteport, localport, service->peer_version);
  25680. + if (service->srvstate == VCHIQ_SRVSTATE_OPENING) {
  25681. + service->remoteport = remoteport;
  25682. + vchiq_set_service_state(service,
  25683. + VCHIQ_SRVSTATE_OPENSYNC);
  25684. + up(&service->remove_event);
  25685. + }
  25686. + release_message_sync(state, header);
  25687. + break;
  25688. +
  25689. + case VCHIQ_MSG_DATA:
  25690. + vchiq_log_trace(vchiq_sync_log_level,
  25691. + "%d: sf DATA@%x,%x (%d->%d)",
  25692. + state->id, (unsigned int)header, size,
  25693. + remoteport, localport);
  25694. +
  25695. + if ((service->remoteport == remoteport) &&
  25696. + (service->srvstate ==
  25697. + VCHIQ_SRVSTATE_OPENSYNC)) {
  25698. + if (make_service_callback(service,
  25699. + VCHIQ_MESSAGE_AVAILABLE, header,
  25700. + NULL) == VCHIQ_RETRY)
  25701. + vchiq_log_error(vchiq_sync_log_level,
  25702. + "synchronous callback to "
  25703. + "service %d returns "
  25704. + "VCHIQ_RETRY",
  25705. + localport);
  25706. + }
  25707. + break;
  25708. +
  25709. + default:
  25710. + vchiq_log_error(vchiq_sync_log_level,
  25711. + "%d: sf unexpected msgid %x@%x,%x",
  25712. + state->id, msgid, (unsigned int)header, size);
  25713. + release_message_sync(state, header);
  25714. + break;
  25715. + }
  25716. +
  25717. + unlock_service(service);
  25718. + }
  25719. +
  25720. + return 0;
  25721. +}
  25722. +
  25723. +
  25724. +static void
  25725. +init_bulk_queue(VCHIQ_BULK_QUEUE_T *queue)
  25726. +{
  25727. + queue->local_insert = 0;
  25728. + queue->remote_insert = 0;
  25729. + queue->process = 0;
  25730. + queue->remote_notify = 0;
  25731. + queue->remove = 0;
  25732. +}
  25733. +
  25734. +
  25735. +inline const char *
  25736. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state)
  25737. +{
  25738. + return conn_state_names[conn_state];
  25739. +}
  25740. +
  25741. +
  25742. +VCHIQ_SLOT_ZERO_T *
  25743. +vchiq_init_slots(void *mem_base, int mem_size)
  25744. +{
  25745. + int mem_align = (VCHIQ_SLOT_SIZE - (int)mem_base) & VCHIQ_SLOT_MASK;
  25746. + VCHIQ_SLOT_ZERO_T *slot_zero =
  25747. + (VCHIQ_SLOT_ZERO_T *)((char *)mem_base + mem_align);
  25748. + int num_slots = (mem_size - mem_align)/VCHIQ_SLOT_SIZE;
  25749. + int first_data_slot = VCHIQ_SLOT_ZERO_SLOTS;
  25750. +
  25751. + /* Ensure there is enough memory to run an absolutely minimum system */
  25752. + num_slots -= first_data_slot;
  25753. +
  25754. + if (num_slots < 4) {
  25755. + vchiq_log_error(vchiq_core_log_level,
  25756. + "vchiq_init_slots - insufficient memory %x bytes",
  25757. + mem_size);
  25758. + return NULL;
  25759. + }
  25760. +
  25761. + memset(slot_zero, 0, sizeof(VCHIQ_SLOT_ZERO_T));
  25762. +
  25763. + slot_zero->magic = VCHIQ_MAGIC;
  25764. + slot_zero->version = VCHIQ_VERSION;
  25765. + slot_zero->version_min = VCHIQ_VERSION_MIN;
  25766. + slot_zero->slot_zero_size = sizeof(VCHIQ_SLOT_ZERO_T);
  25767. + slot_zero->slot_size = VCHIQ_SLOT_SIZE;
  25768. + slot_zero->max_slots = VCHIQ_MAX_SLOTS;
  25769. + slot_zero->max_slots_per_side = VCHIQ_MAX_SLOTS_PER_SIDE;
  25770. +
  25771. + slot_zero->master.slot_sync = first_data_slot;
  25772. + slot_zero->master.slot_first = first_data_slot + 1;
  25773. + slot_zero->master.slot_last = first_data_slot + (num_slots/2) - 1;
  25774. + slot_zero->slave.slot_sync = first_data_slot + (num_slots/2);
  25775. + slot_zero->slave.slot_first = first_data_slot + (num_slots/2) + 1;
  25776. + slot_zero->slave.slot_last = first_data_slot + num_slots - 1;
  25777. +
  25778. + return slot_zero;
  25779. +}
  25780. +
  25781. +VCHIQ_STATUS_T
  25782. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  25783. + int is_master)
  25784. +{
  25785. + VCHIQ_SHARED_STATE_T *local;
  25786. + VCHIQ_SHARED_STATE_T *remote;
  25787. + VCHIQ_STATUS_T status;
  25788. + char threadname[10];
  25789. + static int id;
  25790. + int i;
  25791. +
  25792. + vchiq_log_warning(vchiq_core_log_level,
  25793. + "%s: slot_zero = 0x%08lx, is_master = %d",
  25794. + __func__, (unsigned long)slot_zero, is_master);
  25795. +
  25796. + /* Check the input configuration */
  25797. +
  25798. + if (slot_zero->magic != VCHIQ_MAGIC) {
  25799. + vchiq_loud_error_header();
  25800. + vchiq_loud_error("Invalid VCHIQ magic value found.");
  25801. + vchiq_loud_error("slot_zero=%x: magic=%x (expected %x)",
  25802. + (unsigned int)slot_zero, slot_zero->magic, VCHIQ_MAGIC);
  25803. + vchiq_loud_error_footer();
  25804. + return VCHIQ_ERROR;
  25805. + }
  25806. +
  25807. + if (slot_zero->version < VCHIQ_VERSION_MIN) {
  25808. + vchiq_loud_error_header();
  25809. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  25810. + vchiq_loud_error("slot_zero=%x: VideoCore version=%d "
  25811. + "(minimum %d)",
  25812. + (unsigned int)slot_zero, slot_zero->version,
  25813. + VCHIQ_VERSION_MIN);
  25814. + vchiq_loud_error("Restart with a newer VideoCore image.");
  25815. + vchiq_loud_error_footer();
  25816. + return VCHIQ_ERROR;
  25817. + }
  25818. +
  25819. + if (VCHIQ_VERSION < slot_zero->version_min) {
  25820. + vchiq_loud_error_header();
  25821. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  25822. + vchiq_loud_error("slot_zero=%x: version=%d (VideoCore "
  25823. + "minimum %d)",
  25824. + (unsigned int)slot_zero, VCHIQ_VERSION,
  25825. + slot_zero->version_min);
  25826. + vchiq_loud_error("Restart with a newer kernel.");
  25827. + vchiq_loud_error_footer();
  25828. + return VCHIQ_ERROR;
  25829. + }
  25830. +
  25831. + if ((slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T)) ||
  25832. + (slot_zero->slot_size != VCHIQ_SLOT_SIZE) ||
  25833. + (slot_zero->max_slots != VCHIQ_MAX_SLOTS) ||
  25834. + (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)) {
  25835. + vchiq_loud_error_header();
  25836. + if (slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T))
  25837. + vchiq_loud_error("slot_zero=%x: slot_zero_size=%x "
  25838. + "(expected %x)",
  25839. + (unsigned int)slot_zero,
  25840. + slot_zero->slot_zero_size,
  25841. + sizeof(VCHIQ_SLOT_ZERO_T));
  25842. + if (slot_zero->slot_size != VCHIQ_SLOT_SIZE)
  25843. + vchiq_loud_error("slot_zero=%x: slot_size=%d "
  25844. + "(expected %d",
  25845. + (unsigned int)slot_zero, slot_zero->slot_size,
  25846. + VCHIQ_SLOT_SIZE);
  25847. + if (slot_zero->max_slots != VCHIQ_MAX_SLOTS)
  25848. + vchiq_loud_error("slot_zero=%x: max_slots=%d "
  25849. + "(expected %d)",
  25850. + (unsigned int)slot_zero, slot_zero->max_slots,
  25851. + VCHIQ_MAX_SLOTS);
  25852. + if (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)
  25853. + vchiq_loud_error("slot_zero=%x: max_slots_per_side=%d "
  25854. + "(expected %d)",
  25855. + (unsigned int)slot_zero,
  25856. + slot_zero->max_slots_per_side,
  25857. + VCHIQ_MAX_SLOTS_PER_SIDE);
  25858. + vchiq_loud_error_footer();
  25859. + return VCHIQ_ERROR;
  25860. + }
  25861. +
  25862. + if (is_master) {
  25863. + local = &slot_zero->master;
  25864. + remote = &slot_zero->slave;
  25865. + } else {
  25866. + local = &slot_zero->slave;
  25867. + remote = &slot_zero->master;
  25868. + }
  25869. +
  25870. + if (local->initialised) {
  25871. + vchiq_loud_error_header();
  25872. + if (remote->initialised)
  25873. + vchiq_loud_error("local state has already been "
  25874. + "initialised");
  25875. + else
  25876. + vchiq_loud_error("master/slave mismatch - two %ss",
  25877. + is_master ? "master" : "slave");
  25878. + vchiq_loud_error_footer();
  25879. + return VCHIQ_ERROR;
  25880. + }
  25881. +
  25882. + memset(state, 0, sizeof(VCHIQ_STATE_T));
  25883. +
  25884. + state->id = id++;
  25885. + state->is_master = is_master;
  25886. +
  25887. + /*
  25888. + initialize shared state pointers
  25889. + */
  25890. +
  25891. + state->local = local;
  25892. + state->remote = remote;
  25893. + state->slot_data = (VCHIQ_SLOT_T *)slot_zero;
  25894. +
  25895. + /*
  25896. + initialize events and mutexes
  25897. + */
  25898. +
  25899. + sema_init(&state->connect, 0);
  25900. + mutex_init(&state->mutex);
  25901. + sema_init(&state->trigger_event, 0);
  25902. + sema_init(&state->recycle_event, 0);
  25903. + sema_init(&state->sync_trigger_event, 0);
  25904. + sema_init(&state->sync_release_event, 0);
  25905. +
  25906. + mutex_init(&state->slot_mutex);
  25907. + mutex_init(&state->recycle_mutex);
  25908. + mutex_init(&state->sync_mutex);
  25909. + mutex_init(&state->bulk_transfer_mutex);
  25910. +
  25911. + sema_init(&state->slot_available_event, 0);
  25912. + sema_init(&state->slot_remove_event, 0);
  25913. + sema_init(&state->data_quota_event, 0);
  25914. +
  25915. + state->slot_queue_available = 0;
  25916. +
  25917. + for (i = 0; i < VCHIQ_MAX_SERVICES; i++) {
  25918. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  25919. + &state->service_quotas[i];
  25920. + sema_init(&service_quota->quota_event, 0);
  25921. + }
  25922. +
  25923. + for (i = local->slot_first; i <= local->slot_last; i++) {
  25924. + local->slot_queue[state->slot_queue_available++] = i;
  25925. + up(&state->slot_available_event);
  25926. + }
  25927. +
  25928. + state->default_slot_quota = state->slot_queue_available/2;
  25929. + state->default_message_quota =
  25930. + min((unsigned short)(state->default_slot_quota * 256),
  25931. + (unsigned short)~0);
  25932. +
  25933. + state->previous_data_index = -1;
  25934. + state->data_use_count = 0;
  25935. + state->data_quota = state->slot_queue_available - 1;
  25936. +
  25937. + local->trigger.event = &state->trigger_event;
  25938. + remote_event_create(&local->trigger);
  25939. + local->tx_pos = 0;
  25940. +
  25941. + local->recycle.event = &state->recycle_event;
  25942. + remote_event_create(&local->recycle);
  25943. + local->slot_queue_recycle = state->slot_queue_available;
  25944. +
  25945. + local->sync_trigger.event = &state->sync_trigger_event;
  25946. + remote_event_create(&local->sync_trigger);
  25947. +
  25948. + local->sync_release.event = &state->sync_release_event;
  25949. + remote_event_create(&local->sync_release);
  25950. +
  25951. + /* At start-of-day, the slot is empty and available */
  25952. + ((VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state, local->slot_sync))->msgid
  25953. + = VCHIQ_MSGID_PADDING;
  25954. + remote_event_signal_local(&local->sync_release);
  25955. +
  25956. + local->debug[DEBUG_ENTRIES] = DEBUG_MAX;
  25957. +
  25958. + status = vchiq_platform_init_state(state);
  25959. +
  25960. + /*
  25961. + bring up slot handler thread
  25962. + */
  25963. + snprintf(threadname, sizeof(threadname), "VCHIQ-%d", state->id);
  25964. + state->slot_handler_thread = kthread_create(&slot_handler_func,
  25965. + (void *)state,
  25966. + threadname);
  25967. +
  25968. + if (state->slot_handler_thread == NULL) {
  25969. + vchiq_loud_error_header();
  25970. + vchiq_loud_error("couldn't create thread %s", threadname);
  25971. + vchiq_loud_error_footer();
  25972. + return VCHIQ_ERROR;
  25973. + }
  25974. + set_user_nice(state->slot_handler_thread, -19);
  25975. + wake_up_process(state->slot_handler_thread);
  25976. +
  25977. + snprintf(threadname, sizeof(threadname), "VCHIQr-%d", state->id);
  25978. + state->recycle_thread = kthread_create(&recycle_func,
  25979. + (void *)state,
  25980. + threadname);
  25981. + if (state->recycle_thread == NULL) {
  25982. + vchiq_loud_error_header();
  25983. + vchiq_loud_error("couldn't create thread %s", threadname);
  25984. + vchiq_loud_error_footer();
  25985. + return VCHIQ_ERROR;
  25986. + }
  25987. + set_user_nice(state->recycle_thread, -19);
  25988. + wake_up_process(state->recycle_thread);
  25989. +
  25990. + snprintf(threadname, sizeof(threadname), "VCHIQs-%d", state->id);
  25991. + state->sync_thread = kthread_create(&sync_func,
  25992. + (void *)state,
  25993. + threadname);
  25994. + if (state->sync_thread == NULL) {
  25995. + vchiq_loud_error_header();
  25996. + vchiq_loud_error("couldn't create thread %s", threadname);
  25997. + vchiq_loud_error_footer();
  25998. + return VCHIQ_ERROR;
  25999. + }
  26000. + set_user_nice(state->sync_thread, -20);
  26001. + wake_up_process(state->sync_thread);
  26002. +
  26003. + BUG_ON(state->id >= VCHIQ_MAX_STATES);
  26004. + vchiq_states[state->id] = state;
  26005. +
  26006. + /* Indicate readiness to the other side */
  26007. + local->initialised = 1;
  26008. +
  26009. + return status;
  26010. +}
  26011. +
  26012. +/* Called from application thread when a client or server service is created. */
  26013. +VCHIQ_SERVICE_T *
  26014. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  26015. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  26016. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term)
  26017. +{
  26018. + VCHIQ_SERVICE_T *service;
  26019. +
  26020. + service = kmalloc(sizeof(VCHIQ_SERVICE_T), GFP_KERNEL);
  26021. + if (service) {
  26022. + service->base.fourcc = params->fourcc;
  26023. + service->base.callback = params->callback;
  26024. + service->base.userdata = params->userdata;
  26025. + service->handle = VCHIQ_SERVICE_HANDLE_INVALID;
  26026. + service->ref_count = 1;
  26027. + service->srvstate = VCHIQ_SRVSTATE_FREE;
  26028. + service->userdata_term = userdata_term;
  26029. + service->localport = VCHIQ_PORT_FREE;
  26030. + service->remoteport = VCHIQ_PORT_FREE;
  26031. +
  26032. + service->public_fourcc = (srvstate == VCHIQ_SRVSTATE_OPENING) ?
  26033. + VCHIQ_FOURCC_INVALID : params->fourcc;
  26034. + service->client_id = 0;
  26035. + service->auto_close = 1;
  26036. + service->sync = 0;
  26037. + service->closing = 0;
  26038. + atomic_set(&service->poll_flags, 0);
  26039. + service->version = params->version;
  26040. + service->version_min = params->version_min;
  26041. + service->state = state;
  26042. + service->instance = instance;
  26043. + service->service_use_count = 0;
  26044. + init_bulk_queue(&service->bulk_tx);
  26045. + init_bulk_queue(&service->bulk_rx);
  26046. + sema_init(&service->remove_event, 0);
  26047. + sema_init(&service->bulk_remove_event, 0);
  26048. + mutex_init(&service->bulk_mutex);
  26049. + memset(&service->stats, 0, sizeof(service->stats));
  26050. + } else {
  26051. + vchiq_log_error(vchiq_core_log_level,
  26052. + "Out of memory");
  26053. + }
  26054. +
  26055. + if (service) {
  26056. + VCHIQ_SERVICE_T **pservice = NULL;
  26057. + int i;
  26058. +
  26059. + /* Although it is perfectly possible to use service_spinlock
  26060. + ** to protect the creation of services, it is overkill as it
  26061. + ** disables interrupts while the array is searched.
  26062. + ** The only danger is of another thread trying to create a
  26063. + ** service - service deletion is safe.
  26064. + ** Therefore it is preferable to use state->mutex which,
  26065. + ** although slower to claim, doesn't block interrupts while
  26066. + ** it is held.
  26067. + */
  26068. +
  26069. + mutex_lock(&state->mutex);
  26070. +
  26071. + /* Prepare to use a previously unused service */
  26072. + if (state->unused_service < VCHIQ_MAX_SERVICES)
  26073. + pservice = &state->services[state->unused_service];
  26074. +
  26075. + if (srvstate == VCHIQ_SRVSTATE_OPENING) {
  26076. + for (i = 0; i < state->unused_service; i++) {
  26077. + VCHIQ_SERVICE_T *srv = state->services[i];
  26078. + if (!srv) {
  26079. + pservice = &state->services[i];
  26080. + break;
  26081. + }
  26082. + }
  26083. + } else {
  26084. + for (i = (state->unused_service - 1); i >= 0; i--) {
  26085. + VCHIQ_SERVICE_T *srv = state->services[i];
  26086. + if (!srv)
  26087. + pservice = &state->services[i];
  26088. + else if ((srv->public_fourcc == params->fourcc)
  26089. + && ((srv->instance != instance) ||
  26090. + (srv->base.callback !=
  26091. + params->callback))) {
  26092. + /* There is another server using this
  26093. + ** fourcc which doesn't match. */
  26094. + pservice = NULL;
  26095. + break;
  26096. + }
  26097. + }
  26098. + }
  26099. +
  26100. + if (pservice) {
  26101. + service->localport = (pservice - state->services);
  26102. + if (!handle_seq)
  26103. + handle_seq = VCHIQ_MAX_STATES *
  26104. + VCHIQ_MAX_SERVICES;
  26105. + service->handle = handle_seq |
  26106. + (state->id * VCHIQ_MAX_SERVICES) |
  26107. + service->localport;
  26108. + handle_seq += VCHIQ_MAX_STATES * VCHIQ_MAX_SERVICES;
  26109. + *pservice = service;
  26110. + if (pservice == &state->services[state->unused_service])
  26111. + state->unused_service++;
  26112. + }
  26113. +
  26114. + mutex_unlock(&state->mutex);
  26115. +
  26116. + if (!pservice) {
  26117. + kfree(service);
  26118. + service = NULL;
  26119. + }
  26120. + }
  26121. +
  26122. + if (service) {
  26123. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  26124. + &state->service_quotas[service->localport];
  26125. + service_quota->slot_quota = state->default_slot_quota;
  26126. + service_quota->message_quota = state->default_message_quota;
  26127. + if (service_quota->slot_use_count == 0)
  26128. + service_quota->previous_tx_index =
  26129. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos)
  26130. + - 1;
  26131. +
  26132. + /* Bring this service online */
  26133. + vchiq_set_service_state(service, srvstate);
  26134. +
  26135. + vchiq_log_info(vchiq_core_msg_log_level,
  26136. + "%s Service %c%c%c%c SrcPort:%d",
  26137. + (srvstate == VCHIQ_SRVSTATE_OPENING)
  26138. + ? "Open" : "Add",
  26139. + VCHIQ_FOURCC_AS_4CHARS(params->fourcc),
  26140. + service->localport);
  26141. + }
  26142. +
  26143. + /* Don't unlock the service - leave it with a ref_count of 1. */
  26144. +
  26145. + return service;
  26146. +}
  26147. +
  26148. +VCHIQ_STATUS_T
  26149. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id)
  26150. +{
  26151. + struct vchiq_open_payload payload = {
  26152. + service->base.fourcc,
  26153. + client_id,
  26154. + service->version,
  26155. + service->version_min
  26156. + };
  26157. + VCHIQ_ELEMENT_T body = { &payload, sizeof(payload) };
  26158. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26159. +
  26160. + service->client_id = client_id;
  26161. + vchiq_use_service_internal(service);
  26162. + status = queue_message(service->state, NULL,
  26163. + VCHIQ_MAKE_MSG(VCHIQ_MSG_OPEN, service->localport, 0),
  26164. + &body, 1, sizeof(payload), 1);
  26165. + if (status == VCHIQ_SUCCESS) {
  26166. + if (down_interruptible(&service->remove_event) != 0) {
  26167. + status = VCHIQ_RETRY;
  26168. + vchiq_release_service_internal(service);
  26169. + } else if ((service->srvstate != VCHIQ_SRVSTATE_OPEN) &&
  26170. + (service->srvstate != VCHIQ_SRVSTATE_OPENSYNC)) {
  26171. + if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT)
  26172. + vchiq_log_error(vchiq_core_log_level,
  26173. + "%d: osi - srvstate = %s (ref %d)",
  26174. + service->state->id,
  26175. + srvstate_names[service->srvstate],
  26176. + service->ref_count);
  26177. + status = VCHIQ_ERROR;
  26178. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  26179. + vchiq_release_service_internal(service);
  26180. + }
  26181. + }
  26182. + return status;
  26183. +}
  26184. +
  26185. +static void
  26186. +release_service_messages(VCHIQ_SERVICE_T *service)
  26187. +{
  26188. + VCHIQ_STATE_T *state = service->state;
  26189. + int slot_last = state->remote->slot_last;
  26190. + int i;
  26191. +
  26192. + /* Release any claimed messages */
  26193. + for (i = state->remote->slot_first; i <= slot_last; i++) {
  26194. + VCHIQ_SLOT_INFO_T *slot_info =
  26195. + SLOT_INFO_FROM_INDEX(state, i);
  26196. + if (slot_info->release_count != slot_info->use_count) {
  26197. + char *data =
  26198. + (char *)SLOT_DATA_FROM_INDEX(state, i);
  26199. + unsigned int pos, end;
  26200. +
  26201. + end = VCHIQ_SLOT_SIZE;
  26202. + if (data == state->rx_data)
  26203. + /* This buffer is still being read from - stop
  26204. + ** at the current read position */
  26205. + end = state->rx_pos & VCHIQ_SLOT_MASK;
  26206. +
  26207. + pos = 0;
  26208. +
  26209. + while (pos < end) {
  26210. + VCHIQ_HEADER_T *header =
  26211. + (VCHIQ_HEADER_T *)(data + pos);
  26212. + int msgid = header->msgid;
  26213. + int port = VCHIQ_MSG_DSTPORT(msgid);
  26214. + if ((port == service->localport) &&
  26215. + (msgid & VCHIQ_MSGID_CLAIMED)) {
  26216. + vchiq_log_info(vchiq_core_log_level,
  26217. + " fsi - hdr %x",
  26218. + (unsigned int)header);
  26219. + release_slot(state, slot_info, header,
  26220. + NULL);
  26221. + }
  26222. + pos += calc_stride(header->size);
  26223. + if (pos > VCHIQ_SLOT_SIZE) {
  26224. + vchiq_log_error(vchiq_core_log_level,
  26225. + "fsi - pos %x: header %x, "
  26226. + "msgid %x, header->msgid %x, "
  26227. + "header->size %x",
  26228. + pos, (unsigned int)header,
  26229. + msgid, header->msgid,
  26230. + header->size);
  26231. + WARN(1, "invalid slot position\n");
  26232. + }
  26233. + }
  26234. + }
  26235. + }
  26236. +}
  26237. +
  26238. +static int
  26239. +do_abort_bulks(VCHIQ_SERVICE_T *service)
  26240. +{
  26241. + VCHIQ_STATUS_T status;
  26242. +
  26243. + /* Abort any outstanding bulk transfers */
  26244. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0)
  26245. + return 0;
  26246. + abort_outstanding_bulks(service, &service->bulk_tx);
  26247. + abort_outstanding_bulks(service, &service->bulk_rx);
  26248. + mutex_unlock(&service->bulk_mutex);
  26249. +
  26250. + status = notify_bulks(service, &service->bulk_tx, 0/*!retry_poll*/);
  26251. + if (status == VCHIQ_SUCCESS)
  26252. + status = notify_bulks(service, &service->bulk_rx,
  26253. + 0/*!retry_poll*/);
  26254. + return (status == VCHIQ_SUCCESS);
  26255. +}
  26256. +
  26257. +static VCHIQ_STATUS_T
  26258. +close_service_complete(VCHIQ_SERVICE_T *service, int failstate)
  26259. +{
  26260. + VCHIQ_STATUS_T status;
  26261. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  26262. + int newstate;
  26263. +
  26264. + switch (service->srvstate) {
  26265. + case VCHIQ_SRVSTATE_OPEN:
  26266. + case VCHIQ_SRVSTATE_CLOSESENT:
  26267. + case VCHIQ_SRVSTATE_CLOSERECVD:
  26268. + if (is_server) {
  26269. + if (service->auto_close) {
  26270. + service->client_id = 0;
  26271. + service->remoteport = VCHIQ_PORT_FREE;
  26272. + newstate = VCHIQ_SRVSTATE_LISTENING;
  26273. + } else
  26274. + newstate = VCHIQ_SRVSTATE_CLOSEWAIT;
  26275. + } else
  26276. + newstate = VCHIQ_SRVSTATE_CLOSED;
  26277. + vchiq_set_service_state(service, newstate);
  26278. + break;
  26279. + case VCHIQ_SRVSTATE_LISTENING:
  26280. + break;
  26281. + default:
  26282. + vchiq_log_error(vchiq_core_log_level,
  26283. + "close_service_complete(%x) called in state %s",
  26284. + service->handle, srvstate_names[service->srvstate]);
  26285. + WARN(1, "close_service_complete in unexpected state\n");
  26286. + return VCHIQ_ERROR;
  26287. + }
  26288. +
  26289. + status = make_service_callback(service,
  26290. + VCHIQ_SERVICE_CLOSED, NULL, NULL);
  26291. +
  26292. + if (status != VCHIQ_RETRY) {
  26293. + int uc = service->service_use_count;
  26294. + int i;
  26295. + /* Complete the close process */
  26296. + for (i = 0; i < uc; i++)
  26297. + /* cater for cases where close is forced and the
  26298. + ** client may not close all it's handles */
  26299. + vchiq_release_service_internal(service);
  26300. +
  26301. + service->client_id = 0;
  26302. + service->remoteport = VCHIQ_PORT_FREE;
  26303. +
  26304. + if (service->srvstate == VCHIQ_SRVSTATE_CLOSED)
  26305. + vchiq_free_service_internal(service);
  26306. + else if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT) {
  26307. + if (is_server)
  26308. + service->closing = 0;
  26309. +
  26310. + up(&service->remove_event);
  26311. + }
  26312. + } else
  26313. + vchiq_set_service_state(service, failstate);
  26314. +
  26315. + return status;
  26316. +}
  26317. +
  26318. +/* Called by the slot handler */
  26319. +VCHIQ_STATUS_T
  26320. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd)
  26321. +{
  26322. + VCHIQ_STATE_T *state = service->state;
  26323. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26324. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  26325. +
  26326. + vchiq_log_info(vchiq_core_log_level, "%d: csi:%d,%d (%s)",
  26327. + service->state->id, service->localport, close_recvd,
  26328. + srvstate_names[service->srvstate]);
  26329. +
  26330. + switch (service->srvstate) {
  26331. + case VCHIQ_SRVSTATE_CLOSED:
  26332. + case VCHIQ_SRVSTATE_HIDDEN:
  26333. + case VCHIQ_SRVSTATE_LISTENING:
  26334. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  26335. + if (close_recvd)
  26336. + vchiq_log_error(vchiq_core_log_level,
  26337. + "vchiq_close_service_internal(1) called "
  26338. + "in state %s",
  26339. + srvstate_names[service->srvstate]);
  26340. + else if (is_server) {
  26341. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  26342. + status = VCHIQ_ERROR;
  26343. + } else {
  26344. + service->client_id = 0;
  26345. + service->remoteport = VCHIQ_PORT_FREE;
  26346. + if (service->srvstate ==
  26347. + VCHIQ_SRVSTATE_CLOSEWAIT)
  26348. + vchiq_set_service_state(service,
  26349. + VCHIQ_SRVSTATE_LISTENING);
  26350. + }
  26351. + up(&service->remove_event);
  26352. + } else
  26353. + vchiq_free_service_internal(service);
  26354. + break;
  26355. + case VCHIQ_SRVSTATE_OPENING:
  26356. + if (close_recvd) {
  26357. + /* The open was rejected - tell the user */
  26358. + vchiq_set_service_state(service,
  26359. + VCHIQ_SRVSTATE_CLOSEWAIT);
  26360. + up(&service->remove_event);
  26361. + } else {
  26362. + /* Shutdown mid-open - let the other side know */
  26363. + status = queue_message(state, service,
  26364. + VCHIQ_MAKE_MSG
  26365. + (VCHIQ_MSG_CLOSE,
  26366. + service->localport,
  26367. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  26368. + NULL, 0, 0, 0);
  26369. + }
  26370. + break;
  26371. +
  26372. + case VCHIQ_SRVSTATE_OPENSYNC:
  26373. + mutex_lock(&state->sync_mutex);
  26374. + /* Drop through */
  26375. +
  26376. + case VCHIQ_SRVSTATE_OPEN:
  26377. + if (state->is_master || close_recvd) {
  26378. + if (!do_abort_bulks(service))
  26379. + status = VCHIQ_RETRY;
  26380. + }
  26381. +
  26382. + release_service_messages(service);
  26383. +
  26384. + if (status == VCHIQ_SUCCESS)
  26385. + status = queue_message(state, service,
  26386. + VCHIQ_MAKE_MSG
  26387. + (VCHIQ_MSG_CLOSE,
  26388. + service->localport,
  26389. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  26390. + NULL, 0, 0, 0);
  26391. +
  26392. + if (status == VCHIQ_SUCCESS) {
  26393. + if (!close_recvd)
  26394. + break;
  26395. + } else if (service->srvstate == VCHIQ_SRVSTATE_OPENSYNC) {
  26396. + mutex_unlock(&state->sync_mutex);
  26397. + break;
  26398. + } else
  26399. + break;
  26400. +
  26401. + status = close_service_complete(service,
  26402. + VCHIQ_SRVSTATE_CLOSERECVD);
  26403. + break;
  26404. +
  26405. + case VCHIQ_SRVSTATE_CLOSESENT:
  26406. + if (!close_recvd)
  26407. + /* This happens when a process is killed mid-close */
  26408. + break;
  26409. +
  26410. + if (!state->is_master) {
  26411. + if (!do_abort_bulks(service)) {
  26412. + status = VCHIQ_RETRY;
  26413. + break;
  26414. + }
  26415. + }
  26416. +
  26417. + if (status == VCHIQ_SUCCESS)
  26418. + status = close_service_complete(service,
  26419. + VCHIQ_SRVSTATE_CLOSERECVD);
  26420. + break;
  26421. +
  26422. + case VCHIQ_SRVSTATE_CLOSERECVD:
  26423. + if (!close_recvd && is_server)
  26424. + /* Force into LISTENING mode */
  26425. + vchiq_set_service_state(service,
  26426. + VCHIQ_SRVSTATE_LISTENING);
  26427. + status = close_service_complete(service,
  26428. + VCHIQ_SRVSTATE_CLOSERECVD);
  26429. + break;
  26430. +
  26431. + default:
  26432. + vchiq_log_error(vchiq_core_log_level,
  26433. + "vchiq_close_service_internal(%d) called in state %s",
  26434. + close_recvd, srvstate_names[service->srvstate]);
  26435. + break;
  26436. + }
  26437. +
  26438. + return status;
  26439. +}
  26440. +
  26441. +/* Called from the application process upon process death */
  26442. +void
  26443. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service)
  26444. +{
  26445. + VCHIQ_STATE_T *state = service->state;
  26446. +
  26447. + vchiq_log_info(vchiq_core_log_level, "%d: tsi - (%d<->%d)",
  26448. + state->id, service->localport, service->remoteport);
  26449. +
  26450. + mark_service_closing(service);
  26451. +
  26452. + /* Mark the service for removal by the slot handler */
  26453. + request_poll(state, service, VCHIQ_POLL_REMOVE);
  26454. +}
  26455. +
  26456. +/* Called from the slot handler */
  26457. +void
  26458. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service)
  26459. +{
  26460. + VCHIQ_STATE_T *state = service->state;
  26461. +
  26462. + vchiq_log_info(vchiq_core_log_level, "%d: fsi - (%d)",
  26463. + state->id, service->localport);
  26464. +
  26465. + switch (service->srvstate) {
  26466. + case VCHIQ_SRVSTATE_OPENING:
  26467. + case VCHIQ_SRVSTATE_CLOSED:
  26468. + case VCHIQ_SRVSTATE_HIDDEN:
  26469. + case VCHIQ_SRVSTATE_LISTENING:
  26470. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  26471. + break;
  26472. + default:
  26473. + vchiq_log_error(vchiq_core_log_level,
  26474. + "%d: fsi - (%d) in state %s",
  26475. + state->id, service->localport,
  26476. + srvstate_names[service->srvstate]);
  26477. + return;
  26478. + }
  26479. +
  26480. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_FREE);
  26481. +
  26482. + up(&service->remove_event);
  26483. +
  26484. + /* Release the initial lock */
  26485. + unlock_service(service);
  26486. +}
  26487. +
  26488. +VCHIQ_STATUS_T
  26489. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  26490. +{
  26491. + VCHIQ_SERVICE_T *service;
  26492. + int i;
  26493. +
  26494. + /* Find all services registered to this client and enable them. */
  26495. + i = 0;
  26496. + while ((service = next_service_by_instance(state, instance,
  26497. + &i)) != NULL) {
  26498. + if (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)
  26499. + vchiq_set_service_state(service,
  26500. + VCHIQ_SRVSTATE_LISTENING);
  26501. + unlock_service(service);
  26502. + }
  26503. +
  26504. + if (state->conn_state == VCHIQ_CONNSTATE_DISCONNECTED) {
  26505. + if (queue_message(state, NULL,
  26506. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CONNECT, 0, 0), NULL, 0,
  26507. + 0, 1) == VCHIQ_RETRY)
  26508. + return VCHIQ_RETRY;
  26509. +
  26510. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTING);
  26511. + }
  26512. +
  26513. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTING) {
  26514. + if (down_interruptible(&state->connect) != 0)
  26515. + return VCHIQ_RETRY;
  26516. +
  26517. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  26518. + up(&state->connect);
  26519. + }
  26520. +
  26521. + return VCHIQ_SUCCESS;
  26522. +}
  26523. +
  26524. +VCHIQ_STATUS_T
  26525. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  26526. +{
  26527. + VCHIQ_SERVICE_T *service;
  26528. + int i;
  26529. +
  26530. + /* Find all services registered to this client and enable them. */
  26531. + i = 0;
  26532. + while ((service = next_service_by_instance(state, instance,
  26533. + &i)) != NULL) {
  26534. + (void)vchiq_remove_service(service->handle);
  26535. + unlock_service(service);
  26536. + }
  26537. +
  26538. + return VCHIQ_SUCCESS;
  26539. +}
  26540. +
  26541. +VCHIQ_STATUS_T
  26542. +vchiq_pause_internal(VCHIQ_STATE_T *state)
  26543. +{
  26544. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26545. +
  26546. + switch (state->conn_state) {
  26547. + case VCHIQ_CONNSTATE_CONNECTED:
  26548. + /* Request a pause */
  26549. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSING);
  26550. + request_poll(state, NULL, 0);
  26551. + break;
  26552. + default:
  26553. + vchiq_log_error(vchiq_core_log_level,
  26554. + "vchiq_pause_internal in state %s\n",
  26555. + conn_state_names[state->conn_state]);
  26556. + status = VCHIQ_ERROR;
  26557. + VCHIQ_STATS_INC(state, error_count);
  26558. + break;
  26559. + }
  26560. +
  26561. + return status;
  26562. +}
  26563. +
  26564. +VCHIQ_STATUS_T
  26565. +vchiq_resume_internal(VCHIQ_STATE_T *state)
  26566. +{
  26567. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26568. +
  26569. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  26570. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_RESUMING);
  26571. + request_poll(state, NULL, 0);
  26572. + } else {
  26573. + status = VCHIQ_ERROR;
  26574. + VCHIQ_STATS_INC(state, error_count);
  26575. + }
  26576. +
  26577. + return status;
  26578. +}
  26579. +
  26580. +VCHIQ_STATUS_T
  26581. +vchiq_close_service(VCHIQ_SERVICE_HANDLE_T handle)
  26582. +{
  26583. + /* Unregister the service */
  26584. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26585. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26586. +
  26587. + if (!service)
  26588. + return VCHIQ_ERROR;
  26589. +
  26590. + vchiq_log_info(vchiq_core_log_level,
  26591. + "%d: close_service:%d",
  26592. + service->state->id, service->localport);
  26593. +
  26594. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  26595. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  26596. + (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)) {
  26597. + unlock_service(service);
  26598. + return VCHIQ_ERROR;
  26599. + }
  26600. +
  26601. + mark_service_closing(service);
  26602. +
  26603. + if (current == service->state->slot_handler_thread) {
  26604. + status = vchiq_close_service_internal(service,
  26605. + 0/*!close_recvd*/);
  26606. + BUG_ON(status == VCHIQ_RETRY);
  26607. + } else {
  26608. + /* Mark the service for termination by the slot handler */
  26609. + request_poll(service->state, service, VCHIQ_POLL_TERMINATE);
  26610. + }
  26611. +
  26612. + while (1) {
  26613. + if (down_interruptible(&service->remove_event) != 0) {
  26614. + status = VCHIQ_RETRY;
  26615. + break;
  26616. + }
  26617. +
  26618. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  26619. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  26620. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  26621. + break;
  26622. +
  26623. + vchiq_log_warning(vchiq_core_log_level,
  26624. + "%d: close_service:%d - waiting in state %s",
  26625. + service->state->id, service->localport,
  26626. + srvstate_names[service->srvstate]);
  26627. + }
  26628. +
  26629. + if ((status == VCHIQ_SUCCESS) &&
  26630. + (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  26631. + (service->srvstate != VCHIQ_SRVSTATE_LISTENING))
  26632. + status = VCHIQ_ERROR;
  26633. +
  26634. + unlock_service(service);
  26635. +
  26636. + return status;
  26637. +}
  26638. +
  26639. +VCHIQ_STATUS_T
  26640. +vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T handle)
  26641. +{
  26642. + /* Unregister the service */
  26643. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26644. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26645. +
  26646. + if (!service)
  26647. + return VCHIQ_ERROR;
  26648. +
  26649. + vchiq_log_info(vchiq_core_log_level,
  26650. + "%d: remove_service:%d",
  26651. + service->state->id, service->localport);
  26652. +
  26653. + if (service->srvstate == VCHIQ_SRVSTATE_FREE) {
  26654. + unlock_service(service);
  26655. + return VCHIQ_ERROR;
  26656. + }
  26657. +
  26658. + mark_service_closing(service);
  26659. +
  26660. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  26661. + (current == service->state->slot_handler_thread)) {
  26662. + /* Make it look like a client, because it must be removed and
  26663. + not left in the LISTENING state. */
  26664. + service->public_fourcc = VCHIQ_FOURCC_INVALID;
  26665. +
  26666. + status = vchiq_close_service_internal(service,
  26667. + 0/*!close_recvd*/);
  26668. + BUG_ON(status == VCHIQ_RETRY);
  26669. + } else {
  26670. + /* Mark the service for removal by the slot handler */
  26671. + request_poll(service->state, service, VCHIQ_POLL_REMOVE);
  26672. + }
  26673. + while (1) {
  26674. + if (down_interruptible(&service->remove_event) != 0) {
  26675. + status = VCHIQ_RETRY;
  26676. + break;
  26677. + }
  26678. +
  26679. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  26680. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  26681. + break;
  26682. +
  26683. + vchiq_log_warning(vchiq_core_log_level,
  26684. + "%d: remove_service:%d - waiting in state %s",
  26685. + service->state->id, service->localport,
  26686. + srvstate_names[service->srvstate]);
  26687. + }
  26688. +
  26689. + if ((status == VCHIQ_SUCCESS) &&
  26690. + (service->srvstate != VCHIQ_SRVSTATE_FREE))
  26691. + status = VCHIQ_ERROR;
  26692. +
  26693. + unlock_service(service);
  26694. +
  26695. + return status;
  26696. +}
  26697. +
  26698. +
  26699. +/* This function may be called by kernel threads or user threads.
  26700. + * User threads may receive VCHIQ_RETRY to indicate that a signal has been
  26701. + * received and the call should be retried after being returned to user
  26702. + * context.
  26703. + * When called in blocking mode, the userdata field points to a bulk_waiter
  26704. + * structure.
  26705. + */
  26706. +VCHIQ_STATUS_T
  26707. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  26708. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  26709. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir)
  26710. +{
  26711. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26712. + VCHIQ_BULK_QUEUE_T *queue;
  26713. + VCHIQ_BULK_T *bulk;
  26714. + VCHIQ_STATE_T *state;
  26715. + struct bulk_waiter *bulk_waiter = NULL;
  26716. + const char dir_char = (dir == VCHIQ_BULK_TRANSMIT) ? 't' : 'r';
  26717. + const int dir_msgtype = (dir == VCHIQ_BULK_TRANSMIT) ?
  26718. + VCHIQ_MSG_BULK_TX : VCHIQ_MSG_BULK_RX;
  26719. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  26720. +
  26721. + if (!service ||
  26722. + (service->srvstate != VCHIQ_SRVSTATE_OPEN) ||
  26723. + ((memhandle == VCHI_MEM_HANDLE_INVALID) && (offset == NULL)) ||
  26724. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  26725. + goto error_exit;
  26726. +
  26727. + switch (mode) {
  26728. + case VCHIQ_BULK_MODE_NOCALLBACK:
  26729. + case VCHIQ_BULK_MODE_CALLBACK:
  26730. + break;
  26731. + case VCHIQ_BULK_MODE_BLOCKING:
  26732. + bulk_waiter = (struct bulk_waiter *)userdata;
  26733. + sema_init(&bulk_waiter->event, 0);
  26734. + bulk_waiter->actual = 0;
  26735. + bulk_waiter->bulk = NULL;
  26736. + break;
  26737. + case VCHIQ_BULK_MODE_WAITING:
  26738. + bulk_waiter = (struct bulk_waiter *)userdata;
  26739. + bulk = bulk_waiter->bulk;
  26740. + goto waiting;
  26741. + default:
  26742. + goto error_exit;
  26743. + }
  26744. +
  26745. + state = service->state;
  26746. +
  26747. + queue = (dir == VCHIQ_BULK_TRANSMIT) ?
  26748. + &service->bulk_tx : &service->bulk_rx;
  26749. +
  26750. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0) {
  26751. + status = VCHIQ_RETRY;
  26752. + goto error_exit;
  26753. + }
  26754. +
  26755. + if (queue->local_insert == queue->remove + VCHIQ_NUM_SERVICE_BULKS) {
  26756. + VCHIQ_SERVICE_STATS_INC(service, bulk_stalls);
  26757. + do {
  26758. + mutex_unlock(&service->bulk_mutex);
  26759. + if (down_interruptible(&service->bulk_remove_event)
  26760. + != 0) {
  26761. + status = VCHIQ_RETRY;
  26762. + goto error_exit;
  26763. + }
  26764. + if (mutex_lock_interruptible(&service->bulk_mutex)
  26765. + != 0) {
  26766. + status = VCHIQ_RETRY;
  26767. + goto error_exit;
  26768. + }
  26769. + } while (queue->local_insert == queue->remove +
  26770. + VCHIQ_NUM_SERVICE_BULKS);
  26771. + }
  26772. +
  26773. + bulk = &queue->bulks[BULK_INDEX(queue->local_insert)];
  26774. +
  26775. + bulk->mode = mode;
  26776. + bulk->dir = dir;
  26777. + bulk->userdata = userdata;
  26778. + bulk->size = size;
  26779. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  26780. +
  26781. + if (vchiq_prepare_bulk_data(bulk, memhandle, offset, size, dir) !=
  26782. + VCHIQ_SUCCESS)
  26783. + goto unlock_error_exit;
  26784. +
  26785. + wmb();
  26786. +
  26787. + vchiq_log_info(vchiq_core_log_level,
  26788. + "%d: bt (%d->%d) %cx %x@%x %x",
  26789. + state->id,
  26790. + service->localport, service->remoteport, dir_char,
  26791. + size, (unsigned int)bulk->data, (unsigned int)userdata);
  26792. +
  26793. + if (state->is_master) {
  26794. + queue->local_insert++;
  26795. + if (resolve_bulks(service, queue))
  26796. + request_poll(state, service,
  26797. + (dir == VCHIQ_BULK_TRANSMIT) ?
  26798. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  26799. + } else {
  26800. + int payload[2] = { (int)bulk->data, bulk->size };
  26801. + VCHIQ_ELEMENT_T element = { payload, sizeof(payload) };
  26802. +
  26803. + status = queue_message(state, NULL,
  26804. + VCHIQ_MAKE_MSG(dir_msgtype,
  26805. + service->localport, service->remoteport),
  26806. + &element, 1, sizeof(payload), 1);
  26807. + if (status != VCHIQ_SUCCESS) {
  26808. + vchiq_complete_bulk(bulk);
  26809. + goto unlock_error_exit;
  26810. + }
  26811. + queue->local_insert++;
  26812. + }
  26813. +
  26814. + mutex_unlock(&service->bulk_mutex);
  26815. +
  26816. + vchiq_log_trace(vchiq_core_log_level,
  26817. + "%d: bt:%d %cx li=%x ri=%x p=%x",
  26818. + state->id,
  26819. + service->localport, dir_char,
  26820. + queue->local_insert, queue->remote_insert, queue->process);
  26821. +
  26822. +waiting:
  26823. + unlock_service(service);
  26824. +
  26825. + status = VCHIQ_SUCCESS;
  26826. +
  26827. + if (bulk_waiter) {
  26828. + bulk_waiter->bulk = bulk;
  26829. + if (down_interruptible(&bulk_waiter->event) != 0)
  26830. + status = VCHIQ_RETRY;
  26831. + else if (bulk_waiter->actual == VCHIQ_BULK_ACTUAL_ABORTED)
  26832. + status = VCHIQ_ERROR;
  26833. + }
  26834. +
  26835. + return status;
  26836. +
  26837. +unlock_error_exit:
  26838. + mutex_unlock(&service->bulk_mutex);
  26839. +
  26840. +error_exit:
  26841. + if (service)
  26842. + unlock_service(service);
  26843. + return status;
  26844. +}
  26845. +
  26846. +VCHIQ_STATUS_T
  26847. +vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T handle,
  26848. + const VCHIQ_ELEMENT_T *elements, unsigned int count)
  26849. +{
  26850. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26851. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  26852. +
  26853. + unsigned int size = 0;
  26854. + unsigned int i;
  26855. +
  26856. + if (!service ||
  26857. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  26858. + goto error_exit;
  26859. +
  26860. + for (i = 0; i < (unsigned int)count; i++) {
  26861. + if (elements[i].size) {
  26862. + if (elements[i].data == NULL) {
  26863. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  26864. + goto error_exit;
  26865. + }
  26866. + size += elements[i].size;
  26867. + }
  26868. + }
  26869. +
  26870. + if (size > VCHIQ_MAX_MSG_SIZE) {
  26871. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  26872. + goto error_exit;
  26873. + }
  26874. +
  26875. + switch (service->srvstate) {
  26876. + case VCHIQ_SRVSTATE_OPEN:
  26877. + status = queue_message(service->state, service,
  26878. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  26879. + service->localport,
  26880. + service->remoteport),
  26881. + elements, count, size, 1);
  26882. + break;
  26883. + case VCHIQ_SRVSTATE_OPENSYNC:
  26884. + status = queue_message_sync(service->state, service,
  26885. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  26886. + service->localport,
  26887. + service->remoteport),
  26888. + elements, count, size, 1);
  26889. + break;
  26890. + default:
  26891. + status = VCHIQ_ERROR;
  26892. + break;
  26893. + }
  26894. +
  26895. +error_exit:
  26896. + if (service)
  26897. + unlock_service(service);
  26898. +
  26899. + return status;
  26900. +}
  26901. +
  26902. +void
  26903. +vchiq_release_message(VCHIQ_SERVICE_HANDLE_T handle, VCHIQ_HEADER_T *header)
  26904. +{
  26905. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26906. + VCHIQ_SHARED_STATE_T *remote;
  26907. + VCHIQ_STATE_T *state;
  26908. + int slot_index;
  26909. +
  26910. + if (!service)
  26911. + return;
  26912. +
  26913. + state = service->state;
  26914. + remote = state->remote;
  26915. +
  26916. + slot_index = SLOT_INDEX_FROM_DATA(state, (void *)header);
  26917. +
  26918. + if ((slot_index >= remote->slot_first) &&
  26919. + (slot_index <= remote->slot_last)) {
  26920. + int msgid = header->msgid;
  26921. + if (msgid & VCHIQ_MSGID_CLAIMED) {
  26922. + VCHIQ_SLOT_INFO_T *slot_info =
  26923. + SLOT_INFO_FROM_INDEX(state, slot_index);
  26924. +
  26925. + release_slot(state, slot_info, header, service);
  26926. + }
  26927. + } else if (slot_index == remote->slot_sync)
  26928. + release_message_sync(state, header);
  26929. +
  26930. + unlock_service(service);
  26931. +}
  26932. +
  26933. +static void
  26934. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  26935. +{
  26936. + header->msgid = VCHIQ_MSGID_PADDING;
  26937. + wmb();
  26938. + remote_event_signal(&state->remote->sync_release);
  26939. +}
  26940. +
  26941. +VCHIQ_STATUS_T
  26942. +vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle, short *peer_version)
  26943. +{
  26944. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  26945. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26946. +
  26947. + if (!service ||
  26948. + (vchiq_check_service(service) != VCHIQ_SUCCESS) ||
  26949. + !peer_version)
  26950. + goto exit;
  26951. + *peer_version = service->peer_version;
  26952. + status = VCHIQ_SUCCESS;
  26953. +
  26954. +exit:
  26955. + if (service)
  26956. + unlock_service(service);
  26957. + return status;
  26958. +}
  26959. +
  26960. +VCHIQ_STATUS_T
  26961. +vchiq_get_config(VCHIQ_INSTANCE_T instance,
  26962. + int config_size, VCHIQ_CONFIG_T *pconfig)
  26963. +{
  26964. + VCHIQ_CONFIG_T config;
  26965. +
  26966. + (void)instance;
  26967. +
  26968. + config.max_msg_size = VCHIQ_MAX_MSG_SIZE;
  26969. + config.bulk_threshold = VCHIQ_MAX_MSG_SIZE;
  26970. + config.max_outstanding_bulks = VCHIQ_NUM_SERVICE_BULKS;
  26971. + config.max_services = VCHIQ_MAX_SERVICES;
  26972. + config.version = VCHIQ_VERSION;
  26973. + config.version_min = VCHIQ_VERSION_MIN;
  26974. +
  26975. + if (config_size > sizeof(VCHIQ_CONFIG_T))
  26976. + return VCHIQ_ERROR;
  26977. +
  26978. + memcpy(pconfig, &config,
  26979. + min(config_size, (int)(sizeof(VCHIQ_CONFIG_T))));
  26980. +
  26981. + return VCHIQ_SUCCESS;
  26982. +}
  26983. +
  26984. +VCHIQ_STATUS_T
  26985. +vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T handle,
  26986. + VCHIQ_SERVICE_OPTION_T option, int value)
  26987. +{
  26988. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26989. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  26990. +
  26991. + if (service) {
  26992. + switch (option) {
  26993. + case VCHIQ_SERVICE_OPTION_AUTOCLOSE:
  26994. + service->auto_close = value;
  26995. + status = VCHIQ_SUCCESS;
  26996. + break;
  26997. +
  26998. + case VCHIQ_SERVICE_OPTION_SLOT_QUOTA: {
  26999. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  27000. + &service->state->service_quotas[
  27001. + service->localport];
  27002. + if (value == 0)
  27003. + value = service->state->default_slot_quota;
  27004. + if ((value >= service_quota->slot_use_count) &&
  27005. + (value < (unsigned short)~0)) {
  27006. + service_quota->slot_quota = value;
  27007. + if ((value >= service_quota->slot_use_count) &&
  27008. + (service_quota->message_quota >=
  27009. + service_quota->message_use_count)) {
  27010. + /* Signal the service that it may have
  27011. + ** dropped below its quota */
  27012. + up(&service_quota->quota_event);
  27013. + }
  27014. + status = VCHIQ_SUCCESS;
  27015. + }
  27016. + } break;
  27017. +
  27018. + case VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA: {
  27019. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  27020. + &service->state->service_quotas[
  27021. + service->localport];
  27022. + if (value == 0)
  27023. + value = service->state->default_message_quota;
  27024. + if ((value >= service_quota->message_use_count) &&
  27025. + (value < (unsigned short)~0)) {
  27026. + service_quota->message_quota = value;
  27027. + if ((value >=
  27028. + service_quota->message_use_count) &&
  27029. + (service_quota->slot_quota >=
  27030. + service_quota->slot_use_count))
  27031. + /* Signal the service that it may have
  27032. + ** dropped below its quota */
  27033. + up(&service_quota->quota_event);
  27034. + status = VCHIQ_SUCCESS;
  27035. + }
  27036. + } break;
  27037. +
  27038. + case VCHIQ_SERVICE_OPTION_SYNCHRONOUS:
  27039. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  27040. + (service->srvstate ==
  27041. + VCHIQ_SRVSTATE_LISTENING)) {
  27042. + service->sync = value;
  27043. + status = VCHIQ_SUCCESS;
  27044. + }
  27045. + break;
  27046. +
  27047. + default:
  27048. + break;
  27049. + }
  27050. + unlock_service(service);
  27051. + }
  27052. +
  27053. + return status;
  27054. +}
  27055. +
  27056. +void
  27057. +vchiq_dump_shared_state(void *dump_context, VCHIQ_STATE_T *state,
  27058. + VCHIQ_SHARED_STATE_T *shared, const char *label)
  27059. +{
  27060. + static const char *const debug_names[] = {
  27061. + "<entries>",
  27062. + "SLOT_HANDLER_COUNT",
  27063. + "SLOT_HANDLER_LINE",
  27064. + "PARSE_LINE",
  27065. + "PARSE_HEADER",
  27066. + "PARSE_MSGID",
  27067. + "AWAIT_COMPLETION_LINE",
  27068. + "DEQUEUE_MESSAGE_LINE",
  27069. + "SERVICE_CALLBACK_LINE",
  27070. + "MSG_QUEUE_FULL_COUNT",
  27071. + "COMPLETION_QUEUE_FULL_COUNT"
  27072. + };
  27073. + int i;
  27074. +
  27075. + char buf[80];
  27076. + int len;
  27077. + len = snprintf(buf, sizeof(buf),
  27078. + " %s: slots %d-%d tx_pos=%x recycle=%x",
  27079. + label, shared->slot_first, shared->slot_last,
  27080. + shared->tx_pos, shared->slot_queue_recycle);
  27081. + vchiq_dump(dump_context, buf, len + 1);
  27082. +
  27083. + len = snprintf(buf, sizeof(buf),
  27084. + " Slots claimed:");
  27085. + vchiq_dump(dump_context, buf, len + 1);
  27086. +
  27087. + for (i = shared->slot_first; i <= shared->slot_last; i++) {
  27088. + VCHIQ_SLOT_INFO_T slot_info = *SLOT_INFO_FROM_INDEX(state, i);
  27089. + if (slot_info.use_count != slot_info.release_count) {
  27090. + len = snprintf(buf, sizeof(buf),
  27091. + " %d: %d/%d", i, slot_info.use_count,
  27092. + slot_info.release_count);
  27093. + vchiq_dump(dump_context, buf, len + 1);
  27094. + }
  27095. + }
  27096. +
  27097. + for (i = 1; i < shared->debug[DEBUG_ENTRIES]; i++) {
  27098. + len = snprintf(buf, sizeof(buf), " DEBUG: %s = %d(%x)",
  27099. + debug_names[i], shared->debug[i], shared->debug[i]);
  27100. + vchiq_dump(dump_context, buf, len + 1);
  27101. + }
  27102. +}
  27103. +
  27104. +void
  27105. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state)
  27106. +{
  27107. + char buf[80];
  27108. + int len;
  27109. + int i;
  27110. +
  27111. + len = snprintf(buf, sizeof(buf), "State %d: %s", state->id,
  27112. + conn_state_names[state->conn_state]);
  27113. + vchiq_dump(dump_context, buf, len + 1);
  27114. +
  27115. + len = snprintf(buf, sizeof(buf),
  27116. + " tx_pos=%x(@%x), rx_pos=%x(@%x)",
  27117. + state->local->tx_pos,
  27118. + (uint32_t)state->tx_data +
  27119. + (state->local_tx_pos & VCHIQ_SLOT_MASK),
  27120. + state->rx_pos,
  27121. + (uint32_t)state->rx_data +
  27122. + (state->rx_pos & VCHIQ_SLOT_MASK));
  27123. + vchiq_dump(dump_context, buf, len + 1);
  27124. +
  27125. + len = snprintf(buf, sizeof(buf),
  27126. + " Version: %d (min %d)",
  27127. + VCHIQ_VERSION, VCHIQ_VERSION_MIN);
  27128. + vchiq_dump(dump_context, buf, len + 1);
  27129. +
  27130. + if (VCHIQ_ENABLE_STATS) {
  27131. + len = snprintf(buf, sizeof(buf),
  27132. + " Stats: ctrl_tx_count=%d, ctrl_rx_count=%d, "
  27133. + "error_count=%d",
  27134. + state->stats.ctrl_tx_count, state->stats.ctrl_rx_count,
  27135. + state->stats.error_count);
  27136. + vchiq_dump(dump_context, buf, len + 1);
  27137. + }
  27138. +
  27139. + len = snprintf(buf, sizeof(buf),
  27140. + " Slots: %d available (%d data), %d recyclable, %d stalls "
  27141. + "(%d data)",
  27142. + ((state->slot_queue_available * VCHIQ_SLOT_SIZE) -
  27143. + state->local_tx_pos) / VCHIQ_SLOT_SIZE,
  27144. + state->data_quota - state->data_use_count,
  27145. + state->local->slot_queue_recycle - state->slot_queue_available,
  27146. + state->stats.slot_stalls, state->stats.data_stalls);
  27147. + vchiq_dump(dump_context, buf, len + 1);
  27148. +
  27149. + vchiq_dump_platform_state(dump_context);
  27150. +
  27151. + vchiq_dump_shared_state(dump_context, state, state->local, "Local");
  27152. + vchiq_dump_shared_state(dump_context, state, state->remote, "Remote");
  27153. +
  27154. + vchiq_dump_platform_instances(dump_context);
  27155. +
  27156. + for (i = 0; i < state->unused_service; i++) {
  27157. + VCHIQ_SERVICE_T *service = find_service_by_port(state, i);
  27158. +
  27159. + if (service) {
  27160. + vchiq_dump_service_state(dump_context, service);
  27161. + unlock_service(service);
  27162. + }
  27163. + }
  27164. +}
  27165. +
  27166. +void
  27167. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  27168. +{
  27169. + char buf[80];
  27170. + int len;
  27171. +
  27172. + len = snprintf(buf, sizeof(buf), "Service %d: %s (ref %u)",
  27173. + service->localport, srvstate_names[service->srvstate],
  27174. + service->ref_count - 1); /*Don't include the lock just taken*/
  27175. +
  27176. + if (service->srvstate != VCHIQ_SRVSTATE_FREE) {
  27177. + char remoteport[30];
  27178. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  27179. + &service->state->service_quotas[service->localport];
  27180. + int fourcc = service->base.fourcc;
  27181. + int tx_pending, rx_pending;
  27182. + if (service->remoteport != VCHIQ_PORT_FREE) {
  27183. + int len2 = snprintf(remoteport, sizeof(remoteport),
  27184. + "%d", service->remoteport);
  27185. + if (service->public_fourcc != VCHIQ_FOURCC_INVALID)
  27186. + snprintf(remoteport + len2,
  27187. + sizeof(remoteport) - len2,
  27188. + " (client %x)", service->client_id);
  27189. + } else
  27190. + strcpy(remoteport, "n/a");
  27191. +
  27192. + len += snprintf(buf + len, sizeof(buf) - len,
  27193. + " '%c%c%c%c' remote %s (msg use %d/%d, slot use %d/%d)",
  27194. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  27195. + remoteport,
  27196. + service_quota->message_use_count,
  27197. + service_quota->message_quota,
  27198. + service_quota->slot_use_count,
  27199. + service_quota->slot_quota);
  27200. +
  27201. + vchiq_dump(dump_context, buf, len + 1);
  27202. +
  27203. + tx_pending = service->bulk_tx.local_insert -
  27204. + service->bulk_tx.remote_insert;
  27205. +
  27206. + rx_pending = service->bulk_rx.local_insert -
  27207. + service->bulk_rx.remote_insert;
  27208. +
  27209. + len = snprintf(buf, sizeof(buf),
  27210. + " Bulk: tx_pending=%d (size %d),"
  27211. + " rx_pending=%d (size %d)",
  27212. + tx_pending,
  27213. + tx_pending ? service->bulk_tx.bulks[
  27214. + BULK_INDEX(service->bulk_tx.remove)].size : 0,
  27215. + rx_pending,
  27216. + rx_pending ? service->bulk_rx.bulks[
  27217. + BULK_INDEX(service->bulk_rx.remove)].size : 0);
  27218. +
  27219. + if (VCHIQ_ENABLE_STATS) {
  27220. + vchiq_dump(dump_context, buf, len + 1);
  27221. +
  27222. + len = snprintf(buf, sizeof(buf),
  27223. + " Ctrl: tx_count=%d, tx_bytes=%llu, "
  27224. + "rx_count=%d, rx_bytes=%llu",
  27225. + service->stats.ctrl_tx_count,
  27226. + service->stats.ctrl_tx_bytes,
  27227. + service->stats.ctrl_rx_count,
  27228. + service->stats.ctrl_rx_bytes);
  27229. + vchiq_dump(dump_context, buf, len + 1);
  27230. +
  27231. + len = snprintf(buf, sizeof(buf),
  27232. + " Bulk: tx_count=%d, tx_bytes=%llu, "
  27233. + "rx_count=%d, rx_bytes=%llu",
  27234. + service->stats.bulk_tx_count,
  27235. + service->stats.bulk_tx_bytes,
  27236. + service->stats.bulk_rx_count,
  27237. + service->stats.bulk_rx_bytes);
  27238. + vchiq_dump(dump_context, buf, len + 1);
  27239. +
  27240. + len = snprintf(buf, sizeof(buf),
  27241. + " %d quota stalls, %d slot stalls, "
  27242. + "%d bulk stalls, %d aborted, %d errors",
  27243. + service->stats.quota_stalls,
  27244. + service->stats.slot_stalls,
  27245. + service->stats.bulk_stalls,
  27246. + service->stats.bulk_aborted_count,
  27247. + service->stats.error_count);
  27248. + }
  27249. + }
  27250. +
  27251. + vchiq_dump(dump_context, buf, len + 1);
  27252. +
  27253. + if (service->srvstate != VCHIQ_SRVSTATE_FREE)
  27254. + vchiq_dump_platform_service_state(dump_context, service);
  27255. +}
  27256. +
  27257. +
  27258. +void
  27259. +vchiq_loud_error_header(void)
  27260. +{
  27261. + vchiq_log_error(vchiq_core_log_level,
  27262. + "============================================================"
  27263. + "================");
  27264. + vchiq_log_error(vchiq_core_log_level,
  27265. + "============================================================"
  27266. + "================");
  27267. + vchiq_log_error(vchiq_core_log_level, "=====");
  27268. +}
  27269. +
  27270. +void
  27271. +vchiq_loud_error_footer(void)
  27272. +{
  27273. + vchiq_log_error(vchiq_core_log_level, "=====");
  27274. + vchiq_log_error(vchiq_core_log_level,
  27275. + "============================================================"
  27276. + "================");
  27277. + vchiq_log_error(vchiq_core_log_level,
  27278. + "============================================================"
  27279. + "================");
  27280. +}
  27281. +
  27282. +
  27283. +VCHIQ_STATUS_T vchiq_send_remote_use(VCHIQ_STATE_T *state)
  27284. +{
  27285. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  27286. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  27287. + status = queue_message(state, NULL,
  27288. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE, 0, 0),
  27289. + NULL, 0, 0, 0);
  27290. + return status;
  27291. +}
  27292. +
  27293. +VCHIQ_STATUS_T vchiq_send_remote_release(VCHIQ_STATE_T *state)
  27294. +{
  27295. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  27296. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  27297. + status = queue_message(state, NULL,
  27298. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_RELEASE, 0, 0),
  27299. + NULL, 0, 0, 0);
  27300. + return status;
  27301. +}
  27302. +
  27303. +VCHIQ_STATUS_T vchiq_send_remote_use_active(VCHIQ_STATE_T *state)
  27304. +{
  27305. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  27306. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  27307. + status = queue_message(state, NULL,
  27308. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE_ACTIVE, 0, 0),
  27309. + NULL, 0, 0, 0);
  27310. + return status;
  27311. +}
  27312. +
  27313. +void vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  27314. + size_t numBytes)
  27315. +{
  27316. + const uint8_t *mem = (const uint8_t *)voidMem;
  27317. + size_t offset;
  27318. + char lineBuf[100];
  27319. + char *s;
  27320. +
  27321. + while (numBytes > 0) {
  27322. + s = lineBuf;
  27323. +
  27324. + for (offset = 0; offset < 16; offset++) {
  27325. + if (offset < numBytes)
  27326. + s += snprintf(s, 4, "%02x ", mem[offset]);
  27327. + else
  27328. + s += snprintf(s, 4, " ");
  27329. + }
  27330. +
  27331. + for (offset = 0; offset < 16; offset++) {
  27332. + if (offset < numBytes) {
  27333. + uint8_t ch = mem[offset];
  27334. +
  27335. + if ((ch < ' ') || (ch > '~'))
  27336. + ch = '.';
  27337. + *s++ = (char)ch;
  27338. + }
  27339. + }
  27340. + *s++ = '\0';
  27341. +
  27342. + if ((label != NULL) && (*label != '\0'))
  27343. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  27344. + "%s: %08x: %s", label, addr, lineBuf);
  27345. + else
  27346. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  27347. + "%08x: %s", addr, lineBuf);
  27348. +
  27349. + addr += 16;
  27350. + mem += 16;
  27351. + if (numBytes > 16)
  27352. + numBytes -= 16;
  27353. + else
  27354. + numBytes = 0;
  27355. + }
  27356. +}
  27357. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h
  27358. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 1970-01-01 01:00:00.000000000 +0100
  27359. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 2014-02-18 11:52:14.000000000 +0100
  27360. @@ -0,0 +1,706 @@
  27361. +/**
  27362. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  27363. + *
  27364. + * Redistribution and use in source and binary forms, with or without
  27365. + * modification, are permitted provided that the following conditions
  27366. + * are met:
  27367. + * 1. Redistributions of source code must retain the above copyright
  27368. + * notice, this list of conditions, and the following disclaimer,
  27369. + * without modification.
  27370. + * 2. Redistributions in binary form must reproduce the above copyright
  27371. + * notice, this list of conditions and the following disclaimer in the
  27372. + * documentation and/or other materials provided with the distribution.
  27373. + * 3. The names of the above-listed copyright holders may not be used
  27374. + * to endorse or promote products derived from this software without
  27375. + * specific prior written permission.
  27376. + *
  27377. + * ALTERNATIVELY, this software may be distributed under the terms of the
  27378. + * GNU General Public License ("GPL") version 2, as published by the Free
  27379. + * Software Foundation.
  27380. + *
  27381. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27382. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  27383. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27384. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27385. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27386. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27387. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27388. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27389. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27390. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27391. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27392. + */
  27393. +
  27394. +#ifndef VCHIQ_CORE_H
  27395. +#define VCHIQ_CORE_H
  27396. +
  27397. +#include <linux/mutex.h>
  27398. +#include <linux/semaphore.h>
  27399. +#include <linux/kthread.h>
  27400. +
  27401. +#include "vchiq_cfg.h"
  27402. +
  27403. +#include "vchiq.h"
  27404. +
  27405. +/* Run time control of log level, based on KERN_XXX level. */
  27406. +#define VCHIQ_LOG_DEFAULT 4
  27407. +#define VCHIQ_LOG_ERROR 3
  27408. +#define VCHIQ_LOG_WARNING 4
  27409. +#define VCHIQ_LOG_INFO 6
  27410. +#define VCHIQ_LOG_TRACE 7
  27411. +
  27412. +#define VCHIQ_LOG_PREFIX KERN_INFO "vchiq: "
  27413. +
  27414. +#ifndef vchiq_log_error
  27415. +#define vchiq_log_error(cat, fmt, ...) \
  27416. + do { if (cat >= VCHIQ_LOG_ERROR) \
  27417. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  27418. +#endif
  27419. +#ifndef vchiq_log_warning
  27420. +#define vchiq_log_warning(cat, fmt, ...) \
  27421. + do { if (cat >= VCHIQ_LOG_WARNING) \
  27422. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  27423. +#endif
  27424. +#ifndef vchiq_log_info
  27425. +#define vchiq_log_info(cat, fmt, ...) \
  27426. + do { if (cat >= VCHIQ_LOG_INFO) \
  27427. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  27428. +#endif
  27429. +#ifndef vchiq_log_trace
  27430. +#define vchiq_log_trace(cat, fmt, ...) \
  27431. + do { if (cat >= VCHIQ_LOG_TRACE) \
  27432. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  27433. +#endif
  27434. +
  27435. +#define vchiq_loud_error(...) \
  27436. + vchiq_log_error(vchiq_core_log_level, "===== " __VA_ARGS__)
  27437. +
  27438. +#ifndef vchiq_static_assert
  27439. +#define vchiq_static_assert(cond) __attribute__((unused)) \
  27440. + extern int vchiq_static_assert[(cond) ? 1 : -1]
  27441. +#endif
  27442. +
  27443. +#define IS_POW2(x) (x && ((x & (x - 1)) == 0))
  27444. +
  27445. +/* Ensure that the slot size and maximum number of slots are powers of 2 */
  27446. +vchiq_static_assert(IS_POW2(VCHIQ_SLOT_SIZE));
  27447. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS));
  27448. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS_PER_SIDE));
  27449. +
  27450. +#define VCHIQ_SLOT_MASK (VCHIQ_SLOT_SIZE - 1)
  27451. +#define VCHIQ_SLOT_QUEUE_MASK (VCHIQ_MAX_SLOTS_PER_SIDE - 1)
  27452. +#define VCHIQ_SLOT_ZERO_SLOTS ((sizeof(VCHIQ_SLOT_ZERO_T) + \
  27453. + VCHIQ_SLOT_SIZE - 1) / VCHIQ_SLOT_SIZE)
  27454. +
  27455. +#define VCHIQ_MSG_PADDING 0 /* - */
  27456. +#define VCHIQ_MSG_CONNECT 1 /* - */
  27457. +#define VCHIQ_MSG_OPEN 2 /* + (srcport, -), fourcc, client_id */
  27458. +#define VCHIQ_MSG_OPENACK 3 /* + (srcport, dstport) */
  27459. +#define VCHIQ_MSG_CLOSE 4 /* + (srcport, dstport) */
  27460. +#define VCHIQ_MSG_DATA 5 /* + (srcport, dstport) */
  27461. +#define VCHIQ_MSG_BULK_RX 6 /* + (srcport, dstport), data, size */
  27462. +#define VCHIQ_MSG_BULK_TX 7 /* + (srcport, dstport), data, size */
  27463. +#define VCHIQ_MSG_BULK_RX_DONE 8 /* + (srcport, dstport), actual */
  27464. +#define VCHIQ_MSG_BULK_TX_DONE 9 /* + (srcport, dstport), actual */
  27465. +#define VCHIQ_MSG_PAUSE 10 /* - */
  27466. +#define VCHIQ_MSG_RESUME 11 /* - */
  27467. +#define VCHIQ_MSG_REMOTE_USE 12 /* - */
  27468. +#define VCHIQ_MSG_REMOTE_RELEASE 13 /* - */
  27469. +#define VCHIQ_MSG_REMOTE_USE_ACTIVE 14 /* - */
  27470. +
  27471. +#define VCHIQ_PORT_MAX (VCHIQ_MAX_SERVICES - 1)
  27472. +#define VCHIQ_PORT_FREE 0x1000
  27473. +#define VCHIQ_PORT_IS_VALID(port) (port < VCHIQ_PORT_FREE)
  27474. +#define VCHIQ_MAKE_MSG(type, srcport, dstport) \
  27475. + ((type<<24) | (srcport<<12) | (dstport<<0))
  27476. +#define VCHIQ_MSG_TYPE(msgid) ((unsigned int)msgid >> 24)
  27477. +#define VCHIQ_MSG_SRCPORT(msgid) \
  27478. + (unsigned short)(((unsigned int)msgid >> 12) & 0xfff)
  27479. +#define VCHIQ_MSG_DSTPORT(msgid) \
  27480. + ((unsigned short)msgid & 0xfff)
  27481. +
  27482. +#define VCHIQ_FOURCC_AS_4CHARS(fourcc) \
  27483. + ((fourcc) >> 24) & 0xff, \
  27484. + ((fourcc) >> 16) & 0xff, \
  27485. + ((fourcc) >> 8) & 0xff, \
  27486. + (fourcc) & 0xff
  27487. +
  27488. +/* Ensure the fields are wide enough */
  27489. +vchiq_static_assert(VCHIQ_MSG_SRCPORT(VCHIQ_MAKE_MSG(0, 0, VCHIQ_PORT_MAX))
  27490. + == 0);
  27491. +vchiq_static_assert(VCHIQ_MSG_TYPE(VCHIQ_MAKE_MSG(0, VCHIQ_PORT_MAX, 0)) == 0);
  27492. +vchiq_static_assert((unsigned int)VCHIQ_PORT_MAX <
  27493. + (unsigned int)VCHIQ_PORT_FREE);
  27494. +
  27495. +#define VCHIQ_MSGID_PADDING VCHIQ_MAKE_MSG(VCHIQ_MSG_PADDING, 0, 0)
  27496. +#define VCHIQ_MSGID_CLAIMED 0x40000000
  27497. +
  27498. +#define VCHIQ_FOURCC_INVALID 0x00000000
  27499. +#define VCHIQ_FOURCC_IS_LEGAL(fourcc) (fourcc != VCHIQ_FOURCC_INVALID)
  27500. +
  27501. +#define VCHIQ_BULK_ACTUAL_ABORTED -1
  27502. +
  27503. +typedef uint32_t BITSET_T;
  27504. +
  27505. +vchiq_static_assert((sizeof(BITSET_T) * 8) == 32);
  27506. +
  27507. +#define BITSET_SIZE(b) ((b + 31) >> 5)
  27508. +#define BITSET_WORD(b) (b >> 5)
  27509. +#define BITSET_BIT(b) (1 << (b & 31))
  27510. +#define BITSET_ZERO(bs) memset(bs, 0, sizeof(bs))
  27511. +#define BITSET_IS_SET(bs, b) (bs[BITSET_WORD(b)] & BITSET_BIT(b))
  27512. +#define BITSET_SET(bs, b) (bs[BITSET_WORD(b)] |= BITSET_BIT(b))
  27513. +#define BITSET_CLR(bs, b) (bs[BITSET_WORD(b)] &= ~BITSET_BIT(b))
  27514. +
  27515. +#if VCHIQ_ENABLE_STATS
  27516. +#define VCHIQ_STATS_INC(state, stat) (state->stats. stat++)
  27517. +#define VCHIQ_SERVICE_STATS_INC(service, stat) (service->stats. stat++)
  27518. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) \
  27519. + (service->stats. stat += addend)
  27520. +#else
  27521. +#define VCHIQ_STATS_INC(state, stat) ((void)0)
  27522. +#define VCHIQ_SERVICE_STATS_INC(service, stat) ((void)0)
  27523. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) ((void)0)
  27524. +#endif
  27525. +
  27526. +enum {
  27527. + DEBUG_ENTRIES,
  27528. +#if VCHIQ_ENABLE_DEBUG
  27529. + DEBUG_SLOT_HANDLER_COUNT,
  27530. + DEBUG_SLOT_HANDLER_LINE,
  27531. + DEBUG_PARSE_LINE,
  27532. + DEBUG_PARSE_HEADER,
  27533. + DEBUG_PARSE_MSGID,
  27534. + DEBUG_AWAIT_COMPLETION_LINE,
  27535. + DEBUG_DEQUEUE_MESSAGE_LINE,
  27536. + DEBUG_SERVICE_CALLBACK_LINE,
  27537. + DEBUG_MSG_QUEUE_FULL_COUNT,
  27538. + DEBUG_COMPLETION_QUEUE_FULL_COUNT,
  27539. +#endif
  27540. + DEBUG_MAX
  27541. +};
  27542. +
  27543. +#if VCHIQ_ENABLE_DEBUG
  27544. +
  27545. +#define DEBUG_INITIALISE(local) int *debug_ptr = (local)->debug;
  27546. +#define DEBUG_TRACE(d) \
  27547. + do { debug_ptr[DEBUG_ ## d] = __LINE__; dsb(); } while (0)
  27548. +#define DEBUG_VALUE(d, v) \
  27549. + do { debug_ptr[DEBUG_ ## d] = (v); dsb(); } while (0)
  27550. +#define DEBUG_COUNT(d) \
  27551. + do { debug_ptr[DEBUG_ ## d]++; dsb(); } while (0)
  27552. +
  27553. +#else /* VCHIQ_ENABLE_DEBUG */
  27554. +
  27555. +#define DEBUG_INITIALISE(local)
  27556. +#define DEBUG_TRACE(d)
  27557. +#define DEBUG_VALUE(d, v)
  27558. +#define DEBUG_COUNT(d)
  27559. +
  27560. +#endif /* VCHIQ_ENABLE_DEBUG */
  27561. +
  27562. +typedef enum {
  27563. + VCHIQ_CONNSTATE_DISCONNECTED,
  27564. + VCHIQ_CONNSTATE_CONNECTING,
  27565. + VCHIQ_CONNSTATE_CONNECTED,
  27566. + VCHIQ_CONNSTATE_PAUSING,
  27567. + VCHIQ_CONNSTATE_PAUSE_SENT,
  27568. + VCHIQ_CONNSTATE_PAUSED,
  27569. + VCHIQ_CONNSTATE_RESUMING,
  27570. + VCHIQ_CONNSTATE_PAUSE_TIMEOUT,
  27571. + VCHIQ_CONNSTATE_RESUME_TIMEOUT
  27572. +} VCHIQ_CONNSTATE_T;
  27573. +
  27574. +enum {
  27575. + VCHIQ_SRVSTATE_FREE,
  27576. + VCHIQ_SRVSTATE_HIDDEN,
  27577. + VCHIQ_SRVSTATE_LISTENING,
  27578. + VCHIQ_SRVSTATE_OPENING,
  27579. + VCHIQ_SRVSTATE_OPEN,
  27580. + VCHIQ_SRVSTATE_OPENSYNC,
  27581. + VCHIQ_SRVSTATE_CLOSESENT,
  27582. + VCHIQ_SRVSTATE_CLOSERECVD,
  27583. + VCHIQ_SRVSTATE_CLOSEWAIT,
  27584. + VCHIQ_SRVSTATE_CLOSED
  27585. +};
  27586. +
  27587. +enum {
  27588. + VCHIQ_POLL_TERMINATE,
  27589. + VCHIQ_POLL_REMOVE,
  27590. + VCHIQ_POLL_TXNOTIFY,
  27591. + VCHIQ_POLL_RXNOTIFY,
  27592. + VCHIQ_POLL_COUNT
  27593. +};
  27594. +
  27595. +typedef enum {
  27596. + VCHIQ_BULK_TRANSMIT,
  27597. + VCHIQ_BULK_RECEIVE
  27598. +} VCHIQ_BULK_DIR_T;
  27599. +
  27600. +typedef void (*VCHIQ_USERDATA_TERM_T)(void *userdata);
  27601. +
  27602. +typedef struct vchiq_bulk_struct {
  27603. + short mode;
  27604. + short dir;
  27605. + void *userdata;
  27606. + VCHI_MEM_HANDLE_T handle;
  27607. + void *data;
  27608. + int size;
  27609. + void *remote_data;
  27610. + int remote_size;
  27611. + int actual;
  27612. +} VCHIQ_BULK_T;
  27613. +
  27614. +typedef struct vchiq_bulk_queue_struct {
  27615. + int local_insert; /* Where to insert the next local bulk */
  27616. + int remote_insert; /* Where to insert the next remote bulk (master) */
  27617. + int process; /* Bulk to transfer next */
  27618. + int remote_notify; /* Bulk to notify the remote client of next (mstr) */
  27619. + int remove; /* Bulk to notify the local client of, and remove,
  27620. + ** next */
  27621. + VCHIQ_BULK_T bulks[VCHIQ_NUM_SERVICE_BULKS];
  27622. +} VCHIQ_BULK_QUEUE_T;
  27623. +
  27624. +typedef struct remote_event_struct {
  27625. + int armed;
  27626. + int fired;
  27627. + struct semaphore *event;
  27628. +} REMOTE_EVENT_T;
  27629. +
  27630. +typedef struct opaque_platform_state_t *VCHIQ_PLATFORM_STATE_T;
  27631. +
  27632. +typedef struct vchiq_state_struct VCHIQ_STATE_T;
  27633. +
  27634. +typedef struct vchiq_slot_struct {
  27635. + char data[VCHIQ_SLOT_SIZE];
  27636. +} VCHIQ_SLOT_T;
  27637. +
  27638. +typedef struct vchiq_slot_info_struct {
  27639. + /* Use two counters rather than one to avoid the need for a mutex. */
  27640. + short use_count;
  27641. + short release_count;
  27642. +} VCHIQ_SLOT_INFO_T;
  27643. +
  27644. +typedef struct vchiq_service_struct {
  27645. + VCHIQ_SERVICE_BASE_T base;
  27646. + VCHIQ_SERVICE_HANDLE_T handle;
  27647. + unsigned int ref_count;
  27648. + int srvstate;
  27649. + VCHIQ_USERDATA_TERM_T userdata_term;
  27650. + unsigned int localport;
  27651. + unsigned int remoteport;
  27652. + int public_fourcc;
  27653. + int client_id;
  27654. + char auto_close;
  27655. + char sync;
  27656. + char closing;
  27657. + atomic_t poll_flags;
  27658. + short version;
  27659. + short version_min;
  27660. + short peer_version;
  27661. +
  27662. + VCHIQ_STATE_T *state;
  27663. + VCHIQ_INSTANCE_T instance;
  27664. +
  27665. + int service_use_count;
  27666. +
  27667. + VCHIQ_BULK_QUEUE_T bulk_tx;
  27668. + VCHIQ_BULK_QUEUE_T bulk_rx;
  27669. +
  27670. + struct semaphore remove_event;
  27671. + struct semaphore bulk_remove_event;
  27672. + struct mutex bulk_mutex;
  27673. +
  27674. + struct service_stats_struct {
  27675. + int quota_stalls;
  27676. + int slot_stalls;
  27677. + int bulk_stalls;
  27678. + int error_count;
  27679. + int ctrl_tx_count;
  27680. + int ctrl_rx_count;
  27681. + int bulk_tx_count;
  27682. + int bulk_rx_count;
  27683. + int bulk_aborted_count;
  27684. + uint64_t ctrl_tx_bytes;
  27685. + uint64_t ctrl_rx_bytes;
  27686. + uint64_t bulk_tx_bytes;
  27687. + uint64_t bulk_rx_bytes;
  27688. + } stats;
  27689. +} VCHIQ_SERVICE_T;
  27690. +
  27691. +/* The quota information is outside VCHIQ_SERVICE_T so that it can be
  27692. + statically allocated, since for accounting reasons a service's slot
  27693. + usage is carried over between users of the same port number.
  27694. + */
  27695. +typedef struct vchiq_service_quota_struct {
  27696. + unsigned short slot_quota;
  27697. + unsigned short slot_use_count;
  27698. + unsigned short message_quota;
  27699. + unsigned short message_use_count;
  27700. + struct semaphore quota_event;
  27701. + int previous_tx_index;
  27702. +} VCHIQ_SERVICE_QUOTA_T;
  27703. +
  27704. +typedef struct vchiq_shared_state_struct {
  27705. +
  27706. + /* A non-zero value here indicates that the content is valid. */
  27707. + int initialised;
  27708. +
  27709. + /* The first and last (inclusive) slots allocated to the owner. */
  27710. + int slot_first;
  27711. + int slot_last;
  27712. +
  27713. + /* The slot allocated to synchronous messages from the owner. */
  27714. + int slot_sync;
  27715. +
  27716. + /* Signalling this event indicates that owner's slot handler thread
  27717. + ** should run. */
  27718. + REMOTE_EVENT_T trigger;
  27719. +
  27720. + /* Indicates the byte position within the stream where the next message
  27721. + ** will be written. The least significant bits are an index into the
  27722. + ** slot. The next bits are the index of the slot in slot_queue. */
  27723. + int tx_pos;
  27724. +
  27725. + /* This event should be signalled when a slot is recycled. */
  27726. + REMOTE_EVENT_T recycle;
  27727. +
  27728. + /* The slot_queue index where the next recycled slot will be written. */
  27729. + int slot_queue_recycle;
  27730. +
  27731. + /* This event should be signalled when a synchronous message is sent. */
  27732. + REMOTE_EVENT_T sync_trigger;
  27733. +
  27734. + /* This event should be signalled when a synchronous message has been
  27735. + ** released. */
  27736. + REMOTE_EVENT_T sync_release;
  27737. +
  27738. + /* A circular buffer of slot indexes. */
  27739. + int slot_queue[VCHIQ_MAX_SLOTS_PER_SIDE];
  27740. +
  27741. + /* Debugging state */
  27742. + int debug[DEBUG_MAX];
  27743. +} VCHIQ_SHARED_STATE_T;
  27744. +
  27745. +typedef struct vchiq_slot_zero_struct {
  27746. + int magic;
  27747. + short version;
  27748. + short version_min;
  27749. + int slot_zero_size;
  27750. + int slot_size;
  27751. + int max_slots;
  27752. + int max_slots_per_side;
  27753. + int platform_data[2];
  27754. + VCHIQ_SHARED_STATE_T master;
  27755. + VCHIQ_SHARED_STATE_T slave;
  27756. + VCHIQ_SLOT_INFO_T slots[VCHIQ_MAX_SLOTS];
  27757. +} VCHIQ_SLOT_ZERO_T;
  27758. +
  27759. +struct vchiq_state_struct {
  27760. + int id;
  27761. + int initialised;
  27762. + VCHIQ_CONNSTATE_T conn_state;
  27763. + int is_master;
  27764. +
  27765. + VCHIQ_SHARED_STATE_T *local;
  27766. + VCHIQ_SHARED_STATE_T *remote;
  27767. + VCHIQ_SLOT_T *slot_data;
  27768. +
  27769. + unsigned short default_slot_quota;
  27770. + unsigned short default_message_quota;
  27771. +
  27772. + /* Event indicating connect message received */
  27773. + struct semaphore connect;
  27774. +
  27775. + /* Mutex protecting services */
  27776. + struct mutex mutex;
  27777. + VCHIQ_INSTANCE_T *instance;
  27778. +
  27779. + /* Processes incoming messages */
  27780. + struct task_struct *slot_handler_thread;
  27781. +
  27782. + /* Processes recycled slots */
  27783. + struct task_struct *recycle_thread;
  27784. +
  27785. + /* Processes synchronous messages */
  27786. + struct task_struct *sync_thread;
  27787. +
  27788. + /* Local implementation of the trigger remote event */
  27789. + struct semaphore trigger_event;
  27790. +
  27791. + /* Local implementation of the recycle remote event */
  27792. + struct semaphore recycle_event;
  27793. +
  27794. + /* Local implementation of the sync trigger remote event */
  27795. + struct semaphore sync_trigger_event;
  27796. +
  27797. + /* Local implementation of the sync release remote event */
  27798. + struct semaphore sync_release_event;
  27799. +
  27800. + char *tx_data;
  27801. + char *rx_data;
  27802. + VCHIQ_SLOT_INFO_T *rx_info;
  27803. +
  27804. + struct mutex slot_mutex;
  27805. +
  27806. + struct mutex recycle_mutex;
  27807. +
  27808. + struct mutex sync_mutex;
  27809. +
  27810. + struct mutex bulk_transfer_mutex;
  27811. +
  27812. + /* Indicates the byte position within the stream from where the next
  27813. + ** message will be read. The least significant bits are an index into
  27814. + ** the slot.The next bits are the index of the slot in
  27815. + ** remote->slot_queue. */
  27816. + int rx_pos;
  27817. +
  27818. + /* A cached copy of local->tx_pos. Only write to local->tx_pos, and read
  27819. + from remote->tx_pos. */
  27820. + int local_tx_pos;
  27821. +
  27822. + /* The slot_queue index of the slot to become available next. */
  27823. + int slot_queue_available;
  27824. +
  27825. + /* A flag to indicate if any poll has been requested */
  27826. + int poll_needed;
  27827. +
  27828. + /* Ths index of the previous slot used for data messages. */
  27829. + int previous_data_index;
  27830. +
  27831. + /* The number of slots occupied by data messages. */
  27832. + unsigned short data_use_count;
  27833. +
  27834. + /* The maximum number of slots to be occupied by data messages. */
  27835. + unsigned short data_quota;
  27836. +
  27837. + /* An array of bit sets indicating which services must be polled. */
  27838. + atomic_t poll_services[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  27839. +
  27840. + /* The number of the first unused service */
  27841. + int unused_service;
  27842. +
  27843. + /* Signalled when a free slot becomes available. */
  27844. + struct semaphore slot_available_event;
  27845. +
  27846. + struct semaphore slot_remove_event;
  27847. +
  27848. + /* Signalled when a free data slot becomes available. */
  27849. + struct semaphore data_quota_event;
  27850. +
  27851. + /* Incremented when there are bulk transfers which cannot be processed
  27852. + * whilst paused and must be processed on resume */
  27853. + int deferred_bulks;
  27854. +
  27855. + struct state_stats_struct {
  27856. + int slot_stalls;
  27857. + int data_stalls;
  27858. + int ctrl_tx_count;
  27859. + int ctrl_rx_count;
  27860. + int error_count;
  27861. + } stats;
  27862. +
  27863. + VCHIQ_SERVICE_T * services[VCHIQ_MAX_SERVICES];
  27864. + VCHIQ_SERVICE_QUOTA_T service_quotas[VCHIQ_MAX_SERVICES];
  27865. + VCHIQ_SLOT_INFO_T slot_info[VCHIQ_MAX_SLOTS];
  27866. +
  27867. + VCHIQ_PLATFORM_STATE_T platform_state;
  27868. +};
  27869. +
  27870. +struct bulk_waiter {
  27871. + VCHIQ_BULK_T *bulk;
  27872. + struct semaphore event;
  27873. + int actual;
  27874. +};
  27875. +
  27876. +extern spinlock_t bulk_waiter_spinlock;
  27877. +
  27878. +extern int vchiq_core_log_level;
  27879. +extern int vchiq_core_msg_log_level;
  27880. +extern int vchiq_sync_log_level;
  27881. +
  27882. +extern VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  27883. +
  27884. +extern const char *
  27885. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state);
  27886. +
  27887. +extern VCHIQ_SLOT_ZERO_T *
  27888. +vchiq_init_slots(void *mem_base, int mem_size);
  27889. +
  27890. +extern VCHIQ_STATUS_T
  27891. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  27892. + int is_master);
  27893. +
  27894. +extern VCHIQ_STATUS_T
  27895. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  27896. +
  27897. +extern VCHIQ_SERVICE_T *
  27898. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  27899. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  27900. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term);
  27901. +
  27902. +extern VCHIQ_STATUS_T
  27903. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id);
  27904. +
  27905. +extern VCHIQ_STATUS_T
  27906. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd);
  27907. +
  27908. +extern void
  27909. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service);
  27910. +
  27911. +extern void
  27912. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service);
  27913. +
  27914. +extern VCHIQ_STATUS_T
  27915. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  27916. +
  27917. +extern VCHIQ_STATUS_T
  27918. +vchiq_pause_internal(VCHIQ_STATE_T *state);
  27919. +
  27920. +extern VCHIQ_STATUS_T
  27921. +vchiq_resume_internal(VCHIQ_STATE_T *state);
  27922. +
  27923. +extern void
  27924. +remote_event_pollall(VCHIQ_STATE_T *state);
  27925. +
  27926. +extern VCHIQ_STATUS_T
  27927. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  27928. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  27929. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir);
  27930. +
  27931. +extern void
  27932. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state);
  27933. +
  27934. +extern void
  27935. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service);
  27936. +
  27937. +extern void
  27938. +vchiq_loud_error_header(void);
  27939. +
  27940. +extern void
  27941. +vchiq_loud_error_footer(void);
  27942. +
  27943. +extern void
  27944. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type);
  27945. +
  27946. +static inline VCHIQ_SERVICE_T *
  27947. +handle_to_service(VCHIQ_SERVICE_HANDLE_T handle)
  27948. +{
  27949. + VCHIQ_STATE_T *state = vchiq_states[(handle / VCHIQ_MAX_SERVICES) &
  27950. + (VCHIQ_MAX_STATES - 1)];
  27951. + if (!state)
  27952. + return NULL;
  27953. +
  27954. + return state->services[handle & (VCHIQ_MAX_SERVICES - 1)];
  27955. +}
  27956. +
  27957. +extern VCHIQ_SERVICE_T *
  27958. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle);
  27959. +
  27960. +extern VCHIQ_SERVICE_T *
  27961. +find_service_by_port(VCHIQ_STATE_T *state, int localport);
  27962. +
  27963. +extern VCHIQ_SERVICE_T *
  27964. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  27965. + VCHIQ_SERVICE_HANDLE_T handle);
  27966. +
  27967. +extern VCHIQ_SERVICE_T *
  27968. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  27969. + int *pidx);
  27970. +
  27971. +extern void
  27972. +lock_service(VCHIQ_SERVICE_T *service);
  27973. +
  27974. +extern void
  27975. +unlock_service(VCHIQ_SERVICE_T *service);
  27976. +
  27977. +/* The following functions are called from vchiq_core, and external
  27978. +** implementations must be provided. */
  27979. +
  27980. +extern VCHIQ_STATUS_T
  27981. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk,
  27982. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, int dir);
  27983. +
  27984. +extern void
  27985. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk);
  27986. +
  27987. +extern void
  27988. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk);
  27989. +
  27990. +extern VCHIQ_STATUS_T
  27991. +vchiq_copy_from_user(void *dst, const void *src, int size);
  27992. +
  27993. +extern void
  27994. +remote_event_signal(REMOTE_EVENT_T *event);
  27995. +
  27996. +void
  27997. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state);
  27998. +
  27999. +extern void
  28000. +vchiq_platform_paused(VCHIQ_STATE_T *state);
  28001. +
  28002. +extern VCHIQ_STATUS_T
  28003. +vchiq_platform_resume(VCHIQ_STATE_T *state);
  28004. +
  28005. +extern void
  28006. +vchiq_platform_resumed(VCHIQ_STATE_T *state);
  28007. +
  28008. +extern void
  28009. +vchiq_dump(void *dump_context, const char *str, int len);
  28010. +
  28011. +extern void
  28012. +vchiq_dump_platform_state(void *dump_context);
  28013. +
  28014. +extern void
  28015. +vchiq_dump_platform_instances(void *dump_context);
  28016. +
  28017. +extern void
  28018. +vchiq_dump_platform_service_state(void *dump_context,
  28019. + VCHIQ_SERVICE_T *service);
  28020. +
  28021. +extern VCHIQ_STATUS_T
  28022. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service);
  28023. +
  28024. +extern VCHIQ_STATUS_T
  28025. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service);
  28026. +
  28027. +extern void
  28028. +vchiq_on_remote_use(VCHIQ_STATE_T *state);
  28029. +
  28030. +extern void
  28031. +vchiq_on_remote_release(VCHIQ_STATE_T *state);
  28032. +
  28033. +extern VCHIQ_STATUS_T
  28034. +vchiq_platform_init_state(VCHIQ_STATE_T *state);
  28035. +
  28036. +extern VCHIQ_STATUS_T
  28037. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  28038. +
  28039. +extern void
  28040. +vchiq_on_remote_use_active(VCHIQ_STATE_T *state);
  28041. +
  28042. +extern VCHIQ_STATUS_T
  28043. +vchiq_send_remote_use(VCHIQ_STATE_T *state);
  28044. +
  28045. +extern VCHIQ_STATUS_T
  28046. +vchiq_send_remote_release(VCHIQ_STATE_T *state);
  28047. +
  28048. +extern VCHIQ_STATUS_T
  28049. +vchiq_send_remote_use_active(VCHIQ_STATE_T *state);
  28050. +
  28051. +extern void
  28052. +vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  28053. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate);
  28054. +
  28055. +extern void
  28056. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state);
  28057. +
  28058. +extern void
  28059. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate);
  28060. +
  28061. +
  28062. +extern void
  28063. +vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  28064. + size_t numBytes);
  28065. +
  28066. +#endif
  28067. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion
  28068. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 1970-01-01 01:00:00.000000000 +0100
  28069. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 2014-02-18 11:52:14.000000000 +0100
  28070. @@ -0,0 +1,87 @@
  28071. +#!/usr/bin/perl -w
  28072. +
  28073. +use strict;
  28074. +
  28075. +#
  28076. +# Generate a version from available information
  28077. +#
  28078. +
  28079. +my $prefix = shift @ARGV;
  28080. +my $root = shift @ARGV;
  28081. +
  28082. +
  28083. +if ( not defined $root ) {
  28084. + die "usage: $0 prefix root-dir\n";
  28085. +}
  28086. +
  28087. +if ( ! -d $root ) {
  28088. + die "root directory $root not found\n";
  28089. +}
  28090. +
  28091. +my $version = "unknown";
  28092. +my $tainted = "";
  28093. +
  28094. +if ( -d "$root/.git" ) {
  28095. + # attempt to work out git version. only do so
  28096. + # on a linux build host, as cygwin builds are
  28097. + # already slow enough
  28098. +
  28099. + if ( -f "/usr/bin/git" || -f "/usr/local/bin/git" ) {
  28100. + if (not open(F, "git --git-dir $root/.git rev-parse --verify HEAD|")) {
  28101. + $version = "no git version";
  28102. + }
  28103. + else {
  28104. + $version = <F>;
  28105. + $version =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  28106. + $version =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  28107. + }
  28108. +
  28109. + if (open(G, "git --git-dir $root/.git status --porcelain|")) {
  28110. + $tainted = <G>;
  28111. + $tainted =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  28112. + $tainted =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  28113. + if (length $tainted) {
  28114. + $version = join ' ', $version, "(tainted)";
  28115. + }
  28116. + else {
  28117. + $version = join ' ', $version, "(clean)";
  28118. + }
  28119. + }
  28120. + }
  28121. +}
  28122. +
  28123. +my $hostname = `hostname`;
  28124. +$hostname =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  28125. +$hostname =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  28126. +
  28127. +
  28128. +print STDERR "Version $version\n";
  28129. +print <<EOF;
  28130. +#include "${prefix}_build_info.h"
  28131. +#include <linux/broadcom/vc_debug_sym.h>
  28132. +
  28133. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_hostname, "$hostname" );
  28134. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_version, "$version" );
  28135. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_time, __TIME__ );
  28136. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_date, __DATE__ );
  28137. +
  28138. +const char *vchiq_get_build_hostname( void )
  28139. +{
  28140. + return vchiq_build_hostname;
  28141. +}
  28142. +
  28143. +const char *vchiq_get_build_version( void )
  28144. +{
  28145. + return vchiq_build_version;
  28146. +}
  28147. +
  28148. +const char *vchiq_get_build_date( void )
  28149. +{
  28150. + return vchiq_build_date;
  28151. +}
  28152. +
  28153. +const char *vchiq_get_build_time( void )
  28154. +{
  28155. + return vchiq_build_time;
  28156. +}
  28157. +EOF
  28158. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h
  28159. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 1970-01-01 01:00:00.000000000 +0100
  28160. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 2014-02-18 11:52:14.000000000 +0100
  28161. @@ -0,0 +1,40 @@
  28162. +/**
  28163. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28164. + *
  28165. + * Redistribution and use in source and binary forms, with or without
  28166. + * modification, are permitted provided that the following conditions
  28167. + * are met:
  28168. + * 1. Redistributions of source code must retain the above copyright
  28169. + * notice, this list of conditions, and the following disclaimer,
  28170. + * without modification.
  28171. + * 2. Redistributions in binary form must reproduce the above copyright
  28172. + * notice, this list of conditions and the following disclaimer in the
  28173. + * documentation and/or other materials provided with the distribution.
  28174. + * 3. The names of the above-listed copyright holders may not be used
  28175. + * to endorse or promote products derived from this software without
  28176. + * specific prior written permission.
  28177. + *
  28178. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28179. + * GNU General Public License ("GPL") version 2, as published by the Free
  28180. + * Software Foundation.
  28181. + *
  28182. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28183. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28184. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28185. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28186. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28187. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28188. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28189. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28190. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28191. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28192. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28193. + */
  28194. +
  28195. +#ifndef VCHIQ_VCHIQ_H
  28196. +#define VCHIQ_VCHIQ_H
  28197. +
  28198. +#include "vchiq_if.h"
  28199. +#include "vchiq_util.h"
  28200. +
  28201. +#endif
  28202. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h
  28203. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 1970-01-01 01:00:00.000000000 +0100
  28204. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 2014-02-18 11:52:14.000000000 +0100
  28205. @@ -0,0 +1,188 @@
  28206. +/**
  28207. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28208. + *
  28209. + * Redistribution and use in source and binary forms, with or without
  28210. + * modification, are permitted provided that the following conditions
  28211. + * are met:
  28212. + * 1. Redistributions of source code must retain the above copyright
  28213. + * notice, this list of conditions, and the following disclaimer,
  28214. + * without modification.
  28215. + * 2. Redistributions in binary form must reproduce the above copyright
  28216. + * notice, this list of conditions and the following disclaimer in the
  28217. + * documentation and/or other materials provided with the distribution.
  28218. + * 3. The names of the above-listed copyright holders may not be used
  28219. + * to endorse or promote products derived from this software without
  28220. + * specific prior written permission.
  28221. + *
  28222. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28223. + * GNU General Public License ("GPL") version 2, as published by the Free
  28224. + * Software Foundation.
  28225. + *
  28226. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28227. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28228. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28229. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28230. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28231. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28232. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28233. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28234. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28235. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28236. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28237. + */
  28238. +
  28239. +#ifndef VCHIQ_IF_H
  28240. +#define VCHIQ_IF_H
  28241. +
  28242. +#include "interface/vchi/vchi_mh.h"
  28243. +
  28244. +#define VCHIQ_SERVICE_HANDLE_INVALID 0
  28245. +
  28246. +#define VCHIQ_SLOT_SIZE 4096
  28247. +#define VCHIQ_MAX_MSG_SIZE (VCHIQ_SLOT_SIZE - sizeof(VCHIQ_HEADER_T))
  28248. +#define VCHIQ_CHANNEL_SIZE VCHIQ_MAX_MSG_SIZE /* For backwards compatibility */
  28249. +
  28250. +#define VCHIQ_MAKE_FOURCC(x0, x1, x2, x3) \
  28251. + (((x0) << 24) | ((x1) << 16) | ((x2) << 8) | (x3))
  28252. +#define VCHIQ_GET_SERVICE_USERDATA(service) vchiq_get_service_userdata(service)
  28253. +#define VCHIQ_GET_SERVICE_FOURCC(service) vchiq_get_service_fourcc(service)
  28254. +
  28255. +typedef enum {
  28256. + VCHIQ_SERVICE_OPENED, /* service, -, - */
  28257. + VCHIQ_SERVICE_CLOSED, /* service, -, - */
  28258. + VCHIQ_MESSAGE_AVAILABLE, /* service, header, - */
  28259. + VCHIQ_BULK_TRANSMIT_DONE, /* service, -, bulk_userdata */
  28260. + VCHIQ_BULK_RECEIVE_DONE, /* service, -, bulk_userdata */
  28261. + VCHIQ_BULK_TRANSMIT_ABORTED, /* service, -, bulk_userdata */
  28262. + VCHIQ_BULK_RECEIVE_ABORTED /* service, -, bulk_userdata */
  28263. +} VCHIQ_REASON_T;
  28264. +
  28265. +typedef enum {
  28266. + VCHIQ_ERROR = -1,
  28267. + VCHIQ_SUCCESS = 0,
  28268. + VCHIQ_RETRY = 1
  28269. +} VCHIQ_STATUS_T;
  28270. +
  28271. +typedef enum {
  28272. + VCHIQ_BULK_MODE_CALLBACK,
  28273. + VCHIQ_BULK_MODE_BLOCKING,
  28274. + VCHIQ_BULK_MODE_NOCALLBACK,
  28275. + VCHIQ_BULK_MODE_WAITING /* Reserved for internal use */
  28276. +} VCHIQ_BULK_MODE_T;
  28277. +
  28278. +typedef enum {
  28279. + VCHIQ_SERVICE_OPTION_AUTOCLOSE,
  28280. + VCHIQ_SERVICE_OPTION_SLOT_QUOTA,
  28281. + VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA,
  28282. + VCHIQ_SERVICE_OPTION_SYNCHRONOUS
  28283. +} VCHIQ_SERVICE_OPTION_T;
  28284. +
  28285. +typedef struct vchiq_header_struct {
  28286. + /* The message identifier - opaque to applications. */
  28287. + int msgid;
  28288. +
  28289. + /* Size of message data. */
  28290. + unsigned int size;
  28291. +
  28292. + char data[0]; /* message */
  28293. +} VCHIQ_HEADER_T;
  28294. +
  28295. +typedef struct {
  28296. + const void *data;
  28297. + unsigned int size;
  28298. +} VCHIQ_ELEMENT_T;
  28299. +
  28300. +typedef unsigned int VCHIQ_SERVICE_HANDLE_T;
  28301. +
  28302. +typedef VCHIQ_STATUS_T (*VCHIQ_CALLBACK_T)(VCHIQ_REASON_T, VCHIQ_HEADER_T *,
  28303. + VCHIQ_SERVICE_HANDLE_T, void *);
  28304. +
  28305. +typedef struct vchiq_service_base_struct {
  28306. + int fourcc;
  28307. + VCHIQ_CALLBACK_T callback;
  28308. + void *userdata;
  28309. +} VCHIQ_SERVICE_BASE_T;
  28310. +
  28311. +typedef struct vchiq_service_params_struct {
  28312. + int fourcc;
  28313. + VCHIQ_CALLBACK_T callback;
  28314. + void *userdata;
  28315. + short version; /* Increment for non-trivial changes */
  28316. + short version_min; /* Update for incompatible changes */
  28317. +} VCHIQ_SERVICE_PARAMS_T;
  28318. +
  28319. +typedef struct vchiq_config_struct {
  28320. + unsigned int max_msg_size;
  28321. + unsigned int bulk_threshold; /* The message size above which it
  28322. + is better to use a bulk transfer
  28323. + (<= max_msg_size) */
  28324. + unsigned int max_outstanding_bulks;
  28325. + unsigned int max_services;
  28326. + short version; /* The version of VCHIQ */
  28327. + short version_min; /* The minimum compatible version of VCHIQ */
  28328. +} VCHIQ_CONFIG_T;
  28329. +
  28330. +typedef struct vchiq_instance_struct *VCHIQ_INSTANCE_T;
  28331. +typedef void (*VCHIQ_REMOTE_USE_CALLBACK_T)(void *cb_arg);
  28332. +
  28333. +extern VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *pinstance);
  28334. +extern VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance);
  28335. +extern VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance);
  28336. +extern VCHIQ_STATUS_T vchiq_add_service(VCHIQ_INSTANCE_T instance,
  28337. + const VCHIQ_SERVICE_PARAMS_T *params,
  28338. + VCHIQ_SERVICE_HANDLE_T *pservice);
  28339. +extern VCHIQ_STATUS_T vchiq_open_service(VCHIQ_INSTANCE_T instance,
  28340. + const VCHIQ_SERVICE_PARAMS_T *params,
  28341. + VCHIQ_SERVICE_HANDLE_T *pservice);
  28342. +extern VCHIQ_STATUS_T vchiq_close_service(VCHIQ_SERVICE_HANDLE_T service);
  28343. +extern VCHIQ_STATUS_T vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T service);
  28344. +extern VCHIQ_STATUS_T vchiq_use_service(VCHIQ_SERVICE_HANDLE_T service);
  28345. +extern VCHIQ_STATUS_T vchiq_use_service_no_resume(
  28346. + VCHIQ_SERVICE_HANDLE_T service);
  28347. +extern VCHIQ_STATUS_T vchiq_release_service(VCHIQ_SERVICE_HANDLE_T service);
  28348. +
  28349. +extern VCHIQ_STATUS_T vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T service,
  28350. + const VCHIQ_ELEMENT_T *elements, unsigned int count);
  28351. +extern void vchiq_release_message(VCHIQ_SERVICE_HANDLE_T service,
  28352. + VCHIQ_HEADER_T *header);
  28353. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  28354. + const void *data, unsigned int size, void *userdata);
  28355. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  28356. + void *data, unsigned int size, void *userdata);
  28357. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit_handle(
  28358. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  28359. + const void *offset, unsigned int size, void *userdata);
  28360. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive_handle(
  28361. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  28362. + void *offset, unsigned int size, void *userdata);
  28363. +extern VCHIQ_STATUS_T vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  28364. + const void *data, unsigned int size, void *userdata,
  28365. + VCHIQ_BULK_MODE_T mode);
  28366. +extern VCHIQ_STATUS_T vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  28367. + void *data, unsigned int size, void *userdata,
  28368. + VCHIQ_BULK_MODE_T mode);
  28369. +extern VCHIQ_STATUS_T vchiq_bulk_transmit_handle(VCHIQ_SERVICE_HANDLE_T service,
  28370. + VCHI_MEM_HANDLE_T handle, const void *offset, unsigned int size,
  28371. + void *userdata, VCHIQ_BULK_MODE_T mode);
  28372. +extern VCHIQ_STATUS_T vchiq_bulk_receive_handle(VCHIQ_SERVICE_HANDLE_T service,
  28373. + VCHI_MEM_HANDLE_T handle, void *offset, unsigned int size,
  28374. + void *userdata, VCHIQ_BULK_MODE_T mode);
  28375. +extern int vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T service);
  28376. +extern void *vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T service);
  28377. +extern int vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T service);
  28378. +extern VCHIQ_STATUS_T vchiq_get_config(VCHIQ_INSTANCE_T instance,
  28379. + int config_size, VCHIQ_CONFIG_T *pconfig);
  28380. +extern VCHIQ_STATUS_T vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T service,
  28381. + VCHIQ_SERVICE_OPTION_T option, int value);
  28382. +
  28383. +extern VCHIQ_STATUS_T vchiq_remote_use(VCHIQ_INSTANCE_T instance,
  28384. + VCHIQ_REMOTE_USE_CALLBACK_T callback, void *cb_arg);
  28385. +extern VCHIQ_STATUS_T vchiq_remote_release(VCHIQ_INSTANCE_T instance);
  28386. +
  28387. +extern VCHIQ_STATUS_T vchiq_dump_phys_mem(VCHIQ_SERVICE_HANDLE_T service,
  28388. + void *ptr, size_t num_bytes);
  28389. +
  28390. +extern VCHIQ_STATUS_T vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle,
  28391. + short *peer_version);
  28392. +
  28393. +#endif /* VCHIQ_IF_H */
  28394. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h
  28395. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 1970-01-01 01:00:00.000000000 +0100
  28396. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 2014-02-18 11:52:14.000000000 +0100
  28397. @@ -0,0 +1,129 @@
  28398. +/**
  28399. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28400. + *
  28401. + * Redistribution and use in source and binary forms, with or without
  28402. + * modification, are permitted provided that the following conditions
  28403. + * are met:
  28404. + * 1. Redistributions of source code must retain the above copyright
  28405. + * notice, this list of conditions, and the following disclaimer,
  28406. + * without modification.
  28407. + * 2. Redistributions in binary form must reproduce the above copyright
  28408. + * notice, this list of conditions and the following disclaimer in the
  28409. + * documentation and/or other materials provided with the distribution.
  28410. + * 3. The names of the above-listed copyright holders may not be used
  28411. + * to endorse or promote products derived from this software without
  28412. + * specific prior written permission.
  28413. + *
  28414. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28415. + * GNU General Public License ("GPL") version 2, as published by the Free
  28416. + * Software Foundation.
  28417. + *
  28418. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28419. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28420. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28421. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28422. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28423. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28424. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28425. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28426. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28427. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28428. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28429. + */
  28430. +
  28431. +#ifndef VCHIQ_IOCTLS_H
  28432. +#define VCHIQ_IOCTLS_H
  28433. +
  28434. +#include <linux/ioctl.h>
  28435. +#include "vchiq_if.h"
  28436. +
  28437. +#define VCHIQ_IOC_MAGIC 0xc4
  28438. +#define VCHIQ_INVALID_HANDLE (~0)
  28439. +
  28440. +typedef struct {
  28441. + VCHIQ_SERVICE_PARAMS_T params;
  28442. + int is_open;
  28443. + int is_vchi;
  28444. + unsigned int handle; /* OUT */
  28445. +} VCHIQ_CREATE_SERVICE_T;
  28446. +
  28447. +typedef struct {
  28448. + unsigned int handle;
  28449. + unsigned int count;
  28450. + const VCHIQ_ELEMENT_T *elements;
  28451. +} VCHIQ_QUEUE_MESSAGE_T;
  28452. +
  28453. +typedef struct {
  28454. + unsigned int handle;
  28455. + void *data;
  28456. + unsigned int size;
  28457. + void *userdata;
  28458. + VCHIQ_BULK_MODE_T mode;
  28459. +} VCHIQ_QUEUE_BULK_TRANSFER_T;
  28460. +
  28461. +typedef struct {
  28462. + VCHIQ_REASON_T reason;
  28463. + VCHIQ_HEADER_T *header;
  28464. + void *service_userdata;
  28465. + void *bulk_userdata;
  28466. +} VCHIQ_COMPLETION_DATA_T;
  28467. +
  28468. +typedef struct {
  28469. + unsigned int count;
  28470. + VCHIQ_COMPLETION_DATA_T *buf;
  28471. + unsigned int msgbufsize;
  28472. + unsigned int msgbufcount; /* IN/OUT */
  28473. + void **msgbufs;
  28474. +} VCHIQ_AWAIT_COMPLETION_T;
  28475. +
  28476. +typedef struct {
  28477. + unsigned int handle;
  28478. + int blocking;
  28479. + unsigned int bufsize;
  28480. + void *buf;
  28481. +} VCHIQ_DEQUEUE_MESSAGE_T;
  28482. +
  28483. +typedef struct {
  28484. + unsigned int config_size;
  28485. + VCHIQ_CONFIG_T *pconfig;
  28486. +} VCHIQ_GET_CONFIG_T;
  28487. +
  28488. +typedef struct {
  28489. + unsigned int handle;
  28490. + VCHIQ_SERVICE_OPTION_T option;
  28491. + int value;
  28492. +} VCHIQ_SET_SERVICE_OPTION_T;
  28493. +
  28494. +typedef struct {
  28495. + void *virt_addr;
  28496. + size_t num_bytes;
  28497. +} VCHIQ_DUMP_MEM_T;
  28498. +
  28499. +#define VCHIQ_IOC_CONNECT _IO(VCHIQ_IOC_MAGIC, 0)
  28500. +#define VCHIQ_IOC_SHUTDOWN _IO(VCHIQ_IOC_MAGIC, 1)
  28501. +#define VCHIQ_IOC_CREATE_SERVICE \
  28502. + _IOWR(VCHIQ_IOC_MAGIC, 2, VCHIQ_CREATE_SERVICE_T)
  28503. +#define VCHIQ_IOC_REMOVE_SERVICE _IO(VCHIQ_IOC_MAGIC, 3)
  28504. +#define VCHIQ_IOC_QUEUE_MESSAGE \
  28505. + _IOW(VCHIQ_IOC_MAGIC, 4, VCHIQ_QUEUE_MESSAGE_T)
  28506. +#define VCHIQ_IOC_QUEUE_BULK_TRANSMIT \
  28507. + _IOWR(VCHIQ_IOC_MAGIC, 5, VCHIQ_QUEUE_BULK_TRANSFER_T)
  28508. +#define VCHIQ_IOC_QUEUE_BULK_RECEIVE \
  28509. + _IOWR(VCHIQ_IOC_MAGIC, 6, VCHIQ_QUEUE_BULK_TRANSFER_T)
  28510. +#define VCHIQ_IOC_AWAIT_COMPLETION \
  28511. + _IOWR(VCHIQ_IOC_MAGIC, 7, VCHIQ_AWAIT_COMPLETION_T)
  28512. +#define VCHIQ_IOC_DEQUEUE_MESSAGE \
  28513. + _IOWR(VCHIQ_IOC_MAGIC, 8, VCHIQ_DEQUEUE_MESSAGE_T)
  28514. +#define VCHIQ_IOC_GET_CLIENT_ID _IO(VCHIQ_IOC_MAGIC, 9)
  28515. +#define VCHIQ_IOC_GET_CONFIG \
  28516. + _IOWR(VCHIQ_IOC_MAGIC, 10, VCHIQ_GET_CONFIG_T)
  28517. +#define VCHIQ_IOC_CLOSE_SERVICE _IO(VCHIQ_IOC_MAGIC, 11)
  28518. +#define VCHIQ_IOC_USE_SERVICE _IO(VCHIQ_IOC_MAGIC, 12)
  28519. +#define VCHIQ_IOC_RELEASE_SERVICE _IO(VCHIQ_IOC_MAGIC, 13)
  28520. +#define VCHIQ_IOC_SET_SERVICE_OPTION \
  28521. + _IOW(VCHIQ_IOC_MAGIC, 14, VCHIQ_SET_SERVICE_OPTION_T)
  28522. +#define VCHIQ_IOC_DUMP_PHYS_MEM \
  28523. + _IOW(VCHIQ_IOC_MAGIC, 15, VCHIQ_DUMP_MEM_T)
  28524. +#define VCHIQ_IOC_MAX 15
  28525. +
  28526. +#endif
  28527. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
  28528. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 1970-01-01 01:00:00.000000000 +0100
  28529. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 2014-02-18 11:52:14.000000000 +0100
  28530. @@ -0,0 +1,456 @@
  28531. +/**
  28532. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28533. + *
  28534. + * Redistribution and use in source and binary forms, with or without
  28535. + * modification, are permitted provided that the following conditions
  28536. + * are met:
  28537. + * 1. Redistributions of source code must retain the above copyright
  28538. + * notice, this list of conditions, and the following disclaimer,
  28539. + * without modification.
  28540. + * 2. Redistributions in binary form must reproduce the above copyright
  28541. + * notice, this list of conditions and the following disclaimer in the
  28542. + * documentation and/or other materials provided with the distribution.
  28543. + * 3. The names of the above-listed copyright holders may not be used
  28544. + * to endorse or promote products derived from this software without
  28545. + * specific prior written permission.
  28546. + *
  28547. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28548. + * GNU General Public License ("GPL") version 2, as published by the Free
  28549. + * Software Foundation.
  28550. + *
  28551. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28552. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28553. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28554. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28555. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28556. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28557. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28558. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28559. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28560. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28561. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28562. + */
  28563. +
  28564. +/* ---- Include Files ---------------------------------------------------- */
  28565. +
  28566. +#include <linux/kernel.h>
  28567. +#include <linux/module.h>
  28568. +#include <linux/mutex.h>
  28569. +
  28570. +#include "vchiq_core.h"
  28571. +#include "vchiq_arm.h"
  28572. +
  28573. +/* ---- Public Variables ------------------------------------------------- */
  28574. +
  28575. +/* ---- Private Constants and Types -------------------------------------- */
  28576. +
  28577. +struct bulk_waiter_node {
  28578. + struct bulk_waiter bulk_waiter;
  28579. + int pid;
  28580. + struct list_head list;
  28581. +};
  28582. +
  28583. +struct vchiq_instance_struct {
  28584. + VCHIQ_STATE_T *state;
  28585. +
  28586. + int connected;
  28587. +
  28588. + struct list_head bulk_waiter_list;
  28589. + struct mutex bulk_waiter_list_mutex;
  28590. +};
  28591. +
  28592. +static VCHIQ_STATUS_T
  28593. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  28594. + unsigned int size, VCHIQ_BULK_DIR_T dir);
  28595. +
  28596. +/****************************************************************************
  28597. +*
  28598. +* vchiq_initialise
  28599. +*
  28600. +***************************************************************************/
  28601. +#define VCHIQ_INIT_RETRIES 10
  28602. +VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *instanceOut)
  28603. +{
  28604. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  28605. + VCHIQ_STATE_T *state;
  28606. + VCHIQ_INSTANCE_T instance = NULL;
  28607. + int i;
  28608. +
  28609. + vchiq_log_trace(vchiq_core_log_level, "%s called", __func__);
  28610. +
  28611. + /* VideoCore may not be ready due to boot up timing.
  28612. + It may never be ready if kernel and firmware are mismatched, so don't block forever. */
  28613. + for (i=0; i<VCHIQ_INIT_RETRIES; i++) {
  28614. + state = vchiq_get_state();
  28615. + if (state)
  28616. + break;
  28617. + udelay(500);
  28618. + }
  28619. + if (i==VCHIQ_INIT_RETRIES) {
  28620. + vchiq_log_error(vchiq_core_log_level,
  28621. + "%s: videocore not initialized\n", __func__);
  28622. + goto failed;
  28623. + } else if (i>0) {
  28624. + vchiq_log_warning(vchiq_core_log_level,
  28625. + "%s: videocore initialized after %d retries\n", __func__, i);
  28626. + }
  28627. +
  28628. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  28629. + if (!instance) {
  28630. + vchiq_log_error(vchiq_core_log_level,
  28631. + "%s: error allocating vchiq instance\n", __func__);
  28632. + goto failed;
  28633. + }
  28634. +
  28635. + instance->connected = 0;
  28636. + instance->state = state;
  28637. + mutex_init(&instance->bulk_waiter_list_mutex);
  28638. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  28639. +
  28640. + *instanceOut = instance;
  28641. +
  28642. + status = VCHIQ_SUCCESS;
  28643. +
  28644. +failed:
  28645. + vchiq_log_trace(vchiq_core_log_level,
  28646. + "%s(%p): returning %d", __func__, instance, status);
  28647. +
  28648. + return status;
  28649. +}
  28650. +EXPORT_SYMBOL(vchiq_initialise);
  28651. +
  28652. +/****************************************************************************
  28653. +*
  28654. +* vchiq_shutdown
  28655. +*
  28656. +***************************************************************************/
  28657. +
  28658. +VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance)
  28659. +{
  28660. + VCHIQ_STATUS_T status;
  28661. + VCHIQ_STATE_T *state = instance->state;
  28662. +
  28663. + vchiq_log_trace(vchiq_core_log_level,
  28664. + "%s(%p) called", __func__, instance);
  28665. +
  28666. + if (mutex_lock_interruptible(&state->mutex) != 0)
  28667. + return VCHIQ_RETRY;
  28668. +
  28669. + /* Remove all services */
  28670. + status = vchiq_shutdown_internal(state, instance);
  28671. +
  28672. + mutex_unlock(&state->mutex);
  28673. +
  28674. + vchiq_log_trace(vchiq_core_log_level,
  28675. + "%s(%p): returning %d", __func__, instance, status);
  28676. +
  28677. + if (status == VCHIQ_SUCCESS) {
  28678. + struct list_head *pos, *next;
  28679. + list_for_each_safe(pos, next,
  28680. + &instance->bulk_waiter_list) {
  28681. + struct bulk_waiter_node *waiter;
  28682. + waiter = list_entry(pos,
  28683. + struct bulk_waiter_node,
  28684. + list);
  28685. + list_del(pos);
  28686. + vchiq_log_info(vchiq_arm_log_level,
  28687. + "bulk_waiter - cleaned up %x "
  28688. + "for pid %d",
  28689. + (unsigned int)waiter, waiter->pid);
  28690. + kfree(waiter);
  28691. + }
  28692. + kfree(instance);
  28693. + }
  28694. +
  28695. + return status;
  28696. +}
  28697. +EXPORT_SYMBOL(vchiq_shutdown);
  28698. +
  28699. +/****************************************************************************
  28700. +*
  28701. +* vchiq_is_connected
  28702. +*
  28703. +***************************************************************************/
  28704. +
  28705. +int vchiq_is_connected(VCHIQ_INSTANCE_T instance)
  28706. +{
  28707. + return instance->connected;
  28708. +}
  28709. +
  28710. +/****************************************************************************
  28711. +*
  28712. +* vchiq_connect
  28713. +*
  28714. +***************************************************************************/
  28715. +
  28716. +VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance)
  28717. +{
  28718. + VCHIQ_STATUS_T status;
  28719. + VCHIQ_STATE_T *state = instance->state;
  28720. +
  28721. + vchiq_log_trace(vchiq_core_log_level,
  28722. + "%s(%p) called", __func__, instance);
  28723. +
  28724. + if (mutex_lock_interruptible(&state->mutex) != 0) {
  28725. + vchiq_log_trace(vchiq_core_log_level,
  28726. + "%s: call to mutex_lock failed", __func__);
  28727. + status = VCHIQ_RETRY;
  28728. + goto failed;
  28729. + }
  28730. + status = vchiq_connect_internal(state, instance);
  28731. +
  28732. + if (status == VCHIQ_SUCCESS)
  28733. + instance->connected = 1;
  28734. +
  28735. + mutex_unlock(&state->mutex);
  28736. +
  28737. +failed:
  28738. + vchiq_log_trace(vchiq_core_log_level,
  28739. + "%s(%p): returning %d", __func__, instance, status);
  28740. +
  28741. + return status;
  28742. +}
  28743. +EXPORT_SYMBOL(vchiq_connect);
  28744. +
  28745. +/****************************************************************************
  28746. +*
  28747. +* vchiq_add_service
  28748. +*
  28749. +***************************************************************************/
  28750. +
  28751. +VCHIQ_STATUS_T vchiq_add_service(
  28752. + VCHIQ_INSTANCE_T instance,
  28753. + const VCHIQ_SERVICE_PARAMS_T *params,
  28754. + VCHIQ_SERVICE_HANDLE_T *phandle)
  28755. +{
  28756. + VCHIQ_STATUS_T status;
  28757. + VCHIQ_STATE_T *state = instance->state;
  28758. + VCHIQ_SERVICE_T *service = NULL;
  28759. + int srvstate;
  28760. +
  28761. + vchiq_log_trace(vchiq_core_log_level,
  28762. + "%s(%p) called", __func__, instance);
  28763. +
  28764. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  28765. +
  28766. + srvstate = vchiq_is_connected(instance)
  28767. + ? VCHIQ_SRVSTATE_LISTENING
  28768. + : VCHIQ_SRVSTATE_HIDDEN;
  28769. +
  28770. + service = vchiq_add_service_internal(
  28771. + state,
  28772. + params,
  28773. + srvstate,
  28774. + instance,
  28775. + NULL);
  28776. +
  28777. + if (service) {
  28778. + *phandle = service->handle;
  28779. + status = VCHIQ_SUCCESS;
  28780. + } else
  28781. + status = VCHIQ_ERROR;
  28782. +
  28783. + vchiq_log_trace(vchiq_core_log_level,
  28784. + "%s(%p): returning %d", __func__, instance, status);
  28785. +
  28786. + return status;
  28787. +}
  28788. +EXPORT_SYMBOL(vchiq_add_service);
  28789. +
  28790. +/****************************************************************************
  28791. +*
  28792. +* vchiq_open_service
  28793. +*
  28794. +***************************************************************************/
  28795. +
  28796. +VCHIQ_STATUS_T vchiq_open_service(
  28797. + VCHIQ_INSTANCE_T instance,
  28798. + const VCHIQ_SERVICE_PARAMS_T *params,
  28799. + VCHIQ_SERVICE_HANDLE_T *phandle)
  28800. +{
  28801. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  28802. + VCHIQ_STATE_T *state = instance->state;
  28803. + VCHIQ_SERVICE_T *service = NULL;
  28804. +
  28805. + vchiq_log_trace(vchiq_core_log_level,
  28806. + "%s(%p) called", __func__, instance);
  28807. +
  28808. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  28809. +
  28810. + if (!vchiq_is_connected(instance))
  28811. + goto failed;
  28812. +
  28813. + service = vchiq_add_service_internal(state,
  28814. + params,
  28815. + VCHIQ_SRVSTATE_OPENING,
  28816. + instance,
  28817. + NULL);
  28818. +
  28819. + if (service) {
  28820. + status = vchiq_open_service_internal(service, current->pid);
  28821. + if (status == VCHIQ_SUCCESS)
  28822. + *phandle = service->handle;
  28823. + else
  28824. + vchiq_remove_service(service->handle);
  28825. + }
  28826. +
  28827. +failed:
  28828. + vchiq_log_trace(vchiq_core_log_level,
  28829. + "%s(%p): returning %d", __func__, instance, status);
  28830. +
  28831. + return status;
  28832. +}
  28833. +EXPORT_SYMBOL(vchiq_open_service);
  28834. +
  28835. +VCHIQ_STATUS_T
  28836. +vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle,
  28837. + const void *data, unsigned int size, void *userdata)
  28838. +{
  28839. + return vchiq_bulk_transfer(handle,
  28840. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  28841. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_TRANSMIT);
  28842. +}
  28843. +EXPORT_SYMBOL(vchiq_queue_bulk_transmit);
  28844. +
  28845. +VCHIQ_STATUS_T
  28846. +vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  28847. + unsigned int size, void *userdata)
  28848. +{
  28849. + return vchiq_bulk_transfer(handle,
  28850. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  28851. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_RECEIVE);
  28852. +}
  28853. +EXPORT_SYMBOL(vchiq_queue_bulk_receive);
  28854. +
  28855. +VCHIQ_STATUS_T
  28856. +vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle, const void *data,
  28857. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  28858. +{
  28859. + VCHIQ_STATUS_T status;
  28860. +
  28861. + switch (mode) {
  28862. + case VCHIQ_BULK_MODE_NOCALLBACK:
  28863. + case VCHIQ_BULK_MODE_CALLBACK:
  28864. + status = vchiq_bulk_transfer(handle,
  28865. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  28866. + mode, VCHIQ_BULK_TRANSMIT);
  28867. + break;
  28868. + case VCHIQ_BULK_MODE_BLOCKING:
  28869. + status = vchiq_blocking_bulk_transfer(handle,
  28870. + (void *)data, size, VCHIQ_BULK_TRANSMIT);
  28871. + break;
  28872. + default:
  28873. + return VCHIQ_ERROR;
  28874. + }
  28875. +
  28876. + return status;
  28877. +}
  28878. +EXPORT_SYMBOL(vchiq_bulk_transmit);
  28879. +
  28880. +VCHIQ_STATUS_T
  28881. +vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  28882. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  28883. +{
  28884. + VCHIQ_STATUS_T status;
  28885. +
  28886. + switch (mode) {
  28887. + case VCHIQ_BULK_MODE_NOCALLBACK:
  28888. + case VCHIQ_BULK_MODE_CALLBACK:
  28889. + status = vchiq_bulk_transfer(handle,
  28890. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  28891. + mode, VCHIQ_BULK_RECEIVE);
  28892. + break;
  28893. + case VCHIQ_BULK_MODE_BLOCKING:
  28894. + status = vchiq_blocking_bulk_transfer(handle,
  28895. + (void *)data, size, VCHIQ_BULK_RECEIVE);
  28896. + break;
  28897. + default:
  28898. + return VCHIQ_ERROR;
  28899. + }
  28900. +
  28901. + return status;
  28902. +}
  28903. +EXPORT_SYMBOL(vchiq_bulk_receive);
  28904. +
  28905. +static VCHIQ_STATUS_T
  28906. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  28907. + unsigned int size, VCHIQ_BULK_DIR_T dir)
  28908. +{
  28909. + VCHIQ_INSTANCE_T instance;
  28910. + VCHIQ_SERVICE_T *service;
  28911. + VCHIQ_STATUS_T status;
  28912. + struct bulk_waiter_node *waiter = NULL;
  28913. + struct list_head *pos;
  28914. +
  28915. + service = find_service_by_handle(handle);
  28916. + if (!service)
  28917. + return VCHIQ_ERROR;
  28918. +
  28919. + instance = service->instance;
  28920. +
  28921. + unlock_service(service);
  28922. +
  28923. + mutex_lock(&instance->bulk_waiter_list_mutex);
  28924. + list_for_each(pos, &instance->bulk_waiter_list) {
  28925. + if (list_entry(pos, struct bulk_waiter_node,
  28926. + list)->pid == current->pid) {
  28927. + waiter = list_entry(pos,
  28928. + struct bulk_waiter_node,
  28929. + list);
  28930. + list_del(pos);
  28931. + break;
  28932. + }
  28933. + }
  28934. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  28935. +
  28936. + if (waiter) {
  28937. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  28938. + if (bulk) {
  28939. + /* This thread has an outstanding bulk transfer. */
  28940. + if ((bulk->data != data) ||
  28941. + (bulk->size != size)) {
  28942. + /* This is not a retry of the previous one.
  28943. + ** Cancel the signal when the transfer
  28944. + ** completes. */
  28945. + spin_lock(&bulk_waiter_spinlock);
  28946. + bulk->userdata = NULL;
  28947. + spin_unlock(&bulk_waiter_spinlock);
  28948. + }
  28949. + }
  28950. + }
  28951. +
  28952. + if (!waiter) {
  28953. + waiter = kzalloc(sizeof(struct bulk_waiter_node), GFP_KERNEL);
  28954. + if (!waiter) {
  28955. + vchiq_log_error(vchiq_core_log_level,
  28956. + "%s - out of memory", __func__);
  28957. + return VCHIQ_ERROR;
  28958. + }
  28959. + }
  28960. +
  28961. + status = vchiq_bulk_transfer(handle, VCHI_MEM_HANDLE_INVALID,
  28962. + data, size, &waiter->bulk_waiter, VCHIQ_BULK_MODE_BLOCKING,
  28963. + dir);
  28964. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  28965. + !waiter->bulk_waiter.bulk) {
  28966. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  28967. + if (bulk) {
  28968. + /* Cancel the signal when the transfer
  28969. + ** completes. */
  28970. + spin_lock(&bulk_waiter_spinlock);
  28971. + bulk->userdata = NULL;
  28972. + spin_unlock(&bulk_waiter_spinlock);
  28973. + }
  28974. + kfree(waiter);
  28975. + } else {
  28976. + waiter->pid = current->pid;
  28977. + mutex_lock(&instance->bulk_waiter_list_mutex);
  28978. + list_add(&waiter->list, &instance->bulk_waiter_list);
  28979. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  28980. + vchiq_log_info(vchiq_arm_log_level,
  28981. + "saved bulk_waiter %x for pid %d",
  28982. + (unsigned int)waiter, current->pid);
  28983. + }
  28984. +
  28985. + return status;
  28986. +}
  28987. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h
  28988. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 1970-01-01 01:00:00.000000000 +0100
  28989. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 2014-02-18 11:52:14.000000000 +0100
  28990. @@ -0,0 +1,71 @@
  28991. +/**
  28992. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28993. + *
  28994. + * Redistribution and use in source and binary forms, with or without
  28995. + * modification, are permitted provided that the following conditions
  28996. + * are met:
  28997. + * 1. Redistributions of source code must retain the above copyright
  28998. + * notice, this list of conditions, and the following disclaimer,
  28999. + * without modification.
  29000. + * 2. Redistributions in binary form must reproduce the above copyright
  29001. + * notice, this list of conditions and the following disclaimer in the
  29002. + * documentation and/or other materials provided with the distribution.
  29003. + * 3. The names of the above-listed copyright holders may not be used
  29004. + * to endorse or promote products derived from this software without
  29005. + * specific prior written permission.
  29006. + *
  29007. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29008. + * GNU General Public License ("GPL") version 2, as published by the Free
  29009. + * Software Foundation.
  29010. + *
  29011. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29012. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29013. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29014. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29015. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29016. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29017. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29018. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29019. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29020. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29021. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29022. + */
  29023. +
  29024. +#ifndef VCHIQ_MEMDRV_H
  29025. +#define VCHIQ_MEMDRV_H
  29026. +
  29027. +/* ---- Include Files ----------------------------------------------------- */
  29028. +
  29029. +#include <linux/kernel.h>
  29030. +#include "vchiq_if.h"
  29031. +
  29032. +/* ---- Constants and Types ---------------------------------------------- */
  29033. +
  29034. +typedef struct {
  29035. + void *armSharedMemVirt;
  29036. + dma_addr_t armSharedMemPhys;
  29037. + size_t armSharedMemSize;
  29038. +
  29039. + void *vcSharedMemVirt;
  29040. + dma_addr_t vcSharedMemPhys;
  29041. + size_t vcSharedMemSize;
  29042. +} VCHIQ_SHARED_MEM_INFO_T;
  29043. +
  29044. +/* ---- Variable Externs ------------------------------------------------- */
  29045. +
  29046. +/* ---- Function Prototypes ---------------------------------------------- */
  29047. +
  29048. +void vchiq_get_shared_mem_info(VCHIQ_SHARED_MEM_INFO_T *info);
  29049. +
  29050. +VCHIQ_STATUS_T vchiq_memdrv_initialise(void);
  29051. +
  29052. +VCHIQ_STATUS_T vchiq_userdrv_create_instance(
  29053. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  29054. +
  29055. +VCHIQ_STATUS_T vchiq_userdrv_suspend(
  29056. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  29057. +
  29058. +VCHIQ_STATUS_T vchiq_userdrv_resume(
  29059. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  29060. +
  29061. +#endif
  29062. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h
  29063. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 1970-01-01 01:00:00.000000000 +0100
  29064. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 2014-02-18 11:52:14.000000000 +0100
  29065. @@ -0,0 +1,58 @@
  29066. +/**
  29067. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29068. + *
  29069. + * Redistribution and use in source and binary forms, with or without
  29070. + * modification, are permitted provided that the following conditions
  29071. + * are met:
  29072. + * 1. Redistributions of source code must retain the above copyright
  29073. + * notice, this list of conditions, and the following disclaimer,
  29074. + * without modification.
  29075. + * 2. Redistributions in binary form must reproduce the above copyright
  29076. + * notice, this list of conditions and the following disclaimer in the
  29077. + * documentation and/or other materials provided with the distribution.
  29078. + * 3. The names of the above-listed copyright holders may not be used
  29079. + * to endorse or promote products derived from this software without
  29080. + * specific prior written permission.
  29081. + *
  29082. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29083. + * GNU General Public License ("GPL") version 2, as published by the Free
  29084. + * Software Foundation.
  29085. + *
  29086. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29087. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29088. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29089. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29090. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29091. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29092. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29093. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29094. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29095. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29096. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29097. + */
  29098. +
  29099. +#ifndef VCHIQ_PAGELIST_H
  29100. +#define VCHIQ_PAGELIST_H
  29101. +
  29102. +#ifndef PAGE_SIZE
  29103. +#define PAGE_SIZE 4096
  29104. +#endif
  29105. +#define CACHE_LINE_SIZE 32
  29106. +#define PAGELIST_WRITE 0
  29107. +#define PAGELIST_READ 1
  29108. +#define PAGELIST_READ_WITH_FRAGMENTS 2
  29109. +
  29110. +typedef struct pagelist_struct {
  29111. + unsigned long length;
  29112. + unsigned short type;
  29113. + unsigned short offset;
  29114. + unsigned long addrs[1]; /* N.B. 12 LSBs hold the number of following
  29115. + pages at consecutive addresses. */
  29116. +} PAGELIST_T;
  29117. +
  29118. +typedef struct fragments_struct {
  29119. + char headbuf[CACHE_LINE_SIZE];
  29120. + char tailbuf[CACHE_LINE_SIZE];
  29121. +} FRAGMENTS_T;
  29122. +
  29123. +#endif /* VCHIQ_PAGELIST_H */
  29124. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c
  29125. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c 1970-01-01 01:00:00.000000000 +0100
  29126. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c 2014-02-18 11:52:14.000000000 +0100
  29127. @@ -0,0 +1,253 @@
  29128. +/**
  29129. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29130. + *
  29131. + * Redistribution and use in source and binary forms, with or without
  29132. + * modification, are permitted provided that the following conditions
  29133. + * are met:
  29134. + * 1. Redistributions of source code must retain the above copyright
  29135. + * notice, this list of conditions, and the following disclaimer,
  29136. + * without modification.
  29137. + * 2. Redistributions in binary form must reproduce the above copyright
  29138. + * notice, this list of conditions and the following disclaimer in the
  29139. + * documentation and/or other materials provided with the distribution.
  29140. + * 3. The names of the above-listed copyright holders may not be used
  29141. + * to endorse or promote products derived from this software without
  29142. + * specific prior written permission.
  29143. + *
  29144. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29145. + * GNU General Public License ("GPL") version 2, as published by the Free
  29146. + * Software Foundation.
  29147. + *
  29148. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29149. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29150. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29151. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29152. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29153. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29154. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29155. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29156. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29157. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29158. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29159. + */
  29160. +
  29161. +
  29162. +#include <linux/proc_fs.h>
  29163. +#include "vchiq_core.h"
  29164. +#include "vchiq_arm.h"
  29165. +
  29166. +#if 1
  29167. +
  29168. +int vchiq_proc_init(void)
  29169. +{
  29170. + return 0;
  29171. +}
  29172. +
  29173. +void vchiq_proc_deinit(void)
  29174. +{
  29175. +}
  29176. +
  29177. +#else
  29178. +
  29179. +struct vchiq_proc_info {
  29180. + /* Global 'vc' proc entry used by all instances */
  29181. + struct proc_dir_entry *vc_cfg_dir;
  29182. +
  29183. + /* one entry per client process */
  29184. + struct proc_dir_entry *clients;
  29185. +
  29186. + /* log categories */
  29187. + struct proc_dir_entry *log_categories;
  29188. +};
  29189. +
  29190. +static struct vchiq_proc_info proc_info;
  29191. +
  29192. +struct proc_dir_entry *vchiq_proc_top(void)
  29193. +{
  29194. + BUG_ON(proc_info.vc_cfg_dir == NULL);
  29195. + return proc_info.vc_cfg_dir;
  29196. +}
  29197. +
  29198. +/****************************************************************************
  29199. +*
  29200. +* log category entries
  29201. +*
  29202. +***************************************************************************/
  29203. +#define PROC_WRITE_BUF_SIZE 256
  29204. +
  29205. +#define VCHIQ_LOG_ERROR_STR "error"
  29206. +#define VCHIQ_LOG_WARNING_STR "warning"
  29207. +#define VCHIQ_LOG_INFO_STR "info"
  29208. +#define VCHIQ_LOG_TRACE_STR "trace"
  29209. +
  29210. +static int log_cfg_read(char *buffer,
  29211. + char **start,
  29212. + off_t off,
  29213. + int count,
  29214. + int *eof,
  29215. + void *data)
  29216. +{
  29217. + int len = 0;
  29218. + char *log_value = NULL;
  29219. +
  29220. + switch (*((int *)data)) {
  29221. + case VCHIQ_LOG_ERROR:
  29222. + log_value = VCHIQ_LOG_ERROR_STR;
  29223. + break;
  29224. + case VCHIQ_LOG_WARNING:
  29225. + log_value = VCHIQ_LOG_WARNING_STR;
  29226. + break;
  29227. + case VCHIQ_LOG_INFO:
  29228. + log_value = VCHIQ_LOG_INFO_STR;
  29229. + break;
  29230. + case VCHIQ_LOG_TRACE:
  29231. + log_value = VCHIQ_LOG_TRACE_STR;
  29232. + break;
  29233. + default:
  29234. + break;
  29235. + }
  29236. +
  29237. + len += sprintf(buffer + len,
  29238. + "%s\n",
  29239. + log_value ? log_value : "(null)");
  29240. +
  29241. + return len;
  29242. +}
  29243. +
  29244. +
  29245. +static int log_cfg_write(struct file *file,
  29246. + const char __user *buffer,
  29247. + unsigned long count,
  29248. + void *data)
  29249. +{
  29250. + int *log_module = data;
  29251. + char kbuf[PROC_WRITE_BUF_SIZE + 1];
  29252. +
  29253. + (void)file;
  29254. +
  29255. + memset(kbuf, 0, PROC_WRITE_BUF_SIZE + 1);
  29256. + if (count >= PROC_WRITE_BUF_SIZE)
  29257. + count = PROC_WRITE_BUF_SIZE;
  29258. +
  29259. + if (copy_from_user(kbuf,
  29260. + buffer,
  29261. + count) != 0)
  29262. + return -EFAULT;
  29263. + kbuf[count - 1] = 0;
  29264. +
  29265. + if (strncmp("error", kbuf, strlen("error")) == 0)
  29266. + *log_module = VCHIQ_LOG_ERROR;
  29267. + else if (strncmp("warning", kbuf, strlen("warning")) == 0)
  29268. + *log_module = VCHIQ_LOG_WARNING;
  29269. + else if (strncmp("info", kbuf, strlen("info")) == 0)
  29270. + *log_module = VCHIQ_LOG_INFO;
  29271. + else if (strncmp("trace", kbuf, strlen("trace")) == 0)
  29272. + *log_module = VCHIQ_LOG_TRACE;
  29273. + else
  29274. + *log_module = VCHIQ_LOG_DEFAULT;
  29275. +
  29276. + return count;
  29277. +}
  29278. +
  29279. +/* Log category proc entries */
  29280. +struct vchiq_proc_log_entry {
  29281. + const char *name;
  29282. + int *plevel;
  29283. + struct proc_dir_entry *dir;
  29284. +};
  29285. +
  29286. +static struct vchiq_proc_log_entry vchiq_proc_log_entries[] = {
  29287. + { "core", &vchiq_core_log_level },
  29288. + { "msg", &vchiq_core_msg_log_level },
  29289. + { "sync", &vchiq_sync_log_level },
  29290. + { "susp", &vchiq_susp_log_level },
  29291. + { "arm", &vchiq_arm_log_level },
  29292. +};
  29293. +static int n_log_entries =
  29294. + sizeof(vchiq_proc_log_entries)/sizeof(vchiq_proc_log_entries[0]);
  29295. +
  29296. +/* create an entry under /proc/vc/log for each log category */
  29297. +static int vchiq_proc_create_log_entries(struct proc_dir_entry *top)
  29298. +{
  29299. + struct proc_dir_entry *dir;
  29300. + size_t i;
  29301. + int ret = 0;
  29302. + dir = proc_mkdir("log", proc_info.vc_cfg_dir);
  29303. + if (!dir)
  29304. + return -ENOMEM;
  29305. + proc_info.log_categories = dir;
  29306. +
  29307. + for (i = 0; i < n_log_entries; i++) {
  29308. + dir = create_proc_entry(vchiq_proc_log_entries[i].name,
  29309. + 0644,
  29310. + proc_info.log_categories);
  29311. + if (!dir) {
  29312. + ret = -ENOMEM;
  29313. + break;
  29314. + }
  29315. +
  29316. + dir->read_proc = &log_cfg_read;
  29317. + dir->write_proc = &log_cfg_write;
  29318. + dir->data = (void *)vchiq_proc_log_entries[i].plevel;
  29319. +
  29320. + vchiq_proc_log_entries[i].dir = dir;
  29321. + }
  29322. + return ret;
  29323. +}
  29324. +
  29325. +
  29326. +int vchiq_proc_init(void)
  29327. +{
  29328. + BUG_ON(proc_info.vc_cfg_dir != NULL);
  29329. +
  29330. + proc_info.vc_cfg_dir = proc_mkdir("vc", NULL);
  29331. + if (proc_info.vc_cfg_dir == NULL)
  29332. + goto fail;
  29333. +
  29334. + proc_info.clients = proc_mkdir("clients",
  29335. + proc_info.vc_cfg_dir);
  29336. + if (!proc_info.clients)
  29337. + goto fail;
  29338. +
  29339. + if (vchiq_proc_create_log_entries(proc_info.vc_cfg_dir) != 0)
  29340. + goto fail;
  29341. +
  29342. + return 0;
  29343. +
  29344. +fail:
  29345. + vchiq_proc_deinit();
  29346. + vchiq_log_error(vchiq_arm_log_level,
  29347. + "%s: failed to create proc directory",
  29348. + __func__);
  29349. +
  29350. + return -ENOMEM;
  29351. +}
  29352. +
  29353. +/* remove all the proc entries */
  29354. +void vchiq_proc_deinit(void)
  29355. +{
  29356. + /* log category entries */
  29357. + if (proc_info.log_categories) {
  29358. + size_t i;
  29359. + for (i = 0; i < n_log_entries; i++)
  29360. + if (vchiq_proc_log_entries[i].dir)
  29361. + remove_proc_entry(
  29362. + vchiq_proc_log_entries[i].name,
  29363. + proc_info.log_categories);
  29364. +
  29365. + remove_proc_entry(proc_info.log_categories->name,
  29366. + proc_info.vc_cfg_dir);
  29367. + }
  29368. + if (proc_info.clients)
  29369. + remove_proc_entry(proc_info.clients->name,
  29370. + proc_info.vc_cfg_dir);
  29371. + if (proc_info.vc_cfg_dir)
  29372. + remove_proc_entry(proc_info.vc_cfg_dir->name, NULL);
  29373. +}
  29374. +
  29375. +struct proc_dir_entry *vchiq_clients_top(void)
  29376. +{
  29377. + return proc_info.clients;
  29378. +}
  29379. +
  29380. +#endif
  29381. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c
  29382. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 1970-01-01 01:00:00.000000000 +0100
  29383. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 2014-02-18 11:52:14.000000000 +0100
  29384. @@ -0,0 +1,828 @@
  29385. +/**
  29386. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29387. + *
  29388. + * Redistribution and use in source and binary forms, with or without
  29389. + * modification, are permitted provided that the following conditions
  29390. + * are met:
  29391. + * 1. Redistributions of source code must retain the above copyright
  29392. + * notice, this list of conditions, and the following disclaimer,
  29393. + * without modification.
  29394. + * 2. Redistributions in binary form must reproduce the above copyright
  29395. + * notice, this list of conditions and the following disclaimer in the
  29396. + * documentation and/or other materials provided with the distribution.
  29397. + * 3. The names of the above-listed copyright holders may not be used
  29398. + * to endorse or promote products derived from this software without
  29399. + * specific prior written permission.
  29400. + *
  29401. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29402. + * GNU General Public License ("GPL") version 2, as published by the Free
  29403. + * Software Foundation.
  29404. + *
  29405. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29406. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29407. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29408. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29409. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29410. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29411. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29412. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29413. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29414. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29415. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29416. + */
  29417. +#include <linux/module.h>
  29418. +#include <linux/types.h>
  29419. +
  29420. +#include "interface/vchi/vchi.h"
  29421. +#include "vchiq.h"
  29422. +#include "vchiq_core.h"
  29423. +
  29424. +#include "vchiq_util.h"
  29425. +
  29426. +#include <stddef.h>
  29427. +
  29428. +#define vchiq_status_to_vchi(status) ((int32_t)status)
  29429. +
  29430. +typedef struct {
  29431. + VCHIQ_SERVICE_HANDLE_T handle;
  29432. +
  29433. + VCHIU_QUEUE_T queue;
  29434. +
  29435. + VCHI_CALLBACK_T callback;
  29436. + void *callback_param;
  29437. +} SHIM_SERVICE_T;
  29438. +
  29439. +/* ----------------------------------------------------------------------
  29440. + * return pointer to the mphi message driver function table
  29441. + * -------------------------------------------------------------------- */
  29442. +const VCHI_MESSAGE_DRIVER_T *
  29443. +vchi_mphi_message_driver_func_table(void)
  29444. +{
  29445. + return NULL;
  29446. +}
  29447. +
  29448. +/* ----------------------------------------------------------------------
  29449. + * return a pointer to the 'single' connection driver fops
  29450. + * -------------------------------------------------------------------- */
  29451. +const VCHI_CONNECTION_API_T *
  29452. +single_get_func_table(void)
  29453. +{
  29454. + return NULL;
  29455. +}
  29456. +
  29457. +VCHI_CONNECTION_T *vchi_create_connection(
  29458. + const VCHI_CONNECTION_API_T *function_table,
  29459. + const VCHI_MESSAGE_DRIVER_T *low_level)
  29460. +{
  29461. + (void)function_table;
  29462. + (void)low_level;
  29463. + return NULL;
  29464. +}
  29465. +
  29466. +/***********************************************************
  29467. + * Name: vchi_msg_peek
  29468. + *
  29469. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  29470. + * void **data,
  29471. + * uint32_t *msg_size,
  29472. +
  29473. +
  29474. + * VCHI_FLAGS_T flags
  29475. + *
  29476. + * Description: Routine to return a pointer to the current message (to allow in
  29477. + * place processing). The message can be removed using
  29478. + * vchi_msg_remove when you're finished
  29479. + *
  29480. + * Returns: int32_t - success == 0
  29481. + *
  29482. + ***********************************************************/
  29483. +int32_t vchi_msg_peek(VCHI_SERVICE_HANDLE_T handle,
  29484. + void **data,
  29485. + uint32_t *msg_size,
  29486. + VCHI_FLAGS_T flags)
  29487. +{
  29488. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29489. + VCHIQ_HEADER_T *header;
  29490. +
  29491. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  29492. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  29493. +
  29494. + if (flags == VCHI_FLAGS_NONE)
  29495. + if (vchiu_queue_is_empty(&service->queue))
  29496. + return -1;
  29497. +
  29498. + header = vchiu_queue_peek(&service->queue);
  29499. +
  29500. + *data = header->data;
  29501. + *msg_size = header->size;
  29502. +
  29503. + return 0;
  29504. +}
  29505. +EXPORT_SYMBOL(vchi_msg_peek);
  29506. +
  29507. +/***********************************************************
  29508. + * Name: vchi_msg_remove
  29509. + *
  29510. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  29511. + *
  29512. + * Description: Routine to remove a message (after it has been read with
  29513. + * vchi_msg_peek)
  29514. + *
  29515. + * Returns: int32_t - success == 0
  29516. + *
  29517. + ***********************************************************/
  29518. +int32_t vchi_msg_remove(VCHI_SERVICE_HANDLE_T handle)
  29519. +{
  29520. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29521. + VCHIQ_HEADER_T *header;
  29522. +
  29523. + header = vchiu_queue_pop(&service->queue);
  29524. +
  29525. + vchiq_release_message(service->handle, header);
  29526. +
  29527. + return 0;
  29528. +}
  29529. +EXPORT_SYMBOL(vchi_msg_remove);
  29530. +
  29531. +/***********************************************************
  29532. + * Name: vchi_msg_queue
  29533. + *
  29534. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  29535. + * const void *data,
  29536. + * uint32_t data_size,
  29537. + * VCHI_FLAGS_T flags,
  29538. + * void *msg_handle,
  29539. + *
  29540. + * Description: Thin wrapper to queue a message onto a connection
  29541. + *
  29542. + * Returns: int32_t - success == 0
  29543. + *
  29544. + ***********************************************************/
  29545. +int32_t vchi_msg_queue(VCHI_SERVICE_HANDLE_T handle,
  29546. + const void *data,
  29547. + uint32_t data_size,
  29548. + VCHI_FLAGS_T flags,
  29549. + void *msg_handle)
  29550. +{
  29551. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29552. + VCHIQ_ELEMENT_T element = {data, data_size};
  29553. + VCHIQ_STATUS_T status;
  29554. +
  29555. + (void)msg_handle;
  29556. +
  29557. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  29558. +
  29559. + status = vchiq_queue_message(service->handle, &element, 1);
  29560. +
  29561. + /* vchiq_queue_message() may return VCHIQ_RETRY, so we need to
  29562. + ** implement a retry mechanism since this function is supposed
  29563. + ** to block until queued
  29564. + */
  29565. + while (status == VCHIQ_RETRY) {
  29566. + msleep(1);
  29567. + status = vchiq_queue_message(service->handle, &element, 1);
  29568. + }
  29569. +
  29570. + return vchiq_status_to_vchi(status);
  29571. +}
  29572. +EXPORT_SYMBOL(vchi_msg_queue);
  29573. +
  29574. +/***********************************************************
  29575. + * Name: vchi_bulk_queue_receive
  29576. + *
  29577. + * Arguments: VCHI_BULK_HANDLE_T handle,
  29578. + * void *data_dst,
  29579. + * const uint32_t data_size,
  29580. + * VCHI_FLAGS_T flags
  29581. + * void *bulk_handle
  29582. + *
  29583. + * Description: Routine to setup a rcv buffer
  29584. + *
  29585. + * Returns: int32_t - success == 0
  29586. + *
  29587. + ***********************************************************/
  29588. +int32_t vchi_bulk_queue_receive(VCHI_SERVICE_HANDLE_T handle,
  29589. + void *data_dst,
  29590. + uint32_t data_size,
  29591. + VCHI_FLAGS_T flags,
  29592. + void *bulk_handle)
  29593. +{
  29594. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29595. + VCHIQ_BULK_MODE_T mode;
  29596. + VCHIQ_STATUS_T status;
  29597. +
  29598. + switch ((int)flags) {
  29599. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  29600. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  29601. + WARN_ON(!service->callback);
  29602. + mode = VCHIQ_BULK_MODE_CALLBACK;
  29603. + break;
  29604. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  29605. + mode = VCHIQ_BULK_MODE_BLOCKING;
  29606. + break;
  29607. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  29608. + case VCHI_FLAGS_NONE:
  29609. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  29610. + break;
  29611. + default:
  29612. + WARN(1, "unsupported message\n");
  29613. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  29614. + }
  29615. +
  29616. + status = vchiq_bulk_receive(service->handle, data_dst, data_size,
  29617. + bulk_handle, mode);
  29618. +
  29619. + /* vchiq_bulk_receive() may return VCHIQ_RETRY, so we need to
  29620. + ** implement a retry mechanism since this function is supposed
  29621. + ** to block until queued
  29622. + */
  29623. + while (status == VCHIQ_RETRY) {
  29624. + msleep(1);
  29625. + status = vchiq_bulk_receive(service->handle, data_dst,
  29626. + data_size, bulk_handle, mode);
  29627. + }
  29628. +
  29629. + return vchiq_status_to_vchi(status);
  29630. +}
  29631. +EXPORT_SYMBOL(vchi_bulk_queue_receive);
  29632. +
  29633. +/***********************************************************
  29634. + * Name: vchi_bulk_queue_transmit
  29635. + *
  29636. + * Arguments: VCHI_BULK_HANDLE_T handle,
  29637. + * const void *data_src,
  29638. + * uint32_t data_size,
  29639. + * VCHI_FLAGS_T flags,
  29640. + * void *bulk_handle
  29641. + *
  29642. + * Description: Routine to transmit some data
  29643. + *
  29644. + * Returns: int32_t - success == 0
  29645. + *
  29646. + ***********************************************************/
  29647. +int32_t vchi_bulk_queue_transmit(VCHI_SERVICE_HANDLE_T handle,
  29648. + const void *data_src,
  29649. + uint32_t data_size,
  29650. + VCHI_FLAGS_T flags,
  29651. + void *bulk_handle)
  29652. +{
  29653. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29654. + VCHIQ_BULK_MODE_T mode;
  29655. + VCHIQ_STATUS_T status;
  29656. +
  29657. + switch ((int)flags) {
  29658. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  29659. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  29660. + WARN_ON(!service->callback);
  29661. + mode = VCHIQ_BULK_MODE_CALLBACK;
  29662. + break;
  29663. + case VCHI_FLAGS_BLOCK_UNTIL_DATA_READ:
  29664. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  29665. + mode = VCHIQ_BULK_MODE_BLOCKING;
  29666. + break;
  29667. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  29668. + case VCHI_FLAGS_NONE:
  29669. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  29670. + break;
  29671. + default:
  29672. + WARN(1, "unsupported message\n");
  29673. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  29674. + }
  29675. +
  29676. + status = vchiq_bulk_transmit(service->handle, data_src, data_size,
  29677. + bulk_handle, mode);
  29678. +
  29679. + /* vchiq_bulk_transmit() may return VCHIQ_RETRY, so we need to
  29680. + ** implement a retry mechanism since this function is supposed
  29681. + ** to block until queued
  29682. + */
  29683. + while (status == VCHIQ_RETRY) {
  29684. + msleep(1);
  29685. + status = vchiq_bulk_transmit(service->handle, data_src,
  29686. + data_size, bulk_handle, mode);
  29687. + }
  29688. +
  29689. + return vchiq_status_to_vchi(status);
  29690. +}
  29691. +EXPORT_SYMBOL(vchi_bulk_queue_transmit);
  29692. +
  29693. +/***********************************************************
  29694. + * Name: vchi_msg_dequeue
  29695. + *
  29696. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  29697. + * void *data,
  29698. + * uint32_t max_data_size_to_read,
  29699. + * uint32_t *actual_msg_size
  29700. + * VCHI_FLAGS_T flags
  29701. + *
  29702. + * Description: Routine to dequeue a message into the supplied buffer
  29703. + *
  29704. + * Returns: int32_t - success == 0
  29705. + *
  29706. + ***********************************************************/
  29707. +int32_t vchi_msg_dequeue(VCHI_SERVICE_HANDLE_T handle,
  29708. + void *data,
  29709. + uint32_t max_data_size_to_read,
  29710. + uint32_t *actual_msg_size,
  29711. + VCHI_FLAGS_T flags)
  29712. +{
  29713. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29714. + VCHIQ_HEADER_T *header;
  29715. +
  29716. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  29717. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  29718. +
  29719. + if (flags == VCHI_FLAGS_NONE)
  29720. + if (vchiu_queue_is_empty(&service->queue))
  29721. + return -1;
  29722. +
  29723. + header = vchiu_queue_pop(&service->queue);
  29724. +
  29725. + memcpy(data, header->data, header->size < max_data_size_to_read ?
  29726. + header->size : max_data_size_to_read);
  29727. +
  29728. + *actual_msg_size = header->size;
  29729. +
  29730. + vchiq_release_message(service->handle, header);
  29731. +
  29732. + return 0;
  29733. +}
  29734. +EXPORT_SYMBOL(vchi_msg_dequeue);
  29735. +
  29736. +/***********************************************************
  29737. + * Name: vchi_msg_queuev
  29738. + *
  29739. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  29740. + * VCHI_MSG_VECTOR_T *vector,
  29741. + * uint32_t count,
  29742. + * VCHI_FLAGS_T flags,
  29743. + * void *msg_handle
  29744. + *
  29745. + * Description: Thin wrapper to queue a message onto a connection
  29746. + *
  29747. + * Returns: int32_t - success == 0
  29748. + *
  29749. + ***********************************************************/
  29750. +
  29751. +vchiq_static_assert(sizeof(VCHI_MSG_VECTOR_T) == sizeof(VCHIQ_ELEMENT_T));
  29752. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_base) ==
  29753. + offsetof(VCHIQ_ELEMENT_T, data));
  29754. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_len) ==
  29755. + offsetof(VCHIQ_ELEMENT_T, size));
  29756. +
  29757. +int32_t vchi_msg_queuev(VCHI_SERVICE_HANDLE_T handle,
  29758. + VCHI_MSG_VECTOR_T *vector,
  29759. + uint32_t count,
  29760. + VCHI_FLAGS_T flags,
  29761. + void *msg_handle)
  29762. +{
  29763. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29764. +
  29765. + (void)msg_handle;
  29766. +
  29767. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  29768. +
  29769. + return vchiq_status_to_vchi(vchiq_queue_message(service->handle,
  29770. + (const VCHIQ_ELEMENT_T *)vector, count));
  29771. +}
  29772. +EXPORT_SYMBOL(vchi_msg_queuev);
  29773. +
  29774. +/***********************************************************
  29775. + * Name: vchi_held_msg_release
  29776. + *
  29777. + * Arguments: VCHI_HELD_MSG_T *message
  29778. + *
  29779. + * Description: Routine to release a held message (after it has been read with
  29780. + * vchi_msg_hold)
  29781. + *
  29782. + * Returns: int32_t - success == 0
  29783. + *
  29784. + ***********************************************************/
  29785. +int32_t vchi_held_msg_release(VCHI_HELD_MSG_T *message)
  29786. +{
  29787. + vchiq_release_message((VCHIQ_SERVICE_HANDLE_T)message->service,
  29788. + (VCHIQ_HEADER_T *)message->message);
  29789. +
  29790. + return 0;
  29791. +}
  29792. +EXPORT_SYMBOL(vchi_held_msg_release);
  29793. +
  29794. +/***********************************************************
  29795. + * Name: vchi_msg_hold
  29796. + *
  29797. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  29798. + * void **data,
  29799. + * uint32_t *msg_size,
  29800. + * VCHI_FLAGS_T flags,
  29801. + * VCHI_HELD_MSG_T *message_handle
  29802. + *
  29803. + * Description: Routine to return a pointer to the current message (to allow
  29804. + * in place processing). The message is dequeued - don't forget
  29805. + * to release the message using vchi_held_msg_release when you're
  29806. + * finished.
  29807. + *
  29808. + * Returns: int32_t - success == 0
  29809. + *
  29810. + ***********************************************************/
  29811. +int32_t vchi_msg_hold(VCHI_SERVICE_HANDLE_T handle,
  29812. + void **data,
  29813. + uint32_t *msg_size,
  29814. + VCHI_FLAGS_T flags,
  29815. + VCHI_HELD_MSG_T *message_handle)
  29816. +{
  29817. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29818. + VCHIQ_HEADER_T *header;
  29819. +
  29820. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  29821. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  29822. +
  29823. + if (flags == VCHI_FLAGS_NONE)
  29824. + if (vchiu_queue_is_empty(&service->queue))
  29825. + return -1;
  29826. +
  29827. + header = vchiu_queue_pop(&service->queue);
  29828. +
  29829. + *data = header->data;
  29830. + *msg_size = header->size;
  29831. +
  29832. + message_handle->service =
  29833. + (struct opaque_vchi_service_t *)service->handle;
  29834. + message_handle->message = header;
  29835. +
  29836. + return 0;
  29837. +}
  29838. +EXPORT_SYMBOL(vchi_msg_hold);
  29839. +
  29840. +/***********************************************************
  29841. + * Name: vchi_initialise
  29842. + *
  29843. + * Arguments: VCHI_INSTANCE_T *instance_handle
  29844. + * VCHI_CONNECTION_T **connections
  29845. + * const uint32_t num_connections
  29846. + *
  29847. + * Description: Initialises the hardware but does not transmit anything
  29848. + * When run as a Host App this will be called twice hence the need
  29849. + * to malloc the state information
  29850. + *
  29851. + * Returns: 0 if successful, failure otherwise
  29852. + *
  29853. + ***********************************************************/
  29854. +
  29855. +int32_t vchi_initialise(VCHI_INSTANCE_T *instance_handle)
  29856. +{
  29857. + VCHIQ_INSTANCE_T instance;
  29858. + VCHIQ_STATUS_T status;
  29859. +
  29860. + status = vchiq_initialise(&instance);
  29861. +
  29862. + *instance_handle = (VCHI_INSTANCE_T)instance;
  29863. +
  29864. + return vchiq_status_to_vchi(status);
  29865. +}
  29866. +EXPORT_SYMBOL(vchi_initialise);
  29867. +
  29868. +/***********************************************************
  29869. + * Name: vchi_connect
  29870. + *
  29871. + * Arguments: VCHI_CONNECTION_T **connections
  29872. + * const uint32_t num_connections
  29873. + * VCHI_INSTANCE_T instance_handle)
  29874. + *
  29875. + * Description: Starts the command service on each connection,
  29876. + * causing INIT messages to be pinged back and forth
  29877. + *
  29878. + * Returns: 0 if successful, failure otherwise
  29879. + *
  29880. + ***********************************************************/
  29881. +int32_t vchi_connect(VCHI_CONNECTION_T **connections,
  29882. + const uint32_t num_connections,
  29883. + VCHI_INSTANCE_T instance_handle)
  29884. +{
  29885. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  29886. +
  29887. + (void)connections;
  29888. + (void)num_connections;
  29889. +
  29890. + return vchiq_connect(instance);
  29891. +}
  29892. +EXPORT_SYMBOL(vchi_connect);
  29893. +
  29894. +
  29895. +/***********************************************************
  29896. + * Name: vchi_disconnect
  29897. + *
  29898. + * Arguments: VCHI_INSTANCE_T instance_handle
  29899. + *
  29900. + * Description: Stops the command service on each connection,
  29901. + * causing DE-INIT messages to be pinged back and forth
  29902. + *
  29903. + * Returns: 0 if successful, failure otherwise
  29904. + *
  29905. + ***********************************************************/
  29906. +int32_t vchi_disconnect(VCHI_INSTANCE_T instance_handle)
  29907. +{
  29908. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  29909. + return vchiq_status_to_vchi(vchiq_shutdown(instance));
  29910. +}
  29911. +EXPORT_SYMBOL(vchi_disconnect);
  29912. +
  29913. +
  29914. +/***********************************************************
  29915. + * Name: vchi_service_open
  29916. + * Name: vchi_service_create
  29917. + *
  29918. + * Arguments: VCHI_INSTANCE_T *instance_handle
  29919. + * SERVICE_CREATION_T *setup,
  29920. + * VCHI_SERVICE_HANDLE_T *handle
  29921. + *
  29922. + * Description: Routine to open a service
  29923. + *
  29924. + * Returns: int32_t - success == 0
  29925. + *
  29926. + ***********************************************************/
  29927. +
  29928. +static VCHIQ_STATUS_T shim_callback(VCHIQ_REASON_T reason,
  29929. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_HANDLE_T handle, void *bulk_user)
  29930. +{
  29931. + SHIM_SERVICE_T *service =
  29932. + (SHIM_SERVICE_T *)VCHIQ_GET_SERVICE_USERDATA(handle);
  29933. +
  29934. + if (!service->callback)
  29935. + goto release;
  29936. +
  29937. + switch (reason) {
  29938. + case VCHIQ_MESSAGE_AVAILABLE:
  29939. + vchiu_queue_push(&service->queue, header);
  29940. +
  29941. + service->callback(service->callback_param,
  29942. + VCHI_CALLBACK_MSG_AVAILABLE, NULL);
  29943. +
  29944. + goto done;
  29945. + break;
  29946. +
  29947. + case VCHIQ_BULK_TRANSMIT_DONE:
  29948. + service->callback(service->callback_param,
  29949. + VCHI_CALLBACK_BULK_SENT, bulk_user);
  29950. + break;
  29951. +
  29952. + case VCHIQ_BULK_RECEIVE_DONE:
  29953. + service->callback(service->callback_param,
  29954. + VCHI_CALLBACK_BULK_RECEIVED, bulk_user);
  29955. + break;
  29956. +
  29957. + case VCHIQ_SERVICE_CLOSED:
  29958. + service->callback(service->callback_param,
  29959. + VCHI_CALLBACK_SERVICE_CLOSED, NULL);
  29960. + break;
  29961. +
  29962. + case VCHIQ_SERVICE_OPENED:
  29963. + /* No equivalent VCHI reason */
  29964. + break;
  29965. +
  29966. + case VCHIQ_BULK_TRANSMIT_ABORTED:
  29967. + service->callback(service->callback_param,
  29968. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  29969. + bulk_user);
  29970. + break;
  29971. +
  29972. + case VCHIQ_BULK_RECEIVE_ABORTED:
  29973. + service->callback(service->callback_param,
  29974. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  29975. + bulk_user);
  29976. + break;
  29977. +
  29978. + default:
  29979. + WARN(1, "not supported\n");
  29980. + break;
  29981. + }
  29982. +
  29983. +release:
  29984. + vchiq_release_message(service->handle, header);
  29985. +done:
  29986. + return VCHIQ_SUCCESS;
  29987. +}
  29988. +
  29989. +static SHIM_SERVICE_T *service_alloc(VCHIQ_INSTANCE_T instance,
  29990. + SERVICE_CREATION_T *setup)
  29991. +{
  29992. + SHIM_SERVICE_T *service = kzalloc(sizeof(SHIM_SERVICE_T), GFP_KERNEL);
  29993. +
  29994. + (void)instance;
  29995. +
  29996. + if (service) {
  29997. + if (vchiu_queue_init(&service->queue, 64)) {
  29998. + service->callback = setup->callback;
  29999. + service->callback_param = setup->callback_param;
  30000. + } else {
  30001. + kfree(service);
  30002. + service = NULL;
  30003. + }
  30004. + }
  30005. +
  30006. + return service;
  30007. +}
  30008. +
  30009. +static void service_free(SHIM_SERVICE_T *service)
  30010. +{
  30011. + if (service) {
  30012. + vchiu_queue_delete(&service->queue);
  30013. + kfree(service);
  30014. + }
  30015. +}
  30016. +
  30017. +int32_t vchi_service_open(VCHI_INSTANCE_T instance_handle,
  30018. + SERVICE_CREATION_T *setup,
  30019. + VCHI_SERVICE_HANDLE_T *handle)
  30020. +{
  30021. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  30022. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  30023. + if (service) {
  30024. + VCHIQ_SERVICE_PARAMS_T params;
  30025. + VCHIQ_STATUS_T status;
  30026. +
  30027. + memset(&params, 0, sizeof(params));
  30028. + params.fourcc = setup->service_id;
  30029. + params.callback = shim_callback;
  30030. + params.userdata = service;
  30031. + params.version = setup->version.version;
  30032. + params.version_min = setup->version.version_min;
  30033. +
  30034. + status = vchiq_open_service(instance, &params,
  30035. + &service->handle);
  30036. + if (status != VCHIQ_SUCCESS) {
  30037. + service_free(service);
  30038. + service = NULL;
  30039. + }
  30040. + }
  30041. +
  30042. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  30043. +
  30044. + return (service != NULL) ? 0 : -1;
  30045. +}
  30046. +EXPORT_SYMBOL(vchi_service_open);
  30047. +
  30048. +int32_t vchi_service_create(VCHI_INSTANCE_T instance_handle,
  30049. + SERVICE_CREATION_T *setup,
  30050. + VCHI_SERVICE_HANDLE_T *handle)
  30051. +{
  30052. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  30053. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  30054. + if (service) {
  30055. + VCHIQ_SERVICE_PARAMS_T params;
  30056. + VCHIQ_STATUS_T status;
  30057. +
  30058. + memset(&params, 0, sizeof(params));
  30059. + params.fourcc = setup->service_id;
  30060. + params.callback = shim_callback;
  30061. + params.userdata = service;
  30062. + params.version = setup->version.version;
  30063. + params.version_min = setup->version.version_min;
  30064. + status = vchiq_add_service(instance, &params, &service->handle);
  30065. +
  30066. + if (status != VCHIQ_SUCCESS) {
  30067. + service_free(service);
  30068. + service = NULL;
  30069. + }
  30070. + }
  30071. +
  30072. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  30073. +
  30074. + return (service != NULL) ? 0 : -1;
  30075. +}
  30076. +EXPORT_SYMBOL(vchi_service_create);
  30077. +
  30078. +int32_t vchi_service_close(const VCHI_SERVICE_HANDLE_T handle)
  30079. +{
  30080. + int32_t ret = -1;
  30081. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30082. + if (service) {
  30083. + VCHIQ_STATUS_T status = vchiq_close_service(service->handle);
  30084. + if (status == VCHIQ_SUCCESS) {
  30085. + service_free(service);
  30086. + service = NULL;
  30087. + }
  30088. +
  30089. + ret = vchiq_status_to_vchi(status);
  30090. + }
  30091. + return ret;
  30092. +}
  30093. +EXPORT_SYMBOL(vchi_service_close);
  30094. +
  30095. +int32_t vchi_service_destroy(const VCHI_SERVICE_HANDLE_T handle)
  30096. +{
  30097. + int32_t ret = -1;
  30098. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30099. + if (service) {
  30100. + VCHIQ_STATUS_T status = vchiq_remove_service(service->handle);
  30101. + if (status == VCHIQ_SUCCESS) {
  30102. + service_free(service);
  30103. + service = NULL;
  30104. + }
  30105. +
  30106. + ret = vchiq_status_to_vchi(status);
  30107. + }
  30108. + return ret;
  30109. +}
  30110. +EXPORT_SYMBOL(vchi_service_destroy);
  30111. +
  30112. +int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle, short *peer_version )
  30113. +{
  30114. + int32_t ret = -1;
  30115. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30116. + if(service)
  30117. + {
  30118. + VCHIQ_STATUS_T status = vchiq_get_peer_version(service->handle, peer_version);
  30119. + ret = vchiq_status_to_vchi( status );
  30120. + }
  30121. + return ret;
  30122. +}
  30123. +EXPORT_SYMBOL(vchi_get_peer_version);
  30124. +
  30125. +/* ----------------------------------------------------------------------
  30126. + * read a uint32_t from buffer.
  30127. + * network format is defined to be little endian
  30128. + * -------------------------------------------------------------------- */
  30129. +uint32_t
  30130. +vchi_readbuf_uint32(const void *_ptr)
  30131. +{
  30132. + const unsigned char *ptr = _ptr;
  30133. + return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
  30134. +}
  30135. +
  30136. +/* ----------------------------------------------------------------------
  30137. + * write a uint32_t to buffer.
  30138. + * network format is defined to be little endian
  30139. + * -------------------------------------------------------------------- */
  30140. +void
  30141. +vchi_writebuf_uint32(void *_ptr, uint32_t value)
  30142. +{
  30143. + unsigned char *ptr = _ptr;
  30144. + ptr[0] = (unsigned char)((value >> 0) & 0xFF);
  30145. + ptr[1] = (unsigned char)((value >> 8) & 0xFF);
  30146. + ptr[2] = (unsigned char)((value >> 16) & 0xFF);
  30147. + ptr[3] = (unsigned char)((value >> 24) & 0xFF);
  30148. +}
  30149. +
  30150. +/* ----------------------------------------------------------------------
  30151. + * read a uint16_t from buffer.
  30152. + * network format is defined to be little endian
  30153. + * -------------------------------------------------------------------- */
  30154. +uint16_t
  30155. +vchi_readbuf_uint16(const void *_ptr)
  30156. +{
  30157. + const unsigned char *ptr = _ptr;
  30158. + return ptr[0] | (ptr[1] << 8);
  30159. +}
  30160. +
  30161. +/* ----------------------------------------------------------------------
  30162. + * write a uint16_t into the buffer.
  30163. + * network format is defined to be little endian
  30164. + * -------------------------------------------------------------------- */
  30165. +void
  30166. +vchi_writebuf_uint16(void *_ptr, uint16_t value)
  30167. +{
  30168. + unsigned char *ptr = _ptr;
  30169. + ptr[0] = (value >> 0) & 0xFF;
  30170. + ptr[1] = (value >> 8) & 0xFF;
  30171. +}
  30172. +
  30173. +/***********************************************************
  30174. + * Name: vchi_service_use
  30175. + *
  30176. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  30177. + *
  30178. + * Description: Routine to increment refcount on a service
  30179. + *
  30180. + * Returns: void
  30181. + *
  30182. + ***********************************************************/
  30183. +int32_t vchi_service_use(const VCHI_SERVICE_HANDLE_T handle)
  30184. +{
  30185. + int32_t ret = -1;
  30186. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30187. + if (service)
  30188. + ret = vchiq_status_to_vchi(vchiq_use_service(service->handle));
  30189. + return ret;
  30190. +}
  30191. +EXPORT_SYMBOL(vchi_service_use);
  30192. +
  30193. +/***********************************************************
  30194. + * Name: vchi_service_release
  30195. + *
  30196. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  30197. + *
  30198. + * Description: Routine to decrement refcount on a service
  30199. + *
  30200. + * Returns: void
  30201. + *
  30202. + ***********************************************************/
  30203. +int32_t vchi_service_release(const VCHI_SERVICE_HANDLE_T handle)
  30204. +{
  30205. + int32_t ret = -1;
  30206. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  30207. + if (service)
  30208. + ret = vchiq_status_to_vchi(
  30209. + vchiq_release_service(service->handle));
  30210. + return ret;
  30211. +}
  30212. +EXPORT_SYMBOL(vchi_service_release);
  30213. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
  30214. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 1970-01-01 01:00:00.000000000 +0100
  30215. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 2014-02-18 11:52:14.000000000 +0100
  30216. @@ -0,0 +1,151 @@
  30217. +/**
  30218. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30219. + *
  30220. + * Redistribution and use in source and binary forms, with or without
  30221. + * modification, are permitted provided that the following conditions
  30222. + * are met:
  30223. + * 1. Redistributions of source code must retain the above copyright
  30224. + * notice, this list of conditions, and the following disclaimer,
  30225. + * without modification.
  30226. + * 2. Redistributions in binary form must reproduce the above copyright
  30227. + * notice, this list of conditions and the following disclaimer in the
  30228. + * documentation and/or other materials provided with the distribution.
  30229. + * 3. The names of the above-listed copyright holders may not be used
  30230. + * to endorse or promote products derived from this software without
  30231. + * specific prior written permission.
  30232. + *
  30233. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30234. + * GNU General Public License ("GPL") version 2, as published by the Free
  30235. + * Software Foundation.
  30236. + *
  30237. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30238. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30239. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30240. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30241. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30242. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30243. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30244. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30245. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30246. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30247. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30248. + */
  30249. +
  30250. +#include "vchiq_util.h"
  30251. +
  30252. +static inline int is_pow2(int i)
  30253. +{
  30254. + return i && !(i & (i - 1));
  30255. +}
  30256. +
  30257. +int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size)
  30258. +{
  30259. + WARN_ON(!is_pow2(size));
  30260. +
  30261. + queue->size = size;
  30262. + queue->read = 0;
  30263. + queue->write = 0;
  30264. +
  30265. + sema_init(&queue->pop, 0);
  30266. + sema_init(&queue->push, 0);
  30267. +
  30268. + queue->storage = kzalloc(size * sizeof(VCHIQ_HEADER_T *), GFP_KERNEL);
  30269. + if (queue->storage == NULL) {
  30270. + vchiu_queue_delete(queue);
  30271. + return 0;
  30272. + }
  30273. + return 1;
  30274. +}
  30275. +
  30276. +void vchiu_queue_delete(VCHIU_QUEUE_T *queue)
  30277. +{
  30278. + if (queue->storage != NULL)
  30279. + kfree(queue->storage);
  30280. +}
  30281. +
  30282. +int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue)
  30283. +{
  30284. + return queue->read == queue->write;
  30285. +}
  30286. +
  30287. +int vchiu_queue_is_full(VCHIU_QUEUE_T *queue)
  30288. +{
  30289. + return queue->write == queue->read + queue->size;
  30290. +}
  30291. +
  30292. +void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header)
  30293. +{
  30294. + while (queue->write == queue->read + queue->size) {
  30295. + if (down_interruptible(&queue->pop) != 0) {
  30296. + flush_signals(current);
  30297. + }
  30298. + }
  30299. +
  30300. + /*
  30301. + * Write to queue->storage must be visible after read from
  30302. + * queue->read
  30303. + */
  30304. + smp_mb();
  30305. +
  30306. + queue->storage[queue->write & (queue->size - 1)] = header;
  30307. +
  30308. + /*
  30309. + * Write to queue->storage must be visible before write to
  30310. + * queue->write
  30311. + */
  30312. + smp_wmb();
  30313. +
  30314. + queue->write++;
  30315. +
  30316. + up(&queue->push);
  30317. +}
  30318. +
  30319. +VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue)
  30320. +{
  30321. + while (queue->write == queue->read) {
  30322. + if (down_interruptible(&queue->push) != 0) {
  30323. + flush_signals(current);
  30324. + }
  30325. + }
  30326. +
  30327. + up(&queue->push); // We haven't removed anything from the queue.
  30328. +
  30329. + /*
  30330. + * Read from queue->storage must be visible after read from
  30331. + * queue->write
  30332. + */
  30333. + smp_rmb();
  30334. +
  30335. + return queue->storage[queue->read & (queue->size - 1)];
  30336. +}
  30337. +
  30338. +VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue)
  30339. +{
  30340. + VCHIQ_HEADER_T *header;
  30341. +
  30342. + while (queue->write == queue->read) {
  30343. + if (down_interruptible(&queue->push) != 0) {
  30344. + flush_signals(current);
  30345. + }
  30346. + }
  30347. +
  30348. + /*
  30349. + * Read from queue->storage must be visible after read from
  30350. + * queue->write
  30351. + */
  30352. + smp_rmb();
  30353. +
  30354. + header = queue->storage[queue->read & (queue->size - 1)];
  30355. +
  30356. + /*
  30357. + * Read from queue->storage must be visible before write to
  30358. + * queue->read
  30359. + */
  30360. + smp_mb();
  30361. +
  30362. + queue->read++;
  30363. +
  30364. + up(&queue->pop);
  30365. +
  30366. + return header;
  30367. +}
  30368. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h
  30369. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 1970-01-01 01:00:00.000000000 +0100
  30370. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 2014-02-18 11:52:14.000000000 +0100
  30371. @@ -0,0 +1,81 @@
  30372. +/**
  30373. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30374. + *
  30375. + * Redistribution and use in source and binary forms, with or without
  30376. + * modification, are permitted provided that the following conditions
  30377. + * are met:
  30378. + * 1. Redistributions of source code must retain the above copyright
  30379. + * notice, this list of conditions, and the following disclaimer,
  30380. + * without modification.
  30381. + * 2. Redistributions in binary form must reproduce the above copyright
  30382. + * notice, this list of conditions and the following disclaimer in the
  30383. + * documentation and/or other materials provided with the distribution.
  30384. + * 3. The names of the above-listed copyright holders may not be used
  30385. + * to endorse or promote products derived from this software without
  30386. + * specific prior written permission.
  30387. + *
  30388. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30389. + * GNU General Public License ("GPL") version 2, as published by the Free
  30390. + * Software Foundation.
  30391. + *
  30392. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30393. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30394. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30395. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30396. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30397. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30398. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30399. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30400. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30401. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30402. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30403. + */
  30404. +
  30405. +#ifndef VCHIQ_UTIL_H
  30406. +#define VCHIQ_UTIL_H
  30407. +
  30408. +#include <linux/types.h>
  30409. +#include <linux/semaphore.h>
  30410. +#include <linux/mutex.h>
  30411. +#include <linux/bitops.h>
  30412. +#include <linux/kthread.h>
  30413. +#include <linux/wait.h>
  30414. +#include <linux/vmalloc.h>
  30415. +#include <linux/jiffies.h>
  30416. +#include <linux/delay.h>
  30417. +#include <linux/string.h>
  30418. +#include <linux/types.h>
  30419. +#include <linux/interrupt.h>
  30420. +#include <linux/random.h>
  30421. +#include <linux/sched.h>
  30422. +#include <linux/ctype.h>
  30423. +#include <linux/uaccess.h>
  30424. +#include <linux/time.h> /* for time_t */
  30425. +#include <linux/slab.h>
  30426. +#include <linux/vmalloc.h>
  30427. +
  30428. +#include "vchiq_if.h"
  30429. +
  30430. +typedef struct {
  30431. + int size;
  30432. + int read;
  30433. + int write;
  30434. +
  30435. + struct semaphore pop;
  30436. + struct semaphore push;
  30437. +
  30438. + VCHIQ_HEADER_T **storage;
  30439. +} VCHIU_QUEUE_T;
  30440. +
  30441. +extern int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size);
  30442. +extern void vchiu_queue_delete(VCHIU_QUEUE_T *queue);
  30443. +
  30444. +extern int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue);
  30445. +extern int vchiu_queue_is_full(VCHIU_QUEUE_T *queue);
  30446. +
  30447. +extern void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header);
  30448. +
  30449. +extern VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue);
  30450. +extern VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue);
  30451. +
  30452. +#endif
  30453. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c
  30454. --- linux-3.12.11.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 1970-01-01 01:00:00.000000000 +0100
  30455. +++ linux-3.12.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 2014-02-18 11:52:14.000000000 +0100
  30456. @@ -0,0 +1,59 @@
  30457. +/**
  30458. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30459. + *
  30460. + * Redistribution and use in source and binary forms, with or without
  30461. + * modification, are permitted provided that the following conditions
  30462. + * are met:
  30463. + * 1. Redistributions of source code must retain the above copyright
  30464. + * notice, this list of conditions, and the following disclaimer,
  30465. + * without modification.
  30466. + * 2. Redistributions in binary form must reproduce the above copyright
  30467. + * notice, this list of conditions and the following disclaimer in the
  30468. + * documentation and/or other materials provided with the distribution.
  30469. + * 3. The names of the above-listed copyright holders may not be used
  30470. + * to endorse or promote products derived from this software without
  30471. + * specific prior written permission.
  30472. + *
  30473. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30474. + * GNU General Public License ("GPL") version 2, as published by the Free
  30475. + * Software Foundation.
  30476. + *
  30477. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30478. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30479. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30480. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30481. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30482. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30483. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30484. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30485. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30486. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30487. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30488. + */
  30489. +#include "vchiq_build_info.h"
  30490. +#include <linux/broadcom/vc_debug_sym.h>
  30491. +
  30492. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_hostname, "dc4-arm-01" );
  30493. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_version, "9245b4c35b99b3870e1f7dc598c5692b3c66a6f0 (tainted)" );
  30494. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_time, __TIME__ );
  30495. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_date, __DATE__ );
  30496. +
  30497. +const char *vchiq_get_build_hostname( void )
  30498. +{
  30499. + return vchiq_build_hostname;
  30500. +}
  30501. +
  30502. +const char *vchiq_get_build_version( void )
  30503. +{
  30504. + return vchiq_build_version;
  30505. +}
  30506. +
  30507. +const char *vchiq_get_build_date( void )
  30508. +{
  30509. + return vchiq_build_date;
  30510. +}
  30511. +
  30512. +const char *vchiq_get_build_time( void )
  30513. +{
  30514. + return vchiq_build_time;
  30515. +}
  30516. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/Kconfig linux-3.12.11/drivers/misc/vc04_services/Kconfig
  30517. --- linux-3.12.11.orig/drivers/misc/vc04_services/Kconfig 1970-01-01 01:00:00.000000000 +0100
  30518. +++ linux-3.12.11/drivers/misc/vc04_services/Kconfig 2014-02-18 11:52:14.000000000 +0100
  30519. @@ -0,0 +1,9 @@
  30520. +config BCM2708_VCHIQ
  30521. + tristate "Videocore VCHIQ"
  30522. + depends on MACH_BCM2708
  30523. + default y
  30524. + help
  30525. + Kernel to VideoCore communication interface for the
  30526. + BCM2708 family of products.
  30527. + Defaults to Y when the Broadcom Videocore services
  30528. + are included in the build, N otherwise.
  30529. diff -Nur linux-3.12.11.orig/drivers/misc/vc04_services/Makefile linux-3.12.11/drivers/misc/vc04_services/Makefile
  30530. --- linux-3.12.11.orig/drivers/misc/vc04_services/Makefile 1970-01-01 01:00:00.000000000 +0100
  30531. +++ linux-3.12.11/drivers/misc/vc04_services/Makefile 2014-02-18 11:52:14.000000000 +0100
  30532. @@ -0,0 +1,17 @@
  30533. +ifeq ($(CONFIG_MACH_BCM2708),y)
  30534. +
  30535. +obj-$(CONFIG_BCM2708_VCHIQ) += vchiq.o
  30536. +
  30537. +vchiq-objs := \
  30538. + interface/vchiq_arm/vchiq_core.o \
  30539. + interface/vchiq_arm/vchiq_arm.o \
  30540. + interface/vchiq_arm/vchiq_kern_lib.o \
  30541. + interface/vchiq_arm/vchiq_2835_arm.o \
  30542. + interface/vchiq_arm/vchiq_proc.o \
  30543. + interface/vchiq_arm/vchiq_shim.o \
  30544. + interface/vchiq_arm/vchiq_util.o \
  30545. + interface/vchiq_arm/vchiq_connected.o \
  30546. +
  30547. +EXTRA_CFLAGS += -DVCOS_VERIFY_BKPTS=1 -Idrivers/misc/vc04_services -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000
  30548. +
  30549. +endif
  30550. diff -Nur linux-3.12.11.orig/drivers/mmc/card/block.c linux-3.12.11/drivers/mmc/card/block.c
  30551. --- linux-3.12.11.orig/drivers/mmc/card/block.c 2014-02-13 22:51:06.000000000 +0100
  30552. +++ linux-3.12.11/drivers/mmc/card/block.c 2014-02-18 11:52:14.000000000 +0100
  30553. @@ -1361,7 +1361,7 @@
  30554. brq->data.blocks = 1;
  30555. }
  30556. - if (brq->data.blocks > 1 || do_rel_wr) {
  30557. + if (brq->data.blocks > 1 || do_rel_wr || card->host->caps2 & MMC_CAP2_FORCE_MULTIBLOCK) {
  30558. /* SPI multiblock writes terminate using a special
  30559. * token, not a STOP_TRANSMISSION request.
  30560. */
  30561. diff -Nur linux-3.12.11.orig/drivers/mmc/core/sd.c linux-3.12.11/drivers/mmc/core/sd.c
  30562. --- linux-3.12.11.orig/drivers/mmc/core/sd.c 2014-02-13 22:51:06.000000000 +0100
  30563. +++ linux-3.12.11/drivers/mmc/core/sd.c 2014-02-18 12:04:40.000000000 +0100
  30564. @@ -14,6 +14,8 @@
  30565. #include <linux/sizes.h>
  30566. #include <linux/slab.h>
  30567. #include <linux/stat.h>
  30568. +#include <linux/jiffies.h>
  30569. +#include <linux/nmi.h>
  30570. #include <linux/mmc/host.h>
  30571. #include <linux/mmc/card.h>
  30572. @@ -66,6 +68,15 @@
  30573. __res & __mask; \
  30574. })
  30575. +// timeout for tries
  30576. +static const unsigned long retry_timeout_ms= 10*1000;
  30577. +
  30578. +// try at least 10 times, even if timeout is reached
  30579. +static const int retry_min_tries= 10;
  30580. +
  30581. +// delay between tries
  30582. +static const unsigned long retry_delay_ms= 10;
  30583. +
  30584. /*
  30585. * Given the decoded CSD structure, decode the raw CID to our CID structure.
  30586. */
  30587. @@ -217,13 +228,64 @@
  30588. return 0;
  30589. }
  30590. + /*
  30591. + * Fetch and process SD Configuration Register.
  30592. + */
  30593. +static int mmc_read_scr(struct mmc_card *card)
  30594. +{
  30595. + unsigned long timeout_at;
  30596. + int err, tries;
  30597. +
  30598. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  30599. + tries= 0;
  30600. +
  30601. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  30602. + {
  30603. + unsigned long delay_at;
  30604. + tries++;
  30605. +
  30606. + err = mmc_app_send_scr(card, card->raw_scr);
  30607. + if( !err )
  30608. + break; // success!!!
  30609. +
  30610. + touch_nmi_watchdog(); // we are still alive!
  30611. +
  30612. + // delay
  30613. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  30614. + while( time_before( jiffies, delay_at ) )
  30615. + {
  30616. + mdelay( 1 );
  30617. + touch_nmi_watchdog(); // we are still alive!
  30618. + }
  30619. + }
  30620. +
  30621. + if( err)
  30622. + {
  30623. + 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 );
  30624. + return err;
  30625. + }
  30626. +
  30627. + if( tries > 1 )
  30628. + {
  30629. + pr_info("%s: could read SD Configuration register (SCR) at the %dth attempt\n", mmc_hostname(card->host), tries );
  30630. + }
  30631. +
  30632. + err = mmc_decode_scr(card);
  30633. + if (err)
  30634. + return err;
  30635. +
  30636. + return err;
  30637. +}
  30638. +
  30639. /*
  30640. * Fetch and process SD Status register.
  30641. */
  30642. static int mmc_read_ssr(struct mmc_card *card)
  30643. {
  30644. + unsigned long timeout_at;
  30645. unsigned int au, es, et, eo;
  30646. int err, i;
  30647. + int tries;
  30648. u32 *ssr;
  30649. if (!(card->csd.cmdclass & CCC_APP_SPEC)) {
  30650. @@ -236,14 +298,40 @@
  30651. if (!ssr)
  30652. return -ENOMEM;
  30653. - err = mmc_app_sd_status(card, ssr);
  30654. - if (err) {
  30655. - pr_warning("%s: problem reading SD Status "
  30656. - "register.\n", mmc_hostname(card->host));
  30657. - err = 0;
  30658. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  30659. + tries= 0;
  30660. +
  30661. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  30662. + {
  30663. + unsigned long delay_at;
  30664. + tries++;
  30665. +
  30666. + err= mmc_app_sd_status(card, ssr);
  30667. + if( !err )
  30668. + break; // sucess!!!
  30669. +
  30670. + touch_nmi_watchdog(); // we are still alive!
  30671. +
  30672. + // delay
  30673. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  30674. + while( time_before( jiffies, delay_at ) )
  30675. + {
  30676. + mdelay( 1 );
  30677. + touch_nmi_watchdog(); // we are still alive!
  30678. + }
  30679. + }
  30680. +
  30681. + if( err)
  30682. + {
  30683. + 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 );
  30684. goto out;
  30685. }
  30686. + if( tries > 1 )
  30687. + {
  30688. + pr_info("%s: read SD Status register (SSR) after %d attempts\n", mmc_hostname(card->host), tries );
  30689. + }
  30690. +
  30691. for (i = 0; i < 16; i++)
  30692. ssr[i] = be32_to_cpu(ssr[i]);
  30693. @@ -823,14 +911,10 @@
  30694. if (!reinit) {
  30695. /*
  30696. - * Fetch SCR from card.
  30697. + * Fetch and decode SD Configuration register.
  30698. */
  30699. - err = mmc_app_send_scr(card, card->raw_scr);
  30700. - if (err)
  30701. - return err;
  30702. -
  30703. - err = mmc_decode_scr(card);
  30704. - if (err)
  30705. + err = mmc_read_scr(card);
  30706. + if( err )
  30707. return err;
  30708. /*
  30709. diff -Nur linux-3.12.11.orig/drivers/mmc/host/Kconfig linux-3.12.11/drivers/mmc/host/Kconfig
  30710. --- linux-3.12.11.orig/drivers/mmc/host/Kconfig 2014-02-13 22:51:06.000000000 +0100
  30711. +++ linux-3.12.11/drivers/mmc/host/Kconfig 2014-02-18 11:52:14.000000000 +0100
  30712. @@ -260,6 +260,27 @@
  30713. If you have a controller with this interface, say Y or M here.
  30714. +config MMC_SDHCI_BCM2708
  30715. + tristate "SDHCI support on BCM2708"
  30716. + depends on MMC_SDHCI && MACH_BCM2708
  30717. + select MMC_SDHCI_IO_ACCESSORS
  30718. + help
  30719. + This selects the Secure Digital Host Controller Interface (SDHCI)
  30720. + often referrered to as the eMMC block.
  30721. +
  30722. + If you have a controller with this interface, say Y or M here.
  30723. +
  30724. + If unsure, say N.
  30725. +
  30726. +config MMC_SDHCI_BCM2708_DMA
  30727. + bool "DMA support on BCM2708 Arasan controller"
  30728. + depends on MMC_SDHCI_BCM2708
  30729. + help
  30730. + Enable DMA support on the Arasan SDHCI controller in Broadcom 2708
  30731. + based chips.
  30732. +
  30733. + If unsure, say N.
  30734. +
  30735. config MMC_SDHCI_BCM2835
  30736. tristate "SDHCI platform support for the BCM2835 SD/MMC Controller"
  30737. depends on ARCH_BCM2835
  30738. diff -Nur linux-3.12.11.orig/drivers/mmc/host/Makefile linux-3.12.11/drivers/mmc/host/Makefile
  30739. --- linux-3.12.11.orig/drivers/mmc/host/Makefile 2014-02-13 22:51:06.000000000 +0100
  30740. +++ linux-3.12.11/drivers/mmc/host/Makefile 2014-02-18 11:52:14.000000000 +0100
  30741. @@ -15,6 +15,7 @@
  30742. obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o
  30743. obj-$(CONFIG_MMC_SDHCI_SIRF) += sdhci-sirf.o
  30744. obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o
  30745. +obj-$(CONFIG_MMC_SDHCI_BCM2708) += sdhci-bcm2708.o
  30746. obj-$(CONFIG_MMC_WBSD) += wbsd.o
  30747. obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
  30748. obj-$(CONFIG_MMC_OMAP) += omap.o
  30749. diff -Nur linux-3.12.11.orig/drivers/mmc/host/sdhci-bcm2708.c linux-3.12.11/drivers/mmc/host/sdhci-bcm2708.c
  30750. --- linux-3.12.11.orig/drivers/mmc/host/sdhci-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  30751. +++ linux-3.12.11/drivers/mmc/host/sdhci-bcm2708.c 2014-02-18 11:52:14.000000000 +0100
  30752. @@ -0,0 +1,1410 @@
  30753. +/*
  30754. + * sdhci-bcm2708.c Support for SDHCI device on BCM2708
  30755. + * Copyright (c) 2010 Broadcom
  30756. + *
  30757. + * This program is free software; you can redistribute it and/or modify
  30758. + * it under the terms of the GNU General Public License version 2 as
  30759. + * published by the Free Software Foundation.
  30760. + *
  30761. + * This program is distributed in the hope that it will be useful,
  30762. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  30763. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30764. + * GNU General Public License for more details.
  30765. + *
  30766. + * You should have received a copy of the GNU General Public License
  30767. + * along with this program; if not, write to the Free Software
  30768. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  30769. + */
  30770. +
  30771. +/* Supports:
  30772. + * SDHCI platform device - Arasan SD controller in BCM2708
  30773. + *
  30774. + * Inspired by sdhci-pci.c, by Pierre Ossman
  30775. + */
  30776. +
  30777. +#include <linux/delay.h>
  30778. +#include <linux/highmem.h>
  30779. +#include <linux/platform_device.h>
  30780. +#include <linux/module.h>
  30781. +#include <linux/mmc/mmc.h>
  30782. +#include <linux/mmc/host.h>
  30783. +#include <linux/mmc/sd.h>
  30784. +
  30785. +#include <linux/io.h>
  30786. +#include <linux/dma-mapping.h>
  30787. +#include <mach/dma.h>
  30788. +
  30789. +#include "sdhci.h"
  30790. +
  30791. +/*****************************************************************************\
  30792. + * *
  30793. + * Configuration *
  30794. + * *
  30795. +\*****************************************************************************/
  30796. +
  30797. +#define DRIVER_NAME "bcm2708_sdhci"
  30798. +
  30799. +/* for the time being insist on DMA mode - PIO seems not to work */
  30800. +#ifndef CONFIG_MMC_SDHCI_BCM2708_DMA
  30801. +#warning Non-DMA (PIO) version of this driver currently unavailable
  30802. +#endif
  30803. +#undef CONFIG_MMC_SDHCI_BCM2708_DMA
  30804. +#define CONFIG_MMC_SDHCI_BCM2708_DMA y
  30805. +
  30806. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30807. +/* #define CHECK_DMA_USE */
  30808. +#endif
  30809. +//#define LOG_REGISTERS
  30810. +
  30811. +#define USE_SCHED_TIME
  30812. +#define USE_SPACED_WRITES_2CLK 1 /* space consecutive register writes */
  30813. +#define USE_SOFTWARE_TIMEOUTS 1 /* not hardware timeouts */
  30814. +#define SOFTWARE_ERASE_TIMEOUT_SEC 30
  30815. +
  30816. +#define SDHCI_BCM_DMA_CHAN 4 /* this default is normally overriden */
  30817. +#define SDHCI_BCM_DMA_WAITS 0 /* delays slowing DMA transfers: 0-31 */
  30818. +/* We are worried that SD card DMA use may be blocking the AXI bus for others */
  30819. +
  30820. +/*! TODO: obtain these from the physical address */
  30821. +#define DMA_SDHCI_BASE 0x7e300000 /* EMMC register block on Videocore */
  30822. +#define DMA_SDHCI_BUFFER (DMA_SDHCI_BASE + SDHCI_BUFFER)
  30823. +
  30824. +#define BCM2708_SDHCI_SLEEP_TIMEOUT 1000 /* msecs */
  30825. +
  30826. +/* Mhz clock that the EMMC core is running at. Should match the platform clockman settings */
  30827. +#define BCM2708_EMMC_CLOCK_FREQ 50000000
  30828. +
  30829. +#define REG_EXRDFIFO_EN 0x80
  30830. +#define REG_EXRDFIFO_CFG 0x84
  30831. +
  30832. +int cycle_delay=2;
  30833. +
  30834. +/*****************************************************************************\
  30835. + * *
  30836. + * Debug *
  30837. + * *
  30838. +\*****************************************************************************/
  30839. +
  30840. +
  30841. +
  30842. +#define DBG(f, x...) \
  30843. + pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x)
  30844. +// printk(KERN_INFO DRIVER_NAME " [%s()]: " f, __func__,## x)//GRAYG
  30845. +
  30846. +
  30847. +/*****************************************************************************\
  30848. + * *
  30849. + * High Precision Time *
  30850. + * *
  30851. +\*****************************************************************************/
  30852. +
  30853. +#ifdef USE_SCHED_TIME
  30854. +
  30855. +#include <mach/frc.h>
  30856. +
  30857. +typedef unsigned long hptime_t;
  30858. +
  30859. +#define FMT_HPT "lu"
  30860. +
  30861. +static inline hptime_t hptime(void)
  30862. +{
  30863. + return frc_clock_ticks32();
  30864. +}
  30865. +
  30866. +#define HPTIME_CLK_NS 1000ul
  30867. +
  30868. +#else
  30869. +
  30870. +typedef unsigned long hptime_t;
  30871. +
  30872. +#define FMT_HPT "lu"
  30873. +
  30874. +static inline hptime_t hptime(void)
  30875. +{
  30876. + return jiffies;
  30877. +}
  30878. +
  30879. +#define HPTIME_CLK_NS (1000000000ul/HZ)
  30880. +
  30881. +#endif
  30882. +
  30883. +static inline unsigned long int since_ns(hptime_t t)
  30884. +{
  30885. + return (unsigned long)((hptime() - t) * HPTIME_CLK_NS);
  30886. +}
  30887. +
  30888. +static bool allow_highspeed = 1;
  30889. +static int emmc_clock_freq = BCM2708_EMMC_CLOCK_FREQ;
  30890. +static bool sync_after_dma = 1;
  30891. +static bool missing_status = 1;
  30892. +static bool spurious_crc_acmd51 = 0;
  30893. +bool enable_llm = 1;
  30894. +bool extra_messages = 0;
  30895. +
  30896. +#if 0
  30897. +static void hptime_test(void)
  30898. +{
  30899. + hptime_t now;
  30900. + hptime_t later;
  30901. +
  30902. + now = hptime();
  30903. + msleep(10);
  30904. + later = hptime();
  30905. +
  30906. + printk(KERN_INFO DRIVER_NAME": 10ms = %"FMT_HPT" clks "
  30907. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  30908. + later-now, now, later,
  30909. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  30910. +
  30911. + now = hptime();
  30912. + msleep(1000);
  30913. + later = hptime();
  30914. +
  30915. + printk(KERN_INFO DRIVER_NAME": 1s = %"FMT_HPT" clks "
  30916. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  30917. + later-now, now, later,
  30918. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  30919. +}
  30920. +#endif
  30921. +
  30922. +/*****************************************************************************\
  30923. + * *
  30924. + * SDHCI core callbacks *
  30925. + * *
  30926. +\*****************************************************************************/
  30927. +
  30928. +
  30929. +#ifdef CHECK_DMA_USE
  30930. +/*#define CHECK_DMA_REG_USE*/
  30931. +#endif
  30932. +
  30933. +#ifdef CHECK_DMA_REG_USE
  30934. +/* we don't expect anything to be using these registers during a
  30935. + DMA (except the IRQ status) - so check */
  30936. +static void check_dma_reg_use(struct sdhci_host *host, int reg);
  30937. +#else
  30938. +#define check_dma_reg_use(host, reg)
  30939. +#endif
  30940. +
  30941. +
  30942. +static inline u32 sdhci_bcm2708_raw_readl(struct sdhci_host *host, int reg)
  30943. +{
  30944. + return readl(host->ioaddr + reg);
  30945. +}
  30946. +
  30947. +u32 sdhci_bcm2708_readl(struct sdhci_host *host, int reg)
  30948. +{
  30949. + u32 l = sdhci_bcm2708_raw_readl(host, reg);
  30950. +
  30951. +#ifdef LOG_REGISTERS
  30952. + printk(KERN_ERR "%s: readl from 0x%02x, value 0x%08x\n",
  30953. + mmc_hostname(host->mmc), reg, l);
  30954. +#endif
  30955. + check_dma_reg_use(host, reg);
  30956. +
  30957. + return l;
  30958. +}
  30959. +
  30960. +u16 sdhci_bcm2708_readw(struct sdhci_host *host, int reg)
  30961. +{
  30962. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  30963. + u32 w = l >> (reg << 3 & 0x18) & 0xffff;
  30964. +
  30965. +#ifdef LOG_REGISTERS
  30966. + printk(KERN_ERR "%s: readw from 0x%02x, value 0x%04x\n",
  30967. + mmc_hostname(host->mmc), reg, w);
  30968. +#endif
  30969. + check_dma_reg_use(host, reg);
  30970. +
  30971. + return (u16)w;
  30972. +}
  30973. +
  30974. +u8 sdhci_bcm2708_readb(struct sdhci_host *host, int reg)
  30975. +{
  30976. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  30977. + u32 b = l >> (reg << 3 & 0x18) & 0xff;
  30978. +
  30979. +#ifdef LOG_REGISTERS
  30980. + printk(KERN_ERR "%s: readb from 0x%02x, value 0x%02x\n",
  30981. + mmc_hostname(host->mmc), reg, b);
  30982. +#endif
  30983. + check_dma_reg_use(host, reg);
  30984. +
  30985. + return (u8)b;
  30986. +}
  30987. +
  30988. +
  30989. +static void sdhci_bcm2708_raw_writel(struct sdhci_host *host, u32 val, int reg)
  30990. +{
  30991. + u32 ier;
  30992. +
  30993. +#if USE_SPACED_WRITES_2CLK
  30994. + static bool timeout_disabled = false;
  30995. + unsigned int ns_2clk = 0;
  30996. +
  30997. + /* The Arasan has a bugette whereby it may lose the content of
  30998. + * successive writes to registers that are within two SD-card clock
  30999. + * cycles of each other (a clock domain crossing problem).
  31000. + * It seems, however, that the data register does not have this problem.
  31001. + * (Which is just as well - otherwise we'd have to nobble the DMA engine
  31002. + * too)
  31003. + */
  31004. + if (reg != SDHCI_BUFFER && host->clock != 0) {
  31005. + /* host->clock is the clock freq in Hz */
  31006. + static hptime_t last_write_hpt;
  31007. + hptime_t now = hptime();
  31008. + ns_2clk = cycle_delay*1000000/(host->clock/1000);
  31009. +
  31010. + if (now == last_write_hpt || now == last_write_hpt+1) {
  31011. + /* we can't guarantee any significant time has
  31012. + * passed - we'll have to wait anyway ! */
  31013. + ndelay(ns_2clk);
  31014. + } else
  31015. + {
  31016. + /* we must have waited at least this many ns: */
  31017. + unsigned int ns_wait = HPTIME_CLK_NS *
  31018. + (last_write_hpt - now - 1);
  31019. + if (ns_wait < ns_2clk)
  31020. + ndelay(ns_2clk - ns_wait);
  31021. + }
  31022. + last_write_hpt = now;
  31023. + }
  31024. +#if USE_SOFTWARE_TIMEOUTS
  31025. + /* The Arasan is clocked for timeouts using the SD clock which is too
  31026. + * fast for ERASE commands and causes issues. So we disable timeouts
  31027. + * for ERASE */
  31028. + if (host->cmd != NULL && host->cmd->opcode == MMC_ERASE &&
  31029. + reg == (SDHCI_COMMAND & ~3)) {
  31030. + mod_timer(&host->timer,
  31031. + jiffies + SOFTWARE_ERASE_TIMEOUT_SEC * HZ);
  31032. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  31033. + ier &= ~SDHCI_INT_DATA_TIMEOUT;
  31034. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  31035. + timeout_disabled = true;
  31036. + ndelay(ns_2clk);
  31037. + } else if (timeout_disabled) {
  31038. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  31039. + ier |= SDHCI_INT_DATA_TIMEOUT;
  31040. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  31041. + timeout_disabled = false;
  31042. + ndelay(ns_2clk);
  31043. + }
  31044. +#endif
  31045. + writel(val, host->ioaddr + reg);
  31046. +#else
  31047. + void __iomem * regaddr = host->ioaddr + reg;
  31048. +
  31049. + writel(val, regaddr);
  31050. +
  31051. + if (reg != SDHCI_BUFFER && reg != SDHCI_INT_STATUS && host->clock != 0)
  31052. + {
  31053. + int timeout = 100000;
  31054. + while (val != readl(regaddr) && --timeout > 0)
  31055. + continue;
  31056. +
  31057. + if (timeout <= 0)
  31058. + printk(KERN_ERR "%s: writing 0x%X to reg 0x%X "
  31059. + "always gives 0x%X\n",
  31060. + mmc_hostname(host->mmc),
  31061. + val, reg, readl(regaddr));
  31062. + BUG_ON(timeout <= 0);
  31063. + }
  31064. +#endif
  31065. +}
  31066. +
  31067. +
  31068. +void sdhci_bcm2708_writel(struct sdhci_host *host, u32 val, int reg)
  31069. +{
  31070. +#ifdef LOG_REGISTERS
  31071. + printk(KERN_ERR "%s: writel to 0x%02x, value 0x%08x\n",
  31072. + mmc_hostname(host->mmc), reg, val);
  31073. +#endif
  31074. + check_dma_reg_use(host, reg);
  31075. +
  31076. + sdhci_bcm2708_raw_writel(host, val, reg);
  31077. +}
  31078. +
  31079. +void sdhci_bcm2708_writew(struct sdhci_host *host, u16 val, int reg)
  31080. +{
  31081. + static u32 shadow = 0;
  31082. +
  31083. + u32 p = reg == SDHCI_COMMAND ? shadow :
  31084. + sdhci_bcm2708_raw_readl(host, reg & ~3);
  31085. + u32 s = reg << 3 & 0x18;
  31086. + u32 l = val << s;
  31087. + u32 m = 0xffff << s;
  31088. +
  31089. +#ifdef LOG_REGISTERS
  31090. + printk(KERN_ERR "%s: writew to 0x%02x, value 0x%04x\n",
  31091. + mmc_hostname(host->mmc), reg, val);
  31092. +#endif
  31093. +
  31094. + if (reg == SDHCI_TRANSFER_MODE)
  31095. + shadow = (p & ~m) | l;
  31096. + else {
  31097. + check_dma_reg_use(host, reg);
  31098. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  31099. + }
  31100. +}
  31101. +
  31102. +void sdhci_bcm2708_writeb(struct sdhci_host *host, u8 val, int reg)
  31103. +{
  31104. + u32 p = sdhci_bcm2708_raw_readl(host, reg & ~3);
  31105. + u32 s = reg << 3 & 0x18;
  31106. + u32 l = val << s;
  31107. + u32 m = 0xff << s;
  31108. +
  31109. +#ifdef LOG_REGISTERS
  31110. + printk(KERN_ERR "%s: writeb to 0x%02x, value 0x%02x\n",
  31111. + mmc_hostname(host->mmc), reg, val);
  31112. +#endif
  31113. +
  31114. + check_dma_reg_use(host, reg);
  31115. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  31116. +}
  31117. +
  31118. +static unsigned int sdhci_bcm2708_get_max_clock(struct sdhci_host *host)
  31119. +{
  31120. + return emmc_clock_freq;
  31121. +}
  31122. +
  31123. +/*****************************************************************************\
  31124. + * *
  31125. + * DMA Operation *
  31126. + * *
  31127. +\*****************************************************************************/
  31128. +
  31129. +struct sdhci_bcm2708_priv {
  31130. + int dma_chan;
  31131. + int dma_irq;
  31132. + void __iomem *dma_chan_base;
  31133. + struct bcm2708_dma_cb *cb_base; /* DMA control blocks */
  31134. + dma_addr_t cb_handle;
  31135. + /* tracking scatter gather progress */
  31136. + unsigned sg_ix; /* scatter gather list index */
  31137. + unsigned sg_done; /* bytes in current sg_ix done */
  31138. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31139. + unsigned char dma_wanted; /* DMA transfer requested */
  31140. + unsigned char dma_waits; /* wait states in DMAs */
  31141. +#ifdef CHECK_DMA_USE
  31142. + unsigned char dmas_pending; /* no of unfinished DMAs */
  31143. + hptime_t when_started;
  31144. + hptime_t when_reset;
  31145. + hptime_t when_stopped;
  31146. +#endif
  31147. +#endif
  31148. + /* signalling the end of a transfer */
  31149. + void (*complete)(struct sdhci_host *);
  31150. +};
  31151. +
  31152. +#define SDHCI_HOST_PRIV(host) \
  31153. + (struct sdhci_bcm2708_priv *)((struct sdhci_host *)(host)+1)
  31154. +
  31155. +
  31156. +
  31157. +#ifdef CHECK_DMA_REG_USE
  31158. +static void check_dma_reg_use(struct sdhci_host *host, int reg)
  31159. +{
  31160. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31161. + if (host_priv->dma_wanted && reg != SDHCI_INT_STATUS) {
  31162. + printk(KERN_INFO"%s: accessing register 0x%x during DMA\n",
  31163. + mmc_hostname(host->mmc), reg);
  31164. + }
  31165. +}
  31166. +#endif
  31167. +
  31168. +
  31169. +
  31170. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31171. +
  31172. +static void sdhci_clear_set_irqgen(struct sdhci_host *host, u32 clear, u32 set)
  31173. +{
  31174. + u32 ier;
  31175. +
  31176. + ier = sdhci_bcm2708_raw_readl(host, SDHCI_SIGNAL_ENABLE);
  31177. + ier &= ~clear;
  31178. + ier |= set;
  31179. + /* change which requests generate IRQs - makes no difference to
  31180. + the content of SDHCI_INT_STATUS, or the need to acknowledge IRQs */
  31181. + sdhci_bcm2708_raw_writel(host, ier, SDHCI_SIGNAL_ENABLE);
  31182. +}
  31183. +
  31184. +static void sdhci_signal_irqs(struct sdhci_host *host, u32 irqs)
  31185. +{
  31186. + sdhci_clear_set_irqgen(host, 0, irqs);
  31187. +}
  31188. +
  31189. +static void sdhci_unsignal_irqs(struct sdhci_host *host, u32 irqs)
  31190. +{
  31191. + sdhci_clear_set_irqgen(host, irqs, 0);
  31192. +}
  31193. +
  31194. +
  31195. +
  31196. +static void schci_bcm2708_cb_read(struct sdhci_bcm2708_priv *host,
  31197. + int ix,
  31198. + dma_addr_t dma_addr, unsigned len,
  31199. + int /*bool*/ is_last)
  31200. +{
  31201. + struct bcm2708_dma_cb *cb = &host->cb_base[ix];
  31202. + unsigned char dmawaits = host->dma_waits;
  31203. +
  31204. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  31205. + BCM2708_DMA_WAITS(dmawaits) |
  31206. + BCM2708_DMA_S_DREQ |
  31207. + BCM2708_DMA_D_WIDTH |
  31208. + BCM2708_DMA_D_INC;
  31209. + cb->src = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  31210. + cb->dst = dma_addr;
  31211. + cb->length = len;
  31212. + cb->stride = 0;
  31213. +
  31214. + if (is_last) {
  31215. + cb->info |= BCM2708_DMA_INT_EN |
  31216. + BCM2708_DMA_WAIT_RESP;
  31217. + cb->next = 0;
  31218. + } else
  31219. + cb->next = host->cb_handle +
  31220. + (ix+1)*sizeof(struct bcm2708_dma_cb);
  31221. +
  31222. + cb->pad[0] = 0;
  31223. + cb->pad[1] = 0;
  31224. +}
  31225. +
  31226. +static void schci_bcm2708_cb_write(struct sdhci_bcm2708_priv *host,
  31227. + int ix,
  31228. + dma_addr_t dma_addr, unsigned len,
  31229. + int /*bool*/ is_last)
  31230. +{
  31231. + struct bcm2708_dma_cb *cb = &host->cb_base[ix];
  31232. + unsigned char dmawaits = host->dma_waits;
  31233. +
  31234. + /* We can make arbitrarily large writes as long as we specify DREQ to
  31235. + pace the delivery of bytes to the Arasan hardware */
  31236. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  31237. + BCM2708_DMA_WAITS(dmawaits) |
  31238. + BCM2708_DMA_D_DREQ |
  31239. + BCM2708_DMA_S_WIDTH |
  31240. + BCM2708_DMA_S_INC;
  31241. + cb->src = dma_addr;
  31242. + cb->dst = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  31243. + cb->length = len;
  31244. + cb->stride = 0;
  31245. +
  31246. + if (is_last) {
  31247. + cb->info |= BCM2708_DMA_INT_EN |
  31248. + BCM2708_DMA_WAIT_RESP;
  31249. + cb->next = 0;
  31250. + } else
  31251. + cb->next = host->cb_handle +
  31252. + (ix+1)*sizeof(struct bcm2708_dma_cb);
  31253. +
  31254. + cb->pad[0] = 0;
  31255. + cb->pad[1] = 0;
  31256. +}
  31257. +
  31258. +
  31259. +static void schci_bcm2708_dma_go(struct sdhci_host *host)
  31260. +{
  31261. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31262. + void __iomem *dma_chan_base = host_priv->dma_chan_base;
  31263. +
  31264. + BUG_ON(host_priv->dma_wanted);
  31265. +#ifdef CHECK_DMA_USE
  31266. + if (host_priv->dma_wanted)
  31267. + printk(KERN_ERR "%s: DMA already in progress - "
  31268. + "now %"FMT_HPT", last started %lu "
  31269. + "reset %lu stopped %lu\n",
  31270. + mmc_hostname(host->mmc),
  31271. + hptime(), since_ns(host_priv->when_started),
  31272. + since_ns(host_priv->when_reset),
  31273. + since_ns(host_priv->when_stopped));
  31274. + else if (host_priv->dmas_pending > 0)
  31275. + printk(KERN_INFO "%s: note - new DMA when %d reset DMAs "
  31276. + "already in progress - "
  31277. + "now %"FMT_HPT", started %lu reset %lu stopped %lu\n",
  31278. + mmc_hostname(host->mmc),
  31279. + host_priv->dmas_pending,
  31280. + hptime(), since_ns(host_priv->when_started),
  31281. + since_ns(host_priv->when_reset),
  31282. + since_ns(host_priv->when_stopped));
  31283. + host_priv->dmas_pending += 1;
  31284. + host_priv->when_started = hptime();
  31285. +#endif
  31286. + host_priv->dma_wanted = 1;
  31287. + DBG("PDMA go - base %p handle %08X\n", dma_chan_base,
  31288. + host_priv->cb_handle);
  31289. + bcm_dma_start(dma_chan_base, host_priv->cb_handle);
  31290. +}
  31291. +
  31292. +
  31293. +static void
  31294. +sdhci_platdma_read(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  31295. +{
  31296. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31297. +
  31298. + DBG("PDMA to read %d bytes\n", len);
  31299. + host_priv->sg_done += len;
  31300. + schci_bcm2708_cb_read(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  31301. + schci_bcm2708_dma_go(host);
  31302. +}
  31303. +
  31304. +
  31305. +static void
  31306. +sdhci_platdma_write(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  31307. +{
  31308. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31309. +
  31310. + DBG("PDMA to write %d bytes\n", len);
  31311. + //BUG_ON(0 != (len & 0x1ff));
  31312. +
  31313. + host_priv->sg_done += len;
  31314. + schci_bcm2708_cb_write(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  31315. + schci_bcm2708_dma_go(host);
  31316. +}
  31317. +
  31318. +/*! space is avaiable to receive into or data is available to write
  31319. + Platform DMA exported function
  31320. +*/
  31321. +void
  31322. +sdhci_bcm2708_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  31323. + void(*completion_callback)(struct sdhci_host *host))
  31324. +{
  31325. + struct mmc_data *data = host->data;
  31326. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31327. + int sg_ix;
  31328. + size_t bytes;
  31329. + dma_addr_t addr;
  31330. +
  31331. + BUG_ON(NULL == data);
  31332. + BUG_ON(0 == data->blksz);
  31333. +
  31334. + host_priv->complete = completion_callback;
  31335. +
  31336. + sg_ix = host_priv->sg_ix;
  31337. + BUG_ON(sg_ix >= data->sg_len);
  31338. +
  31339. + /* we can DMA blocks larger than blksz - it may hang the DMA
  31340. + channel but we are its only user */
  31341. + bytes = sg_dma_len(&data->sg[sg_ix]) - host_priv->sg_done;
  31342. + addr = sg_dma_address(&data->sg[sg_ix]) + host_priv->sg_done;
  31343. +
  31344. + if (bytes > 0) {
  31345. + /* We're going to poll for read/write available state until
  31346. + we finish this DMA
  31347. + */
  31348. +
  31349. + if (data->flags & MMC_DATA_READ) {
  31350. + if (*ref_intmask & SDHCI_INT_DATA_AVAIL) {
  31351. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  31352. + SDHCI_INT_SPACE_AVAIL);
  31353. + sdhci_platdma_read(host, addr, bytes);
  31354. + }
  31355. + } else {
  31356. + if (*ref_intmask & SDHCI_INT_SPACE_AVAIL) {
  31357. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  31358. + SDHCI_INT_SPACE_AVAIL);
  31359. + sdhci_platdma_write(host, addr, bytes);
  31360. + }
  31361. + }
  31362. + }
  31363. + /* else:
  31364. + we have run out of bytes that need transferring (e.g. we may be in
  31365. + the middle of the last DMA transfer), or
  31366. + it is also possible that we've been called when another IRQ is
  31367. + signalled, even though we've turned off signalling of our own IRQ */
  31368. +
  31369. + *ref_intmask &= ~SDHCI_INT_DATA_END;
  31370. + /* don't let the main sdhci driver act on this .. we'll deal with it
  31371. + when we respond to the DMA - if one is currently in progress */
  31372. +}
  31373. +
  31374. +/* is it possible to DMA the given mmc_data structure?
  31375. + Platform DMA exported function
  31376. +*/
  31377. +int /*bool*/
  31378. +sdhci_bcm2708_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  31379. +{
  31380. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31381. + int ok = bcm_sg_suitable_for_dma(data->sg, data->sg_len);
  31382. +
  31383. + if (!ok)
  31384. + DBG("Reverting to PIO - bad cache alignment\n");
  31385. +
  31386. + else {
  31387. + host_priv->sg_ix = 0; /* first SG index */
  31388. + host_priv->sg_done = 0; /* no bytes done */
  31389. + }
  31390. +
  31391. + return ok;
  31392. +}
  31393. +
  31394. +#include <mach/arm_control.h> //GRAYG
  31395. +/*! the current SD transacton has been abandonned
  31396. + We need to tidy up if we were in the middle of a DMA
  31397. + Platform DMA exported function
  31398. +*/
  31399. +void
  31400. +sdhci_bcm2708_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  31401. +{
  31402. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31403. +// unsigned long flags;
  31404. +
  31405. + BUG_ON(NULL == host);
  31406. +
  31407. +// spin_lock_irqsave(&host->lock, flags);
  31408. +
  31409. + if (host_priv->dma_wanted) {
  31410. + if (NULL == data) {
  31411. + printk(KERN_ERR "%s: ongoing DMA reset - no data!\n",
  31412. + mmc_hostname(host->mmc));
  31413. + BUG_ON(NULL == data);
  31414. + } else {
  31415. + struct scatterlist *sg;
  31416. + int sg_len;
  31417. + int sg_todo;
  31418. + int rc;
  31419. + unsigned long cs;
  31420. +
  31421. + sg = data->sg;
  31422. + sg_len = data->sg_len;
  31423. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  31424. +
  31425. + cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  31426. +
  31427. + if (!(BCM2708_DMA_ACTIVE & cs))
  31428. + {
  31429. + if (extra_messages)
  31430. + printk(KERN_INFO "%s: missed completion of "
  31431. + "cmd %d DMA (%d/%d [%d]/[%d]) - "
  31432. + "ignoring it\n",
  31433. + mmc_hostname(host->mmc),
  31434. + host->last_cmdop,
  31435. + host_priv->sg_done, sg_todo,
  31436. + host_priv->sg_ix+1, sg_len);
  31437. + }
  31438. + else
  31439. + printk(KERN_INFO "%s: resetting ongoing cmd %d"
  31440. + "DMA before %d/%d [%d]/[%d] complete\n",
  31441. + mmc_hostname(host->mmc),
  31442. + host->last_cmdop,
  31443. + host_priv->sg_done, sg_todo,
  31444. + host_priv->sg_ix+1, sg_len);
  31445. +#ifdef CHECK_DMA_USE
  31446. + printk(KERN_INFO "%s: now %"FMT_HPT" started %lu "
  31447. + "last reset %lu last stopped %lu\n",
  31448. + mmc_hostname(host->mmc),
  31449. + hptime(), since_ns(host_priv->when_started),
  31450. + since_ns(host_priv->when_reset),
  31451. + since_ns(host_priv->when_stopped));
  31452. + { unsigned long info, debug;
  31453. + void __iomem *base;
  31454. + unsigned long pend0, pend1, pend2;
  31455. +
  31456. + base = host_priv->dma_chan_base;
  31457. + cs = readl(base + BCM2708_DMA_CS);
  31458. + info = readl(base + BCM2708_DMA_INFO);
  31459. + debug = readl(base + BCM2708_DMA_DEBUG);
  31460. + printk(KERN_INFO "%s: DMA%d CS=%08lX TI=%08lX "
  31461. + "DEBUG=%08lX\n",
  31462. + mmc_hostname(host->mmc),
  31463. + host_priv->dma_chan,
  31464. + cs, info, debug);
  31465. + pend0 = readl(__io_address(ARM_IRQ_PEND0));
  31466. + pend1 = readl(__io_address(ARM_IRQ_PEND1));
  31467. + pend2 = readl(__io_address(ARM_IRQ_PEND2));
  31468. +
  31469. + printk(KERN_INFO "%s: PEND0=%08lX "
  31470. + "PEND1=%08lX PEND2=%08lX\n",
  31471. + mmc_hostname(host->mmc),
  31472. + pend0, pend1, pend2);
  31473. +
  31474. + //gintsts = readl(__io_address(GINTSTS));
  31475. + //gintmsk = readl(__io_address(GINTMSK));
  31476. + //printk(KERN_INFO "%s: USB GINTSTS=%08lX"
  31477. + // "GINTMSK=%08lX\n",
  31478. + // mmc_hostname(host->mmc), gintsts, gintmsk);
  31479. + }
  31480. +#endif
  31481. + rc = bcm_dma_abort(host_priv->dma_chan_base);
  31482. + BUG_ON(rc != 0);
  31483. + }
  31484. + host_priv->dma_wanted = 0;
  31485. +#ifdef CHECK_DMA_USE
  31486. + host_priv->when_reset = hptime();
  31487. +#endif
  31488. + }
  31489. +
  31490. +// spin_unlock_irqrestore(&host->lock, flags);
  31491. +}
  31492. +
  31493. +
  31494. +static void sdhci_bcm2708_dma_complete_irq(struct sdhci_host *host,
  31495. + u32 dma_cs)
  31496. +{
  31497. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31498. + struct mmc_data *data;
  31499. + struct scatterlist *sg;
  31500. + int sg_len;
  31501. + int sg_ix;
  31502. + int sg_todo;
  31503. +// unsigned long flags;
  31504. +
  31505. + BUG_ON(NULL == host);
  31506. +
  31507. +// spin_lock_irqsave(&host->lock, flags);
  31508. + data = host->data;
  31509. +
  31510. +#ifdef CHECK_DMA_USE
  31511. + if (host_priv->dmas_pending <= 0)
  31512. + DBG("on completion no DMA in progress - "
  31513. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  31514. + hptime(), since_ns(host_priv->when_started),
  31515. + since_ns(host_priv->when_reset),
  31516. + since_ns(host_priv->when_stopped));
  31517. + else if (host_priv->dmas_pending > 1)
  31518. + DBG("still %d DMA in progress after completion - "
  31519. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  31520. + host_priv->dmas_pending - 1,
  31521. + hptime(), since_ns(host_priv->when_started),
  31522. + since_ns(host_priv->when_reset),
  31523. + since_ns(host_priv->when_stopped));
  31524. + BUG_ON(host_priv->dmas_pending <= 0);
  31525. + host_priv->dmas_pending -= 1;
  31526. + host_priv->when_stopped = hptime();
  31527. +#endif
  31528. + host_priv->dma_wanted = 0;
  31529. +
  31530. + if (NULL == data) {
  31531. + DBG("PDMA unused completion - status 0x%X\n", dma_cs);
  31532. +// spin_unlock_irqrestore(&host->lock, flags);
  31533. + return;
  31534. + }
  31535. + sg = data->sg;
  31536. + sg_len = data->sg_len;
  31537. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  31538. +
  31539. + DBG("PDMA complete %d/%d [%d]/[%d]..\n",
  31540. + host_priv->sg_done, sg_todo,
  31541. + host_priv->sg_ix+1, sg_len);
  31542. +
  31543. + BUG_ON(host_priv->sg_done > sg_todo);
  31544. +
  31545. + if (host_priv->sg_done >= sg_todo) {
  31546. + host_priv->sg_ix++;
  31547. + host_priv->sg_done = 0;
  31548. + }
  31549. +
  31550. + sg_ix = host_priv->sg_ix;
  31551. + if (sg_ix < sg_len) {
  31552. + u32 irq_mask;
  31553. + /* Set off next DMA if we've got the capacity */
  31554. +
  31555. + if (data->flags & MMC_DATA_READ)
  31556. + irq_mask = SDHCI_INT_DATA_AVAIL;
  31557. + else
  31558. + irq_mask = SDHCI_INT_SPACE_AVAIL;
  31559. +
  31560. + /* We have to use the interrupt status register on the BCM2708
  31561. + rather than the SDHCI_PRESENT_STATE register because latency
  31562. + in the glue logic means that the information retrieved from
  31563. + the latter is not always up-to-date w.r.t the DMA engine -
  31564. + it may not indicate that a read or a write is ready yet */
  31565. + if (sdhci_bcm2708_raw_readl(host, SDHCI_INT_STATUS) &
  31566. + irq_mask) {
  31567. + size_t bytes = sg_dma_len(&sg[sg_ix]) -
  31568. + host_priv->sg_done;
  31569. + dma_addr_t addr = sg_dma_address(&data->sg[sg_ix]) +
  31570. + host_priv->sg_done;
  31571. +
  31572. + /* acknowledge interrupt */
  31573. + sdhci_bcm2708_raw_writel(host, irq_mask,
  31574. + SDHCI_INT_STATUS);
  31575. +
  31576. + BUG_ON(0 == bytes);
  31577. +
  31578. + if (data->flags & MMC_DATA_READ)
  31579. + sdhci_platdma_read(host, addr, bytes);
  31580. + else
  31581. + sdhci_platdma_write(host, addr, bytes);
  31582. + } else {
  31583. + DBG("PDMA - wait avail\n");
  31584. + /* may generate an IRQ if already present */
  31585. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  31586. + SDHCI_INT_SPACE_AVAIL);
  31587. + }
  31588. + } else {
  31589. + if (sync_after_dma) {
  31590. + /* On the Arasan controller the stop command (which will be
  31591. + scheduled after this completes) does not seem to work
  31592. + properly if we allow it to be issued when we are
  31593. + transferring data to/from the SD card.
  31594. + We get CRC and DEND errors unless we wait for
  31595. + the SD controller to finish reading/writing to the card. */
  31596. + u32 state_mask;
  31597. + int timeout=3*1000*1000;
  31598. +
  31599. + DBG("PDMA over - sync card\n");
  31600. + if (data->flags & MMC_DATA_READ)
  31601. + state_mask = SDHCI_DOING_READ;
  31602. + else
  31603. + state_mask = SDHCI_DOING_WRITE;
  31604. +
  31605. + while (0 != (sdhci_bcm2708_raw_readl(host, SDHCI_PRESENT_STATE)
  31606. + & state_mask) && --timeout > 0)
  31607. + {
  31608. + udelay(1);
  31609. + continue;
  31610. + }
  31611. + if (timeout <= 0)
  31612. + printk(KERN_ERR"%s: final %s to SD card still "
  31613. + "running\n",
  31614. + mmc_hostname(host->mmc),
  31615. + data->flags & MMC_DATA_READ? "read": "write");
  31616. + }
  31617. + if (host_priv->complete) {
  31618. + (*host_priv->complete)(host);
  31619. + DBG("PDMA %s complete\n",
  31620. + data->flags & MMC_DATA_READ?"read":"write");
  31621. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  31622. + SDHCI_INT_SPACE_AVAIL);
  31623. + }
  31624. + }
  31625. +// spin_unlock_irqrestore(&host->lock, flags);
  31626. +}
  31627. +
  31628. +static irqreturn_t sdhci_bcm2708_dma_irq(int irq, void *dev_id)
  31629. +{
  31630. + irqreturn_t result = IRQ_NONE;
  31631. + struct sdhci_host *host = dev_id;
  31632. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31633. + u32 dma_cs; /* control and status register */
  31634. +
  31635. + BUG_ON(NULL == dev_id);
  31636. + BUG_ON(NULL == host_priv->dma_chan_base);
  31637. +
  31638. + sdhci_spin_lock(host);
  31639. +
  31640. + dma_cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  31641. +
  31642. + if (dma_cs & BCM2708_DMA_ERR) {
  31643. + unsigned long debug;
  31644. + debug = readl(host_priv->dma_chan_base +
  31645. + BCM2708_DMA_DEBUG);
  31646. + printk(KERN_ERR "%s: DMA error - CS %lX DEBUG %lX\n",
  31647. + mmc_hostname(host->mmc), (unsigned long)dma_cs,
  31648. + (unsigned long)debug);
  31649. + /* reset error */
  31650. + writel(debug, host_priv->dma_chan_base +
  31651. + BCM2708_DMA_DEBUG);
  31652. + }
  31653. + if (dma_cs & BCM2708_DMA_INT) {
  31654. + /* acknowledge interrupt */
  31655. + writel(BCM2708_DMA_INT,
  31656. + host_priv->dma_chan_base + BCM2708_DMA_CS);
  31657. +
  31658. + dsb(); /* ARM data synchronization (push) operation */
  31659. +
  31660. + if (!host_priv->dma_wanted) {
  31661. + /* ignore this interrupt - it was reset */
  31662. + if (extra_messages)
  31663. + printk(KERN_INFO "%s: DMA IRQ %X ignored - "
  31664. + "results were reset\n",
  31665. + mmc_hostname(host->mmc), dma_cs);
  31666. +#ifdef CHECK_DMA_USE
  31667. + printk(KERN_INFO "%s: now %"FMT_HPT
  31668. + " started %lu reset %lu stopped %lu\n",
  31669. + mmc_hostname(host->mmc), hptime(),
  31670. + since_ns(host_priv->when_started),
  31671. + since_ns(host_priv->when_reset),
  31672. + since_ns(host_priv->when_stopped));
  31673. + host_priv->dmas_pending--;
  31674. +#endif
  31675. + } else
  31676. + sdhci_bcm2708_dma_complete_irq(host, dma_cs);
  31677. +
  31678. + result = IRQ_HANDLED;
  31679. + }
  31680. + sdhci_spin_unlock(host);
  31681. +
  31682. + return result;
  31683. +}
  31684. +#endif /* CONFIG_MMC_SDHCI_BCM2708_DMA */
  31685. +
  31686. +
  31687. +/***************************************************************************** \
  31688. + * *
  31689. + * Device Attributes *
  31690. + * *
  31691. +\*****************************************************************************/
  31692. +
  31693. +
  31694. +/**
  31695. + * Show the DMA-using status
  31696. + */
  31697. +static ssize_t attr_dma_show(struct device *_dev,
  31698. + struct device_attribute *attr, char *buf)
  31699. +{
  31700. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31701. +
  31702. + if (host) {
  31703. + int use_dma = (host->flags & SDHCI_USE_PLATDMA? 1:0);
  31704. + return sprintf(buf, "%d\n", use_dma);
  31705. + } else
  31706. + return -EINVAL;
  31707. +}
  31708. +
  31709. +/**
  31710. + * Set the DMA-using status
  31711. + */
  31712. +static ssize_t attr_dma_store(struct device *_dev,
  31713. + struct device_attribute *attr,
  31714. + const char *buf, size_t count)
  31715. +{
  31716. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31717. +
  31718. + if (host) {
  31719. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31720. + int on = simple_strtol(buf, NULL, 0);
  31721. + if (on) {
  31722. + host->flags |= SDHCI_USE_PLATDMA;
  31723. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  31724. + printk(KERN_INFO "%s: DMA enabled\n",
  31725. + mmc_hostname(host->mmc));
  31726. + } else {
  31727. + host->flags &= ~(SDHCI_USE_PLATDMA | SDHCI_REQ_USE_DMA);
  31728. + sdhci_bcm2708_writel(host, 0, REG_EXRDFIFO_EN);
  31729. + printk(KERN_INFO "%s: DMA disabled\n",
  31730. + mmc_hostname(host->mmc));
  31731. + }
  31732. +#endif
  31733. + return count;
  31734. + } else
  31735. + return -EINVAL;
  31736. +}
  31737. +
  31738. +static DEVICE_ATTR(use_dma, S_IRUGO | S_IWUGO, attr_dma_show, attr_dma_store);
  31739. +
  31740. +
  31741. +/**
  31742. + * Show the DMA wait states used
  31743. + */
  31744. +static ssize_t attr_dmawait_show(struct device *_dev,
  31745. + struct device_attribute *attr, char *buf)
  31746. +{
  31747. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31748. +
  31749. + if (host) {
  31750. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31751. + int dmawait = host_priv->dma_waits;
  31752. + return sprintf(buf, "%d\n", dmawait);
  31753. + } else
  31754. + return -EINVAL;
  31755. +}
  31756. +
  31757. +/**
  31758. + * Set the DMA wait state used
  31759. + */
  31760. +static ssize_t attr_dmawait_store(struct device *_dev,
  31761. + struct device_attribute *attr,
  31762. + const char *buf, size_t count)
  31763. +{
  31764. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31765. +
  31766. + if (host) {
  31767. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31768. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31769. + int dma_waits = simple_strtol(buf, NULL, 0);
  31770. + if (dma_waits >= 0 && dma_waits < 32)
  31771. + host_priv->dma_waits = dma_waits;
  31772. + else
  31773. + printk(KERN_ERR "%s: illegal dma_waits value - %d",
  31774. + mmc_hostname(host->mmc), dma_waits);
  31775. +#endif
  31776. + return count;
  31777. + } else
  31778. + return -EINVAL;
  31779. +}
  31780. +
  31781. +static DEVICE_ATTR(dma_wait, S_IRUGO | S_IWUGO,
  31782. + attr_dmawait_show, attr_dmawait_store);
  31783. +
  31784. +
  31785. +/**
  31786. + * Show the DMA-using status
  31787. + */
  31788. +static ssize_t attr_status_show(struct device *_dev,
  31789. + struct device_attribute *attr, char *buf)
  31790. +{
  31791. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31792. +
  31793. + if (host) {
  31794. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31795. + return sprintf(buf,
  31796. + "present: yes\n"
  31797. + "power: %s\n"
  31798. + "clock: %u Hz\n"
  31799. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31800. + "dma: %s (%d waits)\n",
  31801. +#else
  31802. + "dma: unconfigured\n",
  31803. +#endif
  31804. + "always on",
  31805. + host->clock
  31806. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31807. + , (host->flags & SDHCI_USE_PLATDMA)? "on": "off"
  31808. + , host_priv->dma_waits
  31809. +#endif
  31810. + );
  31811. + } else
  31812. + return -EINVAL;
  31813. +}
  31814. +
  31815. +static DEVICE_ATTR(status, S_IRUGO, attr_status_show, NULL);
  31816. +
  31817. +/***************************************************************************** \
  31818. + * *
  31819. + * Power Management *
  31820. + * *
  31821. +\*****************************************************************************/
  31822. +
  31823. +
  31824. +#ifdef CONFIG_PM
  31825. +static int sdhci_bcm2708_suspend(struct platform_device *dev, pm_message_t state)
  31826. +{
  31827. + struct sdhci_host *host = (struct sdhci_host *)
  31828. + platform_get_drvdata(dev);
  31829. + int ret = 0;
  31830. +
  31831. + if (host->mmc) {
  31832. + ret = mmc_suspend_host(host->mmc);
  31833. + }
  31834. +
  31835. + return ret;
  31836. +}
  31837. +
  31838. +static int sdhci_bcm2708_resume(struct platform_device *dev)
  31839. +{
  31840. + struct sdhci_host *host = (struct sdhci_host *)
  31841. + platform_get_drvdata(dev);
  31842. + int ret = 0;
  31843. +
  31844. + if (host->mmc) {
  31845. + ret = mmc_resume_host(host->mmc);
  31846. + }
  31847. +
  31848. + return ret;
  31849. +}
  31850. +#endif
  31851. +
  31852. +
  31853. +/*****************************************************************************\
  31854. + * *
  31855. + * Device quirk functions. Implemented as local ops because the flags *
  31856. + * field is out of space with newer kernels. This implementation can be *
  31857. + * back ported to older kernels as well. *
  31858. +\****************************************************************************/
  31859. +static unsigned int sdhci_bcm2708_quirk_extra_ints(struct sdhci_host *host)
  31860. +{
  31861. + return 1;
  31862. +}
  31863. +
  31864. +static unsigned int sdhci_bcm2708_quirk_spurious_crc_acmd51(struct sdhci_host *host)
  31865. +{
  31866. + return 1;
  31867. +}
  31868. +
  31869. +static unsigned int sdhci_bcm2708_missing_status(struct sdhci_host *host)
  31870. +{
  31871. + return 1;
  31872. +}
  31873. +
  31874. +/***************************************************************************** \
  31875. + * *
  31876. + * Device ops *
  31877. + * *
  31878. +\*****************************************************************************/
  31879. +
  31880. +static struct sdhci_ops sdhci_bcm2708_ops = {
  31881. +#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
  31882. + .read_l = sdhci_bcm2708_readl,
  31883. + .read_w = sdhci_bcm2708_readw,
  31884. + .read_b = sdhci_bcm2708_readb,
  31885. + .write_l = sdhci_bcm2708_writel,
  31886. + .write_w = sdhci_bcm2708_writew,
  31887. + .write_b = sdhci_bcm2708_writeb,
  31888. +#else
  31889. +#error The BCM2708 SDHCI driver needs CONFIG_MMC_SDHCI_IO_ACCESSORS to be set
  31890. +#endif
  31891. + .get_max_clock = sdhci_bcm2708_get_max_clock,
  31892. +
  31893. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31894. + // Platform DMA operations
  31895. + .pdma_able = sdhci_bcm2708_platdma_dmaable,
  31896. + .pdma_avail = sdhci_bcm2708_platdma_avail,
  31897. + .pdma_reset = sdhci_bcm2708_platdma_reset,
  31898. +#endif
  31899. + .extra_ints = sdhci_bcm2708_quirk_extra_ints,
  31900. +};
  31901. +
  31902. +/*****************************************************************************\
  31903. + * *
  31904. + * Device probing/removal *
  31905. + * *
  31906. +\*****************************************************************************/
  31907. +
  31908. +static int sdhci_bcm2708_probe(struct platform_device *pdev)
  31909. +{
  31910. + struct sdhci_host *host;
  31911. + struct resource *iomem;
  31912. + struct sdhci_bcm2708_priv *host_priv;
  31913. + int ret;
  31914. +
  31915. + BUG_ON(pdev == NULL);
  31916. +
  31917. + iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  31918. + if (!iomem) {
  31919. + ret = -ENOMEM;
  31920. + goto err;
  31921. + }
  31922. +
  31923. + if (resource_size(iomem) != 0x100)
  31924. + dev_err(&pdev->dev, "Invalid iomem size. You may "
  31925. + "experience problems.\n");
  31926. +
  31927. + if (pdev->dev.parent)
  31928. + host = sdhci_alloc_host(pdev->dev.parent,
  31929. + sizeof(struct sdhci_bcm2708_priv));
  31930. + else
  31931. + host = sdhci_alloc_host(&pdev->dev,
  31932. + sizeof(struct sdhci_bcm2708_priv));
  31933. +
  31934. + if (IS_ERR(host)) {
  31935. + ret = PTR_ERR(host);
  31936. + goto err;
  31937. + }
  31938. + if (missing_status) {
  31939. + sdhci_bcm2708_ops.missing_status = sdhci_bcm2708_missing_status;
  31940. + }
  31941. +
  31942. + if( spurious_crc_acmd51 ) {
  31943. + sdhci_bcm2708_ops.spurious_crc_acmd51 = sdhci_bcm2708_quirk_spurious_crc_acmd51;
  31944. + }
  31945. +
  31946. +
  31947. + printk("sdhci: %s low-latency mode\n",enable_llm?"Enable":"Disable");
  31948. +
  31949. + host->hw_name = "BCM2708_Arasan";
  31950. + host->ops = &sdhci_bcm2708_ops;
  31951. + host->irq = platform_get_irq(pdev, 0);
  31952. + host->second_irq = 0;
  31953. +
  31954. + host->quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION |
  31955. + SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  31956. + SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  31957. + SDHCI_QUIRK_MISSING_CAPS |
  31958. + SDHCI_QUIRK_NO_HISPD_BIT |
  31959. + (sync_after_dma ? 0:SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12);
  31960. +
  31961. +
  31962. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31963. + host->flags = SDHCI_USE_PLATDMA;
  31964. +#endif
  31965. +
  31966. + if (!request_mem_region(iomem->start, resource_size(iomem),
  31967. + mmc_hostname(host->mmc))) {
  31968. + dev_err(&pdev->dev, "cannot request region\n");
  31969. + ret = -EBUSY;
  31970. + goto err_request;
  31971. + }
  31972. +
  31973. + host->ioaddr = ioremap(iomem->start, resource_size(iomem));
  31974. + if (!host->ioaddr) {
  31975. + dev_err(&pdev->dev, "failed to remap registers\n");
  31976. + ret = -ENOMEM;
  31977. + goto err_remap;
  31978. + }
  31979. +
  31980. + host_priv = SDHCI_HOST_PRIV(host);
  31981. +
  31982. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31983. + host_priv->dma_wanted = 0;
  31984. +#ifdef CHECK_DMA_USE
  31985. + host_priv->dmas_pending = 0;
  31986. + host_priv->when_started = 0;
  31987. + host_priv->when_reset = 0;
  31988. + host_priv->when_stopped = 0;
  31989. +#endif
  31990. + host_priv->sg_ix = 0;
  31991. + host_priv->sg_done = 0;
  31992. + host_priv->complete = NULL;
  31993. + host_priv->dma_waits = SDHCI_BCM_DMA_WAITS;
  31994. +
  31995. + host_priv->cb_base = dma_alloc_writecombine(&pdev->dev, SZ_4K,
  31996. + &host_priv->cb_handle,
  31997. + GFP_KERNEL);
  31998. + if (!host_priv->cb_base) {
  31999. + dev_err(&pdev->dev, "cannot allocate DMA CBs\n");
  32000. + ret = -ENOMEM;
  32001. + goto err_alloc_cb;
  32002. + }
  32003. +
  32004. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST,
  32005. + &host_priv->dma_chan_base,
  32006. + &host_priv->dma_irq);
  32007. + if (ret < 0) {
  32008. + dev_err(&pdev->dev, "couldn't allocate a DMA channel\n");
  32009. + goto err_add_dma;
  32010. + }
  32011. + host_priv->dma_chan = ret;
  32012. +
  32013. + ret = request_irq(host_priv->dma_irq, sdhci_bcm2708_dma_irq,
  32014. + 0 /*IRQF_SHARED*/, DRIVER_NAME " (dma)", host);
  32015. + if (ret) {
  32016. + dev_err(&pdev->dev, "cannot set DMA IRQ\n");
  32017. + goto err_add_dma_irq;
  32018. + }
  32019. + host->second_irq = host_priv->dma_irq;
  32020. + DBG("DMA CBs %p handle %08X DMA%d %p DMA IRQ %d\n",
  32021. + host_priv->cb_base, (unsigned)host_priv->cb_handle,
  32022. + host_priv->dma_chan, host_priv->dma_chan_base,
  32023. + host_priv->dma_irq);
  32024. +
  32025. + // we support 3.3V
  32026. + host->caps |= SDHCI_CAN_VDD_330;
  32027. + if (allow_highspeed)
  32028. + host->mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
  32029. +
  32030. + /* single block writes cause data loss with some SD cards! */
  32031. + host->mmc->caps2 |= MMC_CAP2_FORCE_MULTIBLOCK;
  32032. +#endif
  32033. +
  32034. + ret = sdhci_add_host(host);
  32035. + if (ret)
  32036. + goto err_add_host;
  32037. +
  32038. + platform_set_drvdata(pdev, host);
  32039. + ret = device_create_file(&pdev->dev, &dev_attr_use_dma);
  32040. + ret = device_create_file(&pdev->dev, &dev_attr_dma_wait);
  32041. + ret = device_create_file(&pdev->dev, &dev_attr_status);
  32042. +
  32043. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32044. + /* enable extension fifo for paced DMA transfers */
  32045. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  32046. + sdhci_bcm2708_writel(host, 4, REG_EXRDFIFO_CFG);
  32047. +#endif
  32048. +
  32049. + printk(KERN_INFO "%s: BCM2708 SDHC host at 0x%08llx DMA %d IRQ %d\n",
  32050. + mmc_hostname(host->mmc), (unsigned long long)iomem->start,
  32051. + host_priv->dma_chan, host_priv->dma_irq);
  32052. +
  32053. + return 0;
  32054. +
  32055. +err_add_host:
  32056. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32057. + free_irq(host_priv->dma_irq, host);
  32058. +err_add_dma_irq:
  32059. + bcm_dma_chan_free(host_priv->dma_chan);
  32060. +err_add_dma:
  32061. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  32062. + host_priv->cb_handle);
  32063. +err_alloc_cb:
  32064. +#endif
  32065. + iounmap(host->ioaddr);
  32066. +err_remap:
  32067. + release_mem_region(iomem->start, resource_size(iomem));
  32068. +err_request:
  32069. + sdhci_free_host(host);
  32070. +err:
  32071. + dev_err(&pdev->dev, "probe failed, err %d\n", ret);
  32072. + return ret;
  32073. +}
  32074. +
  32075. +static int sdhci_bcm2708_remove(struct platform_device *pdev)
  32076. +{
  32077. + struct sdhci_host *host = platform_get_drvdata(pdev);
  32078. + struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  32079. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  32080. + int dead;
  32081. + u32 scratch;
  32082. +
  32083. + dead = 0;
  32084. + scratch = sdhci_bcm2708_readl(host, SDHCI_INT_STATUS);
  32085. + if (scratch == (u32)-1)
  32086. + dead = 1;
  32087. +
  32088. + device_remove_file(&pdev->dev, &dev_attr_status);
  32089. + device_remove_file(&pdev->dev, &dev_attr_dma_wait);
  32090. + device_remove_file(&pdev->dev, &dev_attr_use_dma);
  32091. +
  32092. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  32093. + free_irq(host_priv->dma_irq, host);
  32094. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  32095. + host_priv->cb_handle);
  32096. +#endif
  32097. + sdhci_remove_host(host, dead);
  32098. + iounmap(host->ioaddr);
  32099. + release_mem_region(iomem->start, resource_size(iomem));
  32100. + sdhci_free_host(host);
  32101. + platform_set_drvdata(pdev, NULL);
  32102. +
  32103. + return 0;
  32104. +}
  32105. +
  32106. +static struct platform_driver sdhci_bcm2708_driver = {
  32107. + .driver = {
  32108. + .name = DRIVER_NAME,
  32109. + .owner = THIS_MODULE,
  32110. + },
  32111. + .probe = sdhci_bcm2708_probe,
  32112. + .remove = sdhci_bcm2708_remove,
  32113. +
  32114. +#ifdef CONFIG_PM
  32115. + .suspend = sdhci_bcm2708_suspend,
  32116. + .resume = sdhci_bcm2708_resume,
  32117. +#endif
  32118. +
  32119. +};
  32120. +
  32121. +/*****************************************************************************\
  32122. + * *
  32123. + * Driver init/exit *
  32124. + * *
  32125. +\*****************************************************************************/
  32126. +
  32127. +static int __init sdhci_drv_init(void)
  32128. +{
  32129. + return platform_driver_register(&sdhci_bcm2708_driver);
  32130. +}
  32131. +
  32132. +static void __exit sdhci_drv_exit(void)
  32133. +{
  32134. + platform_driver_unregister(&sdhci_bcm2708_driver);
  32135. +}
  32136. +
  32137. +module_init(sdhci_drv_init);
  32138. +module_exit(sdhci_drv_exit);
  32139. +
  32140. +module_param(allow_highspeed, bool, 0444);
  32141. +module_param(emmc_clock_freq, int, 0444);
  32142. +module_param(sync_after_dma, bool, 0444);
  32143. +module_param(missing_status, bool, 0444);
  32144. +module_param(spurious_crc_acmd51, bool, 0444);
  32145. +module_param(enable_llm, bool, 0444);
  32146. +module_param(cycle_delay, int, 0444);
  32147. +module_param(extra_messages, bool, 0444);
  32148. +
  32149. +MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver");
  32150. +MODULE_AUTHOR("Broadcom <info@broadcom.com>");
  32151. +MODULE_LICENSE("GPL v2");
  32152. +MODULE_ALIAS("platform:"DRIVER_NAME);
  32153. +
  32154. +MODULE_PARM_DESC(allow_highspeed, "Allow high speed transfers modes");
  32155. +MODULE_PARM_DESC(emmc_clock_freq, "Specify the speed of emmc clock");
  32156. +MODULE_PARM_DESC(sync_after_dma, "Block in driver until dma complete");
  32157. +MODULE_PARM_DESC(missing_status, "Use the missing status quirk");
  32158. +MODULE_PARM_DESC(spurious_crc_acmd51, "Use the spurious crc quirk for reading SCR (ACMD51)");
  32159. +MODULE_PARM_DESC(enable_llm, "Enable low-latency mode");
  32160. +MODULE_PARM_DESC(extra_messages, "Enable more sdcard warning messages");
  32161. +
  32162. +
  32163. diff -Nur linux-3.12.11.orig/drivers/mmc/host/sdhci.c linux-3.12.11/drivers/mmc/host/sdhci.c
  32164. --- linux-3.12.11.orig/drivers/mmc/host/sdhci.c 2014-02-13 22:51:06.000000000 +0100
  32165. +++ linux-3.12.11/drivers/mmc/host/sdhci.c 2014-02-18 11:52:14.000000000 +0100
  32166. @@ -28,6 +28,7 @@
  32167. #include <linux/mmc/mmc.h>
  32168. #include <linux/mmc/host.h>
  32169. #include <linux/mmc/card.h>
  32170. +#include <linux/mmc/sd.h>
  32171. #include <linux/mmc/slot-gpio.h>
  32172. #include "sdhci.h"
  32173. @@ -131,6 +132,99 @@
  32174. * Low level functions *
  32175. * *
  32176. \*****************************************************************************/
  32177. +extern bool enable_llm;
  32178. +static int sdhci_locked=0;
  32179. +void sdhci_spin_lock(struct sdhci_host *host)
  32180. +{
  32181. + spin_lock(&host->lock);
  32182. +#ifdef CONFIG_PREEMPT
  32183. + if(enable_llm)
  32184. + {
  32185. + disable_irq_nosync(host->irq);
  32186. + if(host->second_irq)
  32187. + disable_irq_nosync(host->second_irq);
  32188. + local_irq_enable();
  32189. + }
  32190. +#endif
  32191. +}
  32192. +
  32193. +void sdhci_spin_unlock(struct sdhci_host *host)
  32194. +{
  32195. +#ifdef CONFIG_PREEMPT
  32196. + if(enable_llm)
  32197. + {
  32198. + local_irq_disable();
  32199. + if(host->second_irq)
  32200. + enable_irq(host->second_irq);
  32201. + enable_irq(host->irq);
  32202. + }
  32203. +#endif
  32204. + spin_unlock(&host->lock);
  32205. +}
  32206. +
  32207. +void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags)
  32208. +{
  32209. +#ifdef CONFIG_PREEMPT
  32210. + if(enable_llm)
  32211. + {
  32212. + while(sdhci_locked)
  32213. + {
  32214. + preempt_schedule();
  32215. + }
  32216. + spin_lock_irqsave(&host->lock,*flags);
  32217. + disable_irq(host->irq);
  32218. + if(host->second_irq)
  32219. + disable_irq(host->second_irq);
  32220. + local_irq_enable();
  32221. + }
  32222. + else
  32223. +#endif
  32224. + spin_lock_irqsave(&host->lock,*flags);
  32225. +}
  32226. +
  32227. +void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags)
  32228. +{
  32229. +#ifdef CONFIG_PREEMPT
  32230. + if(enable_llm)
  32231. + {
  32232. + local_irq_disable();
  32233. + if(host->second_irq)
  32234. + enable_irq(host->second_irq);
  32235. + enable_irq(host->irq);
  32236. + }
  32237. +#endif
  32238. + spin_unlock_irqrestore(&host->lock,flags);
  32239. +}
  32240. +
  32241. +static void sdhci_spin_enable_schedule(struct sdhci_host *host)
  32242. +{
  32243. +#ifdef CONFIG_PREEMPT
  32244. + if(enable_llm)
  32245. + {
  32246. + sdhci_locked = 1;
  32247. + preempt_enable();
  32248. + }
  32249. +#endif
  32250. +}
  32251. +
  32252. +static void sdhci_spin_disable_schedule(struct sdhci_host *host)
  32253. +{
  32254. +#ifdef CONFIG_PREEMPT
  32255. + if(enable_llm)
  32256. + {
  32257. + preempt_disable();
  32258. + sdhci_locked = 0;
  32259. + }
  32260. +#endif
  32261. +}
  32262. +
  32263. +
  32264. +#undef spin_lock_irqsave
  32265. +#define spin_lock_irqsave(host_lock, flags) sdhci_spin_lock_irqsave(container_of(host_lock, struct sdhci_host, lock), &flags)
  32266. +#define spin_unlock_irqrestore(host_lock, flags) sdhci_spin_unlock_irqrestore(container_of(host_lock, struct sdhci_host, lock), flags)
  32267. +
  32268. +#define spin_lock(host_lock) sdhci_spin_lock(container_of(host_lock, struct sdhci_host, lock))
  32269. +#define spin_unlock(host_lock) sdhci_spin_unlock(container_of(host_lock, struct sdhci_host, lock))
  32270. static void sdhci_clear_set_irqs(struct sdhci_host *host, u32 clear, u32 set)
  32271. {
  32272. @@ -300,7 +394,7 @@
  32273. struct sdhci_host *host = container_of(led, struct sdhci_host, led);
  32274. unsigned long flags;
  32275. - spin_lock_irqsave(&host->lock, flags);
  32276. + sdhci_spin_lock_irqsave(host, &flags);
  32277. if (host->runtime_suspended)
  32278. goto out;
  32279. @@ -310,7 +404,7 @@
  32280. else
  32281. sdhci_activate_led(host);
  32282. out:
  32283. - spin_unlock_irqrestore(&host->lock, flags);
  32284. + sdhci_spin_unlock_irqrestore(host, flags);
  32285. }
  32286. #endif
  32287. @@ -327,7 +421,7 @@
  32288. u32 uninitialized_var(scratch);
  32289. u8 *buf;
  32290. - DBG("PIO reading\n");
  32291. + DBG("PIO reading %db\n", host->data->blksz);
  32292. blksize = host->data->blksz;
  32293. chunk = 0;
  32294. @@ -372,7 +466,7 @@
  32295. u32 scratch;
  32296. u8 *buf;
  32297. - DBG("PIO writing\n");
  32298. + DBG("PIO writing %db\n", host->data->blksz);
  32299. blksize = host->data->blksz;
  32300. chunk = 0;
  32301. @@ -411,19 +505,28 @@
  32302. local_irq_restore(flags);
  32303. }
  32304. -static void sdhci_transfer_pio(struct sdhci_host *host)
  32305. +static void sdhci_transfer_pio(struct sdhci_host *host, u32 intstate)
  32306. {
  32307. u32 mask;
  32308. + u32 state = 0;
  32309. + u32 intmask;
  32310. + int available;
  32311. BUG_ON(!host->data);
  32312. if (host->blocks == 0)
  32313. return;
  32314. - if (host->data->flags & MMC_DATA_READ)
  32315. + if (host->data->flags & MMC_DATA_READ) {
  32316. mask = SDHCI_DATA_AVAILABLE;
  32317. - else
  32318. + intmask = SDHCI_INT_DATA_AVAIL;
  32319. + } else {
  32320. mask = SDHCI_SPACE_AVAILABLE;
  32321. + intmask = SDHCI_INT_SPACE_AVAIL;
  32322. + }
  32323. +
  32324. + /* initially we can see whether we can procede using intstate */
  32325. + available = (intstate & intmask);
  32326. /*
  32327. * Some controllers (JMicron JMB38x) mess up the buffer bits
  32328. @@ -434,7 +537,7 @@
  32329. (host->data->blocks == 1))
  32330. mask = ~0;
  32331. - while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) {
  32332. + while (available) {
  32333. if (host->quirks & SDHCI_QUIRK_PIO_NEEDS_DELAY)
  32334. udelay(100);
  32335. @@ -446,9 +549,12 @@
  32336. host->blocks--;
  32337. if (host->blocks == 0)
  32338. break;
  32339. + state = sdhci_readl(host, SDHCI_PRESENT_STATE);
  32340. + available = state & mask;
  32341. + break;
  32342. }
  32343. - DBG("PIO transfer complete.\n");
  32344. + DBG("PIO transfer complete - %d blocks left.\n", host->blocks);
  32345. }
  32346. static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags)
  32347. @@ -721,7 +827,9 @@
  32348. u32 pio_irqs = SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL;
  32349. u32 dma_irqs = SDHCI_INT_DMA_END | SDHCI_INT_ADMA_ERROR;
  32350. - if (host->flags & SDHCI_REQ_USE_DMA)
  32351. + /* platform DMA will begin on receipt of PIO irqs */
  32352. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  32353. + !(host->flags & SDHCI_USE_PLATDMA))
  32354. sdhci_clear_set_irqs(host, pio_irqs, dma_irqs);
  32355. else
  32356. sdhci_clear_set_irqs(host, dma_irqs, pio_irqs);
  32357. @@ -753,44 +861,25 @@
  32358. host->data_early = 0;
  32359. host->data->bytes_xfered = 0;
  32360. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))
  32361. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA | SDHCI_USE_PLATDMA))
  32362. host->flags |= SDHCI_REQ_USE_DMA;
  32363. /*
  32364. * FIXME: This doesn't account for merging when mapping the
  32365. * scatterlist.
  32366. */
  32367. - if (host->flags & SDHCI_REQ_USE_DMA) {
  32368. - int broken, i;
  32369. - struct scatterlist *sg;
  32370. -
  32371. - broken = 0;
  32372. - if (host->flags & SDHCI_USE_ADMA) {
  32373. - if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE)
  32374. - broken = 1;
  32375. - } else {
  32376. - if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE)
  32377. - broken = 1;
  32378. - }
  32379. -
  32380. - if (unlikely(broken)) {
  32381. - for_each_sg(data->sg, sg, data->sg_len, i) {
  32382. - if (sg->length & 0x3) {
  32383. - DBG("Reverting to PIO because of "
  32384. - "transfer size (%d)\n",
  32385. - sg->length);
  32386. - host->flags &= ~SDHCI_REQ_USE_DMA;
  32387. - break;
  32388. - }
  32389. - }
  32390. - }
  32391. - }
  32392. /*
  32393. * The assumption here being that alignment is the same after
  32394. * translation to device address space.
  32395. */
  32396. - if (host->flags & SDHCI_REQ_USE_DMA) {
  32397. + if ((host->flags & (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) ==
  32398. + (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) {
  32399. +
  32400. + if (! sdhci_platdma_dmaable(host, data))
  32401. + host->flags &= ~SDHCI_REQ_USE_DMA;
  32402. +
  32403. + } else if (host->flags & SDHCI_REQ_USE_DMA) {
  32404. int broken, i;
  32405. struct scatterlist *sg;
  32406. @@ -849,7 +938,8 @@
  32407. */
  32408. WARN_ON(1);
  32409. host->flags &= ~SDHCI_REQ_USE_DMA;
  32410. - } else {
  32411. + } else
  32412. + if (!(host->flags & SDHCI_USE_PLATDMA)) {
  32413. WARN_ON(sg_cnt != 1);
  32414. sdhci_writel(host, sg_dma_address(data->sg),
  32415. SDHCI_DMA_ADDRESS);
  32416. @@ -865,11 +955,13 @@
  32417. if (host->version >= SDHCI_SPEC_200) {
  32418. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  32419. ctrl &= ~SDHCI_CTRL_DMA_MASK;
  32420. + if (! (host->flags & SDHCI_USE_PLATDMA)) {
  32421. if ((host->flags & SDHCI_REQ_USE_DMA) &&
  32422. (host->flags & SDHCI_USE_ADMA))
  32423. ctrl |= SDHCI_CTRL_ADMA32;
  32424. else
  32425. ctrl |= SDHCI_CTRL_SDMA;
  32426. + }
  32427. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  32428. }
  32429. @@ -921,7 +1013,8 @@
  32430. if (data->flags & MMC_DATA_READ)
  32431. mode |= SDHCI_TRNS_READ;
  32432. - if (host->flags & SDHCI_REQ_USE_DMA)
  32433. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  32434. + !(host->flags & SDHCI_USE_PLATDMA))
  32435. mode |= SDHCI_TRNS_DMA;
  32436. sdhci_writew(host, mode, SDHCI_TRANSFER_MODE);
  32437. @@ -937,13 +1030,16 @@
  32438. host->data = NULL;
  32439. if (host->flags & SDHCI_REQ_USE_DMA) {
  32440. - if (host->flags & SDHCI_USE_ADMA)
  32441. - sdhci_adma_table_post(host, data);
  32442. - else {
  32443. + /* we may have to abandon an ongoing platform DMA */
  32444. + if (host->flags & SDHCI_USE_PLATDMA)
  32445. + sdhci_platdma_reset(host, data);
  32446. +
  32447. + if (host->flags & (SDHCI_USE_PLATDMA | SDHCI_USE_SDMA)) {
  32448. dma_unmap_sg(mmc_dev(host->mmc), data->sg,
  32449. data->sg_len, (data->flags & MMC_DATA_READ) ?
  32450. DMA_FROM_DEVICE : DMA_TO_DEVICE);
  32451. - }
  32452. + } else if (host->flags & SDHCI_USE_ADMA)
  32453. + sdhci_adma_table_post(host, data);
  32454. }
  32455. /*
  32456. @@ -996,6 +1092,12 @@
  32457. if ((cmd->data != NULL) || (cmd->flags & MMC_RSP_BUSY))
  32458. mask |= SDHCI_DATA_INHIBIT;
  32459. + if(host->ops->missing_status && (cmd->opcode == MMC_SEND_STATUS)) {
  32460. + timeout = 5000; // Really obscenely large delay to send the status, due to bug in controller
  32461. + // which might cause the STATUS command to get stuck when a data operation is in flow
  32462. + mask |= SDHCI_DATA_INHIBIT;
  32463. + }
  32464. +
  32465. /* We shouldn't wait for data inihibit for stop commands, even
  32466. though they might use busy signaling */
  32467. if (host->mrq->data && (cmd == host->mrq->data->stop))
  32468. @@ -1011,12 +1113,20 @@
  32469. return;
  32470. }
  32471. timeout--;
  32472. + sdhci_spin_enable_schedule(host);
  32473. mdelay(1);
  32474. + sdhci_spin_disable_schedule(host);
  32475. }
  32476. + DBG("send cmd %d - wait 0x%X irq 0x%x\n", cmd->opcode, mask,
  32477. + sdhci_readl(host, SDHCI_INT_STATUS));
  32478. mod_timer(&host->timer, jiffies + 10 * HZ);
  32479. host->cmd = cmd;
  32480. + if (host->last_cmdop == MMC_APP_CMD)
  32481. + host->last_cmdop = -cmd->opcode;
  32482. + else
  32483. + host->last_cmdop = cmd->opcode;
  32484. sdhci_prepare_data(host, cmd);
  32485. @@ -1232,7 +1342,9 @@
  32486. return;
  32487. }
  32488. timeout--;
  32489. + sdhci_spin_enable_schedule(host);
  32490. mdelay(1);
  32491. + sdhci_spin_disable_schedule(host);
  32492. }
  32493. clk |= SDHCI_CLOCK_CARD_EN;
  32494. @@ -1333,7 +1445,7 @@
  32495. sdhci_runtime_pm_get(host);
  32496. - spin_lock_irqsave(&host->lock, flags);
  32497. + sdhci_spin_lock_irqsave(host, &flags);
  32498. WARN_ON(host->mrq != NULL);
  32499. @@ -1391,9 +1503,9 @@
  32500. mmc->card->type == MMC_TYPE_MMC ?
  32501. MMC_SEND_TUNING_BLOCK_HS200 :
  32502. MMC_SEND_TUNING_BLOCK;
  32503. - spin_unlock_irqrestore(&host->lock, flags);
  32504. + sdhci_spin_unlock_irqrestore(host, flags);
  32505. sdhci_execute_tuning(mmc, tuning_opcode);
  32506. - spin_lock_irqsave(&host->lock, flags);
  32507. + sdhci_spin_lock_irqsave(host, &flags);
  32508. /* Restore original mmc_request structure */
  32509. host->mrq = mrq;
  32510. @@ -1407,7 +1519,7 @@
  32511. }
  32512. mmiowb();
  32513. - spin_unlock_irqrestore(&host->lock, flags);
  32514. + sdhci_spin_unlock_irqrestore(host, flags);
  32515. }
  32516. static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
  32517. @@ -1416,10 +1528,10 @@
  32518. int vdd_bit = -1;
  32519. u8 ctrl;
  32520. - spin_lock_irqsave(&host->lock, flags);
  32521. + sdhci_spin_lock_irqsave(host, &flags);
  32522. if (host->flags & SDHCI_DEVICE_DEAD) {
  32523. - spin_unlock_irqrestore(&host->lock, flags);
  32524. + sdhci_spin_unlock_irqrestore(host, flags);
  32525. if (host->vmmc && ios->power_mode == MMC_POWER_OFF)
  32526. mmc_regulator_set_ocr(host->mmc, host->vmmc, 0);
  32527. return;
  32528. @@ -1446,9 +1558,9 @@
  32529. vdd_bit = sdhci_set_power(host, ios->vdd);
  32530. if (host->vmmc && vdd_bit != -1) {
  32531. - spin_unlock_irqrestore(&host->lock, flags);
  32532. + sdhci_spin_unlock_irqrestore(host, flags);
  32533. mmc_regulator_set_ocr(host->mmc, host->vmmc, vdd_bit);
  32534. - spin_lock_irqsave(&host->lock, flags);
  32535. + sdhci_spin_lock_irqsave(host, &flags);
  32536. }
  32537. if (host->ops->platform_send_init_74_clocks)
  32538. @@ -1585,7 +1697,7 @@
  32539. sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
  32540. mmiowb();
  32541. - spin_unlock_irqrestore(&host->lock, flags);
  32542. + sdhci_spin_unlock_irqrestore(host, flags);
  32543. }
  32544. static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  32545. @@ -1633,7 +1745,7 @@
  32546. unsigned long flags;
  32547. int is_readonly;
  32548. - spin_lock_irqsave(&host->lock, flags);
  32549. + sdhci_spin_lock_irqsave(host, &flags);
  32550. if (host->flags & SDHCI_DEVICE_DEAD)
  32551. is_readonly = 0;
  32552. @@ -1643,7 +1755,7 @@
  32553. is_readonly = !(sdhci_readl(host, SDHCI_PRESENT_STATE)
  32554. & SDHCI_WRITE_PROTECT);
  32555. - spin_unlock_irqrestore(&host->lock, flags);
  32556. + sdhci_spin_unlock_irqrestore(host, flags);
  32557. /* This quirk needs to be replaced by a callback-function later */
  32558. return host->quirks & SDHCI_QUIRK_INVERTED_WRITE_PROTECT ?
  32559. @@ -1716,9 +1828,9 @@
  32560. struct sdhci_host *host = mmc_priv(mmc);
  32561. unsigned long flags;
  32562. - spin_lock_irqsave(&host->lock, flags);
  32563. + sdhci_spin_lock_irqsave(host, &flags);
  32564. sdhci_enable_sdio_irq_nolock(host, enable);
  32565. - spin_unlock_irqrestore(&host->lock, flags);
  32566. + sdhci_spin_unlock_irqrestore(host, flags);
  32567. }
  32568. static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
  32569. @@ -2066,7 +2178,7 @@
  32570. if (host->ops->card_event)
  32571. host->ops->card_event(host);
  32572. - spin_lock_irqsave(&host->lock, flags);
  32573. + sdhci_spin_lock_irqsave(host, &flags);
  32574. /* Check host->mrq first in case we are runtime suspended */
  32575. if (host->mrq && !sdhci_do_get_cd(host)) {
  32576. @@ -2082,7 +2194,7 @@
  32577. tasklet_schedule(&host->finish_tasklet);
  32578. }
  32579. - spin_unlock_irqrestore(&host->lock, flags);
  32580. + sdhci_spin_unlock_irqrestore(host, flags);
  32581. }
  32582. static const struct mmc_host_ops sdhci_ops = {
  32583. @@ -2121,14 +2233,14 @@
  32584. host = (struct sdhci_host*)param;
  32585. - spin_lock_irqsave(&host->lock, flags);
  32586. + sdhci_spin_lock_irqsave(host, &flags);
  32587. /*
  32588. * If this tasklet gets rescheduled while running, it will
  32589. * be run again afterwards but without any active request.
  32590. */
  32591. if (!host->mrq) {
  32592. - spin_unlock_irqrestore(&host->lock, flags);
  32593. + sdhci_spin_unlock_irqrestore(host, flags);
  32594. return;
  32595. }
  32596. @@ -2166,7 +2278,7 @@
  32597. #endif
  32598. mmiowb();
  32599. - spin_unlock_irqrestore(&host->lock, flags);
  32600. + sdhci_spin_unlock_irqrestore(host, flags);
  32601. mmc_request_done(host->mmc, mrq);
  32602. sdhci_runtime_pm_put(host);
  32603. @@ -2179,11 +2291,11 @@
  32604. host = (struct sdhci_host*)data;
  32605. - spin_lock_irqsave(&host->lock, flags);
  32606. + sdhci_spin_lock_irqsave(host, &flags);
  32607. if (host->mrq) {
  32608. pr_err("%s: Timeout waiting for hardware "
  32609. - "interrupt.\n", mmc_hostname(host->mmc));
  32610. + "interrupt - cmd%d.\n", mmc_hostname(host->mmc), host->last_cmdop);
  32611. sdhci_dumpregs(host);
  32612. if (host->data) {
  32613. @@ -2200,7 +2312,7 @@
  32614. }
  32615. mmiowb();
  32616. - spin_unlock_irqrestore(&host->lock, flags);
  32617. + sdhci_spin_unlock_irqrestore(host, flags);
  32618. }
  32619. static void sdhci_tuning_timer(unsigned long data)
  32620. @@ -2210,11 +2322,11 @@
  32621. host = (struct sdhci_host *)data;
  32622. - spin_lock_irqsave(&host->lock, flags);
  32623. + sdhci_spin_lock_irqsave(host, &flags);
  32624. host->flags |= SDHCI_NEEDS_RETUNING;
  32625. - spin_unlock_irqrestore(&host->lock, flags);
  32626. + sdhci_spin_unlock_irqrestore(host, flags);
  32627. }
  32628. /*****************************************************************************\
  32629. @@ -2228,10 +2340,13 @@
  32630. BUG_ON(intmask == 0);
  32631. if (!host->cmd) {
  32632. + if (!(host->ops->extra_ints)) {
  32633. pr_err("%s: Got command interrupt 0x%08x even "
  32634. "though no command operation was in progress.\n",
  32635. mmc_hostname(host->mmc), (unsigned)intmask);
  32636. sdhci_dumpregs(host);
  32637. + } else
  32638. + DBG("cmd irq 0x%08x cmd complete\n", (unsigned)intmask);
  32639. return;
  32640. }
  32641. @@ -2301,6 +2416,19 @@
  32642. static void sdhci_show_adma_error(struct sdhci_host *host) { }
  32643. #endif
  32644. +static void sdhci_data_end(struct sdhci_host *host)
  32645. +{
  32646. + if (host->cmd) {
  32647. + /*
  32648. + * Data managed to finish before the
  32649. + * command completed. Make sure we do
  32650. + * things in the proper order.
  32651. + */
  32652. + host->data_early = 1;
  32653. + } else
  32654. + sdhci_finish_data(host);
  32655. +}
  32656. +
  32657. static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
  32658. {
  32659. u32 command;
  32660. @@ -2330,23 +2458,39 @@
  32661. }
  32662. }
  32663. + if (!(host->ops->extra_ints)) {
  32664. pr_err("%s: Got data interrupt 0x%08x even "
  32665. "though no data operation was in progress.\n",
  32666. mmc_hostname(host->mmc), (unsigned)intmask);
  32667. sdhci_dumpregs(host);
  32668. + } else
  32669. + DBG("data irq 0x%08x but no data\n", (unsigned)intmask);
  32670. return;
  32671. }
  32672. if (intmask & SDHCI_INT_DATA_TIMEOUT)
  32673. host->data->error = -ETIMEDOUT;
  32674. - else if (intmask & SDHCI_INT_DATA_END_BIT)
  32675. + else if (intmask & SDHCI_INT_DATA_END_BIT) {
  32676. + DBG("end error in cmd %d\n", host->last_cmdop);
  32677. + if (host->ops->spurious_crc_acmd51 &&
  32678. + host->last_cmdop == -SD_APP_SEND_SCR) {
  32679. + DBG("ignoring spurious data_end_bit error\n");
  32680. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  32681. + } else
  32682. host->data->error = -EILSEQ;
  32683. - else if ((intmask & SDHCI_INT_DATA_CRC) &&
  32684. + } else if ((intmask & SDHCI_INT_DATA_CRC) &&
  32685. SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))
  32686. - != MMC_BUS_TEST_R)
  32687. + != MMC_BUS_TEST_R) {
  32688. + DBG("crc error in cmd %d\n", host->last_cmdop);
  32689. + if (host->ops->spurious_crc_acmd51 &&
  32690. + host->last_cmdop == -SD_APP_SEND_SCR) {
  32691. + DBG("ignoring spurious data_crc_bit error\n");
  32692. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  32693. + } else {
  32694. host->data->error = -EILSEQ;
  32695. - else if (intmask & SDHCI_INT_ADMA_ERROR) {
  32696. + }
  32697. + } else if (intmask & SDHCI_INT_ADMA_ERROR) {
  32698. pr_err("%s: ADMA error\n", mmc_hostname(host->mmc));
  32699. sdhci_show_adma_error(host);
  32700. host->data->error = -EIO;
  32701. @@ -2354,11 +2498,18 @@
  32702. host->ops->adma_workaround(host, intmask);
  32703. }
  32704. - if (host->data->error)
  32705. + if (host->data->error) {
  32706. + DBG("finish request early on error %d\n", host->data->error);
  32707. sdhci_finish_data(host);
  32708. - else {
  32709. - if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
  32710. - sdhci_transfer_pio(host);
  32711. + } else {
  32712. + if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL)) {
  32713. + if (host->flags & SDHCI_REQ_USE_DMA) {
  32714. + /* possible only in PLATDMA mode */
  32715. + sdhci_platdma_avail(host, &intmask,
  32716. + &sdhci_data_end);
  32717. + } else
  32718. + sdhci_transfer_pio(host, intmask);
  32719. + }
  32720. /*
  32721. * We currently don't do anything fancy with DMA
  32722. @@ -2387,18 +2538,8 @@
  32723. sdhci_writel(host, dmanow, SDHCI_DMA_ADDRESS);
  32724. }
  32725. - if (intmask & SDHCI_INT_DATA_END) {
  32726. - if (host->cmd) {
  32727. - /*
  32728. - * Data managed to finish before the
  32729. - * command completed. Make sure we do
  32730. - * things in the proper order.
  32731. - */
  32732. - host->data_early = 1;
  32733. - } else {
  32734. - sdhci_finish_data(host);
  32735. - }
  32736. - }
  32737. + if (intmask & SDHCI_INT_DATA_END)
  32738. + sdhci_data_end(host);
  32739. }
  32740. }
  32741. @@ -2409,10 +2550,10 @@
  32742. u32 intmask, unexpected = 0;
  32743. int cardint = 0, max_loops = 16;
  32744. - spin_lock(&host->lock);
  32745. + sdhci_spin_lock(host);
  32746. if (host->runtime_suspended) {
  32747. - spin_unlock(&host->lock);
  32748. + sdhci_spin_unlock(host);
  32749. pr_warning("%s: got irq while runtime suspended\n",
  32750. mmc_hostname(host->mmc));
  32751. return IRQ_HANDLED;
  32752. @@ -2454,6 +2595,22 @@
  32753. tasklet_schedule(&host->card_tasklet);
  32754. }
  32755. + if (intmask & SDHCI_INT_ERROR_MASK & ~SDHCI_INT_ERROR)
  32756. + DBG("controller reports error 0x%x -"
  32757. + "%s%s%s%s%s%s%s%s%s%s",
  32758. + intmask,
  32759. + intmask & SDHCI_INT_TIMEOUT? " timeout": "",
  32760. + intmask & SDHCI_INT_CRC ? " crc": "",
  32761. + intmask & SDHCI_INT_END_BIT? " endbit": "",
  32762. + intmask & SDHCI_INT_INDEX? " index": "",
  32763. + intmask & SDHCI_INT_DATA_TIMEOUT? " data_timeout": "",
  32764. + intmask & SDHCI_INT_DATA_CRC? " data_crc": "",
  32765. + intmask & SDHCI_INT_DATA_END_BIT? " data_endbit": "",
  32766. + intmask & SDHCI_INT_BUS_POWER? " buspower": "",
  32767. + intmask & SDHCI_INT_ACMD12ERR? " acmd12": "",
  32768. + intmask & SDHCI_INT_ADMA_ERROR? " adma": ""
  32769. + );
  32770. +
  32771. if (intmask & SDHCI_INT_CMD_MASK) {
  32772. sdhci_writel(host, intmask & SDHCI_INT_CMD_MASK,
  32773. SDHCI_INT_STATUS);
  32774. @@ -2468,7 +2625,13 @@
  32775. intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK);
  32776. - intmask &= ~SDHCI_INT_ERROR;
  32777. + if (intmask & SDHCI_INT_ERROR_MASK) {
  32778. + /* collect any uncovered errors */
  32779. + sdhci_writel(host, intmask & SDHCI_INT_ERROR_MASK,
  32780. + SDHCI_INT_STATUS);
  32781. + }
  32782. +
  32783. + intmask &= ~SDHCI_INT_ERROR_MASK;
  32784. if (intmask & SDHCI_INT_BUS_POWER) {
  32785. pr_err("%s: Card is consuming too much power!\n",
  32786. @@ -2494,7 +2657,7 @@
  32787. if (intmask && --max_loops)
  32788. goto again;
  32789. out:
  32790. - spin_unlock(&host->lock);
  32791. + sdhci_spin_unlock(host);
  32792. if (unexpected) {
  32793. pr_err("%s: Unexpected interrupt 0x%08x.\n",
  32794. @@ -2588,13 +2751,14 @@
  32795. {
  32796. int ret;
  32797. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  32798. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  32799. + SDHCI_USE_PLATDMA)) {
  32800. if (host->ops->enable_dma)
  32801. host->ops->enable_dma(host);
  32802. }
  32803. if (!device_may_wakeup(mmc_dev(host->mmc))) {
  32804. - ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  32805. + ret = request_irq(host->irq, sdhci_irq, 0 /*IRQF_SHARED*/,
  32806. mmc_hostname(host->mmc), host);
  32807. if (ret)
  32808. return ret;
  32809. @@ -2671,15 +2835,15 @@
  32810. host->flags &= ~SDHCI_NEEDS_RETUNING;
  32811. }
  32812. - spin_lock_irqsave(&host->lock, flags);
  32813. + sdhci_spin_lock_irqsave(host, &flags);
  32814. sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK);
  32815. - spin_unlock_irqrestore(&host->lock, flags);
  32816. + sdhci_spin_unlock_irqrestore(host, flags);
  32817. synchronize_irq(host->irq);
  32818. - spin_lock_irqsave(&host->lock, flags);
  32819. + sdhci_spin_lock_irqsave(host, &flags);
  32820. host->runtime_suspended = true;
  32821. - spin_unlock_irqrestore(&host->lock, flags);
  32822. + sdhci_spin_unlock_irqrestore(host, flags);
  32823. return ret;
  32824. }
  32825. @@ -2705,16 +2869,16 @@
  32826. sdhci_do_start_signal_voltage_switch(host, &host->mmc->ios);
  32827. if ((host_flags & SDHCI_PV_ENABLED) &&
  32828. !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) {
  32829. - spin_lock_irqsave(&host->lock, flags);
  32830. + sdhci_spin_lock_irqsave(host, &flags);
  32831. sdhci_enable_preset_value(host, true);
  32832. - spin_unlock_irqrestore(&host->lock, flags);
  32833. + sdhci_spin_unlock_irqrestore(host, flags);
  32834. }
  32835. /* Set the re-tuning expiration flag */
  32836. if (host->flags & SDHCI_USING_RETUNING_TIMER)
  32837. host->flags |= SDHCI_NEEDS_RETUNING;
  32838. - spin_lock_irqsave(&host->lock, flags);
  32839. + sdhci_spin_lock_irqsave(host, &flags);
  32840. host->runtime_suspended = false;
  32841. @@ -2725,7 +2889,7 @@
  32842. /* Enable Card Detection */
  32843. sdhci_enable_card_detection(host);
  32844. - spin_unlock_irqrestore(&host->lock, flags);
  32845. + sdhci_spin_unlock_irqrestore(host, flags);
  32846. return ret;
  32847. }
  32848. @@ -2820,14 +2984,16 @@
  32849. host->flags &= ~SDHCI_USE_ADMA;
  32850. }
  32851. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  32852. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  32853. + SDHCI_USE_PLATDMA)) {
  32854. if (host->ops->enable_dma) {
  32855. if (host->ops->enable_dma(host)) {
  32856. pr_warning("%s: No suitable DMA "
  32857. "available. Falling back to PIO.\n",
  32858. mmc_hostname(mmc));
  32859. host->flags &=
  32860. - ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA);
  32861. + ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  32862. + SDHCI_USE_PLATDMA);
  32863. }
  32864. }
  32865. }
  32866. @@ -3218,8 +3384,8 @@
  32867. sdhci_init(host, 0);
  32868. - ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  32869. - mmc_hostname(mmc), host);
  32870. + ret = request_irq(host->irq, sdhci_irq, 0 /*IRQF_SHARED*/,
  32871. + mmc_hostname(mmc), host);
  32872. if (ret) {
  32873. pr_err("%s: Failed to request IRQ %d: %d\n",
  32874. mmc_hostname(mmc), host->irq, ret);
  32875. @@ -3252,6 +3418,7 @@
  32876. pr_info("%s: SDHCI controller on %s [%s] using %s\n",
  32877. mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
  32878. + (host->flags & SDHCI_USE_PLATDMA) ? "platform's DMA" :
  32879. (host->flags & SDHCI_USE_ADMA) ? "ADMA" :
  32880. (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO");
  32881. @@ -3279,7 +3446,7 @@
  32882. unsigned long flags;
  32883. if (dead) {
  32884. - spin_lock_irqsave(&host->lock, flags);
  32885. + sdhci_spin_lock_irqsave(host, &flags);
  32886. host->flags |= SDHCI_DEVICE_DEAD;
  32887. @@ -3291,7 +3458,7 @@
  32888. tasklet_schedule(&host->finish_tasklet);
  32889. }
  32890. - spin_unlock_irqrestore(&host->lock, flags);
  32891. + sdhci_spin_unlock_irqrestore(host, flags);
  32892. }
  32893. sdhci_disable_card_detection(host);
  32894. diff -Nur linux-3.12.11.orig/drivers/mmc/host/sdhci.h linux-3.12.11/drivers/mmc/host/sdhci.h
  32895. --- linux-3.12.11.orig/drivers/mmc/host/sdhci.h 2014-02-13 22:51:06.000000000 +0100
  32896. +++ linux-3.12.11/drivers/mmc/host/sdhci.h 2014-02-18 11:52:14.000000000 +0100
  32897. @@ -289,6 +289,18 @@
  32898. void (*platform_reset_enter)(struct sdhci_host *host, u8 mask);
  32899. void (*platform_reset_exit)(struct sdhci_host *host, u8 mask);
  32900. int (*set_uhs_signaling)(struct sdhci_host *host, unsigned int uhs);
  32901. +
  32902. + int (*pdma_able)(struct sdhci_host *host,
  32903. + struct mmc_data *data);
  32904. + void (*pdma_avail)(struct sdhci_host *host,
  32905. + unsigned int *ref_intmask,
  32906. + void(*complete)(struct sdhci_host *));
  32907. + void (*pdma_reset)(struct sdhci_host *host,
  32908. + struct mmc_data *data);
  32909. + unsigned int (*extra_ints)(struct sdhci_host *host);
  32910. + unsigned int (*spurious_crc_acmd51)(struct sdhci_host *host);
  32911. + unsigned int (*missing_status)(struct sdhci_host *host);
  32912. +
  32913. void (*hw_reset)(struct sdhci_host *host);
  32914. void (*platform_suspend)(struct sdhci_host *host);
  32915. void (*platform_resume)(struct sdhci_host *host);
  32916. @@ -400,9 +412,38 @@
  32917. extern void sdhci_enable_irq_wakeups(struct sdhci_host *host);
  32918. #endif
  32919. +static inline int /*bool*/
  32920. +sdhci_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  32921. +{
  32922. + if (host->ops->pdma_able)
  32923. + return host->ops->pdma_able(host, data);
  32924. + else
  32925. + return 1;
  32926. +}
  32927. +static inline void
  32928. +sdhci_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  32929. + void(*completion_callback)(struct sdhci_host *))
  32930. +{
  32931. + if (host->ops->pdma_avail)
  32932. + host->ops->pdma_avail(host, ref_intmask, completion_callback);
  32933. +}
  32934. +
  32935. +static inline void
  32936. +sdhci_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  32937. +{
  32938. + if (host->ops->pdma_reset)
  32939. + host->ops->pdma_reset(host, data);
  32940. +}
  32941. +
  32942. #ifdef CONFIG_PM_RUNTIME
  32943. extern int sdhci_runtime_suspend_host(struct sdhci_host *host);
  32944. extern int sdhci_runtime_resume_host(struct sdhci_host *host);
  32945. #endif
  32946. +extern void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags);
  32947. +extern void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags);
  32948. +extern void sdhci_spin_lock(struct sdhci_host *host);
  32949. +extern void sdhci_spin_unlock(struct sdhci_host *host);
  32950. +
  32951. +
  32952. #endif /* __SDHCI_HW_H */
  32953. diff -Nur linux-3.12.11.orig/drivers/net/usb/smsc95xx.c linux-3.12.11/drivers/net/usb/smsc95xx.c
  32954. --- linux-3.12.11.orig/drivers/net/usb/smsc95xx.c 2014-02-13 22:51:06.000000000 +0100
  32955. +++ linux-3.12.11/drivers/net/usb/smsc95xx.c 2014-02-18 11:52:14.000000000 +0100
  32956. @@ -61,6 +61,7 @@
  32957. #define SUSPEND_SUSPEND3 (0x08)
  32958. #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
  32959. SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
  32960. +#define MAC_ADDR_LEN (6)
  32961. struct smsc95xx_priv {
  32962. u32 mac_cr;
  32963. @@ -76,6 +77,10 @@
  32964. module_param(turbo_mode, bool, 0644);
  32965. MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
  32966. +static char *macaddr = ":";
  32967. +module_param(macaddr, charp, 0);
  32968. +MODULE_PARM_DESC(macaddr, "MAC address");
  32969. +
  32970. static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
  32971. u32 *data, int in_pm)
  32972. {
  32973. @@ -765,8 +770,59 @@
  32974. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  32975. }
  32976. +/* Check the macaddr module parameter for a MAC address */
  32977. +static int smsc95xx_is_macaddr_param(struct usbnet *dev, u8 *dev_mac)
  32978. +{
  32979. + int i, j, got_num, num;
  32980. + u8 mtbl[MAC_ADDR_LEN];
  32981. +
  32982. + if (macaddr[0] == ':')
  32983. + return 0;
  32984. +
  32985. + i = 0;
  32986. + j = 0;
  32987. + num = 0;
  32988. + got_num = 0;
  32989. + while (j < MAC_ADDR_LEN) {
  32990. + if (macaddr[i] && macaddr[i] != ':') {
  32991. + got_num++;
  32992. + if ('0' <= macaddr[i] && macaddr[i] <= '9')
  32993. + num = num * 16 + macaddr[i] - '0';
  32994. + else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
  32995. + num = num * 16 + 10 + macaddr[i] - 'A';
  32996. + else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
  32997. + num = num * 16 + 10 + macaddr[i] - 'a';
  32998. + else
  32999. + break;
  33000. + i++;
  33001. + } else if (got_num == 2) {
  33002. + mtbl[j++] = (u8) num;
  33003. + num = 0;
  33004. + got_num = 0;
  33005. + i++;
  33006. + } else {
  33007. + break;
  33008. + }
  33009. + }
  33010. +
  33011. + if (j == MAC_ADDR_LEN) {
  33012. + netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
  33013. + "%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
  33014. + mtbl[3], mtbl[4], mtbl[5]);
  33015. + for (i = 0; i < MAC_ADDR_LEN; i++)
  33016. + dev_mac[i] = mtbl[i];
  33017. + return 1;
  33018. + } else {
  33019. + return 0;
  33020. + }
  33021. +}
  33022. +
  33023. static void smsc95xx_init_mac_address(struct usbnet *dev)
  33024. {
  33025. + /* Check module parameters */
  33026. + if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr))
  33027. + return;
  33028. +
  33029. /* try reading mac address from EEPROM */
  33030. if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
  33031. dev->net->dev_addr) == 0) {
  33032. diff -Nur linux-3.12.11.orig/drivers/spi/Kconfig linux-3.12.11/drivers/spi/Kconfig
  33033. --- linux-3.12.11.orig/drivers/spi/Kconfig 2014-02-13 22:51:06.000000000 +0100
  33034. +++ linux-3.12.11/drivers/spi/Kconfig 2014-02-18 11:52:14.000000000 +0100
  33035. @@ -85,6 +85,14 @@
  33036. is for the regular SPI controller. Slave mode operation is not also
  33037. not supported.
  33038. +config SPI_BCM2708
  33039. + tristate "BCM2708 SPI controller driver (SPI0)"
  33040. + depends on MACH_BCM2708
  33041. + help
  33042. + This selects a driver for the Broadcom BCM2708 SPI master (SPI0). This
  33043. + driver is not compatible with the "Universal SPI Master" or the SPI slave
  33044. + device.
  33045. +
  33046. config SPI_BFIN5XX
  33047. tristate "SPI controller driver for ADI Blackfin5xx"
  33048. depends on BLACKFIN && !BF60x
  33049. diff -Nur linux-3.12.11.orig/drivers/spi/Makefile linux-3.12.11/drivers/spi/Makefile
  33050. --- linux-3.12.11.orig/drivers/spi/Makefile 2014-02-13 22:51:06.000000000 +0100
  33051. +++ linux-3.12.11/drivers/spi/Makefile 2014-02-18 11:52:14.000000000 +0100
  33052. @@ -18,6 +18,7 @@
  33053. obj-$(CONFIG_SPI_BCM63XX) += spi-bcm63xx.o
  33054. obj-$(CONFIG_SPI_BFIN5XX) += spi-bfin5xx.o
  33055. obj-$(CONFIG_SPI_BFIN_V3) += spi-bfin-v3.o
  33056. +obj-$(CONFIG_SPI_BCM2708) += spi-bcm2708.o
  33057. obj-$(CONFIG_SPI_BFIN_SPORT) += spi-bfin-sport.o
  33058. obj-$(CONFIG_SPI_BITBANG) += spi-bitbang.o
  33059. obj-$(CONFIG_SPI_BUTTERFLY) += spi-butterfly.o
  33060. diff -Nur linux-3.12.11.orig/drivers/spi/spi-bcm2708.c linux-3.12.11/drivers/spi/spi-bcm2708.c
  33061. --- linux-3.12.11.orig/drivers/spi/spi-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  33062. +++ linux-3.12.11/drivers/spi/spi-bcm2708.c 2014-02-18 11:52:14.000000000 +0100
  33063. @@ -0,0 +1,626 @@
  33064. +/*
  33065. + * Driver for Broadcom BCM2708 SPI Controllers
  33066. + *
  33067. + * Copyright (C) 2012 Chris Boot
  33068. + *
  33069. + * This driver is inspired by:
  33070. + * spi-ath79.c, Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
  33071. + * spi-atmel.c, Copyright (C) 2006 Atmel Corporation
  33072. + *
  33073. + * This program is free software; you can redistribute it and/or modify
  33074. + * it under the terms of the GNU General Public License as published by
  33075. + * the Free Software Foundation; either version 2 of the License, or
  33076. + * (at your option) any later version.
  33077. + *
  33078. + * This program is distributed in the hope that it will be useful,
  33079. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  33080. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33081. + * GNU General Public License for more details.
  33082. + *
  33083. + * You should have received a copy of the GNU General Public License
  33084. + * along with this program; if not, write to the Free Software
  33085. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  33086. + */
  33087. +
  33088. +#include <linux/kernel.h>
  33089. +#include <linux/module.h>
  33090. +#include <linux/spinlock.h>
  33091. +#include <linux/clk.h>
  33092. +#include <linux/err.h>
  33093. +#include <linux/platform_device.h>
  33094. +#include <linux/io.h>
  33095. +#include <linux/spi/spi.h>
  33096. +#include <linux/interrupt.h>
  33097. +#include <linux/delay.h>
  33098. +#include <linux/log2.h>
  33099. +#include <linux/sched.h>
  33100. +#include <linux/wait.h>
  33101. +
  33102. +/* SPI register offsets */
  33103. +#define SPI_CS 0x00
  33104. +#define SPI_FIFO 0x04
  33105. +#define SPI_CLK 0x08
  33106. +#define SPI_DLEN 0x0c
  33107. +#define SPI_LTOH 0x10
  33108. +#define SPI_DC 0x14
  33109. +
  33110. +/* Bitfields in CS */
  33111. +#define SPI_CS_LEN_LONG 0x02000000
  33112. +#define SPI_CS_DMA_LEN 0x01000000
  33113. +#define SPI_CS_CSPOL2 0x00800000
  33114. +#define SPI_CS_CSPOL1 0x00400000
  33115. +#define SPI_CS_CSPOL0 0x00200000
  33116. +#define SPI_CS_RXF 0x00100000
  33117. +#define SPI_CS_RXR 0x00080000
  33118. +#define SPI_CS_TXD 0x00040000
  33119. +#define SPI_CS_RXD 0x00020000
  33120. +#define SPI_CS_DONE 0x00010000
  33121. +#define SPI_CS_LEN 0x00002000
  33122. +#define SPI_CS_REN 0x00001000
  33123. +#define SPI_CS_ADCS 0x00000800
  33124. +#define SPI_CS_INTR 0x00000400
  33125. +#define SPI_CS_INTD 0x00000200
  33126. +#define SPI_CS_DMAEN 0x00000100
  33127. +#define SPI_CS_TA 0x00000080
  33128. +#define SPI_CS_CSPOL 0x00000040
  33129. +#define SPI_CS_CLEAR_RX 0x00000020
  33130. +#define SPI_CS_CLEAR_TX 0x00000010
  33131. +#define SPI_CS_CPOL 0x00000008
  33132. +#define SPI_CS_CPHA 0x00000004
  33133. +#define SPI_CS_CS_10 0x00000002
  33134. +#define SPI_CS_CS_01 0x00000001
  33135. +
  33136. +#define SPI_TIMEOUT_MS 150
  33137. +
  33138. +#define DRV_NAME "bcm2708_spi"
  33139. +
  33140. +struct bcm2708_spi {
  33141. + spinlock_t lock;
  33142. + void __iomem *base;
  33143. + int irq;
  33144. + struct clk *clk;
  33145. + bool stopping;
  33146. +
  33147. + struct list_head queue;
  33148. + struct workqueue_struct *workq;
  33149. + struct work_struct work;
  33150. + struct completion done;
  33151. +
  33152. + const u8 *tx_buf;
  33153. + u8 *rx_buf;
  33154. + int len;
  33155. +};
  33156. +
  33157. +struct bcm2708_spi_state {
  33158. + u32 cs;
  33159. + u16 cdiv;
  33160. +};
  33161. +
  33162. +/*
  33163. + * This function sets the ALT mode on the SPI pins so that we can use them with
  33164. + * the SPI hardware.
  33165. + *
  33166. + * FIXME: This is a hack. Use pinmux / pinctrl.
  33167. + */
  33168. +static void bcm2708_init_pinmode(void)
  33169. +{
  33170. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  33171. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  33172. +
  33173. + int pin;
  33174. + u32 *gpio = ioremap(0x20200000, SZ_16K);
  33175. +
  33176. + /* SPI is on GPIO 7..11 */
  33177. + for (pin = 7; pin <= 11; pin++) {
  33178. + INP_GPIO(pin); /* set mode to GPIO input first */
  33179. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  33180. + }
  33181. +
  33182. + iounmap(gpio);
  33183. +
  33184. +#undef INP_GPIO
  33185. +#undef SET_GPIO_ALT
  33186. +}
  33187. +
  33188. +static inline u32 bcm2708_rd(struct bcm2708_spi *bs, unsigned reg)
  33189. +{
  33190. + return readl(bs->base + reg);
  33191. +}
  33192. +
  33193. +static inline void bcm2708_wr(struct bcm2708_spi *bs, unsigned reg, u32 val)
  33194. +{
  33195. + writel(val, bs->base + reg);
  33196. +}
  33197. +
  33198. +static inline void bcm2708_rd_fifo(struct bcm2708_spi *bs, int len)
  33199. +{
  33200. + u8 byte;
  33201. +
  33202. + while (len--) {
  33203. + byte = bcm2708_rd(bs, SPI_FIFO);
  33204. + if (bs->rx_buf)
  33205. + *bs->rx_buf++ = byte;
  33206. + }
  33207. +}
  33208. +
  33209. +static inline void bcm2708_wr_fifo(struct bcm2708_spi *bs, int len)
  33210. +{
  33211. + u8 byte;
  33212. + u16 val;
  33213. +
  33214. + if (len > bs->len)
  33215. + len = bs->len;
  33216. +
  33217. + if (unlikely(bcm2708_rd(bs, SPI_CS) & SPI_CS_LEN)) {
  33218. + /* LoSSI mode */
  33219. + if (unlikely(len % 2)) {
  33220. + printk(KERN_ERR"bcm2708_wr_fifo: length must be even, skipping.\n");
  33221. + bs->len = 0;
  33222. + return;
  33223. + }
  33224. + while (len) {
  33225. + if (bs->tx_buf) {
  33226. + val = *(const u16 *)bs->tx_buf;
  33227. + bs->tx_buf += 2;
  33228. + } else
  33229. + val = 0;
  33230. + bcm2708_wr(bs, SPI_FIFO, val);
  33231. + bs->len -= 2;
  33232. + len -= 2;
  33233. + }
  33234. + return;
  33235. + }
  33236. +
  33237. + while (len--) {
  33238. + byte = bs->tx_buf ? *bs->tx_buf++ : 0;
  33239. + bcm2708_wr(bs, SPI_FIFO, byte);
  33240. + bs->len--;
  33241. + }
  33242. +}
  33243. +
  33244. +static irqreturn_t bcm2708_spi_interrupt(int irq, void *dev_id)
  33245. +{
  33246. + struct spi_master *master = dev_id;
  33247. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  33248. + u32 cs;
  33249. +
  33250. + spin_lock(&bs->lock);
  33251. +
  33252. + cs = bcm2708_rd(bs, SPI_CS);
  33253. +
  33254. + if (cs & SPI_CS_DONE) {
  33255. + if (bs->len) { /* first interrupt in a transfer */
  33256. + /* fill the TX fifo with up to 16 bytes */
  33257. + bcm2708_wr_fifo(bs, 16);
  33258. + } else { /* transfer complete */
  33259. + /* disable interrupts */
  33260. + cs &= ~(SPI_CS_INTR | SPI_CS_INTD);
  33261. + bcm2708_wr(bs, SPI_CS, cs);
  33262. +
  33263. + /* drain RX FIFO */
  33264. + while (cs & SPI_CS_RXD) {
  33265. + bcm2708_rd_fifo(bs, 1);
  33266. + cs = bcm2708_rd(bs, SPI_CS);
  33267. + }
  33268. +
  33269. + /* wake up our bh */
  33270. + complete(&bs->done);
  33271. + }
  33272. + } else if (cs & SPI_CS_RXR) {
  33273. + /* read 12 bytes of data */
  33274. + bcm2708_rd_fifo(bs, 12);
  33275. +
  33276. + /* write up to 12 bytes */
  33277. + bcm2708_wr_fifo(bs, 12);
  33278. + }
  33279. +
  33280. + spin_unlock(&bs->lock);
  33281. +
  33282. + return IRQ_HANDLED;
  33283. +}
  33284. +
  33285. +static int bcm2708_setup_state(struct spi_master *master,
  33286. + struct device *dev, struct bcm2708_spi_state *state,
  33287. + u32 hz, u8 csel, u8 mode, u8 bpw)
  33288. +{
  33289. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  33290. + int cdiv;
  33291. + unsigned long bus_hz;
  33292. + u32 cs = 0;
  33293. +
  33294. + bus_hz = clk_get_rate(bs->clk);
  33295. +
  33296. + if (hz >= bus_hz) {
  33297. + cdiv = 2; /* bus_hz / 2 is as fast as we can go */
  33298. + } else if (hz) {
  33299. + cdiv = DIV_ROUND_UP(bus_hz, hz);
  33300. +
  33301. + /* CDIV must be a power of 2, so round up */
  33302. + cdiv = roundup_pow_of_two(cdiv);
  33303. +
  33304. + if (cdiv > 65536) {
  33305. + dev_dbg(dev,
  33306. + "setup: %d Hz too slow, cdiv %u; min %ld Hz\n",
  33307. + hz, cdiv, bus_hz / 65536);
  33308. + return -EINVAL;
  33309. + } else if (cdiv == 65536) {
  33310. + cdiv = 0;
  33311. + } else if (cdiv == 1) {
  33312. + cdiv = 2; /* 1 gets rounded down to 0; == 65536 */
  33313. + }
  33314. + } else {
  33315. + cdiv = 0;
  33316. + }
  33317. +
  33318. + switch (bpw) {
  33319. + case 8:
  33320. + break;
  33321. + case 9:
  33322. + /* Reading in LoSSI mode is a special case. See 'BCM2835 ARM Peripherals' datasheet */
  33323. + cs |= SPI_CS_LEN;
  33324. + break;
  33325. + default:
  33326. + dev_dbg(dev, "setup: invalid bits_per_word %u (must be 8 or 9)\n",
  33327. + bpw);
  33328. + return -EINVAL;
  33329. + }
  33330. +
  33331. + if (mode & SPI_CPOL)
  33332. + cs |= SPI_CS_CPOL;
  33333. + if (mode & SPI_CPHA)
  33334. + cs |= SPI_CS_CPHA;
  33335. +
  33336. + if (!(mode & SPI_NO_CS)) {
  33337. + if (mode & SPI_CS_HIGH) {
  33338. + cs |= SPI_CS_CSPOL;
  33339. + cs |= SPI_CS_CSPOL0 << csel;
  33340. + }
  33341. +
  33342. + cs |= csel;
  33343. + } else {
  33344. + cs |= SPI_CS_CS_10 | SPI_CS_CS_01;
  33345. + }
  33346. +
  33347. + if (state) {
  33348. + state->cs = cs;
  33349. + state->cdiv = cdiv;
  33350. + dev_dbg(dev, "setup: want %d Hz; "
  33351. + "bus_hz=%lu / cdiv=%u == %lu Hz; "
  33352. + "mode %u: cs 0x%08X\n",
  33353. + hz, bus_hz, cdiv, bus_hz/cdiv, mode, cs);
  33354. + }
  33355. +
  33356. + return 0;
  33357. +}
  33358. +
  33359. +static int bcm2708_process_transfer(struct bcm2708_spi *bs,
  33360. + struct spi_message *msg, struct spi_transfer *xfer)
  33361. +{
  33362. + struct spi_device *spi = msg->spi;
  33363. + struct bcm2708_spi_state state, *stp;
  33364. + int ret;
  33365. + u32 cs;
  33366. +
  33367. + if (bs->stopping)
  33368. + return -ESHUTDOWN;
  33369. +
  33370. + if (xfer->bits_per_word || xfer->speed_hz) {
  33371. + ret = bcm2708_setup_state(spi->master, &spi->dev, &state,
  33372. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  33373. + spi->chip_select, spi->mode,
  33374. + xfer->bits_per_word ? xfer->bits_per_word :
  33375. + spi->bits_per_word);
  33376. + if (ret)
  33377. + return ret;
  33378. +
  33379. + stp = &state;
  33380. + } else {
  33381. + stp = spi->controller_state;
  33382. + }
  33383. +
  33384. + INIT_COMPLETION(bs->done);
  33385. + bs->tx_buf = xfer->tx_buf;
  33386. + bs->rx_buf = xfer->rx_buf;
  33387. + bs->len = xfer->len;
  33388. +
  33389. + cs = stp->cs | SPI_CS_INTR | SPI_CS_INTD | SPI_CS_TA;
  33390. +
  33391. + bcm2708_wr(bs, SPI_CLK, stp->cdiv);
  33392. + bcm2708_wr(bs, SPI_CS, cs);
  33393. +
  33394. + ret = wait_for_completion_timeout(&bs->done,
  33395. + msecs_to_jiffies(SPI_TIMEOUT_MS));
  33396. + if (ret == 0) {
  33397. + dev_err(&spi->dev, "transfer timed out\n");
  33398. + return -ETIMEDOUT;
  33399. + }
  33400. +
  33401. + if (xfer->delay_usecs)
  33402. + udelay(xfer->delay_usecs);
  33403. +
  33404. + if (list_is_last(&xfer->transfer_list, &msg->transfers) ||
  33405. + xfer->cs_change) {
  33406. + /* clear TA and interrupt flags */
  33407. + bcm2708_wr(bs, SPI_CS, stp->cs);
  33408. + }
  33409. +
  33410. + msg->actual_length += (xfer->len - bs->len);
  33411. +
  33412. + return 0;
  33413. +}
  33414. +
  33415. +static void bcm2708_work(struct work_struct *work)
  33416. +{
  33417. + struct bcm2708_spi *bs = container_of(work, struct bcm2708_spi, work);
  33418. + unsigned long flags;
  33419. + struct spi_message *msg;
  33420. + struct spi_transfer *xfer;
  33421. + int status = 0;
  33422. +
  33423. + spin_lock_irqsave(&bs->lock, flags);
  33424. + while (!list_empty(&bs->queue)) {
  33425. + msg = list_first_entry(&bs->queue, struct spi_message, queue);
  33426. + list_del_init(&msg->queue);
  33427. + spin_unlock_irqrestore(&bs->lock, flags);
  33428. +
  33429. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  33430. + status = bcm2708_process_transfer(bs, msg, xfer);
  33431. + if (status)
  33432. + break;
  33433. + }
  33434. +
  33435. + msg->status = status;
  33436. + msg->complete(msg->context);
  33437. +
  33438. + spin_lock_irqsave(&bs->lock, flags);
  33439. + }
  33440. + spin_unlock_irqrestore(&bs->lock, flags);
  33441. +}
  33442. +
  33443. +static int bcm2708_spi_setup(struct spi_device *spi)
  33444. +{
  33445. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  33446. + struct bcm2708_spi_state *state;
  33447. + int ret;
  33448. +
  33449. + if (bs->stopping)
  33450. + return -ESHUTDOWN;
  33451. +
  33452. + if (!(spi->mode & SPI_NO_CS) &&
  33453. + (spi->chip_select > spi->master->num_chipselect)) {
  33454. + dev_dbg(&spi->dev,
  33455. + "setup: invalid chipselect %u (%u defined)\n",
  33456. + spi->chip_select, spi->master->num_chipselect);
  33457. + return -EINVAL;
  33458. + }
  33459. +
  33460. + state = spi->controller_state;
  33461. + if (!state) {
  33462. + state = kzalloc(sizeof(*state), GFP_KERNEL);
  33463. + if (!state)
  33464. + return -ENOMEM;
  33465. +
  33466. + spi->controller_state = state;
  33467. + }
  33468. +
  33469. + ret = bcm2708_setup_state(spi->master, &spi->dev, state,
  33470. + spi->max_speed_hz, spi->chip_select, spi->mode,
  33471. + spi->bits_per_word);
  33472. + if (ret < 0) {
  33473. + kfree(state);
  33474. + spi->controller_state = NULL;
  33475. + return ret;
  33476. + }
  33477. +
  33478. + dev_dbg(&spi->dev,
  33479. + "setup: cd %d: %d Hz, bpw %u, mode 0x%x -> CS=%08x CDIV=%04x\n",
  33480. + spi->chip_select, spi->max_speed_hz, spi->bits_per_word,
  33481. + spi->mode, state->cs, state->cdiv);
  33482. +
  33483. + return 0;
  33484. +}
  33485. +
  33486. +static int bcm2708_spi_transfer(struct spi_device *spi, struct spi_message *msg)
  33487. +{
  33488. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  33489. + struct spi_transfer *xfer;
  33490. + int ret;
  33491. + unsigned long flags;
  33492. +
  33493. + if (unlikely(list_empty(&msg->transfers)))
  33494. + return -EINVAL;
  33495. +
  33496. + if (bs->stopping)
  33497. + return -ESHUTDOWN;
  33498. +
  33499. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  33500. + if (!(xfer->tx_buf || xfer->rx_buf) && xfer->len) {
  33501. + dev_dbg(&spi->dev, "missing rx or tx buf\n");
  33502. + return -EINVAL;
  33503. + }
  33504. +
  33505. + if (!xfer->bits_per_word || xfer->speed_hz)
  33506. + continue;
  33507. +
  33508. + ret = bcm2708_setup_state(spi->master, &spi->dev, NULL,
  33509. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  33510. + spi->chip_select, spi->mode,
  33511. + xfer->bits_per_word ? xfer->bits_per_word :
  33512. + spi->bits_per_word);
  33513. + if (ret)
  33514. + return ret;
  33515. + }
  33516. +
  33517. + msg->status = -EINPROGRESS;
  33518. + msg->actual_length = 0;
  33519. +
  33520. + spin_lock_irqsave(&bs->lock, flags);
  33521. + list_add_tail(&msg->queue, &bs->queue);
  33522. + queue_work(bs->workq, &bs->work);
  33523. + spin_unlock_irqrestore(&bs->lock, flags);
  33524. +
  33525. + return 0;
  33526. +}
  33527. +
  33528. +static void bcm2708_spi_cleanup(struct spi_device *spi)
  33529. +{
  33530. + if (spi->controller_state) {
  33531. + kfree(spi->controller_state);
  33532. + spi->controller_state = NULL;
  33533. + }
  33534. +}
  33535. +
  33536. +static int bcm2708_spi_probe(struct platform_device *pdev)
  33537. +{
  33538. + struct resource *regs;
  33539. + int irq, err = -ENOMEM;
  33540. + struct clk *clk;
  33541. + struct spi_master *master;
  33542. + struct bcm2708_spi *bs;
  33543. +
  33544. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  33545. + if (!regs) {
  33546. + dev_err(&pdev->dev, "could not get IO memory\n");
  33547. + return -ENXIO;
  33548. + }
  33549. +
  33550. + irq = platform_get_irq(pdev, 0);
  33551. + if (irq < 0) {
  33552. + dev_err(&pdev->dev, "could not get IRQ\n");
  33553. + return irq;
  33554. + }
  33555. +
  33556. + clk = clk_get(&pdev->dev, NULL);
  33557. + if (IS_ERR(clk)) {
  33558. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  33559. + return PTR_ERR(clk);
  33560. + }
  33561. +
  33562. + bcm2708_init_pinmode();
  33563. +
  33564. + master = spi_alloc_master(&pdev->dev, sizeof(*bs));
  33565. + if (!master) {
  33566. + dev_err(&pdev->dev, "spi_alloc_master() failed\n");
  33567. + goto out_clk_put;
  33568. + }
  33569. +
  33570. + /* the spi->mode bits understood by this driver: */
  33571. + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_NO_CS;
  33572. +
  33573. + master->bus_num = pdev->id;
  33574. + master->num_chipselect = 3;
  33575. + master->setup = bcm2708_spi_setup;
  33576. + master->transfer = bcm2708_spi_transfer;
  33577. + master->cleanup = bcm2708_spi_cleanup;
  33578. + platform_set_drvdata(pdev, master);
  33579. +
  33580. + bs = spi_master_get_devdata(master);
  33581. +
  33582. + spin_lock_init(&bs->lock);
  33583. + INIT_LIST_HEAD(&bs->queue);
  33584. + init_completion(&bs->done);
  33585. + INIT_WORK(&bs->work, bcm2708_work);
  33586. +
  33587. + bs->base = ioremap(regs->start, resource_size(regs));
  33588. + if (!bs->base) {
  33589. + dev_err(&pdev->dev, "could not remap memory\n");
  33590. + goto out_master_put;
  33591. + }
  33592. +
  33593. + bs->workq = create_singlethread_workqueue(dev_name(&pdev->dev));
  33594. + if (!bs->workq) {
  33595. + dev_err(&pdev->dev, "could not create workqueue\n");
  33596. + goto out_iounmap;
  33597. + }
  33598. +
  33599. + bs->irq = irq;
  33600. + bs->clk = clk;
  33601. + bs->stopping = false;
  33602. +
  33603. + err = request_irq(irq, bcm2708_spi_interrupt, 0, dev_name(&pdev->dev),
  33604. + master);
  33605. + if (err) {
  33606. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  33607. + goto out_workqueue;
  33608. + }
  33609. +
  33610. + /* initialise the hardware */
  33611. + clk_enable(clk);
  33612. + bcm2708_wr(bs, SPI_CS, SPI_CS_REN | SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  33613. +
  33614. + err = spi_register_master(master);
  33615. + if (err) {
  33616. + dev_err(&pdev->dev, "could not register SPI master: %d\n", err);
  33617. + goto out_free_irq;
  33618. + }
  33619. +
  33620. + dev_info(&pdev->dev, "SPI Controller at 0x%08lx (irq %d)\n",
  33621. + (unsigned long)regs->start, irq);
  33622. +
  33623. + return 0;
  33624. +
  33625. +out_free_irq:
  33626. + free_irq(bs->irq, master);
  33627. +out_workqueue:
  33628. + destroy_workqueue(bs->workq);
  33629. +out_iounmap:
  33630. + iounmap(bs->base);
  33631. +out_master_put:
  33632. + spi_master_put(master);
  33633. +out_clk_put:
  33634. + clk_put(clk);
  33635. + return err;
  33636. +}
  33637. +
  33638. +static int bcm2708_spi_remove(struct platform_device *pdev)
  33639. +{
  33640. + struct spi_master *master = platform_get_drvdata(pdev);
  33641. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  33642. +
  33643. + /* reset the hardware and block queue progress */
  33644. + spin_lock_irq(&bs->lock);
  33645. + bs->stopping = true;
  33646. + bcm2708_wr(bs, SPI_CS, SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  33647. + spin_unlock_irq(&bs->lock);
  33648. +
  33649. + flush_work_sync(&bs->work);
  33650. +
  33651. + clk_disable(bs->clk);
  33652. + clk_put(bs->clk);
  33653. + free_irq(bs->irq, master);
  33654. + iounmap(bs->base);
  33655. +
  33656. + spi_unregister_master(master);
  33657. +
  33658. + return 0;
  33659. +}
  33660. +
  33661. +static struct platform_driver bcm2708_spi_driver = {
  33662. + .driver = {
  33663. + .name = DRV_NAME,
  33664. + .owner = THIS_MODULE,
  33665. + },
  33666. + .probe = bcm2708_spi_probe,
  33667. + .remove = bcm2708_spi_remove,
  33668. +};
  33669. +
  33670. +
  33671. +static int __init bcm2708_spi_init(void)
  33672. +{
  33673. + return platform_driver_probe(&bcm2708_spi_driver, bcm2708_spi_probe);
  33674. +}
  33675. +module_init(bcm2708_spi_init);
  33676. +
  33677. +static void __exit bcm2708_spi_exit(void)
  33678. +{
  33679. + platform_driver_unregister(&bcm2708_spi_driver);
  33680. +}
  33681. +module_exit(bcm2708_spi_exit);
  33682. +
  33683. +
  33684. +//module_platform_driver(bcm2708_spi_driver);
  33685. +
  33686. +MODULE_DESCRIPTION("SPI controller driver for Broadcom BCM2708");
  33687. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  33688. +MODULE_LICENSE("GPL v2");
  33689. +MODULE_ALIAS("platform:" DRV_NAME);
  33690. diff -Nur linux-3.12.11.orig/drivers/staging/media/lirc/Kconfig linux-3.12.11/drivers/staging/media/lirc/Kconfig
  33691. --- linux-3.12.11.orig/drivers/staging/media/lirc/Kconfig 2014-02-13 22:51:06.000000000 +0100
  33692. +++ linux-3.12.11/drivers/staging/media/lirc/Kconfig 2014-02-18 11:52:14.000000000 +0100
  33693. @@ -38,6 +38,12 @@
  33694. help
  33695. Driver for Homebrew Parallel Port Receivers
  33696. +config LIRC_RPI
  33697. + tristate "Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi"
  33698. + depends on LIRC
  33699. + help
  33700. + Driver for Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi
  33701. +
  33702. config LIRC_SASEM
  33703. tristate "Sasem USB IR Remote"
  33704. depends on LIRC && USB
  33705. diff -Nur linux-3.12.11.orig/drivers/staging/media/lirc/lirc_rpi.c linux-3.12.11/drivers/staging/media/lirc/lirc_rpi.c
  33706. --- linux-3.12.11.orig/drivers/staging/media/lirc/lirc_rpi.c 1970-01-01 01:00:00.000000000 +0100
  33707. +++ linux-3.12.11/drivers/staging/media/lirc/lirc_rpi.c 2014-02-18 11:52:14.000000000 +0100
  33708. @@ -0,0 +1,693 @@
  33709. +/*
  33710. + * lirc_rpi.c
  33711. + *
  33712. + * lirc_rpi - Device driver that records pulse- and pause-lengths
  33713. + * (space-lengths) (just like the lirc_serial driver does)
  33714. + * between GPIO interrupt events on the Raspberry Pi.
  33715. + * Lots of code has been taken from the lirc_serial module,
  33716. + * so I would like say thanks to the authors.
  33717. + *
  33718. + * Copyright (C) 2012 Aron Robert Szabo <aron@reon.hu>,
  33719. + * Michael Bishop <cleverca22@gmail.com>
  33720. + * This program is free software; you can redistribute it and/or modify
  33721. + * it under the terms of the GNU General Public License as published by
  33722. + * the Free Software Foundation; either version 2 of the License, or
  33723. + * (at your option) any later version.
  33724. + *
  33725. + * This program is distributed in the hope that it will be useful,
  33726. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  33727. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33728. + * GNU General Public License for more details.
  33729. + *
  33730. + * You should have received a copy of the GNU General Public License
  33731. + * along with this program; if not, write to the Free Software
  33732. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  33733. + */
  33734. +
  33735. +#include <linux/module.h>
  33736. +#include <linux/errno.h>
  33737. +#include <linux/interrupt.h>
  33738. +#include <linux/sched.h>
  33739. +#include <linux/kernel.h>
  33740. +#include <linux/time.h>
  33741. +#include <linux/string.h>
  33742. +#include <linux/delay.h>
  33743. +#include <linux/platform_device.h>
  33744. +#include <linux/irq.h>
  33745. +#include <linux/spinlock.h>
  33746. +#include <media/lirc.h>
  33747. +#include <media/lirc_dev.h>
  33748. +#include <linux/gpio.h>
  33749. +
  33750. +#define LIRC_DRIVER_NAME "lirc_rpi"
  33751. +#define RBUF_LEN 256
  33752. +#define LIRC_TRANSMITTER_LATENCY 256
  33753. +
  33754. +#ifndef MAX_UDELAY_MS
  33755. +#define MAX_UDELAY_US 5000
  33756. +#else
  33757. +#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
  33758. +#endif
  33759. +
  33760. +#define dprintk(fmt, args...) \
  33761. + do { \
  33762. + if (debug) \
  33763. + printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
  33764. + fmt, ## args); \
  33765. + } while (0)
  33766. +
  33767. +/* module parameters */
  33768. +
  33769. +/* set the default GPIO input pin */
  33770. +static int gpio_in_pin = 18;
  33771. +/* set the default GPIO output pin */
  33772. +static int gpio_out_pin = 17;
  33773. +/* enable debugging messages */
  33774. +static bool debug;
  33775. +/* -1 = auto, 0 = active high, 1 = active low */
  33776. +static int sense = -1;
  33777. +/* use softcarrier by default */
  33778. +static bool softcarrier = 1;
  33779. +/* 0 = do not invert output, 1 = invert output */
  33780. +static bool invert = 0;
  33781. +
  33782. +struct gpio_chip *gpiochip;
  33783. +struct irq_chip *irqchip;
  33784. +struct irq_data *irqdata;
  33785. +
  33786. +/* forward declarations */
  33787. +static long send_pulse(unsigned long length);
  33788. +static void send_space(long length);
  33789. +static void lirc_rpi_exit(void);
  33790. +
  33791. +int valid_gpio_pins[] = { 0, 1, 4, 8, 7, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23,
  33792. + 24, 25 };
  33793. +
  33794. +static struct platform_device *lirc_rpi_dev;
  33795. +static struct timeval lasttv = { 0, 0 };
  33796. +static struct lirc_buffer rbuf;
  33797. +static spinlock_t lock;
  33798. +
  33799. +/* initialized/set in init_timing_params() */
  33800. +static unsigned int freq = 38000;
  33801. +static unsigned int duty_cycle = 50;
  33802. +static unsigned long period;
  33803. +static unsigned long pulse_width;
  33804. +static unsigned long space_width;
  33805. +
  33806. +static void safe_udelay(unsigned long usecs)
  33807. +{
  33808. + while (usecs > MAX_UDELAY_US) {
  33809. + udelay(MAX_UDELAY_US);
  33810. + usecs -= MAX_UDELAY_US;
  33811. + }
  33812. + udelay(usecs);
  33813. +}
  33814. +
  33815. +static int init_timing_params(unsigned int new_duty_cycle,
  33816. + unsigned int new_freq)
  33817. +{
  33818. + /*
  33819. + * period, pulse/space width are kept with 8 binary places -
  33820. + * IE multiplied by 256.
  33821. + */
  33822. + if (256 * 1000000L / new_freq * new_duty_cycle / 100 <=
  33823. + LIRC_TRANSMITTER_LATENCY)
  33824. + return -EINVAL;
  33825. + if (256 * 1000000L / new_freq * (100 - new_duty_cycle) / 100 <=
  33826. + LIRC_TRANSMITTER_LATENCY)
  33827. + return -EINVAL;
  33828. + duty_cycle = new_duty_cycle;
  33829. + freq = new_freq;
  33830. + period = 256 * 1000000L / freq;
  33831. + pulse_width = period * duty_cycle / 100;
  33832. + space_width = period - pulse_width;
  33833. + dprintk("in init_timing_params, freq=%d pulse=%ld, "
  33834. + "space=%ld\n", freq, pulse_width, space_width);
  33835. + return 0;
  33836. +}
  33837. +
  33838. +static long send_pulse_softcarrier(unsigned long length)
  33839. +{
  33840. + int flag;
  33841. + unsigned long actual, target, d;
  33842. +
  33843. + length <<= 8;
  33844. +
  33845. + actual = 0; target = 0; flag = 0;
  33846. + while (actual < length) {
  33847. + if (flag) {
  33848. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  33849. + target += space_width;
  33850. + } else {
  33851. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  33852. + target += pulse_width;
  33853. + }
  33854. + d = (target - actual -
  33855. + LIRC_TRANSMITTER_LATENCY + 128) >> 8;
  33856. + /*
  33857. + * Note - we've checked in ioctl that the pulse/space
  33858. + * widths are big enough so that d is > 0
  33859. + */
  33860. + udelay(d);
  33861. + actual += (d << 8) + LIRC_TRANSMITTER_LATENCY;
  33862. + flag = !flag;
  33863. + }
  33864. + return (actual-length) >> 8;
  33865. +}
  33866. +
  33867. +static long send_pulse(unsigned long length)
  33868. +{
  33869. + if (length <= 0)
  33870. + return 0;
  33871. +
  33872. + if (softcarrier) {
  33873. + return send_pulse_softcarrier(length);
  33874. + } else {
  33875. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  33876. + safe_udelay(length);
  33877. + return 0;
  33878. + }
  33879. +}
  33880. +
  33881. +static void send_space(long length)
  33882. +{
  33883. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  33884. + if (length <= 0)
  33885. + return;
  33886. + safe_udelay(length);
  33887. +}
  33888. +
  33889. +static void rbwrite(int l)
  33890. +{
  33891. + if (lirc_buffer_full(&rbuf)) {
  33892. + /* no new signals will be accepted */
  33893. + dprintk("Buffer overrun\n");
  33894. + return;
  33895. + }
  33896. + lirc_buffer_write(&rbuf, (void *)&l);
  33897. +}
  33898. +
  33899. +static void frbwrite(int l)
  33900. +{
  33901. + /* simple noise filter */
  33902. + static int pulse, space;
  33903. + static unsigned int ptr;
  33904. +
  33905. + if (ptr > 0 && (l & PULSE_BIT)) {
  33906. + pulse += l & PULSE_MASK;
  33907. + if (pulse > 250) {
  33908. + rbwrite(space);
  33909. + rbwrite(pulse | PULSE_BIT);
  33910. + ptr = 0;
  33911. + pulse = 0;
  33912. + }
  33913. + return;
  33914. + }
  33915. + if (!(l & PULSE_BIT)) {
  33916. + if (ptr == 0) {
  33917. + if (l > 20000) {
  33918. + space = l;
  33919. + ptr++;
  33920. + return;
  33921. + }
  33922. + } else {
  33923. + if (l > 20000) {
  33924. + space += pulse;
  33925. + if (space > PULSE_MASK)
  33926. + space = PULSE_MASK;
  33927. + space += l;
  33928. + if (space > PULSE_MASK)
  33929. + space = PULSE_MASK;
  33930. + pulse = 0;
  33931. + return;
  33932. + }
  33933. + rbwrite(space);
  33934. + rbwrite(pulse | PULSE_BIT);
  33935. + ptr = 0;
  33936. + pulse = 0;
  33937. + }
  33938. + }
  33939. + rbwrite(l);
  33940. +}
  33941. +
  33942. +static irqreturn_t irq_handler(int i, void *blah, struct pt_regs *regs)
  33943. +{
  33944. + struct timeval tv;
  33945. + long deltv;
  33946. + int data;
  33947. + int signal;
  33948. +
  33949. + /* use the GPIO signal level */
  33950. + signal = gpiochip->get(gpiochip, gpio_in_pin);
  33951. +
  33952. + /* unmask the irq */
  33953. + irqchip->irq_unmask(irqdata);
  33954. +
  33955. + if (sense != -1) {
  33956. + /* get current time */
  33957. + do_gettimeofday(&tv);
  33958. +
  33959. + /* calc time since last interrupt in microseconds */
  33960. + deltv = tv.tv_sec-lasttv.tv_sec;
  33961. + if (tv.tv_sec < lasttv.tv_sec ||
  33962. + (tv.tv_sec == lasttv.tv_sec &&
  33963. + tv.tv_usec < lasttv.tv_usec)) {
  33964. + printk(KERN_WARNING LIRC_DRIVER_NAME
  33965. + ": AIEEEE: your clock just jumped backwards\n");
  33966. + printk(KERN_WARNING LIRC_DRIVER_NAME
  33967. + ": %d %d %lx %lx %lx %lx\n", signal, sense,
  33968. + tv.tv_sec, lasttv.tv_sec,
  33969. + tv.tv_usec, lasttv.tv_usec);
  33970. + data = PULSE_MASK;
  33971. + } else if (deltv > 15) {
  33972. + data = PULSE_MASK; /* really long time */
  33973. + if (!(signal^sense)) {
  33974. + /* sanity check */
  33975. + printk(KERN_WARNING LIRC_DRIVER_NAME
  33976. + ": AIEEEE: %d %d %lx %lx %lx %lx\n",
  33977. + signal, sense, tv.tv_sec, lasttv.tv_sec,
  33978. + tv.tv_usec, lasttv.tv_usec);
  33979. + /*
  33980. + * detecting pulse while this
  33981. + * MUST be a space!
  33982. + */
  33983. + sense = sense ? 0 : 1;
  33984. + }
  33985. + } else {
  33986. + data = (int) (deltv*1000000 +
  33987. + (tv.tv_usec - lasttv.tv_usec));
  33988. + }
  33989. + frbwrite(signal^sense ? data : (data|PULSE_BIT));
  33990. + lasttv = tv;
  33991. + wake_up_interruptible(&rbuf.wait_poll);
  33992. + }
  33993. +
  33994. + return IRQ_HANDLED;
  33995. +}
  33996. +
  33997. +static int is_right_chip(struct gpio_chip *chip, void *data)
  33998. +{
  33999. + dprintk("is_right_chip %s %d\n", chip->label, strcmp(data, chip->label));
  34000. +
  34001. + if (strcmp(data, chip->label) == 0)
  34002. + return 1;
  34003. + return 0;
  34004. +}
  34005. +
  34006. +static int init_port(void)
  34007. +{
  34008. + int i, nlow, nhigh, ret, irq;
  34009. +
  34010. + gpiochip = gpiochip_find("bcm2708_gpio", is_right_chip);
  34011. +
  34012. + if (!gpiochip)
  34013. + return -ENODEV;
  34014. +
  34015. + if (gpio_request(gpio_out_pin, LIRC_DRIVER_NAME " ir/out")) {
  34016. + printk(KERN_ALERT LIRC_DRIVER_NAME
  34017. + ": cant claim gpio pin %d\n", gpio_out_pin);
  34018. + ret = -ENODEV;
  34019. + goto exit_init_port;
  34020. + }
  34021. +
  34022. + if (gpio_request(gpio_in_pin, LIRC_DRIVER_NAME " ir/in")) {
  34023. + printk(KERN_ALERT LIRC_DRIVER_NAME
  34024. + ": cant claim gpio pin %d\n", gpio_in_pin);
  34025. + ret = -ENODEV;
  34026. + goto exit_gpio_free_out_pin;
  34027. + }
  34028. +
  34029. + gpiochip->direction_input(gpiochip, gpio_in_pin);
  34030. + gpiochip->direction_output(gpiochip, gpio_out_pin, 1);
  34031. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  34032. +
  34033. + irq = gpiochip->to_irq(gpiochip, gpio_in_pin);
  34034. + dprintk("to_irq %d\n", irq);
  34035. + irqdata = irq_get_irq_data(irq);
  34036. +
  34037. + if (irqdata && irqdata->chip) {
  34038. + irqchip = irqdata->chip;
  34039. + } else {
  34040. + ret = -ENODEV;
  34041. + goto exit_gpio_free_in_pin;
  34042. + }
  34043. +
  34044. + /* if pin is high, then this must be an active low receiver. */
  34045. + if (sense == -1) {
  34046. + /* wait 1/2 sec for the power supply */
  34047. + msleep(500);
  34048. +
  34049. + /*
  34050. + * probe 9 times every 0.04s, collect "votes" for
  34051. + * active high/low
  34052. + */
  34053. + nlow = 0;
  34054. + nhigh = 0;
  34055. + for (i = 0; i < 9; i++) {
  34056. + if (gpiochip->get(gpiochip, gpio_in_pin))
  34057. + nlow++;
  34058. + else
  34059. + nhigh++;
  34060. + msleep(40);
  34061. + }
  34062. + sense = (nlow >= nhigh ? 1 : 0);
  34063. + printk(KERN_INFO LIRC_DRIVER_NAME
  34064. + ": auto-detected active %s receiver on GPIO pin %d\n",
  34065. + sense ? "low" : "high", gpio_in_pin);
  34066. + } else {
  34067. + printk(KERN_INFO LIRC_DRIVER_NAME
  34068. + ": manually using active %s receiver on GPIO pin %d\n",
  34069. + sense ? "low" : "high", gpio_in_pin);
  34070. + }
  34071. +
  34072. + return 0;
  34073. +
  34074. + exit_gpio_free_in_pin:
  34075. + gpio_free(gpio_in_pin);
  34076. +
  34077. + exit_gpio_free_out_pin:
  34078. + gpio_free(gpio_out_pin);
  34079. +
  34080. + exit_init_port:
  34081. + return ret;
  34082. +}
  34083. +
  34084. +// called when the character device is opened
  34085. +static int set_use_inc(void *data)
  34086. +{
  34087. + int result;
  34088. + unsigned long flags;
  34089. +
  34090. + /* initialize timestamp */
  34091. + do_gettimeofday(&lasttv);
  34092. +
  34093. + result = request_irq(gpiochip->to_irq(gpiochip, gpio_in_pin),
  34094. + (irq_handler_t) irq_handler, 0,
  34095. + LIRC_DRIVER_NAME, (void*) 0);
  34096. +
  34097. + switch (result) {
  34098. + case -EBUSY:
  34099. + printk(KERN_ERR LIRC_DRIVER_NAME
  34100. + ": IRQ %d is busy\n",
  34101. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  34102. + return -EBUSY;
  34103. + case -EINVAL:
  34104. + printk(KERN_ERR LIRC_DRIVER_NAME
  34105. + ": Bad irq number or handler\n");
  34106. + return -EINVAL;
  34107. + default:
  34108. + dprintk("Interrupt %d obtained\n",
  34109. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  34110. + break;
  34111. + };
  34112. +
  34113. + /* initialize pulse/space widths */
  34114. + init_timing_params(duty_cycle, freq);
  34115. +
  34116. + spin_lock_irqsave(&lock, flags);
  34117. +
  34118. + /* GPIO Pin Falling/Rising Edge Detect Enable */
  34119. + irqchip->irq_set_type(irqdata,
  34120. + IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING);
  34121. +
  34122. + /* unmask the irq */
  34123. + irqchip->irq_unmask(irqdata);
  34124. +
  34125. + spin_unlock_irqrestore(&lock, flags);
  34126. +
  34127. + return 0;
  34128. +}
  34129. +
  34130. +static void set_use_dec(void *data)
  34131. +{
  34132. + unsigned long flags;
  34133. +
  34134. + spin_lock_irqsave(&lock, flags);
  34135. +
  34136. + /* GPIO Pin Falling/Rising Edge Detect Disable */
  34137. + irqchip->irq_set_type(irqdata, 0);
  34138. + irqchip->irq_mask(irqdata);
  34139. +
  34140. + spin_unlock_irqrestore(&lock, flags);
  34141. +
  34142. + free_irq(gpiochip->to_irq(gpiochip, gpio_in_pin), (void *) 0);
  34143. +
  34144. + dprintk(KERN_INFO LIRC_DRIVER_NAME
  34145. + ": freed IRQ %d\n", gpiochip->to_irq(gpiochip, gpio_in_pin));
  34146. +}
  34147. +
  34148. +static ssize_t lirc_write(struct file *file, const char *buf,
  34149. + size_t n, loff_t *ppos)
  34150. +{
  34151. + int i, count;
  34152. + unsigned long flags;
  34153. + long delta = 0;
  34154. + int *wbuf;
  34155. +
  34156. + count = n / sizeof(int);
  34157. + if (n % sizeof(int) || count % 2 == 0)
  34158. + return -EINVAL;
  34159. + wbuf = memdup_user(buf, n);
  34160. + if (IS_ERR(wbuf))
  34161. + return PTR_ERR(wbuf);
  34162. + spin_lock_irqsave(&lock, flags);
  34163. +
  34164. + for (i = 0; i < count; i++) {
  34165. + if (i%2)
  34166. + send_space(wbuf[i] - delta);
  34167. + else
  34168. + delta = send_pulse(wbuf[i]);
  34169. + }
  34170. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  34171. +
  34172. + spin_unlock_irqrestore(&lock, flags);
  34173. + kfree(wbuf);
  34174. + return n;
  34175. +}
  34176. +
  34177. +static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
  34178. +{
  34179. + int result;
  34180. + __u32 value;
  34181. +
  34182. + switch (cmd) {
  34183. + case LIRC_GET_SEND_MODE:
  34184. + return -ENOIOCTLCMD;
  34185. + break;
  34186. +
  34187. + case LIRC_SET_SEND_MODE:
  34188. + result = get_user(value, (__u32 *) arg);
  34189. + if (result)
  34190. + return result;
  34191. + /* only LIRC_MODE_PULSE supported */
  34192. + if (value != LIRC_MODE_PULSE)
  34193. + return -ENOSYS;
  34194. + break;
  34195. +
  34196. + case LIRC_GET_LENGTH:
  34197. + return -ENOSYS;
  34198. + break;
  34199. +
  34200. + case LIRC_SET_SEND_DUTY_CYCLE:
  34201. + dprintk("SET_SEND_DUTY_CYCLE\n");
  34202. + result = get_user(value, (__u32 *) arg);
  34203. + if (result)
  34204. + return result;
  34205. + if (value <= 0 || value > 100)
  34206. + return -EINVAL;
  34207. + return init_timing_params(value, freq);
  34208. + break;
  34209. +
  34210. + case LIRC_SET_SEND_CARRIER:
  34211. + dprintk("SET_SEND_CARRIER\n");
  34212. + result = get_user(value, (__u32 *) arg);
  34213. + if (result)
  34214. + return result;
  34215. + if (value > 500000 || value < 20000)
  34216. + return -EINVAL;
  34217. + return init_timing_params(duty_cycle, value);
  34218. + break;
  34219. +
  34220. + default:
  34221. + return lirc_dev_fop_ioctl(filep, cmd, arg);
  34222. + }
  34223. + return 0;
  34224. +}
  34225. +
  34226. +static const struct file_operations lirc_fops = {
  34227. + .owner = THIS_MODULE,
  34228. + .write = lirc_write,
  34229. + .unlocked_ioctl = lirc_ioctl,
  34230. + .read = lirc_dev_fop_read,
  34231. + .poll = lirc_dev_fop_poll,
  34232. + .open = lirc_dev_fop_open,
  34233. + .release = lirc_dev_fop_close,
  34234. + .llseek = no_llseek,
  34235. +};
  34236. +
  34237. +static struct lirc_driver driver = {
  34238. + .name = LIRC_DRIVER_NAME,
  34239. + .minor = -1,
  34240. + .code_length = 1,
  34241. + .sample_rate = 0,
  34242. + .data = NULL,
  34243. + .add_to_buf = NULL,
  34244. + .rbuf = &rbuf,
  34245. + .set_use_inc = set_use_inc,
  34246. + .set_use_dec = set_use_dec,
  34247. + .fops = &lirc_fops,
  34248. + .dev = NULL,
  34249. + .owner = THIS_MODULE,
  34250. +};
  34251. +
  34252. +static struct platform_driver lirc_rpi_driver = {
  34253. + .driver = {
  34254. + .name = LIRC_DRIVER_NAME,
  34255. + .owner = THIS_MODULE,
  34256. + },
  34257. +};
  34258. +
  34259. +static int __init lirc_rpi_init(void)
  34260. +{
  34261. + int result;
  34262. +
  34263. + /* Init read buffer. */
  34264. + result = lirc_buffer_init(&rbuf, sizeof(int), RBUF_LEN);
  34265. + if (result < 0)
  34266. + return -ENOMEM;
  34267. +
  34268. + result = platform_driver_register(&lirc_rpi_driver);
  34269. + if (result) {
  34270. + printk(KERN_ERR LIRC_DRIVER_NAME
  34271. + ": lirc register returned %d\n", result);
  34272. + goto exit_buffer_free;
  34273. + }
  34274. +
  34275. + lirc_rpi_dev = platform_device_alloc(LIRC_DRIVER_NAME, 0);
  34276. + if (!lirc_rpi_dev) {
  34277. + result = -ENOMEM;
  34278. + goto exit_driver_unregister;
  34279. + }
  34280. +
  34281. + result = platform_device_add(lirc_rpi_dev);
  34282. + if (result)
  34283. + goto exit_device_put;
  34284. +
  34285. + return 0;
  34286. +
  34287. + exit_device_put:
  34288. + platform_device_put(lirc_rpi_dev);
  34289. +
  34290. + exit_driver_unregister:
  34291. + platform_driver_unregister(&lirc_rpi_driver);
  34292. +
  34293. + exit_buffer_free:
  34294. + lirc_buffer_free(&rbuf);
  34295. +
  34296. + return result;
  34297. +}
  34298. +
  34299. +static void lirc_rpi_exit(void)
  34300. +{
  34301. + platform_device_unregister(lirc_rpi_dev);
  34302. + platform_driver_unregister(&lirc_rpi_driver);
  34303. + lirc_buffer_free(&rbuf);
  34304. +}
  34305. +
  34306. +static int __init lirc_rpi_init_module(void)
  34307. +{
  34308. + int result, i;
  34309. +
  34310. + result = lirc_rpi_init();
  34311. + if (result)
  34312. + return result;
  34313. +
  34314. + /* check if the module received valid gpio pin numbers */
  34315. + result = 0;
  34316. + if (gpio_in_pin != gpio_out_pin) {
  34317. + for(i = 0; (i < ARRAY_SIZE(valid_gpio_pins)) && (result != 2); i++) {
  34318. + if (gpio_in_pin == valid_gpio_pins[i] ||
  34319. + gpio_out_pin == valid_gpio_pins[i]) {
  34320. + result++;
  34321. + }
  34322. + }
  34323. + }
  34324. +
  34325. + if (result != 2) {
  34326. + result = -EINVAL;
  34327. + printk(KERN_ERR LIRC_DRIVER_NAME
  34328. + ": invalid GPIO pin(s) specified!\n");
  34329. + goto exit_rpi;
  34330. + }
  34331. +
  34332. + result = init_port();
  34333. + if (result < 0)
  34334. + goto exit_rpi;
  34335. +
  34336. + driver.features = LIRC_CAN_SET_SEND_DUTY_CYCLE |
  34337. + LIRC_CAN_SET_SEND_CARRIER |
  34338. + LIRC_CAN_SEND_PULSE |
  34339. + LIRC_CAN_REC_MODE2;
  34340. +
  34341. + driver.dev = &lirc_rpi_dev->dev;
  34342. + driver.minor = lirc_register_driver(&driver);
  34343. +
  34344. + if (driver.minor < 0) {
  34345. + printk(KERN_ERR LIRC_DRIVER_NAME
  34346. + ": device registration failed with %d\n", result);
  34347. + result = -EIO;
  34348. + goto exit_rpi;
  34349. + }
  34350. +
  34351. + printk(KERN_INFO LIRC_DRIVER_NAME ": driver registered!\n");
  34352. +
  34353. + return 0;
  34354. +
  34355. + exit_rpi:
  34356. + lirc_rpi_exit();
  34357. +
  34358. + return result;
  34359. +}
  34360. +
  34361. +static void __exit lirc_rpi_exit_module(void)
  34362. +{
  34363. + gpio_free(gpio_out_pin);
  34364. + gpio_free(gpio_in_pin);
  34365. +
  34366. + lirc_rpi_exit();
  34367. +
  34368. + lirc_unregister_driver(driver.minor);
  34369. + printk(KERN_INFO LIRC_DRIVER_NAME ": cleaned up module\n");
  34370. +}
  34371. +
  34372. +module_init(lirc_rpi_init_module);
  34373. +module_exit(lirc_rpi_exit_module);
  34374. +
  34375. +MODULE_DESCRIPTION("Infra-red receiver and blaster driver for Raspberry Pi GPIO.");
  34376. +MODULE_AUTHOR("Aron Robert Szabo <aron@reon.hu>");
  34377. +MODULE_AUTHOR("Michael Bishop <cleverca22@gmail.com>");
  34378. +MODULE_LICENSE("GPL");
  34379. +
  34380. +module_param(gpio_out_pin, int, S_IRUGO);
  34381. +MODULE_PARM_DESC(gpio_out_pin, "GPIO output/transmitter pin number of the BCM"
  34382. + " processor. Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11,"
  34383. + " 14, 15, 17, 18, 21, 22, 23, 24, 25, default 17");
  34384. +
  34385. +module_param(gpio_in_pin, int, S_IRUGO);
  34386. +MODULE_PARM_DESC(gpio_in_pin, "GPIO input pin number of the BCM processor."
  34387. + " Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11, 14, 15,"
  34388. + " 17, 18, 21, 22, 23, 24, 25, default 18");
  34389. +
  34390. +module_param(sense, int, S_IRUGO);
  34391. +MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit"
  34392. + " (0 = active high, 1 = active low )");
  34393. +
  34394. +module_param(softcarrier, bool, S_IRUGO);
  34395. +MODULE_PARM_DESC(softcarrier, "Software carrier (0 = off, 1 = on, default on)");
  34396. +
  34397. +module_param(invert, bool, S_IRUGO);
  34398. +MODULE_PARM_DESC(invert, "Invert output (0 = off, 1 = on, default off");
  34399. +
  34400. +module_param(debug, bool, S_IRUGO | S_IWUSR);
  34401. +MODULE_PARM_DESC(debug, "Enable debugging messages");
  34402. diff -Nur linux-3.12.11.orig/drivers/staging/media/lirc/Makefile linux-3.12.11/drivers/staging/media/lirc/Makefile
  34403. --- linux-3.12.11.orig/drivers/staging/media/lirc/Makefile 2014-02-13 22:51:06.000000000 +0100
  34404. +++ linux-3.12.11/drivers/staging/media/lirc/Makefile 2014-02-18 11:52:14.000000000 +0100
  34405. @@ -7,6 +7,7 @@
  34406. obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o
  34407. obj-$(CONFIG_LIRC_IMON) += lirc_imon.o
  34408. obj-$(CONFIG_LIRC_PARALLEL) += lirc_parallel.o
  34409. +obj-$(CONFIG_LIRC_RPI) += lirc_rpi.o
  34410. obj-$(CONFIG_LIRC_SASEM) += lirc_sasem.o
  34411. obj-$(CONFIG_LIRC_SERIAL) += lirc_serial.o
  34412. obj-$(CONFIG_LIRC_SIR) += lirc_sir.o
  34413. diff -Nur linux-3.12.11.orig/drivers/thermal/bcm2835-thermal.c linux-3.12.11/drivers/thermal/bcm2835-thermal.c
  34414. --- linux-3.12.11.orig/drivers/thermal/bcm2835-thermal.c 1970-01-01 01:00:00.000000000 +0100
  34415. +++ linux-3.12.11/drivers/thermal/bcm2835-thermal.c 2014-02-18 11:52:14.000000000 +0100
  34416. @@ -0,0 +1,184 @@
  34417. +/*****************************************************************************
  34418. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  34419. +*
  34420. +* Unless you and Broadcom execute a separate written software license
  34421. +* agreement governing use of this software, this software is licensed to you
  34422. +* under the terms of the GNU General Public License version 2, available at
  34423. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  34424. +*
  34425. +* Notwithstanding the above, under no circumstances may you combine this
  34426. +* software in any way with any other Broadcom software provided under a
  34427. +* license other than the GPL, without Broadcom's express prior written
  34428. +* consent.
  34429. +*****************************************************************************/
  34430. +
  34431. +#include <linux/kernel.h>
  34432. +#include <linux/module.h>
  34433. +#include <linux/init.h>
  34434. +#include <linux/platform_device.h>
  34435. +#include <linux/slab.h>
  34436. +#include <linux/sysfs.h>
  34437. +#include <mach/vcio.h>
  34438. +#include <linux/thermal.h>
  34439. +
  34440. +
  34441. +/* --- DEFINITIONS --- */
  34442. +#define MODULE_NAME "bcm2835_thermal"
  34443. +
  34444. +/*#define THERMAL_DEBUG_ENABLE*/
  34445. +
  34446. +#ifdef THERMAL_DEBUG_ENABLE
  34447. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  34448. +#else
  34449. +#define print_debug(fmt,...)
  34450. +#endif
  34451. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  34452. +
  34453. +#define VC_TAG_GET_TEMP 0x00030006
  34454. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  34455. +
  34456. +typedef enum {
  34457. + TEMP,
  34458. + MAX_TEMP,
  34459. +} temp_type;
  34460. +
  34461. +/* --- STRUCTS --- */
  34462. +/* tag part of the message */
  34463. +struct vc_msg_tag {
  34464. + uint32_t tag_id; /* the tag ID for the temperature */
  34465. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  34466. + uint32_t request_code; /* identifies message as a request (should be 0) */
  34467. + uint32_t id; /* extra ID field (should be 0) */
  34468. + uint32_t val; /* returned value of the temperature */
  34469. +};
  34470. +
  34471. +/* message structure to be sent to videocore */
  34472. +struct vc_msg {
  34473. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  34474. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  34475. + struct vc_msg_tag tag; /* the tag structure above to make */
  34476. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  34477. +};
  34478. +
  34479. +struct bcm2835_thermal_data {
  34480. + struct thermal_zone_device *thermal_dev;
  34481. + struct vc_msg msg;
  34482. +};
  34483. +
  34484. +/* --- GLOBALS --- */
  34485. +static struct bcm2835_thermal_data bcm2835_data;
  34486. +
  34487. +/* Thermal Device Operations */
  34488. +static struct thermal_zone_device_ops ops;
  34489. +
  34490. +/* --- FUNCTIONS --- */
  34491. +
  34492. +static int bcm2835_get_temp_or_max(struct thermal_zone_device *thermal_dev, unsigned long *temp, unsigned tag_id)
  34493. +{
  34494. + int result = -1, retry = 3;
  34495. + print_debug("IN");
  34496. +
  34497. + *temp = 0;
  34498. + while (result != 0 && retry-- > 0) {
  34499. + /* wipe all previous message data */
  34500. + memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
  34501. +
  34502. + /* prepare message */
  34503. + bcm2835_data.msg.msg_size = sizeof bcm2835_data.msg;
  34504. + bcm2835_data.msg.tag.buffer_size = 8;
  34505. + bcm2835_data.msg.tag.tag_id = tag_id;
  34506. +
  34507. + /* send the message */
  34508. + result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
  34509. + 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);
  34510. + if (!(bcm2835_data.msg.request_code & 0x80000000))
  34511. + result = -1;
  34512. + }
  34513. +
  34514. + /* check if it was all ok and return the rate in milli degrees C */
  34515. + if (result == 0)
  34516. + *temp = (uint)bcm2835_data.msg.tag.val;
  34517. + else
  34518. + print_err("Failed to get temperature! (%x:%d)\n", tag_id, result);
  34519. + print_debug("OUT");
  34520. + return result;
  34521. +}
  34522. +
  34523. +static int bcm2835_get_temp(struct thermal_zone_device *thermal_dev, unsigned long *temp)
  34524. +{
  34525. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_TEMP);
  34526. +}
  34527. +
  34528. +static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int trip_num, unsigned long *temp)
  34529. +{
  34530. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_MAX_TEMP);
  34531. +}
  34532. +
  34533. +static int bcm2835_get_trip_type(struct thermal_zone_device * thermal_dev, int trip_num, enum thermal_trip_type *trip_type)
  34534. +{
  34535. + *trip_type = THERMAL_TRIP_HOT;
  34536. + return 0;
  34537. +}
  34538. +
  34539. +
  34540. +static int bcm2835_get_mode(struct thermal_zone_device *thermal_dev, enum thermal_device_mode *dev_mode)
  34541. +{
  34542. + *dev_mode = THERMAL_DEVICE_ENABLED;
  34543. + return 0;
  34544. +}
  34545. +
  34546. +
  34547. +static int bcm2835_thermal_probe(struct platform_device *pdev)
  34548. +{
  34549. + print_debug("IN");
  34550. + print_debug("THERMAL Driver has been probed!");
  34551. +
  34552. + /* check that the device isn't null!*/
  34553. + if(pdev == NULL)
  34554. + {
  34555. + print_debug("Platform device is empty!");
  34556. + return -ENODEV;
  34557. + }
  34558. +
  34559. + if(!(bcm2835_data.thermal_dev = thermal_zone_device_register("bcm2835_thermal", 1, 0, NULL, &ops, NULL, 0, 0)))
  34560. + {
  34561. + print_debug("Unable to register the thermal device!");
  34562. + return -EFAULT;
  34563. + }
  34564. + return 0;
  34565. +}
  34566. +
  34567. +
  34568. +static int bcm2835_thermal_remove(struct platform_device *pdev)
  34569. +{
  34570. + print_debug("IN");
  34571. +
  34572. + thermal_zone_device_unregister(bcm2835_data.thermal_dev);
  34573. +
  34574. + print_debug("OUT");
  34575. +
  34576. + return 0;
  34577. +}
  34578. +
  34579. +static struct thermal_zone_device_ops ops = {
  34580. + .get_temp = bcm2835_get_temp,
  34581. + .get_trip_temp = bcm2835_get_max_temp,
  34582. + .get_trip_type = bcm2835_get_trip_type,
  34583. + .get_mode = bcm2835_get_mode,
  34584. +};
  34585. +
  34586. +/* Thermal Driver */
  34587. +static struct platform_driver bcm2835_thermal_driver = {
  34588. + .probe = bcm2835_thermal_probe,
  34589. + .remove = bcm2835_thermal_remove,
  34590. + .driver = {
  34591. + .name = "bcm2835_thermal",
  34592. + .owner = THIS_MODULE,
  34593. + },
  34594. +};
  34595. +
  34596. +MODULE_LICENSE("GPL");
  34597. +MODULE_AUTHOR("Dorian Peake");
  34598. +MODULE_DESCRIPTION("Thermal driver for bcm2835 chip");
  34599. +
  34600. +module_platform_driver(bcm2835_thermal_driver);
  34601. diff -Nur linux-3.12.11.orig/drivers/thermal/Kconfig linux-3.12.11/drivers/thermal/Kconfig
  34602. --- linux-3.12.11.orig/drivers/thermal/Kconfig 2014-02-13 22:51:06.000000000 +0100
  34603. +++ linux-3.12.11/drivers/thermal/Kconfig 2014-02-18 11:52:14.000000000 +0100
  34604. @@ -181,6 +181,12 @@
  34605. enforce idle time which results in more package C-state residency. The
  34606. user interface is exposed via generic thermal framework.
  34607. +config THERMAL_BCM2835
  34608. + tristate "BCM2835 Thermal Driver"
  34609. + help
  34610. + This will enable temperature monitoring for the Broadcom BCM2835
  34611. + chip. If built as a module, it will be called 'bcm2835-thermal'.
  34612. +
  34613. config X86_PKG_TEMP_THERMAL
  34614. tristate "X86 package temperature thermal driver"
  34615. depends on X86_THERMAL_VECTOR
  34616. diff -Nur linux-3.12.11.orig/drivers/thermal/Makefile linux-3.12.11/drivers/thermal/Makefile
  34617. --- linux-3.12.11.orig/drivers/thermal/Makefile 2014-02-13 22:51:06.000000000 +0100
  34618. +++ linux-3.12.11/drivers/thermal/Makefile 2014-02-18 11:52:14.000000000 +0100
  34619. @@ -27,5 +27,6 @@
  34620. obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o
  34621. obj-$(CONFIG_DB8500_CPUFREQ_COOLING) += db8500_cpufreq_cooling.o
  34622. obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o
  34623. +obj-$(CONFIG_THERMAL_BCM2835) += bcm2835-thermal.o
  34624. obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o
  34625. obj-$(CONFIG_TI_SOC_THERMAL) += ti-soc-thermal/
  34626. diff -Nur linux-3.12.11.orig/drivers/tty/serial/amba-pl011.c linux-3.12.11/drivers/tty/serial/amba-pl011.c
  34627. --- linux-3.12.11.orig/drivers/tty/serial/amba-pl011.c 2014-02-13 22:51:06.000000000 +0100
  34628. +++ linux-3.12.11/drivers/tty/serial/amba-pl011.c 2014-02-18 11:52:14.000000000 +0100
  34629. @@ -84,7 +84,7 @@
  34630. static unsigned int get_fifosize_arm(struct amba_device *dev)
  34631. {
  34632. - return amba_rev(dev) < 3 ? 16 : 32;
  34633. + return 16; //TODO: fix: amba_rev(dev) < 3 ? 16 : 32;
  34634. }
  34635. static struct vendor_data vendor_arm = {
  34636. diff -Nur linux-3.12.11.orig/drivers/usb/core/generic.c linux-3.12.11/drivers/usb/core/generic.c
  34637. --- linux-3.12.11.orig/drivers/usb/core/generic.c 2014-02-13 22:51:06.000000000 +0100
  34638. +++ linux-3.12.11/drivers/usb/core/generic.c 2014-02-18 11:52:14.000000000 +0100
  34639. @@ -152,6 +152,7 @@
  34640. dev_warn(&udev->dev,
  34641. "no configuration chosen from %d choice%s\n",
  34642. num_configs, plural(num_configs));
  34643. + dev_warn(&udev->dev, "No support over %dmA\n", udev->bus_mA);
  34644. }
  34645. return i;
  34646. }
  34647. diff -Nur linux-3.12.11.orig/drivers/usb/core/message.c linux-3.12.11/drivers/usb/core/message.c
  34648. --- linux-3.12.11.orig/drivers/usb/core/message.c 2014-02-13 22:51:06.000000000 +0100
  34649. +++ linux-3.12.11/drivers/usb/core/message.c 2014-02-18 11:52:14.000000000 +0100
  34650. @@ -1885,6 +1885,85 @@
  34651. if (cp->string == NULL &&
  34652. !(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
  34653. cp->string = usb_cache_string(dev, cp->desc.iConfiguration);
  34654. +/* Uncomment this define to enable the HS Electrical Test support */
  34655. +#define DWC_HS_ELECT_TST 1
  34656. +#ifdef DWC_HS_ELECT_TST
  34657. + /* Here we implement the HS Electrical Test support. The
  34658. + * tester uses a vendor ID of 0x1A0A to indicate we should
  34659. + * run a special test sequence. The product ID tells us
  34660. + * which sequence to run. We invoke the test sequence by
  34661. + * sending a non-standard SetFeature command to our root
  34662. + * hub port. Our dwc_otg_hcd_hub_control() routine will
  34663. + * recognize the command and perform the desired test
  34664. + * sequence.
  34665. + */
  34666. + if (dev->descriptor.idVendor == 0x1A0A) {
  34667. + /* HSOTG Electrical Test */
  34668. + dev_warn(&dev->dev, "VID from HSOTG Electrical Test Fixture\n");
  34669. +
  34670. + if (dev->bus && dev->bus->root_hub) {
  34671. + struct usb_device *hdev = dev->bus->root_hub;
  34672. + dev_warn(&dev->dev, "Got PID 0x%x\n", dev->descriptor.idProduct);
  34673. +
  34674. + switch (dev->descriptor.idProduct) {
  34675. + case 0x0101: /* TEST_SE0_NAK */
  34676. + dev_warn(&dev->dev, "TEST_SE0_NAK\n");
  34677. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34678. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34679. + USB_PORT_FEAT_TEST, 0x300, NULL, 0, HZ);
  34680. + break;
  34681. +
  34682. + case 0x0102: /* TEST_J */
  34683. + dev_warn(&dev->dev, "TEST_J\n");
  34684. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34685. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34686. + USB_PORT_FEAT_TEST, 0x100, NULL, 0, HZ);
  34687. + break;
  34688. +
  34689. + case 0x0103: /* TEST_K */
  34690. + dev_warn(&dev->dev, "TEST_K\n");
  34691. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34692. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34693. + USB_PORT_FEAT_TEST, 0x200, NULL, 0, HZ);
  34694. + break;
  34695. +
  34696. + case 0x0104: /* TEST_PACKET */
  34697. + dev_warn(&dev->dev, "TEST_PACKET\n");
  34698. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34699. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34700. + USB_PORT_FEAT_TEST, 0x400, NULL, 0, HZ);
  34701. + break;
  34702. +
  34703. + case 0x0105: /* TEST_FORCE_ENABLE */
  34704. + dev_warn(&dev->dev, "TEST_FORCE_ENABLE\n");
  34705. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34706. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34707. + USB_PORT_FEAT_TEST, 0x500, NULL, 0, HZ);
  34708. + break;
  34709. +
  34710. + case 0x0106: /* HS_HOST_PORT_SUSPEND_RESUME */
  34711. + dev_warn(&dev->dev, "HS_HOST_PORT_SUSPEND_RESUME\n");
  34712. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34713. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34714. + USB_PORT_FEAT_TEST, 0x600, NULL, 0, 40 * HZ);
  34715. + break;
  34716. +
  34717. + case 0x0107: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  34718. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup\n");
  34719. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34720. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34721. + USB_PORT_FEAT_TEST, 0x700, NULL, 0, 40 * HZ);
  34722. + break;
  34723. +
  34724. + case 0x0108: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  34725. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute\n");
  34726. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34727. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34728. + USB_PORT_FEAT_TEST, 0x800, NULL, 0, 40 * HZ);
  34729. + }
  34730. + }
  34731. + }
  34732. +#endif /* DWC_HS_ELECT_TST */
  34733. /* Now that the interfaces are installed, re-enable LPM. */
  34734. usb_unlocked_enable_lpm(dev);
  34735. diff -Nur linux-3.12.11.orig/drivers/usb/core/otg_whitelist.h linux-3.12.11/drivers/usb/core/otg_whitelist.h
  34736. --- linux-3.12.11.orig/drivers/usb/core/otg_whitelist.h 2014-02-13 22:51:06.000000000 +0100
  34737. +++ linux-3.12.11/drivers/usb/core/otg_whitelist.h 2014-02-18 11:52:14.000000000 +0100
  34738. @@ -19,33 +19,82 @@
  34739. static struct usb_device_id whitelist_table [] = {
  34740. /* hubs are optional in OTG, but very handy ... */
  34741. +#define CERT_WITHOUT_HUBS
  34742. +#if defined(CERT_WITHOUT_HUBS)
  34743. +{ USB_DEVICE( 0x0000, 0x0000 ), }, /* Root HUB Only*/
  34744. +#else
  34745. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 0), },
  34746. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 1), },
  34747. +{ USB_DEVICE_INFO(USB_CLASS_HUB, 0, 2), },
  34748. +#endif
  34749. #ifdef CONFIG_USB_PRINTER /* ignoring nonstatic linkage! */
  34750. /* FIXME actually, printers are NOT supposed to use device classes;
  34751. * they're supposed to use interface classes...
  34752. */
  34753. -{ USB_DEVICE_INFO(7, 1, 1) },
  34754. -{ USB_DEVICE_INFO(7, 1, 2) },
  34755. -{ USB_DEVICE_INFO(7, 1, 3) },
  34756. +//{ USB_DEVICE_INFO(7, 1, 1) },
  34757. +//{ USB_DEVICE_INFO(7, 1, 2) },
  34758. +//{ USB_DEVICE_INFO(7, 1, 3) },
  34759. #endif
  34760. #ifdef CONFIG_USB_NET_CDCETHER
  34761. /* Linux-USB CDC Ethernet gadget */
  34762. -{ USB_DEVICE(0x0525, 0xa4a1), },
  34763. +//{ USB_DEVICE(0x0525, 0xa4a1), },
  34764. /* Linux-USB CDC Ethernet + RNDIS gadget */
  34765. -{ USB_DEVICE(0x0525, 0xa4a2), },
  34766. +//{ USB_DEVICE(0x0525, 0xa4a2), },
  34767. #endif
  34768. #if defined(CONFIG_USB_TEST) || defined(CONFIG_USB_TEST_MODULE)
  34769. /* gadget zero, for testing */
  34770. -{ USB_DEVICE(0x0525, 0xa4a0), },
  34771. +//{ USB_DEVICE(0x0525, 0xa4a0), },
  34772. #endif
  34773. +/* OPT Tester */
  34774. +{ USB_DEVICE( 0x1a0a, 0x0101 ), }, /* TEST_SE0_NAK */
  34775. +{ USB_DEVICE( 0x1a0a, 0x0102 ), }, /* Test_J */
  34776. +{ USB_DEVICE( 0x1a0a, 0x0103 ), }, /* Test_K */
  34777. +{ USB_DEVICE( 0x1a0a, 0x0104 ), }, /* Test_PACKET */
  34778. +{ USB_DEVICE( 0x1a0a, 0x0105 ), }, /* Test_FORCE_ENABLE */
  34779. +{ USB_DEVICE( 0x1a0a, 0x0106 ), }, /* HS_PORT_SUSPEND_RESUME */
  34780. +{ USB_DEVICE( 0x1a0a, 0x0107 ), }, /* SINGLE_STEP_GET_DESCRIPTOR setup */
  34781. +{ USB_DEVICE( 0x1a0a, 0x0108 ), }, /* SINGLE_STEP_GET_DESCRIPTOR execute */
  34782. +
  34783. +/* Sony cameras */
  34784. +{ USB_DEVICE_VER(0x054c,0x0010,0x0410, 0x0500), },
  34785. +
  34786. +/* Memory Devices */
  34787. +//{ USB_DEVICE( 0x0781, 0x5150 ), }, /* SanDisk */
  34788. +//{ USB_DEVICE( 0x05DC, 0x0080 ), }, /* Lexar */
  34789. +//{ USB_DEVICE( 0x4146, 0x9281 ), }, /* IOMEGA */
  34790. +//{ USB_DEVICE( 0x067b, 0x2507 ), }, /* Hammer 20GB External HD */
  34791. +{ USB_DEVICE( 0x0EA0, 0x2168 ), }, /* Ours Technology Inc. (BUFFALO ClipDrive)*/
  34792. +//{ USB_DEVICE( 0x0457, 0x0150 ), }, /* Silicon Integrated Systems Corp. */
  34793. +
  34794. +/* HP Printers */
  34795. +//{ USB_DEVICE( 0x03F0, 0x1102 ), }, /* HP Photosmart 245 */
  34796. +//{ USB_DEVICE( 0x03F0, 0x1302 ), }, /* HP Photosmart 370 Series */
  34797. +
  34798. +/* Speakers */
  34799. +//{ USB_DEVICE( 0x0499, 0x3002 ), }, /* YAMAHA YST-MS35D USB Speakers */
  34800. +//{ USB_DEVICE( 0x0672, 0x1041 ), }, /* Labtec USB Headset */
  34801. +
  34802. { } /* Terminating entry */
  34803. };
  34804. +static inline void report_errors(struct usb_device *dev)
  34805. +{
  34806. + /* OTG MESSAGE: report errors here, customize to match your product */
  34807. + dev_info(&dev->dev, "device Vendor:%04x Product:%04x is not supported\n",
  34808. + le16_to_cpu(dev->descriptor.idVendor),
  34809. + le16_to_cpu(dev->descriptor.idProduct));
  34810. + if (USB_CLASS_HUB == dev->descriptor.bDeviceClass){
  34811. + dev_printk(KERN_CRIT, &dev->dev, "Unsupported Hub Topology\n");
  34812. + } else {
  34813. + dev_printk(KERN_CRIT, &dev->dev, "Attached Device is not Supported\n");
  34814. + }
  34815. +}
  34816. +
  34817. +
  34818. static int is_targeted(struct usb_device *dev)
  34819. {
  34820. struct usb_device_id *id = whitelist_table;
  34821. @@ -55,58 +104,83 @@
  34822. return 1;
  34823. /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */
  34824. - if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a &&
  34825. - le16_to_cpu(dev->descriptor.idProduct) == 0xbadd))
  34826. - return 0;
  34827. + if (dev->descriptor.idVendor == 0x1a0a &&
  34828. + dev->descriptor.idProduct == 0xbadd) {
  34829. + return 0;
  34830. + } else if (!enable_whitelist) {
  34831. + return 1;
  34832. + } else {
  34833. - /* NOTE: can't use usb_match_id() since interface caches
  34834. - * aren't set up yet. this is cut/paste from that code.
  34835. - */
  34836. - for (id = whitelist_table; id->match_flags; id++) {
  34837. - if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  34838. - id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  34839. - continue;
  34840. -
  34841. - if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  34842. - id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  34843. - continue;
  34844. -
  34845. - /* No need to test id->bcdDevice_lo != 0, since 0 is never
  34846. - greater than any unsigned number. */
  34847. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  34848. - (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  34849. - continue;
  34850. -
  34851. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  34852. - (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  34853. - continue;
  34854. -
  34855. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  34856. - (id->bDeviceClass != dev->descriptor.bDeviceClass))
  34857. - continue;
  34858. -
  34859. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  34860. - (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  34861. - continue;
  34862. -
  34863. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  34864. - (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  34865. - continue;
  34866. +#ifdef DEBUG
  34867. + dev_dbg(&dev->dev, "device V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  34868. + dev->descriptor.idVendor,
  34869. + dev->descriptor.idProduct,
  34870. + dev->descriptor.bDeviceClass,
  34871. + dev->descriptor.bDeviceSubClass,
  34872. + dev->descriptor.bDeviceProtocol);
  34873. +#endif
  34874. return 1;
  34875. + /* NOTE: can't use usb_match_id() since interface caches
  34876. + * aren't set up yet. this is cut/paste from that code.
  34877. + */
  34878. + for (id = whitelist_table; id->match_flags; id++) {
  34879. +#ifdef DEBUG
  34880. + dev_dbg(&dev->dev,
  34881. + "ID: V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  34882. + id->idVendor,
  34883. + id->idProduct,
  34884. + id->bDeviceClass,
  34885. + id->bDeviceSubClass,
  34886. + id->bDeviceProtocol);
  34887. +#endif
  34888. +
  34889. + if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  34890. + id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  34891. + continue;
  34892. +
  34893. + if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  34894. + id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  34895. + continue;
  34896. +
  34897. + /* No need to test id->bcdDevice_lo != 0, since 0 is never
  34898. + greater than any unsigned number. */
  34899. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  34900. + (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  34901. + continue;
  34902. +
  34903. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  34904. + (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  34905. + continue;
  34906. +
  34907. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  34908. + (id->bDeviceClass != dev->descriptor.bDeviceClass))
  34909. + continue;
  34910. +
  34911. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  34912. + (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  34913. + continue;
  34914. +
  34915. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  34916. + (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  34917. + continue;
  34918. +
  34919. + return 1;
  34920. + }
  34921. }
  34922. /* add other match criteria here ... */
  34923. -
  34924. - /* OTG MESSAGE: report errors here, customize to match your product */
  34925. - dev_err(&dev->dev, "device v%04x p%04x is not supported\n",
  34926. - le16_to_cpu(dev->descriptor.idVendor),
  34927. - le16_to_cpu(dev->descriptor.idProduct));
  34928. #ifdef CONFIG_USB_OTG_WHITELIST
  34929. + report_errors(dev);
  34930. return 0;
  34931. #else
  34932. - return 1;
  34933. + if (enable_whitelist) {
  34934. + report_errors(dev);
  34935. + return 0;
  34936. + } else {
  34937. + return 1;
  34938. + }
  34939. #endif
  34940. }
  34941. diff -Nur linux-3.12.11.orig/drivers/usb/gadget/file_storage.c linux-3.12.11/drivers/usb/gadget/file_storage.c
  34942. --- linux-3.12.11.orig/drivers/usb/gadget/file_storage.c 1970-01-01 01:00:00.000000000 +0100
  34943. +++ linux-3.12.11/drivers/usb/gadget/file_storage.c 2014-02-18 11:52:14.000000000 +0100
  34944. @@ -0,0 +1,3676 @@
  34945. +/*
  34946. + * file_storage.c -- File-backed USB Storage Gadget, for USB development
  34947. + *
  34948. + * Copyright (C) 2003-2008 Alan Stern
  34949. + * All rights reserved.
  34950. + *
  34951. + * Redistribution and use in source and binary forms, with or without
  34952. + * modification, are permitted provided that the following conditions
  34953. + * are met:
  34954. + * 1. Redistributions of source code must retain the above copyright
  34955. + * notice, this list of conditions, and the following disclaimer,
  34956. + * without modification.
  34957. + * 2. Redistributions in binary form must reproduce the above copyright
  34958. + * notice, this list of conditions and the following disclaimer in the
  34959. + * documentation and/or other materials provided with the distribution.
  34960. + * 3. The names of the above-listed copyright holders may not be used
  34961. + * to endorse or promote products derived from this software without
  34962. + * specific prior written permission.
  34963. + *
  34964. + * ALTERNATIVELY, this software may be distributed under the terms of the
  34965. + * GNU General Public License ("GPL") as published by the Free Software
  34966. + * Foundation, either version 2 of that License or (at your option) any
  34967. + * later version.
  34968. + *
  34969. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  34970. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  34971. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34972. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34973. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  34974. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34975. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34976. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34977. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34978. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34979. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34980. + */
  34981. +
  34982. +
  34983. +/*
  34984. + * The File-backed Storage Gadget acts as a USB Mass Storage device,
  34985. + * appearing to the host as a disk drive or as a CD-ROM drive. In addition
  34986. + * to providing an example of a genuinely useful gadget driver for a USB
  34987. + * device, it also illustrates a technique of double-buffering for increased
  34988. + * throughput. Last but not least, it gives an easy way to probe the
  34989. + * behavior of the Mass Storage drivers in a USB host.
  34990. + *
  34991. + * Backing storage is provided by a regular file or a block device, specified
  34992. + * by the "file" module parameter. Access can be limited to read-only by
  34993. + * setting the optional "ro" module parameter. (For CD-ROM emulation,
  34994. + * access is always read-only.) The gadget will indicate that it has
  34995. + * removable media if the optional "removable" module parameter is set.
  34996. + *
  34997. + * The gadget supports the Control-Bulk (CB), Control-Bulk-Interrupt (CBI),
  34998. + * and Bulk-Only (also known as Bulk-Bulk-Bulk or BBB) transports, selected
  34999. + * by the optional "transport" module parameter. It also supports the
  35000. + * following protocols: RBC (0x01), ATAPI or SFF-8020i (0x02), QIC-157 (0c03),
  35001. + * UFI (0x04), SFF-8070i (0x05), and transparent SCSI (0x06), selected by
  35002. + * the optional "protocol" module parameter. In addition, the default
  35003. + * Vendor ID, Product ID, release number and serial number can be overridden.
  35004. + *
  35005. + * There is support for multiple logical units (LUNs), each of which has
  35006. + * its own backing file. The number of LUNs can be set using the optional
  35007. + * "luns" module parameter (anywhere from 1 to 8), and the corresponding
  35008. + * files are specified using comma-separated lists for "file" and "ro".
  35009. + * The default number of LUNs is taken from the number of "file" elements;
  35010. + * it is 1 if "file" is not given. If "removable" is not set then a backing
  35011. + * file must be specified for each LUN. If it is set, then an unspecified
  35012. + * or empty backing filename means the LUN's medium is not loaded. Ideally
  35013. + * each LUN would be settable independently as a disk drive or a CD-ROM
  35014. + * drive, but currently all LUNs have to be the same type. The CD-ROM
  35015. + * emulation includes a single data track and no audio tracks; hence there
  35016. + * need be only one backing file per LUN.
  35017. + *
  35018. + * Requirements are modest; only a bulk-in and a bulk-out endpoint are
  35019. + * needed (an interrupt-out endpoint is also needed for CBI). The memory
  35020. + * requirement amounts to two 16K buffers, size configurable by a parameter.
  35021. + * Support is included for both full-speed and high-speed operation.
  35022. + *
  35023. + * Note that the driver is slightly non-portable in that it assumes a
  35024. + * single memory/DMA buffer will be useable for bulk-in, bulk-out, and
  35025. + * interrupt-in endpoints. With most device controllers this isn't an
  35026. + * issue, but there may be some with hardware restrictions that prevent
  35027. + * a buffer from being used by more than one endpoint.
  35028. + *
  35029. + * Module options:
  35030. + *
  35031. + * file=filename[,filename...]
  35032. + * Required if "removable" is not set, names of
  35033. + * the files or block devices used for
  35034. + * backing storage
  35035. + * serial=HHHH... Required serial number (string of hex chars)
  35036. + * ro=b[,b...] Default false, booleans for read-only access
  35037. + * removable Default false, boolean for removable media
  35038. + * luns=N Default N = number of filenames, number of
  35039. + * LUNs to support
  35040. + * nofua=b[,b...] Default false, booleans for ignore FUA flag
  35041. + * in SCSI WRITE(10,12) commands
  35042. + * stall Default determined according to the type of
  35043. + * USB device controller (usually true),
  35044. + * boolean to permit the driver to halt
  35045. + * bulk endpoints
  35046. + * cdrom Default false, boolean for whether to emulate
  35047. + * a CD-ROM drive
  35048. + * transport=XXX Default BBB, transport name (CB, CBI, or BBB)
  35049. + * protocol=YYY Default SCSI, protocol name (RBC, 8020 or
  35050. + * ATAPI, QIC, UFI, 8070, or SCSI;
  35051. + * also 1 - 6)
  35052. + * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID
  35053. + * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID
  35054. + * release=0xRRRR Override the USB release number (bcdDevice)
  35055. + * buflen=N Default N=16384, buffer size used (will be
  35056. + * rounded down to a multiple of
  35057. + * PAGE_CACHE_SIZE)
  35058. + *
  35059. + * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "serial", "ro",
  35060. + * "removable", "luns", "nofua", "stall", and "cdrom" options are available;
  35061. + * default values are used for everything else.
  35062. + *
  35063. + * The pathnames of the backing files and the ro settings are available in
  35064. + * the attribute files "file", "nofua", and "ro" in the lun<n> subdirectory of
  35065. + * the gadget's sysfs directory. If the "removable" option is set, writing to
  35066. + * these files will simulate ejecting/loading the medium (writing an empty
  35067. + * line means eject) and adjusting a write-enable tab. Changes to the ro
  35068. + * setting are not allowed when the medium is loaded or if CD-ROM emulation
  35069. + * is being used.
  35070. + *
  35071. + * This gadget driver is heavily based on "Gadget Zero" by David Brownell.
  35072. + * The driver's SCSI command interface was based on the "Information
  35073. + * technology - Small Computer System Interface - 2" document from
  35074. + * X3T9.2 Project 375D, Revision 10L, 7-SEP-93, available at
  35075. + * <http://www.t10.org/ftp/t10/drafts/s2/s2-r10l.pdf>. The single exception
  35076. + * is opcode 0x23 (READ FORMAT CAPACITIES), which was based on the
  35077. + * "Universal Serial Bus Mass Storage Class UFI Command Specification"
  35078. + * document, Revision 1.0, December 14, 1998, available at
  35079. + * <http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf>.
  35080. + */
  35081. +
  35082. +
  35083. +/*
  35084. + * Driver Design
  35085. + *
  35086. + * The FSG driver is fairly straightforward. There is a main kernel
  35087. + * thread that handles most of the work. Interrupt routines field
  35088. + * callbacks from the controller driver: bulk- and interrupt-request
  35089. + * completion notifications, endpoint-0 events, and disconnect events.
  35090. + * Completion events are passed to the main thread by wakeup calls. Many
  35091. + * ep0 requests are handled at interrupt time, but SetInterface,
  35092. + * SetConfiguration, and device reset requests are forwarded to the
  35093. + * thread in the form of "exceptions" using SIGUSR1 signals (since they
  35094. + * should interrupt any ongoing file I/O operations).
  35095. + *
  35096. + * The thread's main routine implements the standard command/data/status
  35097. + * parts of a SCSI interaction. It and its subroutines are full of tests
  35098. + * for pending signals/exceptions -- all this polling is necessary since
  35099. + * the kernel has no setjmp/longjmp equivalents. (Maybe this is an
  35100. + * indication that the driver really wants to be running in userspace.)
  35101. + * An important point is that so long as the thread is alive it keeps an
  35102. + * open reference to the backing file. This will prevent unmounting
  35103. + * the backing file's underlying filesystem and could cause problems
  35104. + * during system shutdown, for example. To prevent such problems, the
  35105. + * thread catches INT, TERM, and KILL signals and converts them into
  35106. + * an EXIT exception.
  35107. + *
  35108. + * In normal operation the main thread is started during the gadget's
  35109. + * fsg_bind() callback and stopped during fsg_unbind(). But it can also
  35110. + * exit when it receives a signal, and there's no point leaving the
  35111. + * gadget running when the thread is dead. So just before the thread
  35112. + * exits, it deregisters the gadget driver. This makes things a little
  35113. + * tricky: The driver is deregistered at two places, and the exiting
  35114. + * thread can indirectly call fsg_unbind() which in turn can tell the
  35115. + * thread to exit. The first problem is resolved through the use of the
  35116. + * REGISTERED atomic bitflag; the driver will only be deregistered once.
  35117. + * The second problem is resolved by having fsg_unbind() check
  35118. + * fsg->state; it won't try to stop the thread if the state is already
  35119. + * FSG_STATE_TERMINATED.
  35120. + *
  35121. + * To provide maximum throughput, the driver uses a circular pipeline of
  35122. + * buffer heads (struct fsg_buffhd). In principle the pipeline can be
  35123. + * arbitrarily long; in practice the benefits don't justify having more
  35124. + * than 2 stages (i.e., double buffering). But it helps to think of the
  35125. + * pipeline as being a long one. Each buffer head contains a bulk-in and
  35126. + * a bulk-out request pointer (since the buffer can be used for both
  35127. + * output and input -- directions always are given from the host's
  35128. + * point of view) as well as a pointer to the buffer and various state
  35129. + * variables.
  35130. + *
  35131. + * Use of the pipeline follows a simple protocol. There is a variable
  35132. + * (fsg->next_buffhd_to_fill) that points to the next buffer head to use.
  35133. + * At any time that buffer head may still be in use from an earlier
  35134. + * request, so each buffer head has a state variable indicating whether
  35135. + * it is EMPTY, FULL, or BUSY. Typical use involves waiting for the
  35136. + * buffer head to be EMPTY, filling the buffer either by file I/O or by
  35137. + * USB I/O (during which the buffer head is BUSY), and marking the buffer
  35138. + * head FULL when the I/O is complete. Then the buffer will be emptied
  35139. + * (again possibly by USB I/O, during which it is marked BUSY) and
  35140. + * finally marked EMPTY again (possibly by a completion routine).
  35141. + *
  35142. + * A module parameter tells the driver to avoid stalling the bulk
  35143. + * endpoints wherever the transport specification allows. This is
  35144. + * necessary for some UDCs like the SuperH, which cannot reliably clear a
  35145. + * halt on a bulk endpoint. However, under certain circumstances the
  35146. + * Bulk-only specification requires a stall. In such cases the driver
  35147. + * will halt the endpoint and set a flag indicating that it should clear
  35148. + * the halt in software during the next device reset. Hopefully this
  35149. + * will permit everything to work correctly. Furthermore, although the
  35150. + * specification allows the bulk-out endpoint to halt when the host sends
  35151. + * too much data, implementing this would cause an unavoidable race.
  35152. + * The driver will always use the "no-stall" approach for OUT transfers.
  35153. + *
  35154. + * One subtle point concerns sending status-stage responses for ep0
  35155. + * requests. Some of these requests, such as device reset, can involve
  35156. + * interrupting an ongoing file I/O operation, which might take an
  35157. + * arbitrarily long time. During that delay the host might give up on
  35158. + * the original ep0 request and issue a new one. When that happens the
  35159. + * driver should not notify the host about completion of the original
  35160. + * request, as the host will no longer be waiting for it. So the driver
  35161. + * assigns to each ep0 request a unique tag, and it keeps track of the
  35162. + * tag value of the request associated with a long-running exception
  35163. + * (device-reset, interface-change, or configuration-change). When the
  35164. + * exception handler is finished, the status-stage response is submitted
  35165. + * only if the current ep0 request tag is equal to the exception request
  35166. + * tag. Thus only the most recently received ep0 request will get a
  35167. + * status-stage response.
  35168. + *
  35169. + * Warning: This driver source file is too long. It ought to be split up
  35170. + * into a header file plus about 3 separate .c files, to handle the details
  35171. + * of the Gadget, USB Mass Storage, and SCSI protocols.
  35172. + */
  35173. +
  35174. +
  35175. +/* #define VERBOSE_DEBUG */
  35176. +/* #define DUMP_MSGS */
  35177. +
  35178. +
  35179. +#include <linux/blkdev.h>
  35180. +#include <linux/completion.h>
  35181. +#include <linux/dcache.h>
  35182. +#include <linux/delay.h>
  35183. +#include <linux/device.h>
  35184. +#include <linux/fcntl.h>
  35185. +#include <linux/file.h>
  35186. +#include <linux/fs.h>
  35187. +#include <linux/kref.h>
  35188. +#include <linux/kthread.h>
  35189. +#include <linux/limits.h>
  35190. +#include <linux/module.h>
  35191. +#include <linux/rwsem.h>
  35192. +#include <linux/slab.h>
  35193. +#include <linux/spinlock.h>
  35194. +#include <linux/string.h>
  35195. +#include <linux/freezer.h>
  35196. +#include <linux/utsname.h>
  35197. +
  35198. +#include <linux/usb/ch9.h>
  35199. +#include <linux/usb/gadget.h>
  35200. +
  35201. +#include "gadget_chips.h"
  35202. +
  35203. +
  35204. +
  35205. +/*
  35206. + * Kbuild is not very cooperative with respect to linking separately
  35207. + * compiled library objects into one module. So for now we won't use
  35208. + * separate compilation ... ensuring init/exit sections work to shrink
  35209. + * the runtime footprint, and giving us at least some parts of what
  35210. + * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  35211. + */
  35212. +#include "usbstring.c"
  35213. +#include "config.c"
  35214. +#include "epautoconf.c"
  35215. +
  35216. +/*-------------------------------------------------------------------------*/
  35217. +
  35218. +#define DRIVER_DESC "File-backed Storage Gadget"
  35219. +#define DRIVER_NAME "g_file_storage"
  35220. +#define DRIVER_VERSION "1 September 2010"
  35221. +
  35222. +static char fsg_string_manufacturer[64];
  35223. +static const char fsg_string_product[] = DRIVER_DESC;
  35224. +static const char fsg_string_config[] = "Self-powered";
  35225. +static const char fsg_string_interface[] = "Mass Storage";
  35226. +
  35227. +
  35228. +#include "storage_common.c"
  35229. +
  35230. +
  35231. +MODULE_DESCRIPTION(DRIVER_DESC);
  35232. +MODULE_AUTHOR("Alan Stern");
  35233. +MODULE_LICENSE("Dual BSD/GPL");
  35234. +
  35235. +/*
  35236. + * This driver assumes self-powered hardware and has no way for users to
  35237. + * trigger remote wakeup. It uses autoconfiguration to select endpoints
  35238. + * and endpoint addresses.
  35239. + */
  35240. +
  35241. +
  35242. +/*-------------------------------------------------------------------------*/
  35243. +
  35244. +
  35245. +/* Encapsulate the module parameter settings */
  35246. +
  35247. +static struct {
  35248. + char *file[FSG_MAX_LUNS];
  35249. + char *serial;
  35250. + bool ro[FSG_MAX_LUNS];
  35251. + bool nofua[FSG_MAX_LUNS];
  35252. + unsigned int num_filenames;
  35253. + unsigned int num_ros;
  35254. + unsigned int num_nofuas;
  35255. + unsigned int nluns;
  35256. +
  35257. + bool removable;
  35258. + bool can_stall;
  35259. + bool cdrom;
  35260. +
  35261. + char *transport_parm;
  35262. + char *protocol_parm;
  35263. + unsigned short vendor;
  35264. + unsigned short product;
  35265. + unsigned short release;
  35266. + unsigned int buflen;
  35267. +
  35268. + int transport_type;
  35269. + char *transport_name;
  35270. + int protocol_type;
  35271. + char *protocol_name;
  35272. +
  35273. +} mod_data = { // Default values
  35274. + .transport_parm = "BBB",
  35275. + .protocol_parm = "SCSI",
  35276. + .removable = 0,
  35277. + .can_stall = 1,
  35278. + .cdrom = 0,
  35279. + .vendor = FSG_VENDOR_ID,
  35280. + .product = FSG_PRODUCT_ID,
  35281. + .release = 0xffff, // Use controller chip type
  35282. + .buflen = 16384,
  35283. + };
  35284. +
  35285. +
  35286. +module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames,
  35287. + S_IRUGO);
  35288. +MODULE_PARM_DESC(file, "names of backing files or devices");
  35289. +
  35290. +module_param_named(serial, mod_data.serial, charp, S_IRUGO);
  35291. +MODULE_PARM_DESC(serial, "USB serial number");
  35292. +
  35293. +module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO);
  35294. +MODULE_PARM_DESC(ro, "true to force read-only");
  35295. +
  35296. +module_param_array_named(nofua, mod_data.nofua, bool, &mod_data.num_nofuas,
  35297. + S_IRUGO);
  35298. +MODULE_PARM_DESC(nofua, "true to ignore SCSI WRITE(10,12) FUA bit");
  35299. +
  35300. +module_param_named(luns, mod_data.nluns, uint, S_IRUGO);
  35301. +MODULE_PARM_DESC(luns, "number of LUNs");
  35302. +
  35303. +module_param_named(removable, mod_data.removable, bool, S_IRUGO);
  35304. +MODULE_PARM_DESC(removable, "true to simulate removable media");
  35305. +
  35306. +module_param_named(stall, mod_data.can_stall, bool, S_IRUGO);
  35307. +MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
  35308. +
  35309. +module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO);
  35310. +MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk");
  35311. +
  35312. +/* In the non-TEST version, only the module parameters listed above
  35313. + * are available. */
  35314. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  35315. +
  35316. +module_param_named(transport, mod_data.transport_parm, charp, S_IRUGO);
  35317. +MODULE_PARM_DESC(transport, "type of transport (BBB, CBI, or CB)");
  35318. +
  35319. +module_param_named(protocol, mod_data.protocol_parm, charp, S_IRUGO);
  35320. +MODULE_PARM_DESC(protocol, "type of protocol (RBC, 8020, QIC, UFI, "
  35321. + "8070, or SCSI)");
  35322. +
  35323. +module_param_named(vendor, mod_data.vendor, ushort, S_IRUGO);
  35324. +MODULE_PARM_DESC(vendor, "USB Vendor ID");
  35325. +
  35326. +module_param_named(product, mod_data.product, ushort, S_IRUGO);
  35327. +MODULE_PARM_DESC(product, "USB Product ID");
  35328. +
  35329. +module_param_named(release, mod_data.release, ushort, S_IRUGO);
  35330. +MODULE_PARM_DESC(release, "USB release number");
  35331. +
  35332. +module_param_named(buflen, mod_data.buflen, uint, S_IRUGO);
  35333. +MODULE_PARM_DESC(buflen, "I/O buffer size");
  35334. +
  35335. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  35336. +
  35337. +
  35338. +/*
  35339. + * These definitions will permit the compiler to avoid generating code for
  35340. + * parts of the driver that aren't used in the non-TEST version. Even gcc
  35341. + * can recognize when a test of a constant expression yields a dead code
  35342. + * path.
  35343. + */
  35344. +
  35345. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  35346. +
  35347. +#define transport_is_bbb() (mod_data.transport_type == USB_PR_BULK)
  35348. +#define transport_is_cbi() (mod_data.transport_type == USB_PR_CBI)
  35349. +#define protocol_is_scsi() (mod_data.protocol_type == USB_SC_SCSI)
  35350. +
  35351. +#else
  35352. +
  35353. +#define transport_is_bbb() 1
  35354. +#define transport_is_cbi() 0
  35355. +#define protocol_is_scsi() 1
  35356. +
  35357. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  35358. +
  35359. +
  35360. +/*-------------------------------------------------------------------------*/
  35361. +
  35362. +
  35363. +struct fsg_dev {
  35364. + /* lock protects: state, all the req_busy's, and cbbuf_cmnd */
  35365. + spinlock_t lock;
  35366. + struct usb_gadget *gadget;
  35367. +
  35368. + /* filesem protects: backing files in use */
  35369. + struct rw_semaphore filesem;
  35370. +
  35371. + /* reference counting: wait until all LUNs are released */
  35372. + struct kref ref;
  35373. +
  35374. + struct usb_ep *ep0; // Handy copy of gadget->ep0
  35375. + struct usb_request *ep0req; // For control responses
  35376. + unsigned int ep0_req_tag;
  35377. + const char *ep0req_name;
  35378. +
  35379. + struct usb_request *intreq; // For interrupt responses
  35380. + int intreq_busy;
  35381. + struct fsg_buffhd *intr_buffhd;
  35382. +
  35383. + unsigned int bulk_out_maxpacket;
  35384. + enum fsg_state state; // For exception handling
  35385. + unsigned int exception_req_tag;
  35386. +
  35387. + u8 config, new_config;
  35388. +
  35389. + unsigned int running : 1;
  35390. + unsigned int bulk_in_enabled : 1;
  35391. + unsigned int bulk_out_enabled : 1;
  35392. + unsigned int intr_in_enabled : 1;
  35393. + unsigned int phase_error : 1;
  35394. + unsigned int short_packet_received : 1;
  35395. + unsigned int bad_lun_okay : 1;
  35396. +
  35397. + unsigned long atomic_bitflags;
  35398. +#define REGISTERED 0
  35399. +#define IGNORE_BULK_OUT 1
  35400. +#define SUSPENDED 2
  35401. +
  35402. + struct usb_ep *bulk_in;
  35403. + struct usb_ep *bulk_out;
  35404. + struct usb_ep *intr_in;
  35405. +
  35406. + struct fsg_buffhd *next_buffhd_to_fill;
  35407. + struct fsg_buffhd *next_buffhd_to_drain;
  35408. +
  35409. + int thread_wakeup_needed;
  35410. + struct completion thread_notifier;
  35411. + struct task_struct *thread_task;
  35412. +
  35413. + int cmnd_size;
  35414. + u8 cmnd[MAX_COMMAND_SIZE];
  35415. + enum data_direction data_dir;
  35416. + u32 data_size;
  35417. + u32 data_size_from_cmnd;
  35418. + u32 tag;
  35419. + unsigned int lun;
  35420. + u32 residue;
  35421. + u32 usb_amount_left;
  35422. +
  35423. + /* The CB protocol offers no way for a host to know when a command
  35424. + * has completed. As a result the next command may arrive early,
  35425. + * and we will still have to handle it. For that reason we need
  35426. + * a buffer to store new commands when using CB (or CBI, which
  35427. + * does not oblige a host to wait for command completion either). */
  35428. + int cbbuf_cmnd_size;
  35429. + u8 cbbuf_cmnd[MAX_COMMAND_SIZE];
  35430. +
  35431. + unsigned int nluns;
  35432. + struct fsg_lun *luns;
  35433. + struct fsg_lun *curlun;
  35434. + /* Must be the last entry */
  35435. + struct fsg_buffhd buffhds[];
  35436. +};
  35437. +
  35438. +typedef void (*fsg_routine_t)(struct fsg_dev *);
  35439. +
  35440. +static int exception_in_progress(struct fsg_dev *fsg)
  35441. +{
  35442. + return (fsg->state > FSG_STATE_IDLE);
  35443. +}
  35444. +
  35445. +/* Make bulk-out requests be divisible by the maxpacket size */
  35446. +static void set_bulk_out_req_length(struct fsg_dev *fsg,
  35447. + struct fsg_buffhd *bh, unsigned int length)
  35448. +{
  35449. + unsigned int rem;
  35450. +
  35451. + bh->bulk_out_intended_length = length;
  35452. + rem = length % fsg->bulk_out_maxpacket;
  35453. + if (rem > 0)
  35454. + length += fsg->bulk_out_maxpacket - rem;
  35455. + bh->outreq->length = length;
  35456. +}
  35457. +
  35458. +static struct fsg_dev *the_fsg;
  35459. +static struct usb_gadget_driver fsg_driver;
  35460. +
  35461. +
  35462. +/*-------------------------------------------------------------------------*/
  35463. +
  35464. +static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
  35465. +{
  35466. + const char *name;
  35467. +
  35468. + if (ep == fsg->bulk_in)
  35469. + name = "bulk-in";
  35470. + else if (ep == fsg->bulk_out)
  35471. + name = "bulk-out";
  35472. + else
  35473. + name = ep->name;
  35474. + DBG(fsg, "%s set halt\n", name);
  35475. + return usb_ep_set_halt(ep);
  35476. +}
  35477. +
  35478. +
  35479. +/*-------------------------------------------------------------------------*/
  35480. +
  35481. +/*
  35482. + * DESCRIPTORS ... most are static, but strings and (full) configuration
  35483. + * descriptors are built on demand. Also the (static) config and interface
  35484. + * descriptors are adjusted during fsg_bind().
  35485. + */
  35486. +
  35487. +/* There is only one configuration. */
  35488. +#define CONFIG_VALUE 1
  35489. +
  35490. +static struct usb_device_descriptor
  35491. +device_desc = {
  35492. + .bLength = sizeof device_desc,
  35493. + .bDescriptorType = USB_DT_DEVICE,
  35494. +
  35495. + .bcdUSB = cpu_to_le16(0x0200),
  35496. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  35497. +
  35498. + /* The next three values can be overridden by module parameters */
  35499. + .idVendor = cpu_to_le16(FSG_VENDOR_ID),
  35500. + .idProduct = cpu_to_le16(FSG_PRODUCT_ID),
  35501. + .bcdDevice = cpu_to_le16(0xffff),
  35502. +
  35503. + .iManufacturer = FSG_STRING_MANUFACTURER,
  35504. + .iProduct = FSG_STRING_PRODUCT,
  35505. + .iSerialNumber = FSG_STRING_SERIAL,
  35506. + .bNumConfigurations = 1,
  35507. +};
  35508. +
  35509. +static struct usb_config_descriptor
  35510. +config_desc = {
  35511. + .bLength = sizeof config_desc,
  35512. + .bDescriptorType = USB_DT_CONFIG,
  35513. +
  35514. + /* wTotalLength computed by usb_gadget_config_buf() */
  35515. + .bNumInterfaces = 1,
  35516. + .bConfigurationValue = CONFIG_VALUE,
  35517. + .iConfiguration = FSG_STRING_CONFIG,
  35518. + .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
  35519. + .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2,
  35520. +};
  35521. +
  35522. +
  35523. +static struct usb_qualifier_descriptor
  35524. +dev_qualifier = {
  35525. + .bLength = sizeof dev_qualifier,
  35526. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  35527. +
  35528. + .bcdUSB = cpu_to_le16(0x0200),
  35529. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  35530. +
  35531. + .bNumConfigurations = 1,
  35532. +};
  35533. +
  35534. +static int populate_bos(struct fsg_dev *fsg, u8 *buf)
  35535. +{
  35536. + memcpy(buf, &fsg_bos_desc, USB_DT_BOS_SIZE);
  35537. + buf += USB_DT_BOS_SIZE;
  35538. +
  35539. + memcpy(buf, &fsg_ext_cap_desc, USB_DT_USB_EXT_CAP_SIZE);
  35540. + buf += USB_DT_USB_EXT_CAP_SIZE;
  35541. +
  35542. + memcpy(buf, &fsg_ss_cap_desc, USB_DT_USB_SS_CAP_SIZE);
  35543. +
  35544. + return USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE
  35545. + + USB_DT_USB_EXT_CAP_SIZE;
  35546. +}
  35547. +
  35548. +/*
  35549. + * Config descriptors must agree with the code that sets configurations
  35550. + * and with code managing interfaces and their altsettings. They must
  35551. + * also handle different speeds and other-speed requests.
  35552. + */
  35553. +static int populate_config_buf(struct usb_gadget *gadget,
  35554. + u8 *buf, u8 type, unsigned index)
  35555. +{
  35556. + enum usb_device_speed speed = gadget->speed;
  35557. + int len;
  35558. + const struct usb_descriptor_header **function;
  35559. +
  35560. + if (index > 0)
  35561. + return -EINVAL;
  35562. +
  35563. + if (gadget_is_dualspeed(gadget) && type == USB_DT_OTHER_SPEED_CONFIG)
  35564. + speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed;
  35565. + function = gadget_is_dualspeed(gadget) && speed == USB_SPEED_HIGH
  35566. + ? (const struct usb_descriptor_header **)fsg_hs_function
  35567. + : (const struct usb_descriptor_header **)fsg_fs_function;
  35568. +
  35569. + /* for now, don't advertise srp-only devices */
  35570. + if (!gadget_is_otg(gadget))
  35571. + function++;
  35572. +
  35573. + len = usb_gadget_config_buf(&config_desc, buf, EP0_BUFSIZE, function);
  35574. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  35575. + return len;
  35576. +}
  35577. +
  35578. +
  35579. +/*-------------------------------------------------------------------------*/
  35580. +
  35581. +/* These routines may be called in process context or in_irq */
  35582. +
  35583. +/* Caller must hold fsg->lock */
  35584. +static void wakeup_thread(struct fsg_dev *fsg)
  35585. +{
  35586. + /* Tell the main thread that something has happened */
  35587. + fsg->thread_wakeup_needed = 1;
  35588. + if (fsg->thread_task)
  35589. + wake_up_process(fsg->thread_task);
  35590. +}
  35591. +
  35592. +
  35593. +static void raise_exception(struct fsg_dev *fsg, enum fsg_state new_state)
  35594. +{
  35595. + unsigned long flags;
  35596. +
  35597. + /* Do nothing if a higher-priority exception is already in progress.
  35598. + * If a lower-or-equal priority exception is in progress, preempt it
  35599. + * and notify the main thread by sending it a signal. */
  35600. + spin_lock_irqsave(&fsg->lock, flags);
  35601. + if (fsg->state <= new_state) {
  35602. + fsg->exception_req_tag = fsg->ep0_req_tag;
  35603. + fsg->state = new_state;
  35604. + if (fsg->thread_task)
  35605. + send_sig_info(SIGUSR1, SEND_SIG_FORCED,
  35606. + fsg->thread_task);
  35607. + }
  35608. + spin_unlock_irqrestore(&fsg->lock, flags);
  35609. +}
  35610. +
  35611. +
  35612. +/*-------------------------------------------------------------------------*/
  35613. +
  35614. +/* The disconnect callback and ep0 routines. These always run in_irq,
  35615. + * except that ep0_queue() is called in the main thread to acknowledge
  35616. + * completion of various requests: set config, set interface, and
  35617. + * Bulk-only device reset. */
  35618. +
  35619. +static void fsg_disconnect(struct usb_gadget *gadget)
  35620. +{
  35621. + struct fsg_dev *fsg = get_gadget_data(gadget);
  35622. +
  35623. + DBG(fsg, "disconnect or port reset\n");
  35624. + raise_exception(fsg, FSG_STATE_DISCONNECT);
  35625. +}
  35626. +
  35627. +
  35628. +static int ep0_queue(struct fsg_dev *fsg)
  35629. +{
  35630. + int rc;
  35631. +
  35632. + rc = usb_ep_queue(fsg->ep0, fsg->ep0req, GFP_ATOMIC);
  35633. + if (rc != 0 && rc != -ESHUTDOWN) {
  35634. +
  35635. + /* We can't do much more than wait for a reset */
  35636. + WARNING(fsg, "error in submission: %s --> %d\n",
  35637. + fsg->ep0->name, rc);
  35638. + }
  35639. + return rc;
  35640. +}
  35641. +
  35642. +static void ep0_complete(struct usb_ep *ep, struct usb_request *req)
  35643. +{
  35644. + struct fsg_dev *fsg = ep->driver_data;
  35645. +
  35646. + if (req->actual > 0)
  35647. + dump_msg(fsg, fsg->ep0req_name, req->buf, req->actual);
  35648. + if (req->status || req->actual != req->length)
  35649. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  35650. + req->status, req->actual, req->length);
  35651. + if (req->status == -ECONNRESET) // Request was cancelled
  35652. + usb_ep_fifo_flush(ep);
  35653. +
  35654. + if (req->status == 0 && req->context)
  35655. + ((fsg_routine_t) (req->context))(fsg);
  35656. +}
  35657. +
  35658. +
  35659. +/*-------------------------------------------------------------------------*/
  35660. +
  35661. +/* Bulk and interrupt endpoint completion handlers.
  35662. + * These always run in_irq. */
  35663. +
  35664. +static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
  35665. +{
  35666. + struct fsg_dev *fsg = ep->driver_data;
  35667. + struct fsg_buffhd *bh = req->context;
  35668. +
  35669. + if (req->status || req->actual != req->length)
  35670. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  35671. + req->status, req->actual, req->length);
  35672. + if (req->status == -ECONNRESET) // Request was cancelled
  35673. + usb_ep_fifo_flush(ep);
  35674. +
  35675. + /* Hold the lock while we update the request and buffer states */
  35676. + smp_wmb();
  35677. + spin_lock(&fsg->lock);
  35678. + bh->inreq_busy = 0;
  35679. + bh->state = BUF_STATE_EMPTY;
  35680. + wakeup_thread(fsg);
  35681. + spin_unlock(&fsg->lock);
  35682. +}
  35683. +
  35684. +static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
  35685. +{
  35686. + struct fsg_dev *fsg = ep->driver_data;
  35687. + struct fsg_buffhd *bh = req->context;
  35688. +
  35689. + dump_msg(fsg, "bulk-out", req->buf, req->actual);
  35690. + if (req->status || req->actual != bh->bulk_out_intended_length)
  35691. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  35692. + req->status, req->actual,
  35693. + bh->bulk_out_intended_length);
  35694. + if (req->status == -ECONNRESET) // Request was cancelled
  35695. + usb_ep_fifo_flush(ep);
  35696. +
  35697. + /* Hold the lock while we update the request and buffer states */
  35698. + smp_wmb();
  35699. + spin_lock(&fsg->lock);
  35700. + bh->outreq_busy = 0;
  35701. + bh->state = BUF_STATE_FULL;
  35702. + wakeup_thread(fsg);
  35703. + spin_unlock(&fsg->lock);
  35704. +}
  35705. +
  35706. +
  35707. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  35708. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  35709. +{
  35710. + struct fsg_dev *fsg = ep->driver_data;
  35711. + struct fsg_buffhd *bh = req->context;
  35712. +
  35713. + if (req->status || req->actual != req->length)
  35714. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  35715. + req->status, req->actual, req->length);
  35716. + if (req->status == -ECONNRESET) // Request was cancelled
  35717. + usb_ep_fifo_flush(ep);
  35718. +
  35719. + /* Hold the lock while we update the request and buffer states */
  35720. + smp_wmb();
  35721. + spin_lock(&fsg->lock);
  35722. + fsg->intreq_busy = 0;
  35723. + bh->state = BUF_STATE_EMPTY;
  35724. + wakeup_thread(fsg);
  35725. + spin_unlock(&fsg->lock);
  35726. +}
  35727. +
  35728. +#else
  35729. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  35730. +{}
  35731. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  35732. +
  35733. +
  35734. +/*-------------------------------------------------------------------------*/
  35735. +
  35736. +/* Ep0 class-specific handlers. These always run in_irq. */
  35737. +
  35738. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  35739. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  35740. +{
  35741. + struct usb_request *req = fsg->ep0req;
  35742. + static u8 cbi_reset_cmnd[6] = {
  35743. + SEND_DIAGNOSTIC, 4, 0xff, 0xff, 0xff, 0xff};
  35744. +
  35745. + /* Error in command transfer? */
  35746. + if (req->status || req->length != req->actual ||
  35747. + req->actual < 6 || req->actual > MAX_COMMAND_SIZE) {
  35748. +
  35749. + /* Not all controllers allow a protocol stall after
  35750. + * receiving control-out data, but we'll try anyway. */
  35751. + fsg_set_halt(fsg, fsg->ep0);
  35752. + return; // Wait for reset
  35753. + }
  35754. +
  35755. + /* Is it the special reset command? */
  35756. + if (req->actual >= sizeof cbi_reset_cmnd &&
  35757. + memcmp(req->buf, cbi_reset_cmnd,
  35758. + sizeof cbi_reset_cmnd) == 0) {
  35759. +
  35760. + /* Raise an exception to stop the current operation
  35761. + * and reinitialize our state. */
  35762. + DBG(fsg, "cbi reset request\n");
  35763. + raise_exception(fsg, FSG_STATE_RESET);
  35764. + return;
  35765. + }
  35766. +
  35767. + VDBG(fsg, "CB[I] accept device-specific command\n");
  35768. + spin_lock(&fsg->lock);
  35769. +
  35770. + /* Save the command for later */
  35771. + if (fsg->cbbuf_cmnd_size)
  35772. + WARNING(fsg, "CB[I] overwriting previous command\n");
  35773. + fsg->cbbuf_cmnd_size = req->actual;
  35774. + memcpy(fsg->cbbuf_cmnd, req->buf, fsg->cbbuf_cmnd_size);
  35775. +
  35776. + wakeup_thread(fsg);
  35777. + spin_unlock(&fsg->lock);
  35778. +}
  35779. +
  35780. +#else
  35781. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  35782. +{}
  35783. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  35784. +
  35785. +
  35786. +static int class_setup_req(struct fsg_dev *fsg,
  35787. + const struct usb_ctrlrequest *ctrl)
  35788. +{
  35789. + struct usb_request *req = fsg->ep0req;
  35790. + int value = -EOPNOTSUPP;
  35791. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  35792. + u16 w_value = le16_to_cpu(ctrl->wValue);
  35793. + u16 w_length = le16_to_cpu(ctrl->wLength);
  35794. +
  35795. + if (!fsg->config)
  35796. + return value;
  35797. +
  35798. + /* Handle Bulk-only class-specific requests */
  35799. + if (transport_is_bbb()) {
  35800. + switch (ctrl->bRequest) {
  35801. +
  35802. + case US_BULK_RESET_REQUEST:
  35803. + if (ctrl->bRequestType != (USB_DIR_OUT |
  35804. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  35805. + break;
  35806. + if (w_index != 0 || w_value != 0 || w_length != 0) {
  35807. + value = -EDOM;
  35808. + break;
  35809. + }
  35810. +
  35811. + /* Raise an exception to stop the current operation
  35812. + * and reinitialize our state. */
  35813. + DBG(fsg, "bulk reset request\n");
  35814. + raise_exception(fsg, FSG_STATE_RESET);
  35815. + value = DELAYED_STATUS;
  35816. + break;
  35817. +
  35818. + case US_BULK_GET_MAX_LUN:
  35819. + if (ctrl->bRequestType != (USB_DIR_IN |
  35820. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  35821. + break;
  35822. + if (w_index != 0 || w_value != 0 || w_length != 1) {
  35823. + value = -EDOM;
  35824. + break;
  35825. + }
  35826. + VDBG(fsg, "get max LUN\n");
  35827. + *(u8 *) req->buf = fsg->nluns - 1;
  35828. + value = 1;
  35829. + break;
  35830. + }
  35831. + }
  35832. +
  35833. + /* Handle CBI class-specific requests */
  35834. + else {
  35835. + switch (ctrl->bRequest) {
  35836. +
  35837. + case USB_CBI_ADSC_REQUEST:
  35838. + if (ctrl->bRequestType != (USB_DIR_OUT |
  35839. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  35840. + break;
  35841. + if (w_index != 0 || w_value != 0) {
  35842. + value = -EDOM;
  35843. + break;
  35844. + }
  35845. + if (w_length > MAX_COMMAND_SIZE) {
  35846. + value = -EOVERFLOW;
  35847. + break;
  35848. + }
  35849. + value = w_length;
  35850. + fsg->ep0req->context = received_cbi_adsc;
  35851. + break;
  35852. + }
  35853. + }
  35854. +
  35855. + if (value == -EOPNOTSUPP)
  35856. + VDBG(fsg,
  35857. + "unknown class-specific control req "
  35858. + "%02x.%02x v%04x i%04x l%u\n",
  35859. + ctrl->bRequestType, ctrl->bRequest,
  35860. + le16_to_cpu(ctrl->wValue), w_index, w_length);
  35861. + return value;
  35862. +}
  35863. +
  35864. +
  35865. +/*-------------------------------------------------------------------------*/
  35866. +
  35867. +/* Ep0 standard request handlers. These always run in_irq. */
  35868. +
  35869. +static int standard_setup_req(struct fsg_dev *fsg,
  35870. + const struct usb_ctrlrequest *ctrl)
  35871. +{
  35872. + struct usb_request *req = fsg->ep0req;
  35873. + int value = -EOPNOTSUPP;
  35874. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  35875. + u16 w_value = le16_to_cpu(ctrl->wValue);
  35876. +
  35877. + /* Usually this just stores reply data in the pre-allocated ep0 buffer,
  35878. + * but config change events will also reconfigure hardware. */
  35879. + switch (ctrl->bRequest) {
  35880. +
  35881. + case USB_REQ_GET_DESCRIPTOR:
  35882. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  35883. + USB_RECIP_DEVICE))
  35884. + break;
  35885. + switch (w_value >> 8) {
  35886. +
  35887. + case USB_DT_DEVICE:
  35888. + VDBG(fsg, "get device descriptor\n");
  35889. + device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket;
  35890. + value = sizeof device_desc;
  35891. + memcpy(req->buf, &device_desc, value);
  35892. + break;
  35893. + case USB_DT_DEVICE_QUALIFIER:
  35894. + VDBG(fsg, "get device qualifier\n");
  35895. + if (!gadget_is_dualspeed(fsg->gadget) ||
  35896. + fsg->gadget->speed == USB_SPEED_SUPER)
  35897. + break;
  35898. + /*
  35899. + * Assume ep0 uses the same maxpacket value for both
  35900. + * speeds
  35901. + */
  35902. + dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
  35903. + value = sizeof dev_qualifier;
  35904. + memcpy(req->buf, &dev_qualifier, value);
  35905. + break;
  35906. +
  35907. + case USB_DT_OTHER_SPEED_CONFIG:
  35908. + VDBG(fsg, "get other-speed config descriptor\n");
  35909. + if (!gadget_is_dualspeed(fsg->gadget) ||
  35910. + fsg->gadget->speed == USB_SPEED_SUPER)
  35911. + break;
  35912. + goto get_config;
  35913. + case USB_DT_CONFIG:
  35914. + VDBG(fsg, "get configuration descriptor\n");
  35915. +get_config:
  35916. + value = populate_config_buf(fsg->gadget,
  35917. + req->buf,
  35918. + w_value >> 8,
  35919. + w_value & 0xff);
  35920. + break;
  35921. +
  35922. + case USB_DT_STRING:
  35923. + VDBG(fsg, "get string descriptor\n");
  35924. +
  35925. + /* wIndex == language code */
  35926. + value = usb_gadget_get_string(&fsg_stringtab,
  35927. + w_value & 0xff, req->buf);
  35928. + break;
  35929. +
  35930. + case USB_DT_BOS:
  35931. + VDBG(fsg, "get bos descriptor\n");
  35932. +
  35933. + if (gadget_is_superspeed(fsg->gadget))
  35934. + value = populate_bos(fsg, req->buf);
  35935. + break;
  35936. + }
  35937. +
  35938. + break;
  35939. +
  35940. + /* One config, two speeds */
  35941. + case USB_REQ_SET_CONFIGURATION:
  35942. + if (ctrl->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD |
  35943. + USB_RECIP_DEVICE))
  35944. + break;
  35945. + VDBG(fsg, "set configuration\n");
  35946. + if (w_value == CONFIG_VALUE || w_value == 0) {
  35947. + fsg->new_config = w_value;
  35948. +
  35949. + /* Raise an exception to wipe out previous transaction
  35950. + * state (queued bufs, etc) and set the new config. */
  35951. + raise_exception(fsg, FSG_STATE_CONFIG_CHANGE);
  35952. + value = DELAYED_STATUS;
  35953. + }
  35954. + break;
  35955. + case USB_REQ_GET_CONFIGURATION:
  35956. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  35957. + USB_RECIP_DEVICE))
  35958. + break;
  35959. + VDBG(fsg, "get configuration\n");
  35960. + *(u8 *) req->buf = fsg->config;
  35961. + value = 1;
  35962. + break;
  35963. +
  35964. + case USB_REQ_SET_INTERFACE:
  35965. + if (ctrl->bRequestType != (USB_DIR_OUT| USB_TYPE_STANDARD |
  35966. + USB_RECIP_INTERFACE))
  35967. + break;
  35968. + if (fsg->config && w_index == 0) {
  35969. +
  35970. + /* Raise an exception to wipe out previous transaction
  35971. + * state (queued bufs, etc) and install the new
  35972. + * interface altsetting. */
  35973. + raise_exception(fsg, FSG_STATE_INTERFACE_CHANGE);
  35974. + value = DELAYED_STATUS;
  35975. + }
  35976. + break;
  35977. + case USB_REQ_GET_INTERFACE:
  35978. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  35979. + USB_RECIP_INTERFACE))
  35980. + break;
  35981. + if (!fsg->config)
  35982. + break;
  35983. + if (w_index != 0) {
  35984. + value = -EDOM;
  35985. + break;
  35986. + }
  35987. + VDBG(fsg, "get interface\n");
  35988. + *(u8 *) req->buf = 0;
  35989. + value = 1;
  35990. + break;
  35991. +
  35992. + default:
  35993. + VDBG(fsg,
  35994. + "unknown control req %02x.%02x v%04x i%04x l%u\n",
  35995. + ctrl->bRequestType, ctrl->bRequest,
  35996. + w_value, w_index, le16_to_cpu(ctrl->wLength));
  35997. + }
  35998. +
  35999. + return value;
  36000. +}
  36001. +
  36002. +
  36003. +static int fsg_setup(struct usb_gadget *gadget,
  36004. + const struct usb_ctrlrequest *ctrl)
  36005. +{
  36006. + struct fsg_dev *fsg = get_gadget_data(gadget);
  36007. + int rc;
  36008. + int w_length = le16_to_cpu(ctrl->wLength);
  36009. +
  36010. + ++fsg->ep0_req_tag; // Record arrival of a new request
  36011. + fsg->ep0req->context = NULL;
  36012. + fsg->ep0req->length = 0;
  36013. + dump_msg(fsg, "ep0-setup", (u8 *) ctrl, sizeof(*ctrl));
  36014. +
  36015. + if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_CLASS)
  36016. + rc = class_setup_req(fsg, ctrl);
  36017. + else
  36018. + rc = standard_setup_req(fsg, ctrl);
  36019. +
  36020. + /* Respond with data/status or defer until later? */
  36021. + if (rc >= 0 && rc != DELAYED_STATUS) {
  36022. + rc = min(rc, w_length);
  36023. + fsg->ep0req->length = rc;
  36024. + fsg->ep0req->zero = rc < w_length;
  36025. + fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ?
  36026. + "ep0-in" : "ep0-out");
  36027. + rc = ep0_queue(fsg);
  36028. + }
  36029. +
  36030. + /* Device either stalls (rc < 0) or reports success */
  36031. + return rc;
  36032. +}
  36033. +
  36034. +
  36035. +/*-------------------------------------------------------------------------*/
  36036. +
  36037. +/* All the following routines run in process context */
  36038. +
  36039. +
  36040. +/* Use this for bulk or interrupt transfers, not ep0 */
  36041. +static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
  36042. + struct usb_request *req, int *pbusy,
  36043. + enum fsg_buffer_state *state)
  36044. +{
  36045. + int rc;
  36046. +
  36047. + if (ep == fsg->bulk_in)
  36048. + dump_msg(fsg, "bulk-in", req->buf, req->length);
  36049. + else if (ep == fsg->intr_in)
  36050. + dump_msg(fsg, "intr-in", req->buf, req->length);
  36051. +
  36052. + spin_lock_irq(&fsg->lock);
  36053. + *pbusy = 1;
  36054. + *state = BUF_STATE_BUSY;
  36055. + spin_unlock_irq(&fsg->lock);
  36056. + rc = usb_ep_queue(ep, req, GFP_KERNEL);
  36057. + if (rc != 0) {
  36058. + *pbusy = 0;
  36059. + *state = BUF_STATE_EMPTY;
  36060. +
  36061. + /* We can't do much more than wait for a reset */
  36062. +
  36063. + /* Note: currently the net2280 driver fails zero-length
  36064. + * submissions if DMA is enabled. */
  36065. + if (rc != -ESHUTDOWN && !(rc == -EOPNOTSUPP &&
  36066. + req->length == 0))
  36067. + WARNING(fsg, "error in submission: %s --> %d\n",
  36068. + ep->name, rc);
  36069. + }
  36070. +}
  36071. +
  36072. +
  36073. +static int sleep_thread(struct fsg_dev *fsg)
  36074. +{
  36075. + int rc = 0;
  36076. +
  36077. + /* Wait until a signal arrives or we are woken up */
  36078. + for (;;) {
  36079. + try_to_freeze();
  36080. + set_current_state(TASK_INTERRUPTIBLE);
  36081. + if (signal_pending(current)) {
  36082. + rc = -EINTR;
  36083. + break;
  36084. + }
  36085. + if (fsg->thread_wakeup_needed)
  36086. + break;
  36087. + schedule();
  36088. + }
  36089. + __set_current_state(TASK_RUNNING);
  36090. + fsg->thread_wakeup_needed = 0;
  36091. + return rc;
  36092. +}
  36093. +
  36094. +
  36095. +/*-------------------------------------------------------------------------*/
  36096. +
  36097. +static int do_read(struct fsg_dev *fsg)
  36098. +{
  36099. + struct fsg_lun *curlun = fsg->curlun;
  36100. + u32 lba;
  36101. + struct fsg_buffhd *bh;
  36102. + int rc;
  36103. + u32 amount_left;
  36104. + loff_t file_offset, file_offset_tmp;
  36105. + unsigned int amount;
  36106. + ssize_t nread;
  36107. +
  36108. + /* Get the starting Logical Block Address and check that it's
  36109. + * not too big */
  36110. + if (fsg->cmnd[0] == READ_6)
  36111. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  36112. + else {
  36113. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  36114. +
  36115. + /* We allow DPO (Disable Page Out = don't save data in the
  36116. + * cache) and FUA (Force Unit Access = don't read from the
  36117. + * cache), but we don't implement them. */
  36118. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  36119. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36120. + return -EINVAL;
  36121. + }
  36122. + }
  36123. + if (lba >= curlun->num_sectors) {
  36124. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36125. + return -EINVAL;
  36126. + }
  36127. + file_offset = ((loff_t) lba) << curlun->blkbits;
  36128. +
  36129. + /* Carry out the file reads */
  36130. + amount_left = fsg->data_size_from_cmnd;
  36131. + if (unlikely(amount_left == 0))
  36132. + return -EIO; // No default reply
  36133. +
  36134. + for (;;) {
  36135. +
  36136. + /* Figure out how much we need to read:
  36137. + * Try to read the remaining amount.
  36138. + * But don't read more than the buffer size.
  36139. + * And don't try to read past the end of the file.
  36140. + */
  36141. + amount = min((unsigned int) amount_left, mod_data.buflen);
  36142. + amount = min((loff_t) amount,
  36143. + curlun->file_length - file_offset);
  36144. +
  36145. + /* Wait for the next buffer to become available */
  36146. + bh = fsg->next_buffhd_to_fill;
  36147. + while (bh->state != BUF_STATE_EMPTY) {
  36148. + rc = sleep_thread(fsg);
  36149. + if (rc)
  36150. + return rc;
  36151. + }
  36152. +
  36153. + /* If we were asked to read past the end of file,
  36154. + * end with an empty buffer. */
  36155. + if (amount == 0) {
  36156. + curlun->sense_data =
  36157. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36158. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36159. + curlun->info_valid = 1;
  36160. + bh->inreq->length = 0;
  36161. + bh->state = BUF_STATE_FULL;
  36162. + break;
  36163. + }
  36164. +
  36165. + /* Perform the read */
  36166. + file_offset_tmp = file_offset;
  36167. + nread = vfs_read(curlun->filp,
  36168. + (char __user *) bh->buf,
  36169. + amount, &file_offset_tmp);
  36170. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  36171. + (unsigned long long) file_offset,
  36172. + (int) nread);
  36173. + if (signal_pending(current))
  36174. + return -EINTR;
  36175. +
  36176. + if (nread < 0) {
  36177. + LDBG(curlun, "error in file read: %d\n",
  36178. + (int) nread);
  36179. + nread = 0;
  36180. + } else if (nread < amount) {
  36181. + LDBG(curlun, "partial file read: %d/%u\n",
  36182. + (int) nread, amount);
  36183. + nread = round_down(nread, curlun->blksize);
  36184. + }
  36185. + file_offset += nread;
  36186. + amount_left -= nread;
  36187. + fsg->residue -= nread;
  36188. +
  36189. + /* Except at the end of the transfer, nread will be
  36190. + * equal to the buffer size, which is divisible by the
  36191. + * bulk-in maxpacket size.
  36192. + */
  36193. + bh->inreq->length = nread;
  36194. + bh->state = BUF_STATE_FULL;
  36195. +
  36196. + /* If an error occurred, report it and its position */
  36197. + if (nread < amount) {
  36198. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  36199. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36200. + curlun->info_valid = 1;
  36201. + break;
  36202. + }
  36203. +
  36204. + if (amount_left == 0)
  36205. + break; // No more left to read
  36206. +
  36207. + /* Send this buffer and go read some more */
  36208. + bh->inreq->zero = 0;
  36209. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  36210. + &bh->inreq_busy, &bh->state);
  36211. + fsg->next_buffhd_to_fill = bh->next;
  36212. + }
  36213. +
  36214. + return -EIO; // No default reply
  36215. +}
  36216. +
  36217. +
  36218. +/*-------------------------------------------------------------------------*/
  36219. +
  36220. +static int do_write(struct fsg_dev *fsg)
  36221. +{
  36222. + struct fsg_lun *curlun = fsg->curlun;
  36223. + u32 lba;
  36224. + struct fsg_buffhd *bh;
  36225. + int get_some_more;
  36226. + u32 amount_left_to_req, amount_left_to_write;
  36227. + loff_t usb_offset, file_offset, file_offset_tmp;
  36228. + unsigned int amount;
  36229. + ssize_t nwritten;
  36230. + int rc;
  36231. +
  36232. + if (curlun->ro) {
  36233. + curlun->sense_data = SS_WRITE_PROTECTED;
  36234. + return -EINVAL;
  36235. + }
  36236. + spin_lock(&curlun->filp->f_lock);
  36237. + curlun->filp->f_flags &= ~O_SYNC; // Default is not to wait
  36238. + spin_unlock(&curlun->filp->f_lock);
  36239. +
  36240. + /* Get the starting Logical Block Address and check that it's
  36241. + * not too big */
  36242. + if (fsg->cmnd[0] == WRITE_6)
  36243. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  36244. + else {
  36245. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  36246. +
  36247. + /* We allow DPO (Disable Page Out = don't save data in the
  36248. + * cache) and FUA (Force Unit Access = write directly to the
  36249. + * medium). We don't implement DPO; we implement FUA by
  36250. + * performing synchronous output. */
  36251. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  36252. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36253. + return -EINVAL;
  36254. + }
  36255. + /* FUA */
  36256. + if (!curlun->nofua && (fsg->cmnd[1] & 0x08)) {
  36257. + spin_lock(&curlun->filp->f_lock);
  36258. + curlun->filp->f_flags |= O_DSYNC;
  36259. + spin_unlock(&curlun->filp->f_lock);
  36260. + }
  36261. + }
  36262. + if (lba >= curlun->num_sectors) {
  36263. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36264. + return -EINVAL;
  36265. + }
  36266. +
  36267. + /* Carry out the file writes */
  36268. + get_some_more = 1;
  36269. + file_offset = usb_offset = ((loff_t) lba) << curlun->blkbits;
  36270. + amount_left_to_req = amount_left_to_write = fsg->data_size_from_cmnd;
  36271. +
  36272. + while (amount_left_to_write > 0) {
  36273. +
  36274. + /* Queue a request for more data from the host */
  36275. + bh = fsg->next_buffhd_to_fill;
  36276. + if (bh->state == BUF_STATE_EMPTY && get_some_more) {
  36277. +
  36278. + /* Figure out how much we want to get:
  36279. + * Try to get the remaining amount,
  36280. + * but not more than the buffer size.
  36281. + */
  36282. + amount = min(amount_left_to_req, mod_data.buflen);
  36283. +
  36284. + /* Beyond the end of the backing file? */
  36285. + if (usb_offset >= curlun->file_length) {
  36286. + get_some_more = 0;
  36287. + curlun->sense_data =
  36288. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36289. + curlun->sense_data_info = usb_offset >> curlun->blkbits;
  36290. + curlun->info_valid = 1;
  36291. + continue;
  36292. + }
  36293. +
  36294. + /* Get the next buffer */
  36295. + usb_offset += amount;
  36296. + fsg->usb_amount_left -= amount;
  36297. + amount_left_to_req -= amount;
  36298. + if (amount_left_to_req == 0)
  36299. + get_some_more = 0;
  36300. +
  36301. + /* Except at the end of the transfer, amount will be
  36302. + * equal to the buffer size, which is divisible by
  36303. + * the bulk-out maxpacket size.
  36304. + */
  36305. + set_bulk_out_req_length(fsg, bh, amount);
  36306. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  36307. + &bh->outreq_busy, &bh->state);
  36308. + fsg->next_buffhd_to_fill = bh->next;
  36309. + continue;
  36310. + }
  36311. +
  36312. + /* Write the received data to the backing file */
  36313. + bh = fsg->next_buffhd_to_drain;
  36314. + if (bh->state == BUF_STATE_EMPTY && !get_some_more)
  36315. + break; // We stopped early
  36316. + if (bh->state == BUF_STATE_FULL) {
  36317. + smp_rmb();
  36318. + fsg->next_buffhd_to_drain = bh->next;
  36319. + bh->state = BUF_STATE_EMPTY;
  36320. +
  36321. + /* Did something go wrong with the transfer? */
  36322. + if (bh->outreq->status != 0) {
  36323. + curlun->sense_data = SS_COMMUNICATION_FAILURE;
  36324. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36325. + curlun->info_valid = 1;
  36326. + break;
  36327. + }
  36328. +
  36329. + amount = bh->outreq->actual;
  36330. + if (curlun->file_length - file_offset < amount) {
  36331. + LERROR(curlun,
  36332. + "write %u @ %llu beyond end %llu\n",
  36333. + amount, (unsigned long long) file_offset,
  36334. + (unsigned long long) curlun->file_length);
  36335. + amount = curlun->file_length - file_offset;
  36336. + }
  36337. +
  36338. + /* Don't accept excess data. The spec doesn't say
  36339. + * what to do in this case. We'll ignore the error.
  36340. + */
  36341. + amount = min(amount, bh->bulk_out_intended_length);
  36342. +
  36343. + /* Don't write a partial block */
  36344. + amount = round_down(amount, curlun->blksize);
  36345. + if (amount == 0)
  36346. + goto empty_write;
  36347. +
  36348. + /* Perform the write */
  36349. + file_offset_tmp = file_offset;
  36350. + nwritten = vfs_write(curlun->filp,
  36351. + (char __user *) bh->buf,
  36352. + amount, &file_offset_tmp);
  36353. + VLDBG(curlun, "file write %u @ %llu -> %d\n", amount,
  36354. + (unsigned long long) file_offset,
  36355. + (int) nwritten);
  36356. + if (signal_pending(current))
  36357. + return -EINTR; // Interrupted!
  36358. +
  36359. + if (nwritten < 0) {
  36360. + LDBG(curlun, "error in file write: %d\n",
  36361. + (int) nwritten);
  36362. + nwritten = 0;
  36363. + } else if (nwritten < amount) {
  36364. + LDBG(curlun, "partial file write: %d/%u\n",
  36365. + (int) nwritten, amount);
  36366. + nwritten = round_down(nwritten, curlun->blksize);
  36367. + }
  36368. + file_offset += nwritten;
  36369. + amount_left_to_write -= nwritten;
  36370. + fsg->residue -= nwritten;
  36371. +
  36372. + /* If an error occurred, report it and its position */
  36373. + if (nwritten < amount) {
  36374. + curlun->sense_data = SS_WRITE_ERROR;
  36375. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36376. + curlun->info_valid = 1;
  36377. + break;
  36378. + }
  36379. +
  36380. + empty_write:
  36381. + /* Did the host decide to stop early? */
  36382. + if (bh->outreq->actual < bh->bulk_out_intended_length) {
  36383. + fsg->short_packet_received = 1;
  36384. + break;
  36385. + }
  36386. + continue;
  36387. + }
  36388. +
  36389. + /* Wait for something to happen */
  36390. + rc = sleep_thread(fsg);
  36391. + if (rc)
  36392. + return rc;
  36393. + }
  36394. +
  36395. + return -EIO; // No default reply
  36396. +}
  36397. +
  36398. +
  36399. +/*-------------------------------------------------------------------------*/
  36400. +
  36401. +static int do_synchronize_cache(struct fsg_dev *fsg)
  36402. +{
  36403. + struct fsg_lun *curlun = fsg->curlun;
  36404. + int rc;
  36405. +
  36406. + /* We ignore the requested LBA and write out all file's
  36407. + * dirty data buffers. */
  36408. + rc = fsg_lun_fsync_sub(curlun);
  36409. + if (rc)
  36410. + curlun->sense_data = SS_WRITE_ERROR;
  36411. + return 0;
  36412. +}
  36413. +
  36414. +
  36415. +/*-------------------------------------------------------------------------*/
  36416. +
  36417. +static void invalidate_sub(struct fsg_lun *curlun)
  36418. +{
  36419. + struct file *filp = curlun->filp;
  36420. + struct inode *inode = filp->f_path.dentry->d_inode;
  36421. + unsigned long rc;
  36422. +
  36423. + rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);
  36424. + VLDBG(curlun, "invalidate_mapping_pages -> %ld\n", rc);
  36425. +}
  36426. +
  36427. +static int do_verify(struct fsg_dev *fsg)
  36428. +{
  36429. + struct fsg_lun *curlun = fsg->curlun;
  36430. + u32 lba;
  36431. + u32 verification_length;
  36432. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  36433. + loff_t file_offset, file_offset_tmp;
  36434. + u32 amount_left;
  36435. + unsigned int amount;
  36436. + ssize_t nread;
  36437. +
  36438. + /* Get the starting Logical Block Address and check that it's
  36439. + * not too big */
  36440. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  36441. + if (lba >= curlun->num_sectors) {
  36442. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36443. + return -EINVAL;
  36444. + }
  36445. +
  36446. + /* We allow DPO (Disable Page Out = don't save data in the
  36447. + * cache) but we don't implement it. */
  36448. + if ((fsg->cmnd[1] & ~0x10) != 0) {
  36449. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36450. + return -EINVAL;
  36451. + }
  36452. +
  36453. + verification_length = get_unaligned_be16(&fsg->cmnd[7]);
  36454. + if (unlikely(verification_length == 0))
  36455. + return -EIO; // No default reply
  36456. +
  36457. + /* Prepare to carry out the file verify */
  36458. + amount_left = verification_length << curlun->blkbits;
  36459. + file_offset = ((loff_t) lba) << curlun->blkbits;
  36460. +
  36461. + /* Write out all the dirty buffers before invalidating them */
  36462. + fsg_lun_fsync_sub(curlun);
  36463. + if (signal_pending(current))
  36464. + return -EINTR;
  36465. +
  36466. + invalidate_sub(curlun);
  36467. + if (signal_pending(current))
  36468. + return -EINTR;
  36469. +
  36470. + /* Just try to read the requested blocks */
  36471. + while (amount_left > 0) {
  36472. +
  36473. + /* Figure out how much we need to read:
  36474. + * Try to read the remaining amount, but not more than
  36475. + * the buffer size.
  36476. + * And don't try to read past the end of the file.
  36477. + */
  36478. + amount = min((unsigned int) amount_left, mod_data.buflen);
  36479. + amount = min((loff_t) amount,
  36480. + curlun->file_length - file_offset);
  36481. + if (amount == 0) {
  36482. + curlun->sense_data =
  36483. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36484. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36485. + curlun->info_valid = 1;
  36486. + break;
  36487. + }
  36488. +
  36489. + /* Perform the read */
  36490. + file_offset_tmp = file_offset;
  36491. + nread = vfs_read(curlun->filp,
  36492. + (char __user *) bh->buf,
  36493. + amount, &file_offset_tmp);
  36494. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  36495. + (unsigned long long) file_offset,
  36496. + (int) nread);
  36497. + if (signal_pending(current))
  36498. + return -EINTR;
  36499. +
  36500. + if (nread < 0) {
  36501. + LDBG(curlun, "error in file verify: %d\n",
  36502. + (int) nread);
  36503. + nread = 0;
  36504. + } else if (nread < amount) {
  36505. + LDBG(curlun, "partial file verify: %d/%u\n",
  36506. + (int) nread, amount);
  36507. + nread = round_down(nread, curlun->blksize);
  36508. + }
  36509. + if (nread == 0) {
  36510. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  36511. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36512. + curlun->info_valid = 1;
  36513. + break;
  36514. + }
  36515. + file_offset += nread;
  36516. + amount_left -= nread;
  36517. + }
  36518. + return 0;
  36519. +}
  36520. +
  36521. +
  36522. +/*-------------------------------------------------------------------------*/
  36523. +
  36524. +static int do_inquiry(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36525. +{
  36526. + u8 *buf = (u8 *) bh->buf;
  36527. +
  36528. + static char vendor_id[] = "Linux ";
  36529. + static char product_disk_id[] = "File-Stor Gadget";
  36530. + static char product_cdrom_id[] = "File-CD Gadget ";
  36531. +
  36532. + if (!fsg->curlun) { // Unsupported LUNs are okay
  36533. + fsg->bad_lun_okay = 1;
  36534. + memset(buf, 0, 36);
  36535. + buf[0] = 0x7f; // Unsupported, no device-type
  36536. + buf[4] = 31; // Additional length
  36537. + return 36;
  36538. + }
  36539. +
  36540. + memset(buf, 0, 8);
  36541. + buf[0] = (mod_data.cdrom ? TYPE_ROM : TYPE_DISK);
  36542. + if (mod_data.removable)
  36543. + buf[1] = 0x80;
  36544. + buf[2] = 2; // ANSI SCSI level 2
  36545. + buf[3] = 2; // SCSI-2 INQUIRY data format
  36546. + buf[4] = 31; // Additional length
  36547. + // No special options
  36548. + sprintf(buf + 8, "%-8s%-16s%04x", vendor_id,
  36549. + (mod_data.cdrom ? product_cdrom_id :
  36550. + product_disk_id),
  36551. + mod_data.release);
  36552. + return 36;
  36553. +}
  36554. +
  36555. +
  36556. +static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36557. +{
  36558. + struct fsg_lun *curlun = fsg->curlun;
  36559. + u8 *buf = (u8 *) bh->buf;
  36560. + u32 sd, sdinfo;
  36561. + int valid;
  36562. +
  36563. + /*
  36564. + * From the SCSI-2 spec., section 7.9 (Unit attention condition):
  36565. + *
  36566. + * If a REQUEST SENSE command is received from an initiator
  36567. + * with a pending unit attention condition (before the target
  36568. + * generates the contingent allegiance condition), then the
  36569. + * target shall either:
  36570. + * a) report any pending sense data and preserve the unit
  36571. + * attention condition on the logical unit, or,
  36572. + * b) report the unit attention condition, may discard any
  36573. + * pending sense data, and clear the unit attention
  36574. + * condition on the logical unit for that initiator.
  36575. + *
  36576. + * FSG normally uses option a); enable this code to use option b).
  36577. + */
  36578. +#if 0
  36579. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE) {
  36580. + curlun->sense_data = curlun->unit_attention_data;
  36581. + curlun->unit_attention_data = SS_NO_SENSE;
  36582. + }
  36583. +#endif
  36584. +
  36585. + if (!curlun) { // Unsupported LUNs are okay
  36586. + fsg->bad_lun_okay = 1;
  36587. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  36588. + sdinfo = 0;
  36589. + valid = 0;
  36590. + } else {
  36591. + sd = curlun->sense_data;
  36592. + sdinfo = curlun->sense_data_info;
  36593. + valid = curlun->info_valid << 7;
  36594. + curlun->sense_data = SS_NO_SENSE;
  36595. + curlun->sense_data_info = 0;
  36596. + curlun->info_valid = 0;
  36597. + }
  36598. +
  36599. + memset(buf, 0, 18);
  36600. + buf[0] = valid | 0x70; // Valid, current error
  36601. + buf[2] = SK(sd);
  36602. + put_unaligned_be32(sdinfo, &buf[3]); /* Sense information */
  36603. + buf[7] = 18 - 8; // Additional sense length
  36604. + buf[12] = ASC(sd);
  36605. + buf[13] = ASCQ(sd);
  36606. + return 18;
  36607. +}
  36608. +
  36609. +
  36610. +static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36611. +{
  36612. + struct fsg_lun *curlun = fsg->curlun;
  36613. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  36614. + int pmi = fsg->cmnd[8];
  36615. + u8 *buf = (u8 *) bh->buf;
  36616. +
  36617. + /* Check the PMI and LBA fields */
  36618. + if (pmi > 1 || (pmi == 0 && lba != 0)) {
  36619. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36620. + return -EINVAL;
  36621. + }
  36622. +
  36623. + put_unaligned_be32(curlun->num_sectors - 1, &buf[0]);
  36624. + /* Max logical block */
  36625. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  36626. + return 8;
  36627. +}
  36628. +
  36629. +
  36630. +static int do_read_header(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36631. +{
  36632. + struct fsg_lun *curlun = fsg->curlun;
  36633. + int msf = fsg->cmnd[1] & 0x02;
  36634. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  36635. + u8 *buf = (u8 *) bh->buf;
  36636. +
  36637. + if ((fsg->cmnd[1] & ~0x02) != 0) { /* Mask away MSF */
  36638. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36639. + return -EINVAL;
  36640. + }
  36641. + if (lba >= curlun->num_sectors) {
  36642. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36643. + return -EINVAL;
  36644. + }
  36645. +
  36646. + memset(buf, 0, 8);
  36647. + buf[0] = 0x01; /* 2048 bytes of user data, rest is EC */
  36648. + store_cdrom_address(&buf[4], msf, lba);
  36649. + return 8;
  36650. +}
  36651. +
  36652. +
  36653. +static int do_read_toc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36654. +{
  36655. + struct fsg_lun *curlun = fsg->curlun;
  36656. + int msf = fsg->cmnd[1] & 0x02;
  36657. + int start_track = fsg->cmnd[6];
  36658. + u8 *buf = (u8 *) bh->buf;
  36659. +
  36660. + if ((fsg->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */
  36661. + start_track > 1) {
  36662. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36663. + return -EINVAL;
  36664. + }
  36665. +
  36666. + memset(buf, 0, 20);
  36667. + buf[1] = (20-2); /* TOC data length */
  36668. + buf[2] = 1; /* First track number */
  36669. + buf[3] = 1; /* Last track number */
  36670. + buf[5] = 0x16; /* Data track, copying allowed */
  36671. + buf[6] = 0x01; /* Only track is number 1 */
  36672. + store_cdrom_address(&buf[8], msf, 0);
  36673. +
  36674. + buf[13] = 0x16; /* Lead-out track is data */
  36675. + buf[14] = 0xAA; /* Lead-out track number */
  36676. + store_cdrom_address(&buf[16], msf, curlun->num_sectors);
  36677. + return 20;
  36678. +}
  36679. +
  36680. +
  36681. +static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36682. +{
  36683. + struct fsg_lun *curlun = fsg->curlun;
  36684. + int mscmnd = fsg->cmnd[0];
  36685. + u8 *buf = (u8 *) bh->buf;
  36686. + u8 *buf0 = buf;
  36687. + int pc, page_code;
  36688. + int changeable_values, all_pages;
  36689. + int valid_page = 0;
  36690. + int len, limit;
  36691. +
  36692. + if ((fsg->cmnd[1] & ~0x08) != 0) { // Mask away DBD
  36693. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36694. + return -EINVAL;
  36695. + }
  36696. + pc = fsg->cmnd[2] >> 6;
  36697. + page_code = fsg->cmnd[2] & 0x3f;
  36698. + if (pc == 3) {
  36699. + curlun->sense_data = SS_SAVING_PARAMETERS_NOT_SUPPORTED;
  36700. + return -EINVAL;
  36701. + }
  36702. + changeable_values = (pc == 1);
  36703. + all_pages = (page_code == 0x3f);
  36704. +
  36705. + /* Write the mode parameter header. Fixed values are: default
  36706. + * medium type, no cache control (DPOFUA), and no block descriptors.
  36707. + * The only variable value is the WriteProtect bit. We will fill in
  36708. + * the mode data length later. */
  36709. + memset(buf, 0, 8);
  36710. + if (mscmnd == MODE_SENSE) {
  36711. + buf[2] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  36712. + buf += 4;
  36713. + limit = 255;
  36714. + } else { // MODE_SENSE_10
  36715. + buf[3] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  36716. + buf += 8;
  36717. + limit = 65535; // Should really be mod_data.buflen
  36718. + }
  36719. +
  36720. + /* No block descriptors */
  36721. +
  36722. + /* The mode pages, in numerical order. The only page we support
  36723. + * is the Caching page. */
  36724. + if (page_code == 0x08 || all_pages) {
  36725. + valid_page = 1;
  36726. + buf[0] = 0x08; // Page code
  36727. + buf[1] = 10; // Page length
  36728. + memset(buf+2, 0, 10); // None of the fields are changeable
  36729. +
  36730. + if (!changeable_values) {
  36731. + buf[2] = 0x04; // Write cache enable,
  36732. + // Read cache not disabled
  36733. + // No cache retention priorities
  36734. + put_unaligned_be16(0xffff, &buf[4]);
  36735. + /* Don't disable prefetch */
  36736. + /* Minimum prefetch = 0 */
  36737. + put_unaligned_be16(0xffff, &buf[8]);
  36738. + /* Maximum prefetch */
  36739. + put_unaligned_be16(0xffff, &buf[10]);
  36740. + /* Maximum prefetch ceiling */
  36741. + }
  36742. + buf += 12;
  36743. + }
  36744. +
  36745. + /* Check that a valid page was requested and the mode data length
  36746. + * isn't too long. */
  36747. + len = buf - buf0;
  36748. + if (!valid_page || len > limit) {
  36749. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36750. + return -EINVAL;
  36751. + }
  36752. +
  36753. + /* Store the mode data length */
  36754. + if (mscmnd == MODE_SENSE)
  36755. + buf0[0] = len - 1;
  36756. + else
  36757. + put_unaligned_be16(len - 2, buf0);
  36758. + return len;
  36759. +}
  36760. +
  36761. +
  36762. +static int do_start_stop(struct fsg_dev *fsg)
  36763. +{
  36764. + struct fsg_lun *curlun = fsg->curlun;
  36765. + int loej, start;
  36766. +
  36767. + if (!mod_data.removable) {
  36768. + curlun->sense_data = SS_INVALID_COMMAND;
  36769. + return -EINVAL;
  36770. + }
  36771. +
  36772. + // int immed = fsg->cmnd[1] & 0x01;
  36773. + loej = fsg->cmnd[4] & 0x02;
  36774. + start = fsg->cmnd[4] & 0x01;
  36775. +
  36776. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  36777. + if ((fsg->cmnd[1] & ~0x01) != 0 || // Mask away Immed
  36778. + (fsg->cmnd[4] & ~0x03) != 0) { // Mask LoEj, Start
  36779. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36780. + return -EINVAL;
  36781. + }
  36782. +
  36783. + if (!start) {
  36784. +
  36785. + /* Are we allowed to unload the media? */
  36786. + if (curlun->prevent_medium_removal) {
  36787. + LDBG(curlun, "unload attempt prevented\n");
  36788. + curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED;
  36789. + return -EINVAL;
  36790. + }
  36791. + if (loej) { // Simulate an unload/eject
  36792. + up_read(&fsg->filesem);
  36793. + down_write(&fsg->filesem);
  36794. + fsg_lun_close(curlun);
  36795. + up_write(&fsg->filesem);
  36796. + down_read(&fsg->filesem);
  36797. + }
  36798. + } else {
  36799. +
  36800. + /* Our emulation doesn't support mounting; the medium is
  36801. + * available for use as soon as it is loaded. */
  36802. + if (!fsg_lun_is_open(curlun)) {
  36803. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  36804. + return -EINVAL;
  36805. + }
  36806. + }
  36807. +#endif
  36808. + return 0;
  36809. +}
  36810. +
  36811. +
  36812. +static int do_prevent_allow(struct fsg_dev *fsg)
  36813. +{
  36814. + struct fsg_lun *curlun = fsg->curlun;
  36815. + int prevent;
  36816. +
  36817. + if (!mod_data.removable) {
  36818. + curlun->sense_data = SS_INVALID_COMMAND;
  36819. + return -EINVAL;
  36820. + }
  36821. +
  36822. + prevent = fsg->cmnd[4] & 0x01;
  36823. + if ((fsg->cmnd[4] & ~0x01) != 0) { // Mask away Prevent
  36824. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36825. + return -EINVAL;
  36826. + }
  36827. +
  36828. + if (curlun->prevent_medium_removal && !prevent)
  36829. + fsg_lun_fsync_sub(curlun);
  36830. + curlun->prevent_medium_removal = prevent;
  36831. + return 0;
  36832. +}
  36833. +
  36834. +
  36835. +static int do_read_format_capacities(struct fsg_dev *fsg,
  36836. + struct fsg_buffhd *bh)
  36837. +{
  36838. + struct fsg_lun *curlun = fsg->curlun;
  36839. + u8 *buf = (u8 *) bh->buf;
  36840. +
  36841. + buf[0] = buf[1] = buf[2] = 0;
  36842. + buf[3] = 8; // Only the Current/Maximum Capacity Descriptor
  36843. + buf += 4;
  36844. +
  36845. + put_unaligned_be32(curlun->num_sectors, &buf[0]);
  36846. + /* Number of blocks */
  36847. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  36848. + buf[4] = 0x02; /* Current capacity */
  36849. + return 12;
  36850. +}
  36851. +
  36852. +
  36853. +static int do_mode_select(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36854. +{
  36855. + struct fsg_lun *curlun = fsg->curlun;
  36856. +
  36857. + /* We don't support MODE SELECT */
  36858. + curlun->sense_data = SS_INVALID_COMMAND;
  36859. + return -EINVAL;
  36860. +}
  36861. +
  36862. +
  36863. +/*-------------------------------------------------------------------------*/
  36864. +
  36865. +static int halt_bulk_in_endpoint(struct fsg_dev *fsg)
  36866. +{
  36867. + int rc;
  36868. +
  36869. + rc = fsg_set_halt(fsg, fsg->bulk_in);
  36870. + if (rc == -EAGAIN)
  36871. + VDBG(fsg, "delayed bulk-in endpoint halt\n");
  36872. + while (rc != 0) {
  36873. + if (rc != -EAGAIN) {
  36874. + WARNING(fsg, "usb_ep_set_halt -> %d\n", rc);
  36875. + rc = 0;
  36876. + break;
  36877. + }
  36878. +
  36879. + /* Wait for a short time and then try again */
  36880. + if (msleep_interruptible(100) != 0)
  36881. + return -EINTR;
  36882. + rc = usb_ep_set_halt(fsg->bulk_in);
  36883. + }
  36884. + return rc;
  36885. +}
  36886. +
  36887. +static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
  36888. +{
  36889. + int rc;
  36890. +
  36891. + DBG(fsg, "bulk-in set wedge\n");
  36892. + rc = usb_ep_set_wedge(fsg->bulk_in);
  36893. + if (rc == -EAGAIN)
  36894. + VDBG(fsg, "delayed bulk-in endpoint wedge\n");
  36895. + while (rc != 0) {
  36896. + if (rc != -EAGAIN) {
  36897. + WARNING(fsg, "usb_ep_set_wedge -> %d\n", rc);
  36898. + rc = 0;
  36899. + break;
  36900. + }
  36901. +
  36902. + /* Wait for a short time and then try again */
  36903. + if (msleep_interruptible(100) != 0)
  36904. + return -EINTR;
  36905. + rc = usb_ep_set_wedge(fsg->bulk_in);
  36906. + }
  36907. + return rc;
  36908. +}
  36909. +
  36910. +static int throw_away_data(struct fsg_dev *fsg)
  36911. +{
  36912. + struct fsg_buffhd *bh;
  36913. + u32 amount;
  36914. + int rc;
  36915. +
  36916. + while ((bh = fsg->next_buffhd_to_drain)->state != BUF_STATE_EMPTY ||
  36917. + fsg->usb_amount_left > 0) {
  36918. +
  36919. + /* Throw away the data in a filled buffer */
  36920. + if (bh->state == BUF_STATE_FULL) {
  36921. + smp_rmb();
  36922. + bh->state = BUF_STATE_EMPTY;
  36923. + fsg->next_buffhd_to_drain = bh->next;
  36924. +
  36925. + /* A short packet or an error ends everything */
  36926. + if (bh->outreq->actual < bh->bulk_out_intended_length ||
  36927. + bh->outreq->status != 0) {
  36928. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  36929. + return -EINTR;
  36930. + }
  36931. + continue;
  36932. + }
  36933. +
  36934. + /* Try to submit another request if we need one */
  36935. + bh = fsg->next_buffhd_to_fill;
  36936. + if (bh->state == BUF_STATE_EMPTY && fsg->usb_amount_left > 0) {
  36937. + amount = min(fsg->usb_amount_left,
  36938. + (u32) mod_data.buflen);
  36939. +
  36940. + /* Except at the end of the transfer, amount will be
  36941. + * equal to the buffer size, which is divisible by
  36942. + * the bulk-out maxpacket size.
  36943. + */
  36944. + set_bulk_out_req_length(fsg, bh, amount);
  36945. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  36946. + &bh->outreq_busy, &bh->state);
  36947. + fsg->next_buffhd_to_fill = bh->next;
  36948. + fsg->usb_amount_left -= amount;
  36949. + continue;
  36950. + }
  36951. +
  36952. + /* Otherwise wait for something to happen */
  36953. + rc = sleep_thread(fsg);
  36954. + if (rc)
  36955. + return rc;
  36956. + }
  36957. + return 0;
  36958. +}
  36959. +
  36960. +
  36961. +static int finish_reply(struct fsg_dev *fsg)
  36962. +{
  36963. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  36964. + int rc = 0;
  36965. +
  36966. + switch (fsg->data_dir) {
  36967. + case DATA_DIR_NONE:
  36968. + break; // Nothing to send
  36969. +
  36970. + /* If we don't know whether the host wants to read or write,
  36971. + * this must be CB or CBI with an unknown command. We mustn't
  36972. + * try to send or receive any data. So stall both bulk pipes
  36973. + * if we can and wait for a reset. */
  36974. + case DATA_DIR_UNKNOWN:
  36975. + if (mod_data.can_stall) {
  36976. + fsg_set_halt(fsg, fsg->bulk_out);
  36977. + rc = halt_bulk_in_endpoint(fsg);
  36978. + }
  36979. + break;
  36980. +
  36981. + /* All but the last buffer of data must have already been sent */
  36982. + case DATA_DIR_TO_HOST:
  36983. + if (fsg->data_size == 0)
  36984. + ; // Nothing to send
  36985. +
  36986. + /* If there's no residue, simply send the last buffer */
  36987. + else if (fsg->residue == 0) {
  36988. + bh->inreq->zero = 0;
  36989. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  36990. + &bh->inreq_busy, &bh->state);
  36991. + fsg->next_buffhd_to_fill = bh->next;
  36992. + }
  36993. +
  36994. + /* There is a residue. For CB and CBI, simply mark the end
  36995. + * of the data with a short packet. However, if we are
  36996. + * allowed to stall, there was no data at all (residue ==
  36997. + * data_size), and the command failed (invalid LUN or
  36998. + * sense data is set), then halt the bulk-in endpoint
  36999. + * instead. */
  37000. + else if (!transport_is_bbb()) {
  37001. + if (mod_data.can_stall &&
  37002. + fsg->residue == fsg->data_size &&
  37003. + (!fsg->curlun || fsg->curlun->sense_data != SS_NO_SENSE)) {
  37004. + bh->state = BUF_STATE_EMPTY;
  37005. + rc = halt_bulk_in_endpoint(fsg);
  37006. + } else {
  37007. + bh->inreq->zero = 1;
  37008. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  37009. + &bh->inreq_busy, &bh->state);
  37010. + fsg->next_buffhd_to_fill = bh->next;
  37011. + }
  37012. + }
  37013. +
  37014. + /*
  37015. + * For Bulk-only, mark the end of the data with a short
  37016. + * packet. If we are allowed to stall, halt the bulk-in
  37017. + * endpoint. (Note: This violates the Bulk-Only Transport
  37018. + * specification, which requires us to pad the data if we
  37019. + * don't halt the endpoint. Presumably nobody will mind.)
  37020. + */
  37021. + else {
  37022. + bh->inreq->zero = 1;
  37023. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  37024. + &bh->inreq_busy, &bh->state);
  37025. + fsg->next_buffhd_to_fill = bh->next;
  37026. + if (mod_data.can_stall)
  37027. + rc = halt_bulk_in_endpoint(fsg);
  37028. + }
  37029. + break;
  37030. +
  37031. + /* We have processed all we want from the data the host has sent.
  37032. + * There may still be outstanding bulk-out requests. */
  37033. + case DATA_DIR_FROM_HOST:
  37034. + if (fsg->residue == 0)
  37035. + ; // Nothing to receive
  37036. +
  37037. + /* Did the host stop sending unexpectedly early? */
  37038. + else if (fsg->short_packet_received) {
  37039. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  37040. + rc = -EINTR;
  37041. + }
  37042. +
  37043. + /* We haven't processed all the incoming data. Even though
  37044. + * we may be allowed to stall, doing so would cause a race.
  37045. + * The controller may already have ACK'ed all the remaining
  37046. + * bulk-out packets, in which case the host wouldn't see a
  37047. + * STALL. Not realizing the endpoint was halted, it wouldn't
  37048. + * clear the halt -- leading to problems later on. */
  37049. +#if 0
  37050. + else if (mod_data.can_stall) {
  37051. + fsg_set_halt(fsg, fsg->bulk_out);
  37052. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  37053. + rc = -EINTR;
  37054. + }
  37055. +#endif
  37056. +
  37057. + /* We can't stall. Read in the excess data and throw it
  37058. + * all away. */
  37059. + else
  37060. + rc = throw_away_data(fsg);
  37061. + break;
  37062. + }
  37063. + return rc;
  37064. +}
  37065. +
  37066. +
  37067. +static int send_status(struct fsg_dev *fsg)
  37068. +{
  37069. + struct fsg_lun *curlun = fsg->curlun;
  37070. + struct fsg_buffhd *bh;
  37071. + int rc;
  37072. + u8 status = US_BULK_STAT_OK;
  37073. + u32 sd, sdinfo = 0;
  37074. +
  37075. + /* Wait for the next buffer to become available */
  37076. + bh = fsg->next_buffhd_to_fill;
  37077. + while (bh->state != BUF_STATE_EMPTY) {
  37078. + rc = sleep_thread(fsg);
  37079. + if (rc)
  37080. + return rc;
  37081. + }
  37082. +
  37083. + if (curlun) {
  37084. + sd = curlun->sense_data;
  37085. + sdinfo = curlun->sense_data_info;
  37086. + } else if (fsg->bad_lun_okay)
  37087. + sd = SS_NO_SENSE;
  37088. + else
  37089. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  37090. +
  37091. + if (fsg->phase_error) {
  37092. + DBG(fsg, "sending phase-error status\n");
  37093. + status = US_BULK_STAT_PHASE;
  37094. + sd = SS_INVALID_COMMAND;
  37095. + } else if (sd != SS_NO_SENSE) {
  37096. + DBG(fsg, "sending command-failure status\n");
  37097. + status = US_BULK_STAT_FAIL;
  37098. + VDBG(fsg, " sense data: SK x%02x, ASC x%02x, ASCQ x%02x;"
  37099. + " info x%x\n",
  37100. + SK(sd), ASC(sd), ASCQ(sd), sdinfo);
  37101. + }
  37102. +
  37103. + if (transport_is_bbb()) {
  37104. + struct bulk_cs_wrap *csw = bh->buf;
  37105. +
  37106. + /* Store and send the Bulk-only CSW */
  37107. + csw->Signature = cpu_to_le32(US_BULK_CS_SIGN);
  37108. + csw->Tag = fsg->tag;
  37109. + csw->Residue = cpu_to_le32(fsg->residue);
  37110. + csw->Status = status;
  37111. +
  37112. + bh->inreq->length = US_BULK_CS_WRAP_LEN;
  37113. + bh->inreq->zero = 0;
  37114. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  37115. + &bh->inreq_busy, &bh->state);
  37116. +
  37117. + } else if (mod_data.transport_type == USB_PR_CB) {
  37118. +
  37119. + /* Control-Bulk transport has no status phase! */
  37120. + return 0;
  37121. +
  37122. + } else { // USB_PR_CBI
  37123. + struct interrupt_data *buf = bh->buf;
  37124. +
  37125. + /* Store and send the Interrupt data. UFI sends the ASC
  37126. + * and ASCQ bytes. Everything else sends a Type (which
  37127. + * is always 0) and the status Value. */
  37128. + if (mod_data.protocol_type == USB_SC_UFI) {
  37129. + buf->bType = ASC(sd);
  37130. + buf->bValue = ASCQ(sd);
  37131. + } else {
  37132. + buf->bType = 0;
  37133. + buf->bValue = status;
  37134. + }
  37135. + fsg->intreq->length = CBI_INTERRUPT_DATA_LEN;
  37136. +
  37137. + fsg->intr_buffhd = bh; // Point to the right buffhd
  37138. + fsg->intreq->buf = bh->inreq->buf;
  37139. + fsg->intreq->context = bh;
  37140. + start_transfer(fsg, fsg->intr_in, fsg->intreq,
  37141. + &fsg->intreq_busy, &bh->state);
  37142. + }
  37143. +
  37144. + fsg->next_buffhd_to_fill = bh->next;
  37145. + return 0;
  37146. +}
  37147. +
  37148. +
  37149. +/*-------------------------------------------------------------------------*/
  37150. +
  37151. +/* Check whether the command is properly formed and whether its data size
  37152. + * and direction agree with the values we already have. */
  37153. +static int check_command(struct fsg_dev *fsg, int cmnd_size,
  37154. + enum data_direction data_dir, unsigned int mask,
  37155. + int needs_medium, const char *name)
  37156. +{
  37157. + int i;
  37158. + int lun = fsg->cmnd[1] >> 5;
  37159. + static const char dirletter[4] = {'u', 'o', 'i', 'n'};
  37160. + char hdlen[20];
  37161. + struct fsg_lun *curlun;
  37162. +
  37163. + /* Adjust the expected cmnd_size for protocol encapsulation padding.
  37164. + * Transparent SCSI doesn't pad. */
  37165. + if (protocol_is_scsi())
  37166. + ;
  37167. +
  37168. + /* There's some disagreement as to whether RBC pads commands or not.
  37169. + * We'll play it safe and accept either form. */
  37170. + else if (mod_data.protocol_type == USB_SC_RBC) {
  37171. + if (fsg->cmnd_size == 12)
  37172. + cmnd_size = 12;
  37173. +
  37174. + /* All the other protocols pad to 12 bytes */
  37175. + } else
  37176. + cmnd_size = 12;
  37177. +
  37178. + hdlen[0] = 0;
  37179. + if (fsg->data_dir != DATA_DIR_UNKNOWN)
  37180. + sprintf(hdlen, ", H%c=%u", dirletter[(int) fsg->data_dir],
  37181. + fsg->data_size);
  37182. + VDBG(fsg, "SCSI command: %s; Dc=%d, D%c=%u; Hc=%d%s\n",
  37183. + name, cmnd_size, dirletter[(int) data_dir],
  37184. + fsg->data_size_from_cmnd, fsg->cmnd_size, hdlen);
  37185. +
  37186. + /* We can't reply at all until we know the correct data direction
  37187. + * and size. */
  37188. + if (fsg->data_size_from_cmnd == 0)
  37189. + data_dir = DATA_DIR_NONE;
  37190. + if (fsg->data_dir == DATA_DIR_UNKNOWN) { // CB or CBI
  37191. + fsg->data_dir = data_dir;
  37192. + fsg->data_size = fsg->data_size_from_cmnd;
  37193. +
  37194. + } else { // Bulk-only
  37195. + if (fsg->data_size < fsg->data_size_from_cmnd) {
  37196. +
  37197. + /* Host data size < Device data size is a phase error.
  37198. + * Carry out the command, but only transfer as much
  37199. + * as we are allowed. */
  37200. + fsg->data_size_from_cmnd = fsg->data_size;
  37201. + fsg->phase_error = 1;
  37202. + }
  37203. + }
  37204. + fsg->residue = fsg->usb_amount_left = fsg->data_size;
  37205. +
  37206. + /* Conflicting data directions is a phase error */
  37207. + if (fsg->data_dir != data_dir && fsg->data_size_from_cmnd > 0) {
  37208. + fsg->phase_error = 1;
  37209. + return -EINVAL;
  37210. + }
  37211. +
  37212. + /* Verify the length of the command itself */
  37213. + if (cmnd_size != fsg->cmnd_size) {
  37214. +
  37215. + /* Special case workaround: There are plenty of buggy SCSI
  37216. + * implementations. Many have issues with cbw->Length
  37217. + * field passing a wrong command size. For those cases we
  37218. + * always try to work around the problem by using the length
  37219. + * sent by the host side provided it is at least as large
  37220. + * as the correct command length.
  37221. + * Examples of such cases would be MS-Windows, which issues
  37222. + * REQUEST SENSE with cbw->Length == 12 where it should
  37223. + * be 6, and xbox360 issuing INQUIRY, TEST UNIT READY and
  37224. + * REQUEST SENSE with cbw->Length == 10 where it should
  37225. + * be 6 as well.
  37226. + */
  37227. + if (cmnd_size <= fsg->cmnd_size) {
  37228. + DBG(fsg, "%s is buggy! Expected length %d "
  37229. + "but we got %d\n", name,
  37230. + cmnd_size, fsg->cmnd_size);
  37231. + cmnd_size = fsg->cmnd_size;
  37232. + } else {
  37233. + fsg->phase_error = 1;
  37234. + return -EINVAL;
  37235. + }
  37236. + }
  37237. +
  37238. + /* Check that the LUN values are consistent */
  37239. + if (transport_is_bbb()) {
  37240. + if (fsg->lun != lun)
  37241. + DBG(fsg, "using LUN %d from CBW, "
  37242. + "not LUN %d from CDB\n",
  37243. + fsg->lun, lun);
  37244. + }
  37245. +
  37246. + /* Check the LUN */
  37247. + curlun = fsg->curlun;
  37248. + if (curlun) {
  37249. + if (fsg->cmnd[0] != REQUEST_SENSE) {
  37250. + curlun->sense_data = SS_NO_SENSE;
  37251. + curlun->sense_data_info = 0;
  37252. + curlun->info_valid = 0;
  37253. + }
  37254. + } else {
  37255. + fsg->bad_lun_okay = 0;
  37256. +
  37257. + /* INQUIRY and REQUEST SENSE commands are explicitly allowed
  37258. + * to use unsupported LUNs; all others may not. */
  37259. + if (fsg->cmnd[0] != INQUIRY &&
  37260. + fsg->cmnd[0] != REQUEST_SENSE) {
  37261. + DBG(fsg, "unsupported LUN %d\n", fsg->lun);
  37262. + return -EINVAL;
  37263. + }
  37264. + }
  37265. +
  37266. + /* If a unit attention condition exists, only INQUIRY and
  37267. + * REQUEST SENSE commands are allowed; anything else must fail. */
  37268. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE &&
  37269. + fsg->cmnd[0] != INQUIRY &&
  37270. + fsg->cmnd[0] != REQUEST_SENSE) {
  37271. + curlun->sense_data = curlun->unit_attention_data;
  37272. + curlun->unit_attention_data = SS_NO_SENSE;
  37273. + return -EINVAL;
  37274. + }
  37275. +
  37276. + /* Check that only command bytes listed in the mask are non-zero */
  37277. + fsg->cmnd[1] &= 0x1f; // Mask away the LUN
  37278. + for (i = 1; i < cmnd_size; ++i) {
  37279. + if (fsg->cmnd[i] && !(mask & (1 << i))) {
  37280. + if (curlun)
  37281. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  37282. + return -EINVAL;
  37283. + }
  37284. + }
  37285. +
  37286. + /* If the medium isn't mounted and the command needs to access
  37287. + * it, return an error. */
  37288. + if (curlun && !fsg_lun_is_open(curlun) && needs_medium) {
  37289. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  37290. + return -EINVAL;
  37291. + }
  37292. +
  37293. + return 0;
  37294. +}
  37295. +
  37296. +/* wrapper of check_command for data size in blocks handling */
  37297. +static int check_command_size_in_blocks(struct fsg_dev *fsg, int cmnd_size,
  37298. + enum data_direction data_dir, unsigned int mask,
  37299. + int needs_medium, const char *name)
  37300. +{
  37301. + if (fsg->curlun)
  37302. + fsg->data_size_from_cmnd <<= fsg->curlun->blkbits;
  37303. + return check_command(fsg, cmnd_size, data_dir,
  37304. + mask, needs_medium, name);
  37305. +}
  37306. +
  37307. +static int do_scsi_command(struct fsg_dev *fsg)
  37308. +{
  37309. + struct fsg_buffhd *bh;
  37310. + int rc;
  37311. + int reply = -EINVAL;
  37312. + int i;
  37313. + static char unknown[16];
  37314. +
  37315. + dump_cdb(fsg);
  37316. +
  37317. + /* Wait for the next buffer to become available for data or status */
  37318. + bh = fsg->next_buffhd_to_drain = fsg->next_buffhd_to_fill;
  37319. + while (bh->state != BUF_STATE_EMPTY) {
  37320. + rc = sleep_thread(fsg);
  37321. + if (rc)
  37322. + return rc;
  37323. + }
  37324. + fsg->phase_error = 0;
  37325. + fsg->short_packet_received = 0;
  37326. +
  37327. + down_read(&fsg->filesem); // We're using the backing file
  37328. + switch (fsg->cmnd[0]) {
  37329. +
  37330. + case INQUIRY:
  37331. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  37332. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  37333. + (1<<4), 0,
  37334. + "INQUIRY")) == 0)
  37335. + reply = do_inquiry(fsg, bh);
  37336. + break;
  37337. +
  37338. + case MODE_SELECT:
  37339. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  37340. + if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST,
  37341. + (1<<1) | (1<<4), 0,
  37342. + "MODE SELECT(6)")) == 0)
  37343. + reply = do_mode_select(fsg, bh);
  37344. + break;
  37345. +
  37346. + case MODE_SELECT_10:
  37347. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37348. + if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST,
  37349. + (1<<1) | (3<<7), 0,
  37350. + "MODE SELECT(10)")) == 0)
  37351. + reply = do_mode_select(fsg, bh);
  37352. + break;
  37353. +
  37354. + case MODE_SENSE:
  37355. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  37356. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  37357. + (1<<1) | (1<<2) | (1<<4), 0,
  37358. + "MODE SENSE(6)")) == 0)
  37359. + reply = do_mode_sense(fsg, bh);
  37360. + break;
  37361. +
  37362. + case MODE_SENSE_10:
  37363. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37364. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37365. + (1<<1) | (1<<2) | (3<<7), 0,
  37366. + "MODE SENSE(10)")) == 0)
  37367. + reply = do_mode_sense(fsg, bh);
  37368. + break;
  37369. +
  37370. + case ALLOW_MEDIUM_REMOVAL:
  37371. + fsg->data_size_from_cmnd = 0;
  37372. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  37373. + (1<<4), 0,
  37374. + "PREVENT-ALLOW MEDIUM REMOVAL")) == 0)
  37375. + reply = do_prevent_allow(fsg);
  37376. + break;
  37377. +
  37378. + case READ_6:
  37379. + i = fsg->cmnd[4];
  37380. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  37381. + if ((reply = check_command_size_in_blocks(fsg, 6,
  37382. + DATA_DIR_TO_HOST,
  37383. + (7<<1) | (1<<4), 1,
  37384. + "READ(6)")) == 0)
  37385. + reply = do_read(fsg);
  37386. + break;
  37387. +
  37388. + case READ_10:
  37389. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37390. + if ((reply = check_command_size_in_blocks(fsg, 10,
  37391. + DATA_DIR_TO_HOST,
  37392. + (1<<1) | (0xf<<2) | (3<<7), 1,
  37393. + "READ(10)")) == 0)
  37394. + reply = do_read(fsg);
  37395. + break;
  37396. +
  37397. + case READ_12:
  37398. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  37399. + if ((reply = check_command_size_in_blocks(fsg, 12,
  37400. + DATA_DIR_TO_HOST,
  37401. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  37402. + "READ(12)")) == 0)
  37403. + reply = do_read(fsg);
  37404. + break;
  37405. +
  37406. + case READ_CAPACITY:
  37407. + fsg->data_size_from_cmnd = 8;
  37408. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37409. + (0xf<<2) | (1<<8), 1,
  37410. + "READ CAPACITY")) == 0)
  37411. + reply = do_read_capacity(fsg, bh);
  37412. + break;
  37413. +
  37414. + case READ_HEADER:
  37415. + if (!mod_data.cdrom)
  37416. + goto unknown_cmnd;
  37417. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37418. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37419. + (3<<7) | (0x1f<<1), 1,
  37420. + "READ HEADER")) == 0)
  37421. + reply = do_read_header(fsg, bh);
  37422. + break;
  37423. +
  37424. + case READ_TOC:
  37425. + if (!mod_data.cdrom)
  37426. + goto unknown_cmnd;
  37427. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37428. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37429. + (7<<6) | (1<<1), 1,
  37430. + "READ TOC")) == 0)
  37431. + reply = do_read_toc(fsg, bh);
  37432. + break;
  37433. +
  37434. + case READ_FORMAT_CAPACITIES:
  37435. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37436. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37437. + (3<<7), 1,
  37438. + "READ FORMAT CAPACITIES")) == 0)
  37439. + reply = do_read_format_capacities(fsg, bh);
  37440. + break;
  37441. +
  37442. + case REQUEST_SENSE:
  37443. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  37444. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  37445. + (1<<4), 0,
  37446. + "REQUEST SENSE")) == 0)
  37447. + reply = do_request_sense(fsg, bh);
  37448. + break;
  37449. +
  37450. + case START_STOP:
  37451. + fsg->data_size_from_cmnd = 0;
  37452. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  37453. + (1<<1) | (1<<4), 0,
  37454. + "START-STOP UNIT")) == 0)
  37455. + reply = do_start_stop(fsg);
  37456. + break;
  37457. +
  37458. + case SYNCHRONIZE_CACHE:
  37459. + fsg->data_size_from_cmnd = 0;
  37460. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  37461. + (0xf<<2) | (3<<7), 1,
  37462. + "SYNCHRONIZE CACHE")) == 0)
  37463. + reply = do_synchronize_cache(fsg);
  37464. + break;
  37465. +
  37466. + case TEST_UNIT_READY:
  37467. + fsg->data_size_from_cmnd = 0;
  37468. + reply = check_command(fsg, 6, DATA_DIR_NONE,
  37469. + 0, 1,
  37470. + "TEST UNIT READY");
  37471. + break;
  37472. +
  37473. + /* Although optional, this command is used by MS-Windows. We
  37474. + * support a minimal version: BytChk must be 0. */
  37475. + case VERIFY:
  37476. + fsg->data_size_from_cmnd = 0;
  37477. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  37478. + (1<<1) | (0xf<<2) | (3<<7), 1,
  37479. + "VERIFY")) == 0)
  37480. + reply = do_verify(fsg);
  37481. + break;
  37482. +
  37483. + case WRITE_6:
  37484. + i = fsg->cmnd[4];
  37485. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  37486. + if ((reply = check_command_size_in_blocks(fsg, 6,
  37487. + DATA_DIR_FROM_HOST,
  37488. + (7<<1) | (1<<4), 1,
  37489. + "WRITE(6)")) == 0)
  37490. + reply = do_write(fsg);
  37491. + break;
  37492. +
  37493. + case WRITE_10:
  37494. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37495. + if ((reply = check_command_size_in_blocks(fsg, 10,
  37496. + DATA_DIR_FROM_HOST,
  37497. + (1<<1) | (0xf<<2) | (3<<7), 1,
  37498. + "WRITE(10)")) == 0)
  37499. + reply = do_write(fsg);
  37500. + break;
  37501. +
  37502. + case WRITE_12:
  37503. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  37504. + if ((reply = check_command_size_in_blocks(fsg, 12,
  37505. + DATA_DIR_FROM_HOST,
  37506. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  37507. + "WRITE(12)")) == 0)
  37508. + reply = do_write(fsg);
  37509. + break;
  37510. +
  37511. + /* Some mandatory commands that we recognize but don't implement.
  37512. + * They don't mean much in this setting. It's left as an exercise
  37513. + * for anyone interested to implement RESERVE and RELEASE in terms
  37514. + * of Posix locks. */
  37515. + case FORMAT_UNIT:
  37516. + case RELEASE:
  37517. + case RESERVE:
  37518. + case SEND_DIAGNOSTIC:
  37519. + // Fall through
  37520. +
  37521. + default:
  37522. + unknown_cmnd:
  37523. + fsg->data_size_from_cmnd = 0;
  37524. + sprintf(unknown, "Unknown x%02x", fsg->cmnd[0]);
  37525. + if ((reply = check_command(fsg, fsg->cmnd_size,
  37526. + DATA_DIR_UNKNOWN, ~0, 0, unknown)) == 0) {
  37527. + fsg->curlun->sense_data = SS_INVALID_COMMAND;
  37528. + reply = -EINVAL;
  37529. + }
  37530. + break;
  37531. + }
  37532. + up_read(&fsg->filesem);
  37533. +
  37534. + if (reply == -EINTR || signal_pending(current))
  37535. + return -EINTR;
  37536. +
  37537. + /* Set up the single reply buffer for finish_reply() */
  37538. + if (reply == -EINVAL)
  37539. + reply = 0; // Error reply length
  37540. + if (reply >= 0 && fsg->data_dir == DATA_DIR_TO_HOST) {
  37541. + reply = min((u32) reply, fsg->data_size_from_cmnd);
  37542. + bh->inreq->length = reply;
  37543. + bh->state = BUF_STATE_FULL;
  37544. + fsg->residue -= reply;
  37545. + } // Otherwise it's already set
  37546. +
  37547. + return 0;
  37548. +}
  37549. +
  37550. +
  37551. +/*-------------------------------------------------------------------------*/
  37552. +
  37553. +static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37554. +{
  37555. + struct usb_request *req = bh->outreq;
  37556. + struct bulk_cb_wrap *cbw = req->buf;
  37557. +
  37558. + /* Was this a real packet? Should it be ignored? */
  37559. + if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  37560. + return -EINVAL;
  37561. +
  37562. + /* Is the CBW valid? */
  37563. + if (req->actual != US_BULK_CB_WRAP_LEN ||
  37564. + cbw->Signature != cpu_to_le32(
  37565. + US_BULK_CB_SIGN)) {
  37566. + DBG(fsg, "invalid CBW: len %u sig 0x%x\n",
  37567. + req->actual,
  37568. + le32_to_cpu(cbw->Signature));
  37569. +
  37570. + /* The Bulk-only spec says we MUST stall the IN endpoint
  37571. + * (6.6.1), so it's unavoidable. It also says we must
  37572. + * retain this state until the next reset, but there's
  37573. + * no way to tell the controller driver it should ignore
  37574. + * Clear-Feature(HALT) requests.
  37575. + *
  37576. + * We aren't required to halt the OUT endpoint; instead
  37577. + * we can simply accept and discard any data received
  37578. + * until the next reset. */
  37579. + wedge_bulk_in_endpoint(fsg);
  37580. + set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  37581. + return -EINVAL;
  37582. + }
  37583. +
  37584. + /* Is the CBW meaningful? */
  37585. + if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~US_BULK_FLAG_IN ||
  37586. + cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
  37587. + DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
  37588. + "cmdlen %u\n",
  37589. + cbw->Lun, cbw->Flags, cbw->Length);
  37590. +
  37591. + /* We can do anything we want here, so let's stall the
  37592. + * bulk pipes if we are allowed to. */
  37593. + if (mod_data.can_stall) {
  37594. + fsg_set_halt(fsg, fsg->bulk_out);
  37595. + halt_bulk_in_endpoint(fsg);
  37596. + }
  37597. + return -EINVAL;
  37598. + }
  37599. +
  37600. + /* Save the command for later */
  37601. + fsg->cmnd_size = cbw->Length;
  37602. + memcpy(fsg->cmnd, cbw->CDB, fsg->cmnd_size);
  37603. + if (cbw->Flags & US_BULK_FLAG_IN)
  37604. + fsg->data_dir = DATA_DIR_TO_HOST;
  37605. + else
  37606. + fsg->data_dir = DATA_DIR_FROM_HOST;
  37607. + fsg->data_size = le32_to_cpu(cbw->DataTransferLength);
  37608. + if (fsg->data_size == 0)
  37609. + fsg->data_dir = DATA_DIR_NONE;
  37610. + fsg->lun = cbw->Lun;
  37611. + fsg->tag = cbw->Tag;
  37612. + return 0;
  37613. +}
  37614. +
  37615. +
  37616. +static int get_next_command(struct fsg_dev *fsg)
  37617. +{
  37618. + struct fsg_buffhd *bh;
  37619. + int rc = 0;
  37620. +
  37621. + if (transport_is_bbb()) {
  37622. +
  37623. + /* Wait for the next buffer to become available */
  37624. + bh = fsg->next_buffhd_to_fill;
  37625. + while (bh->state != BUF_STATE_EMPTY) {
  37626. + rc = sleep_thread(fsg);
  37627. + if (rc)
  37628. + return rc;
  37629. + }
  37630. +
  37631. + /* Queue a request to read a Bulk-only CBW */
  37632. + set_bulk_out_req_length(fsg, bh, US_BULK_CB_WRAP_LEN);
  37633. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  37634. + &bh->outreq_busy, &bh->state);
  37635. +
  37636. + /* We will drain the buffer in software, which means we
  37637. + * can reuse it for the next filling. No need to advance
  37638. + * next_buffhd_to_fill. */
  37639. +
  37640. + /* Wait for the CBW to arrive */
  37641. + while (bh->state != BUF_STATE_FULL) {
  37642. + rc = sleep_thread(fsg);
  37643. + if (rc)
  37644. + return rc;
  37645. + }
  37646. + smp_rmb();
  37647. + rc = received_cbw(fsg, bh);
  37648. + bh->state = BUF_STATE_EMPTY;
  37649. +
  37650. + } else { // USB_PR_CB or USB_PR_CBI
  37651. +
  37652. + /* Wait for the next command to arrive */
  37653. + while (fsg->cbbuf_cmnd_size == 0) {
  37654. + rc = sleep_thread(fsg);
  37655. + if (rc)
  37656. + return rc;
  37657. + }
  37658. +
  37659. + /* Is the previous status interrupt request still busy?
  37660. + * The host is allowed to skip reading the status,
  37661. + * so we must cancel it. */
  37662. + if (fsg->intreq_busy)
  37663. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  37664. +
  37665. + /* Copy the command and mark the buffer empty */
  37666. + fsg->data_dir = DATA_DIR_UNKNOWN;
  37667. + spin_lock_irq(&fsg->lock);
  37668. + fsg->cmnd_size = fsg->cbbuf_cmnd_size;
  37669. + memcpy(fsg->cmnd, fsg->cbbuf_cmnd, fsg->cmnd_size);
  37670. + fsg->cbbuf_cmnd_size = 0;
  37671. + spin_unlock_irq(&fsg->lock);
  37672. +
  37673. + /* Use LUN from the command */
  37674. + fsg->lun = fsg->cmnd[1] >> 5;
  37675. + }
  37676. +
  37677. + /* Update current lun */
  37678. + if (fsg->lun >= 0 && fsg->lun < fsg->nluns)
  37679. + fsg->curlun = &fsg->luns[fsg->lun];
  37680. + else
  37681. + fsg->curlun = NULL;
  37682. +
  37683. + return rc;
  37684. +}
  37685. +
  37686. +
  37687. +/*-------------------------------------------------------------------------*/
  37688. +
  37689. +static int enable_endpoint(struct fsg_dev *fsg, struct usb_ep *ep,
  37690. + const struct usb_endpoint_descriptor *d)
  37691. +{
  37692. + int rc;
  37693. +
  37694. + ep->driver_data = fsg;
  37695. + ep->desc = d;
  37696. + rc = usb_ep_enable(ep);
  37697. + if (rc)
  37698. + ERROR(fsg, "can't enable %s, result %d\n", ep->name, rc);
  37699. + return rc;
  37700. +}
  37701. +
  37702. +static int alloc_request(struct fsg_dev *fsg, struct usb_ep *ep,
  37703. + struct usb_request **preq)
  37704. +{
  37705. + *preq = usb_ep_alloc_request(ep, GFP_ATOMIC);
  37706. + if (*preq)
  37707. + return 0;
  37708. + ERROR(fsg, "can't allocate request for %s\n", ep->name);
  37709. + return -ENOMEM;
  37710. +}
  37711. +
  37712. +/*
  37713. + * Reset interface setting and re-init endpoint state (toggle etc).
  37714. + * Call with altsetting < 0 to disable the interface. The only other
  37715. + * available altsetting is 0, which enables the interface.
  37716. + */
  37717. +static int do_set_interface(struct fsg_dev *fsg, int altsetting)
  37718. +{
  37719. + int rc = 0;
  37720. + int i;
  37721. + const struct usb_endpoint_descriptor *d;
  37722. +
  37723. + if (fsg->running)
  37724. + DBG(fsg, "reset interface\n");
  37725. +
  37726. +reset:
  37727. + /* Deallocate the requests */
  37728. + for (i = 0; i < fsg_num_buffers; ++i) {
  37729. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  37730. +
  37731. + if (bh->inreq) {
  37732. + usb_ep_free_request(fsg->bulk_in, bh->inreq);
  37733. + bh->inreq = NULL;
  37734. + }
  37735. + if (bh->outreq) {
  37736. + usb_ep_free_request(fsg->bulk_out, bh->outreq);
  37737. + bh->outreq = NULL;
  37738. + }
  37739. + }
  37740. + if (fsg->intreq) {
  37741. + usb_ep_free_request(fsg->intr_in, fsg->intreq);
  37742. + fsg->intreq = NULL;
  37743. + }
  37744. +
  37745. + /* Disable the endpoints */
  37746. + if (fsg->bulk_in_enabled) {
  37747. + usb_ep_disable(fsg->bulk_in);
  37748. + fsg->bulk_in_enabled = 0;
  37749. + }
  37750. + if (fsg->bulk_out_enabled) {
  37751. + usb_ep_disable(fsg->bulk_out);
  37752. + fsg->bulk_out_enabled = 0;
  37753. + }
  37754. + if (fsg->intr_in_enabled) {
  37755. + usb_ep_disable(fsg->intr_in);
  37756. + fsg->intr_in_enabled = 0;
  37757. + }
  37758. +
  37759. + fsg->running = 0;
  37760. + if (altsetting < 0 || rc != 0)
  37761. + return rc;
  37762. +
  37763. + DBG(fsg, "set interface %d\n", altsetting);
  37764. +
  37765. + /* Enable the endpoints */
  37766. + d = fsg_ep_desc(fsg->gadget,
  37767. + &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc,
  37768. + &fsg_ss_bulk_in_desc);
  37769. + if ((rc = enable_endpoint(fsg, fsg->bulk_in, d)) != 0)
  37770. + goto reset;
  37771. + fsg->bulk_in_enabled = 1;
  37772. +
  37773. + d = fsg_ep_desc(fsg->gadget,
  37774. + &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc,
  37775. + &fsg_ss_bulk_out_desc);
  37776. + if ((rc = enable_endpoint(fsg, fsg->bulk_out, d)) != 0)
  37777. + goto reset;
  37778. + fsg->bulk_out_enabled = 1;
  37779. + fsg->bulk_out_maxpacket = usb_endpoint_maxp(d);
  37780. + clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  37781. +
  37782. + if (transport_is_cbi()) {
  37783. + d = fsg_ep_desc(fsg->gadget,
  37784. + &fsg_fs_intr_in_desc, &fsg_hs_intr_in_desc,
  37785. + &fsg_ss_intr_in_desc);
  37786. + if ((rc = enable_endpoint(fsg, fsg->intr_in, d)) != 0)
  37787. + goto reset;
  37788. + fsg->intr_in_enabled = 1;
  37789. + }
  37790. +
  37791. + /* Allocate the requests */
  37792. + for (i = 0; i < fsg_num_buffers; ++i) {
  37793. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  37794. +
  37795. + if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0)
  37796. + goto reset;
  37797. + if ((rc = alloc_request(fsg, fsg->bulk_out, &bh->outreq)) != 0)
  37798. + goto reset;
  37799. + bh->inreq->buf = bh->outreq->buf = bh->buf;
  37800. + bh->inreq->context = bh->outreq->context = bh;
  37801. + bh->inreq->complete = bulk_in_complete;
  37802. + bh->outreq->complete = bulk_out_complete;
  37803. + }
  37804. + if (transport_is_cbi()) {
  37805. + if ((rc = alloc_request(fsg, fsg->intr_in, &fsg->intreq)) != 0)
  37806. + goto reset;
  37807. + fsg->intreq->complete = intr_in_complete;
  37808. + }
  37809. +
  37810. + fsg->running = 1;
  37811. + for (i = 0; i < fsg->nluns; ++i)
  37812. + fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  37813. + return rc;
  37814. +}
  37815. +
  37816. +
  37817. +/*
  37818. + * Change our operational configuration. This code must agree with the code
  37819. + * that returns config descriptors, and with interface altsetting code.
  37820. + *
  37821. + * It's also responsible for power management interactions. Some
  37822. + * configurations might not work with our current power sources.
  37823. + * For now we just assume the gadget is always self-powered.
  37824. + */
  37825. +static int do_set_config(struct fsg_dev *fsg, u8 new_config)
  37826. +{
  37827. + int rc = 0;
  37828. +
  37829. + /* Disable the single interface */
  37830. + if (fsg->config != 0) {
  37831. + DBG(fsg, "reset config\n");
  37832. + fsg->config = 0;
  37833. + rc = do_set_interface(fsg, -1);
  37834. + }
  37835. +
  37836. + /* Enable the interface */
  37837. + if (new_config != 0) {
  37838. + fsg->config = new_config;
  37839. + if ((rc = do_set_interface(fsg, 0)) != 0)
  37840. + fsg->config = 0; // Reset on errors
  37841. + else
  37842. + INFO(fsg, "%s config #%d\n",
  37843. + usb_speed_string(fsg->gadget->speed),
  37844. + fsg->config);
  37845. + }
  37846. + return rc;
  37847. +}
  37848. +
  37849. +
  37850. +/*-------------------------------------------------------------------------*/
  37851. +
  37852. +static void handle_exception(struct fsg_dev *fsg)
  37853. +{
  37854. + siginfo_t info;
  37855. + int sig;
  37856. + int i;
  37857. + int num_active;
  37858. + struct fsg_buffhd *bh;
  37859. + enum fsg_state old_state;
  37860. + u8 new_config;
  37861. + struct fsg_lun *curlun;
  37862. + unsigned int exception_req_tag;
  37863. + int rc;
  37864. +
  37865. + /* Clear the existing signals. Anything but SIGUSR1 is converted
  37866. + * into a high-priority EXIT exception. */
  37867. + for (;;) {
  37868. + sig = dequeue_signal_lock(current, &current->blocked, &info);
  37869. + if (!sig)
  37870. + break;
  37871. + if (sig != SIGUSR1) {
  37872. + if (fsg->state < FSG_STATE_EXIT)
  37873. + DBG(fsg, "Main thread exiting on signal\n");
  37874. + raise_exception(fsg, FSG_STATE_EXIT);
  37875. + }
  37876. + }
  37877. +
  37878. + /* Cancel all the pending transfers */
  37879. + if (fsg->intreq_busy)
  37880. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  37881. + for (i = 0; i < fsg_num_buffers; ++i) {
  37882. + bh = &fsg->buffhds[i];
  37883. + if (bh->inreq_busy)
  37884. + usb_ep_dequeue(fsg->bulk_in, bh->inreq);
  37885. + if (bh->outreq_busy)
  37886. + usb_ep_dequeue(fsg->bulk_out, bh->outreq);
  37887. + }
  37888. +
  37889. + /* Wait until everything is idle */
  37890. + for (;;) {
  37891. + num_active = fsg->intreq_busy;
  37892. + for (i = 0; i < fsg_num_buffers; ++i) {
  37893. + bh = &fsg->buffhds[i];
  37894. + num_active += bh->inreq_busy + bh->outreq_busy;
  37895. + }
  37896. + if (num_active == 0)
  37897. + break;
  37898. + if (sleep_thread(fsg))
  37899. + return;
  37900. + }
  37901. +
  37902. + /* Clear out the controller's fifos */
  37903. + if (fsg->bulk_in_enabled)
  37904. + usb_ep_fifo_flush(fsg->bulk_in);
  37905. + if (fsg->bulk_out_enabled)
  37906. + usb_ep_fifo_flush(fsg->bulk_out);
  37907. + if (fsg->intr_in_enabled)
  37908. + usb_ep_fifo_flush(fsg->intr_in);
  37909. +
  37910. + /* Reset the I/O buffer states and pointers, the SCSI
  37911. + * state, and the exception. Then invoke the handler. */
  37912. + spin_lock_irq(&fsg->lock);
  37913. +
  37914. + for (i = 0; i < fsg_num_buffers; ++i) {
  37915. + bh = &fsg->buffhds[i];
  37916. + bh->state = BUF_STATE_EMPTY;
  37917. + }
  37918. + fsg->next_buffhd_to_fill = fsg->next_buffhd_to_drain =
  37919. + &fsg->buffhds[0];
  37920. +
  37921. + exception_req_tag = fsg->exception_req_tag;
  37922. + new_config = fsg->new_config;
  37923. + old_state = fsg->state;
  37924. +
  37925. + if (old_state == FSG_STATE_ABORT_BULK_OUT)
  37926. + fsg->state = FSG_STATE_STATUS_PHASE;
  37927. + else {
  37928. + for (i = 0; i < fsg->nluns; ++i) {
  37929. + curlun = &fsg->luns[i];
  37930. + curlun->prevent_medium_removal = 0;
  37931. + curlun->sense_data = curlun->unit_attention_data =
  37932. + SS_NO_SENSE;
  37933. + curlun->sense_data_info = 0;
  37934. + curlun->info_valid = 0;
  37935. + }
  37936. + fsg->state = FSG_STATE_IDLE;
  37937. + }
  37938. + spin_unlock_irq(&fsg->lock);
  37939. +
  37940. + /* Carry out any extra actions required for the exception */
  37941. + switch (old_state) {
  37942. + default:
  37943. + break;
  37944. +
  37945. + case FSG_STATE_ABORT_BULK_OUT:
  37946. + send_status(fsg);
  37947. + spin_lock_irq(&fsg->lock);
  37948. + if (fsg->state == FSG_STATE_STATUS_PHASE)
  37949. + fsg->state = FSG_STATE_IDLE;
  37950. + spin_unlock_irq(&fsg->lock);
  37951. + break;
  37952. +
  37953. + case FSG_STATE_RESET:
  37954. + /* In case we were forced against our will to halt a
  37955. + * bulk endpoint, clear the halt now. (The SuperH UDC
  37956. + * requires this.) */
  37957. + if (test_and_clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  37958. + usb_ep_clear_halt(fsg->bulk_in);
  37959. +
  37960. + if (transport_is_bbb()) {
  37961. + if (fsg->ep0_req_tag == exception_req_tag)
  37962. + ep0_queue(fsg); // Complete the status stage
  37963. +
  37964. + } else if (transport_is_cbi())
  37965. + send_status(fsg); // Status by interrupt pipe
  37966. +
  37967. + /* Technically this should go here, but it would only be
  37968. + * a waste of time. Ditto for the INTERFACE_CHANGE and
  37969. + * CONFIG_CHANGE cases. */
  37970. + // for (i = 0; i < fsg->nluns; ++i)
  37971. + // fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  37972. + break;
  37973. +
  37974. + case FSG_STATE_INTERFACE_CHANGE:
  37975. + rc = do_set_interface(fsg, 0);
  37976. + if (fsg->ep0_req_tag != exception_req_tag)
  37977. + break;
  37978. + if (rc != 0) // STALL on errors
  37979. + fsg_set_halt(fsg, fsg->ep0);
  37980. + else // Complete the status stage
  37981. + ep0_queue(fsg);
  37982. + break;
  37983. +
  37984. + case FSG_STATE_CONFIG_CHANGE:
  37985. + rc = do_set_config(fsg, new_config);
  37986. + if (fsg->ep0_req_tag != exception_req_tag)
  37987. + break;
  37988. + if (rc != 0) // STALL on errors
  37989. + fsg_set_halt(fsg, fsg->ep0);
  37990. + else // Complete the status stage
  37991. + ep0_queue(fsg);
  37992. + break;
  37993. +
  37994. + case FSG_STATE_DISCONNECT:
  37995. + for (i = 0; i < fsg->nluns; ++i)
  37996. + fsg_lun_fsync_sub(fsg->luns + i);
  37997. + do_set_config(fsg, 0); // Unconfigured state
  37998. + break;
  37999. +
  38000. + case FSG_STATE_EXIT:
  38001. + case FSG_STATE_TERMINATED:
  38002. + do_set_config(fsg, 0); // Free resources
  38003. + spin_lock_irq(&fsg->lock);
  38004. + fsg->state = FSG_STATE_TERMINATED; // Stop the thread
  38005. + spin_unlock_irq(&fsg->lock);
  38006. + break;
  38007. + }
  38008. +}
  38009. +
  38010. +
  38011. +/*-------------------------------------------------------------------------*/
  38012. +
  38013. +static int fsg_main_thread(void *fsg_)
  38014. +{
  38015. + struct fsg_dev *fsg = fsg_;
  38016. +
  38017. + /* Allow the thread to be killed by a signal, but set the signal mask
  38018. + * to block everything but INT, TERM, KILL, and USR1. */
  38019. + allow_signal(SIGINT);
  38020. + allow_signal(SIGTERM);
  38021. + allow_signal(SIGKILL);
  38022. + allow_signal(SIGUSR1);
  38023. +
  38024. + /* Allow the thread to be frozen */
  38025. + set_freezable();
  38026. +
  38027. + /* Arrange for userspace references to be interpreted as kernel
  38028. + * pointers. That way we can pass a kernel pointer to a routine
  38029. + * that expects a __user pointer and it will work okay. */
  38030. + set_fs(get_ds());
  38031. +
  38032. + /* The main loop */
  38033. + while (fsg->state != FSG_STATE_TERMINATED) {
  38034. + if (exception_in_progress(fsg) || signal_pending(current)) {
  38035. + handle_exception(fsg);
  38036. + continue;
  38037. + }
  38038. +
  38039. + if (!fsg->running) {
  38040. + sleep_thread(fsg);
  38041. + continue;
  38042. + }
  38043. +
  38044. + if (get_next_command(fsg))
  38045. + continue;
  38046. +
  38047. + spin_lock_irq(&fsg->lock);
  38048. + if (!exception_in_progress(fsg))
  38049. + fsg->state = FSG_STATE_DATA_PHASE;
  38050. + spin_unlock_irq(&fsg->lock);
  38051. +
  38052. + if (do_scsi_command(fsg) || finish_reply(fsg))
  38053. + continue;
  38054. +
  38055. + spin_lock_irq(&fsg->lock);
  38056. + if (!exception_in_progress(fsg))
  38057. + fsg->state = FSG_STATE_STATUS_PHASE;
  38058. + spin_unlock_irq(&fsg->lock);
  38059. +
  38060. + if (send_status(fsg))
  38061. + continue;
  38062. +
  38063. + spin_lock_irq(&fsg->lock);
  38064. + if (!exception_in_progress(fsg))
  38065. + fsg->state = FSG_STATE_IDLE;
  38066. + spin_unlock_irq(&fsg->lock);
  38067. + }
  38068. +
  38069. + spin_lock_irq(&fsg->lock);
  38070. + fsg->thread_task = NULL;
  38071. + spin_unlock_irq(&fsg->lock);
  38072. +
  38073. + /* If we are exiting because of a signal, unregister the
  38074. + * gadget driver. */
  38075. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  38076. + usb_gadget_unregister_driver(&fsg_driver);
  38077. +
  38078. + /* Let the unbind and cleanup routines know the thread has exited */
  38079. + complete_and_exit(&fsg->thread_notifier, 0);
  38080. +}
  38081. +
  38082. +
  38083. +/*-------------------------------------------------------------------------*/
  38084. +
  38085. +
  38086. +/* The write permissions and store_xxx pointers are set in fsg_bind() */
  38087. +static DEVICE_ATTR(ro, 0444, fsg_show_ro, NULL);
  38088. +static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, NULL);
  38089. +static DEVICE_ATTR(file, 0444, fsg_show_file, NULL);
  38090. +
  38091. +
  38092. +/*-------------------------------------------------------------------------*/
  38093. +
  38094. +static void fsg_release(struct kref *ref)
  38095. +{
  38096. + struct fsg_dev *fsg = container_of(ref, struct fsg_dev, ref);
  38097. +
  38098. + kfree(fsg->luns);
  38099. + kfree(fsg);
  38100. +}
  38101. +
  38102. +static void lun_release(struct device *dev)
  38103. +{
  38104. + struct rw_semaphore *filesem = dev_get_drvdata(dev);
  38105. + struct fsg_dev *fsg =
  38106. + container_of(filesem, struct fsg_dev, filesem);
  38107. +
  38108. + kref_put(&fsg->ref, fsg_release);
  38109. +}
  38110. +
  38111. +static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
  38112. +{
  38113. + struct fsg_dev *fsg = get_gadget_data(gadget);
  38114. + int i;
  38115. + struct fsg_lun *curlun;
  38116. + struct usb_request *req = fsg->ep0req;
  38117. +
  38118. + DBG(fsg, "unbind\n");
  38119. + clear_bit(REGISTERED, &fsg->atomic_bitflags);
  38120. +
  38121. + /* If the thread isn't already dead, tell it to exit now */
  38122. + if (fsg->state != FSG_STATE_TERMINATED) {
  38123. + raise_exception(fsg, FSG_STATE_EXIT);
  38124. + wait_for_completion(&fsg->thread_notifier);
  38125. +
  38126. + /* The cleanup routine waits for this completion also */
  38127. + complete(&fsg->thread_notifier);
  38128. + }
  38129. +
  38130. + /* Unregister the sysfs attribute files and the LUNs */
  38131. + for (i = 0; i < fsg->nluns; ++i) {
  38132. + curlun = &fsg->luns[i];
  38133. + if (curlun->registered) {
  38134. + device_remove_file(&curlun->dev, &dev_attr_nofua);
  38135. + device_remove_file(&curlun->dev, &dev_attr_ro);
  38136. + device_remove_file(&curlun->dev, &dev_attr_file);
  38137. + fsg_lun_close(curlun);
  38138. + device_unregister(&curlun->dev);
  38139. + curlun->registered = 0;
  38140. + }
  38141. + }
  38142. +
  38143. + /* Free the data buffers */
  38144. + for (i = 0; i < fsg_num_buffers; ++i)
  38145. + kfree(fsg->buffhds[i].buf);
  38146. +
  38147. + /* Free the request and buffer for endpoint 0 */
  38148. + if (req) {
  38149. + kfree(req->buf);
  38150. + usb_ep_free_request(fsg->ep0, req);
  38151. + }
  38152. +
  38153. + set_gadget_data(gadget, NULL);
  38154. +}
  38155. +
  38156. +
  38157. +static int __init check_parameters(struct fsg_dev *fsg)
  38158. +{
  38159. + int prot;
  38160. + int gcnum;
  38161. +
  38162. + /* Store the default values */
  38163. + mod_data.transport_type = USB_PR_BULK;
  38164. + mod_data.transport_name = "Bulk-only";
  38165. + mod_data.protocol_type = USB_SC_SCSI;
  38166. + mod_data.protocol_name = "Transparent SCSI";
  38167. +
  38168. + /* Some peripheral controllers are known not to be able to
  38169. + * halt bulk endpoints correctly. If one of them is present,
  38170. + * disable stalls.
  38171. + */
  38172. + if (gadget_is_at91(fsg->gadget))
  38173. + mod_data.can_stall = 0;
  38174. +
  38175. + if (mod_data.release == 0xffff) { // Parameter wasn't set
  38176. + gcnum = usb_gadget_controller_number(fsg->gadget);
  38177. + if (gcnum >= 0)
  38178. + mod_data.release = 0x0300 + gcnum;
  38179. + else {
  38180. + WARNING(fsg, "controller '%s' not recognized\n",
  38181. + fsg->gadget->name);
  38182. + mod_data.release = 0x0399;
  38183. + }
  38184. + }
  38185. +
  38186. + prot = simple_strtol(mod_data.protocol_parm, NULL, 0);
  38187. +
  38188. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  38189. + if (strnicmp(mod_data.transport_parm, "BBB", 10) == 0) {
  38190. + ; // Use default setting
  38191. + } else if (strnicmp(mod_data.transport_parm, "CB", 10) == 0) {
  38192. + mod_data.transport_type = USB_PR_CB;
  38193. + mod_data.transport_name = "Control-Bulk";
  38194. + } else if (strnicmp(mod_data.transport_parm, "CBI", 10) == 0) {
  38195. + mod_data.transport_type = USB_PR_CBI;
  38196. + mod_data.transport_name = "Control-Bulk-Interrupt";
  38197. + } else {
  38198. + ERROR(fsg, "invalid transport: %s\n", mod_data.transport_parm);
  38199. + return -EINVAL;
  38200. + }
  38201. +
  38202. + if (strnicmp(mod_data.protocol_parm, "SCSI", 10) == 0 ||
  38203. + prot == USB_SC_SCSI) {
  38204. + ; // Use default setting
  38205. + } else if (strnicmp(mod_data.protocol_parm, "RBC", 10) == 0 ||
  38206. + prot == USB_SC_RBC) {
  38207. + mod_data.protocol_type = USB_SC_RBC;
  38208. + mod_data.protocol_name = "RBC";
  38209. + } else if (strnicmp(mod_data.protocol_parm, "8020", 4) == 0 ||
  38210. + strnicmp(mod_data.protocol_parm, "ATAPI", 10) == 0 ||
  38211. + prot == USB_SC_8020) {
  38212. + mod_data.protocol_type = USB_SC_8020;
  38213. + mod_data.protocol_name = "8020i (ATAPI)";
  38214. + } else if (strnicmp(mod_data.protocol_parm, "QIC", 3) == 0 ||
  38215. + prot == USB_SC_QIC) {
  38216. + mod_data.protocol_type = USB_SC_QIC;
  38217. + mod_data.protocol_name = "QIC-157";
  38218. + } else if (strnicmp(mod_data.protocol_parm, "UFI", 10) == 0 ||
  38219. + prot == USB_SC_UFI) {
  38220. + mod_data.protocol_type = USB_SC_UFI;
  38221. + mod_data.protocol_name = "UFI";
  38222. + } else if (strnicmp(mod_data.protocol_parm, "8070", 4) == 0 ||
  38223. + prot == USB_SC_8070) {
  38224. + mod_data.protocol_type = USB_SC_8070;
  38225. + mod_data.protocol_name = "8070i";
  38226. + } else {
  38227. + ERROR(fsg, "invalid protocol: %s\n", mod_data.protocol_parm);
  38228. + return -EINVAL;
  38229. + }
  38230. +
  38231. + mod_data.buflen &= PAGE_CACHE_MASK;
  38232. + if (mod_data.buflen <= 0) {
  38233. + ERROR(fsg, "invalid buflen\n");
  38234. + return -ETOOSMALL;
  38235. + }
  38236. +
  38237. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  38238. +
  38239. + /* Serial string handling.
  38240. + * On a real device, the serial string would be loaded
  38241. + * from permanent storage. */
  38242. + if (mod_data.serial) {
  38243. + const char *ch;
  38244. + unsigned len = 0;
  38245. +
  38246. + /* Sanity check :
  38247. + * The CB[I] specification limits the serial string to
  38248. + * 12 uppercase hexadecimal characters.
  38249. + * BBB need at least 12 uppercase hexadecimal characters,
  38250. + * with a maximum of 126. */
  38251. + for (ch = mod_data.serial; *ch; ++ch) {
  38252. + ++len;
  38253. + if ((*ch < '0' || *ch > '9') &&
  38254. + (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */
  38255. + WARNING(fsg,
  38256. + "Invalid serial string character: %c\n",
  38257. + *ch);
  38258. + goto no_serial;
  38259. + }
  38260. + }
  38261. + if (len > 126 ||
  38262. + (mod_data.transport_type == USB_PR_BULK && len < 12) ||
  38263. + (mod_data.transport_type != USB_PR_BULK && len > 12)) {
  38264. + WARNING(fsg, "Invalid serial string length!\n");
  38265. + goto no_serial;
  38266. + }
  38267. + fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial;
  38268. + } else {
  38269. + WARNING(fsg, "No serial-number string provided!\n");
  38270. + no_serial:
  38271. + device_desc.iSerialNumber = 0;
  38272. + }
  38273. +
  38274. + return 0;
  38275. +}
  38276. +
  38277. +
  38278. +static int __init fsg_bind(struct usb_gadget *gadget)
  38279. +{
  38280. + struct fsg_dev *fsg = the_fsg;
  38281. + int rc;
  38282. + int i;
  38283. + struct fsg_lun *curlun;
  38284. + struct usb_ep *ep;
  38285. + struct usb_request *req;
  38286. + char *pathbuf, *p;
  38287. +
  38288. + fsg->gadget = gadget;
  38289. + set_gadget_data(gadget, fsg);
  38290. + fsg->ep0 = gadget->ep0;
  38291. + fsg->ep0->driver_data = fsg;
  38292. +
  38293. + if ((rc = check_parameters(fsg)) != 0)
  38294. + goto out;
  38295. +
  38296. + if (mod_data.removable) { // Enable the store_xxx attributes
  38297. + dev_attr_file.attr.mode = 0644;
  38298. + dev_attr_file.store = fsg_store_file;
  38299. + if (!mod_data.cdrom) {
  38300. + dev_attr_ro.attr.mode = 0644;
  38301. + dev_attr_ro.store = fsg_store_ro;
  38302. + }
  38303. + }
  38304. +
  38305. + /* Only for removable media? */
  38306. + dev_attr_nofua.attr.mode = 0644;
  38307. + dev_attr_nofua.store = fsg_store_nofua;
  38308. +
  38309. + /* Find out how many LUNs there should be */
  38310. + i = mod_data.nluns;
  38311. + if (i == 0)
  38312. + i = max(mod_data.num_filenames, 1u);
  38313. + if (i > FSG_MAX_LUNS) {
  38314. + ERROR(fsg, "invalid number of LUNs: %d\n", i);
  38315. + rc = -EINVAL;
  38316. + goto out;
  38317. + }
  38318. +
  38319. + /* Create the LUNs, open their backing files, and register the
  38320. + * LUN devices in sysfs. */
  38321. + fsg->luns = kzalloc(i * sizeof(struct fsg_lun), GFP_KERNEL);
  38322. + if (!fsg->luns) {
  38323. + rc = -ENOMEM;
  38324. + goto out;
  38325. + }
  38326. + fsg->nluns = i;
  38327. +
  38328. + for (i = 0; i < fsg->nluns; ++i) {
  38329. + curlun = &fsg->luns[i];
  38330. + curlun->cdrom = !!mod_data.cdrom;
  38331. + curlun->ro = mod_data.cdrom || mod_data.ro[i];
  38332. + curlun->initially_ro = curlun->ro;
  38333. + curlun->removable = mod_data.removable;
  38334. + curlun->nofua = mod_data.nofua[i];
  38335. + curlun->dev.release = lun_release;
  38336. + curlun->dev.parent = &gadget->dev;
  38337. + curlun->dev.driver = &fsg_driver.driver;
  38338. + dev_set_drvdata(&curlun->dev, &fsg->filesem);
  38339. + dev_set_name(&curlun->dev,"%s-lun%d",
  38340. + dev_name(&gadget->dev), i);
  38341. +
  38342. + kref_get(&fsg->ref);
  38343. + rc = device_register(&curlun->dev);
  38344. + if (rc) {
  38345. + INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
  38346. + put_device(&curlun->dev);
  38347. + goto out;
  38348. + }
  38349. + curlun->registered = 1;
  38350. +
  38351. + rc = device_create_file(&curlun->dev, &dev_attr_ro);
  38352. + if (rc)
  38353. + goto out;
  38354. + rc = device_create_file(&curlun->dev, &dev_attr_nofua);
  38355. + if (rc)
  38356. + goto out;
  38357. + rc = device_create_file(&curlun->dev, &dev_attr_file);
  38358. + if (rc)
  38359. + goto out;
  38360. +
  38361. + if (mod_data.file[i] && *mod_data.file[i]) {
  38362. + rc = fsg_lun_open(curlun, mod_data.file[i]);
  38363. + if (rc)
  38364. + goto out;
  38365. + } else if (!mod_data.removable) {
  38366. + ERROR(fsg, "no file given for LUN%d\n", i);
  38367. + rc = -EINVAL;
  38368. + goto out;
  38369. + }
  38370. + }
  38371. +
  38372. + /* Find all the endpoints we will use */
  38373. + usb_ep_autoconfig_reset(gadget);
  38374. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_in_desc);
  38375. + if (!ep)
  38376. + goto autoconf_fail;
  38377. + ep->driver_data = fsg; // claim the endpoint
  38378. + fsg->bulk_in = ep;
  38379. +
  38380. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_out_desc);
  38381. + if (!ep)
  38382. + goto autoconf_fail;
  38383. + ep->driver_data = fsg; // claim the endpoint
  38384. + fsg->bulk_out = ep;
  38385. +
  38386. + if (transport_is_cbi()) {
  38387. + ep = usb_ep_autoconfig(gadget, &fsg_fs_intr_in_desc);
  38388. + if (!ep)
  38389. + goto autoconf_fail;
  38390. + ep->driver_data = fsg; // claim the endpoint
  38391. + fsg->intr_in = ep;
  38392. + }
  38393. +
  38394. + /* Fix up the descriptors */
  38395. + device_desc.idVendor = cpu_to_le16(mod_data.vendor);
  38396. + device_desc.idProduct = cpu_to_le16(mod_data.product);
  38397. + device_desc.bcdDevice = cpu_to_le16(mod_data.release);
  38398. +
  38399. + i = (transport_is_cbi() ? 3 : 2); // Number of endpoints
  38400. + fsg_intf_desc.bNumEndpoints = i;
  38401. + fsg_intf_desc.bInterfaceSubClass = mod_data.protocol_type;
  38402. + fsg_intf_desc.bInterfaceProtocol = mod_data.transport_type;
  38403. + fsg_fs_function[i + FSG_FS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  38404. +
  38405. + if (gadget_is_dualspeed(gadget)) {
  38406. + fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  38407. +
  38408. + /* Assume endpoint addresses are the same for both speeds */
  38409. + fsg_hs_bulk_in_desc.bEndpointAddress =
  38410. + fsg_fs_bulk_in_desc.bEndpointAddress;
  38411. + fsg_hs_bulk_out_desc.bEndpointAddress =
  38412. + fsg_fs_bulk_out_desc.bEndpointAddress;
  38413. + fsg_hs_intr_in_desc.bEndpointAddress =
  38414. + fsg_fs_intr_in_desc.bEndpointAddress;
  38415. + }
  38416. +
  38417. + if (gadget_is_superspeed(gadget)) {
  38418. + unsigned max_burst;
  38419. +
  38420. + fsg_ss_function[i + FSG_SS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  38421. +
  38422. + /* Calculate bMaxBurst, we know packet size is 1024 */
  38423. + max_burst = min_t(unsigned, mod_data.buflen / 1024, 15);
  38424. +
  38425. + /* Assume endpoint addresses are the same for both speeds */
  38426. + fsg_ss_bulk_in_desc.bEndpointAddress =
  38427. + fsg_fs_bulk_in_desc.bEndpointAddress;
  38428. + fsg_ss_bulk_in_comp_desc.bMaxBurst = max_burst;
  38429. +
  38430. + fsg_ss_bulk_out_desc.bEndpointAddress =
  38431. + fsg_fs_bulk_out_desc.bEndpointAddress;
  38432. + fsg_ss_bulk_out_comp_desc.bMaxBurst = max_burst;
  38433. + }
  38434. +
  38435. + if (gadget_is_otg(gadget))
  38436. + fsg_otg_desc.bmAttributes |= USB_OTG_HNP;
  38437. +
  38438. + rc = -ENOMEM;
  38439. +
  38440. + /* Allocate the request and buffer for endpoint 0 */
  38441. + fsg->ep0req = req = usb_ep_alloc_request(fsg->ep0, GFP_KERNEL);
  38442. + if (!req)
  38443. + goto out;
  38444. + req->buf = kmalloc(EP0_BUFSIZE, GFP_KERNEL);
  38445. + if (!req->buf)
  38446. + goto out;
  38447. + req->complete = ep0_complete;
  38448. +
  38449. + /* Allocate the data buffers */
  38450. + for (i = 0; i < fsg_num_buffers; ++i) {
  38451. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  38452. +
  38453. + /* Allocate for the bulk-in endpoint. We assume that
  38454. + * the buffer will also work with the bulk-out (and
  38455. + * interrupt-in) endpoint. */
  38456. + bh->buf = kmalloc(mod_data.buflen, GFP_KERNEL);
  38457. + if (!bh->buf)
  38458. + goto out;
  38459. + bh->next = bh + 1;
  38460. + }
  38461. + fsg->buffhds[fsg_num_buffers - 1].next = &fsg->buffhds[0];
  38462. +
  38463. + /* This should reflect the actual gadget power source */
  38464. + usb_gadget_set_selfpowered(gadget);
  38465. +
  38466. + snprintf(fsg_string_manufacturer, sizeof fsg_string_manufacturer,
  38467. + "%s %s with %s",
  38468. + init_utsname()->sysname, init_utsname()->release,
  38469. + gadget->name);
  38470. +
  38471. + fsg->thread_task = kthread_create(fsg_main_thread, fsg,
  38472. + "file-storage-gadget");
  38473. + if (IS_ERR(fsg->thread_task)) {
  38474. + rc = PTR_ERR(fsg->thread_task);
  38475. + goto out;
  38476. + }
  38477. +
  38478. + INFO(fsg, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
  38479. + INFO(fsg, "NOTE: This driver is deprecated. "
  38480. + "Consider using g_mass_storage instead.\n");
  38481. + INFO(fsg, "Number of LUNs=%d\n", fsg->nluns);
  38482. +
  38483. + pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
  38484. + for (i = 0; i < fsg->nluns; ++i) {
  38485. + curlun = &fsg->luns[i];
  38486. + if (fsg_lun_is_open(curlun)) {
  38487. + p = NULL;
  38488. + if (pathbuf) {
  38489. + p = d_path(&curlun->filp->f_path,
  38490. + pathbuf, PATH_MAX);
  38491. + if (IS_ERR(p))
  38492. + p = NULL;
  38493. + }
  38494. + LINFO(curlun, "ro=%d, nofua=%d, file: %s\n",
  38495. + curlun->ro, curlun->nofua, (p ? p : "(error)"));
  38496. + }
  38497. + }
  38498. + kfree(pathbuf);
  38499. +
  38500. + DBG(fsg, "transport=%s (x%02x)\n",
  38501. + mod_data.transport_name, mod_data.transport_type);
  38502. + DBG(fsg, "protocol=%s (x%02x)\n",
  38503. + mod_data.protocol_name, mod_data.protocol_type);
  38504. + DBG(fsg, "VendorID=x%04x, ProductID=x%04x, Release=x%04x\n",
  38505. + mod_data.vendor, mod_data.product, mod_data.release);
  38506. + DBG(fsg, "removable=%d, stall=%d, cdrom=%d, buflen=%u\n",
  38507. + mod_data.removable, mod_data.can_stall,
  38508. + mod_data.cdrom, mod_data.buflen);
  38509. + DBG(fsg, "I/O thread pid: %d\n", task_pid_nr(fsg->thread_task));
  38510. +
  38511. + set_bit(REGISTERED, &fsg->atomic_bitflags);
  38512. +
  38513. + /* Tell the thread to start working */
  38514. + wake_up_process(fsg->thread_task);
  38515. + return 0;
  38516. +
  38517. +autoconf_fail:
  38518. + ERROR(fsg, "unable to autoconfigure all endpoints\n");
  38519. + rc = -ENOTSUPP;
  38520. +
  38521. +out:
  38522. + fsg->state = FSG_STATE_TERMINATED; // The thread is dead
  38523. + fsg_unbind(gadget);
  38524. + complete(&fsg->thread_notifier);
  38525. + return rc;
  38526. +}
  38527. +
  38528. +
  38529. +/*-------------------------------------------------------------------------*/
  38530. +
  38531. +static void fsg_suspend(struct usb_gadget *gadget)
  38532. +{
  38533. + struct fsg_dev *fsg = get_gadget_data(gadget);
  38534. +
  38535. + DBG(fsg, "suspend\n");
  38536. + set_bit(SUSPENDED, &fsg->atomic_bitflags);
  38537. +}
  38538. +
  38539. +static void fsg_resume(struct usb_gadget *gadget)
  38540. +{
  38541. + struct fsg_dev *fsg = get_gadget_data(gadget);
  38542. +
  38543. + DBG(fsg, "resume\n");
  38544. + clear_bit(SUSPENDED, &fsg->atomic_bitflags);
  38545. +}
  38546. +
  38547. +
  38548. +/*-------------------------------------------------------------------------*/
  38549. +
  38550. +static struct usb_gadget_driver fsg_driver = {
  38551. + .max_speed = USB_SPEED_SUPER,
  38552. + .function = (char *) fsg_string_product,
  38553. + .unbind = fsg_unbind,
  38554. + .disconnect = fsg_disconnect,
  38555. + .setup = fsg_setup,
  38556. + .suspend = fsg_suspend,
  38557. + .resume = fsg_resume,
  38558. +
  38559. + .driver = {
  38560. + .name = DRIVER_NAME,
  38561. + .owner = THIS_MODULE,
  38562. + // .release = ...
  38563. + // .suspend = ...
  38564. + // .resume = ...
  38565. + },
  38566. +};
  38567. +
  38568. +
  38569. +static int __init fsg_alloc(void)
  38570. +{
  38571. + struct fsg_dev *fsg;
  38572. +
  38573. + fsg = kzalloc(sizeof *fsg +
  38574. + fsg_num_buffers * sizeof *(fsg->buffhds), GFP_KERNEL);
  38575. +
  38576. + if (!fsg)
  38577. + return -ENOMEM;
  38578. + spin_lock_init(&fsg->lock);
  38579. + init_rwsem(&fsg->filesem);
  38580. + kref_init(&fsg->ref);
  38581. + init_completion(&fsg->thread_notifier);
  38582. +
  38583. + the_fsg = fsg;
  38584. + return 0;
  38585. +}
  38586. +
  38587. +
  38588. +static int __init fsg_init(void)
  38589. +{
  38590. + int rc;
  38591. + struct fsg_dev *fsg;
  38592. +
  38593. + rc = fsg_num_buffers_validate();
  38594. + if (rc != 0)
  38595. + return rc;
  38596. +
  38597. + if ((rc = fsg_alloc()) != 0)
  38598. + return rc;
  38599. + fsg = the_fsg;
  38600. + if ((rc = usb_gadget_probe_driver(&fsg_driver, fsg_bind)) != 0)
  38601. + kref_put(&fsg->ref, fsg_release);
  38602. + return rc;
  38603. +}
  38604. +module_init(fsg_init);
  38605. +
  38606. +
  38607. +static void __exit fsg_cleanup(void)
  38608. +{
  38609. + struct fsg_dev *fsg = the_fsg;
  38610. +
  38611. + /* Unregister the driver iff the thread hasn't already done so */
  38612. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  38613. + usb_gadget_unregister_driver(&fsg_driver);
  38614. +
  38615. + /* Wait for the thread to finish up */
  38616. + wait_for_completion(&fsg->thread_notifier);
  38617. +
  38618. + kref_put(&fsg->ref, fsg_release);
  38619. +}
  38620. +module_exit(fsg_cleanup);
  38621. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/changes.txt linux-3.12.11/drivers/usb/host/dwc_common_port/changes.txt
  38622. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/changes.txt 1970-01-01 01:00:00.000000000 +0100
  38623. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/changes.txt 2014-02-18 11:52:14.000000000 +0100
  38624. @@ -0,0 +1,174 @@
  38625. +
  38626. +dwc_read_reg32() and friends now take an additional parameter, a pointer to an
  38627. +IO context struct. The IO context struct should live in an os-dependent struct
  38628. +in your driver. As an example, the dwc_usb3 driver has an os-dependent struct
  38629. +named 'os_dep' embedded in the main device struct. So there these calls look
  38630. +like this:
  38631. +
  38632. + dwc_read_reg32(&usb3_dev->os_dep.ioctx, &pcd->dev_global_regs->dcfg);
  38633. +
  38634. + dwc_write_reg32(&usb3_dev->os_dep.ioctx,
  38635. + &pcd->dev_global_regs->dcfg, 0);
  38636. +
  38637. +Note that for the existing Linux driver ports, it is not necessary to actually
  38638. +define the 'ioctx' member in the os-dependent struct. Since Linux does not
  38639. +require an IO context, its macros for dwc_read_reg32() and friends do not
  38640. +use the context pointer, so it is optimized away by the compiler. But it is
  38641. +necessary to add the pointer parameter to all of the call sites, to be ready
  38642. +for any future ports (such as FreeBSD) which do require an IO context.
  38643. +
  38644. +
  38645. +Similarly, dwc_alloc(), dwc_alloc_atomic(), dwc_strdup(), and dwc_free() now
  38646. +take an additional parameter, a pointer to a memory context. Examples:
  38647. +
  38648. + addr = dwc_alloc(&usb3_dev->os_dep.memctx, size);
  38649. +
  38650. + dwc_free(&usb3_dev->os_dep.memctx, addr);
  38651. +
  38652. +Again, for the Linux ports, it is not necessary to actually define the memctx
  38653. +member, but it is necessary to add the pointer parameter to all of the call
  38654. +sites.
  38655. +
  38656. +
  38657. +Same for dwc_dma_alloc() and dwc_dma_free(). Examples:
  38658. +
  38659. + virt_addr = dwc_dma_alloc(&usb3_dev->os_dep.dmactx, size, &phys_addr);
  38660. +
  38661. + dwc_dma_free(&usb3_dev->os_dep.dmactx, size, virt_addr, phys_addr);
  38662. +
  38663. +
  38664. +Same for dwc_mutex_alloc() and dwc_mutex_free(). Examples:
  38665. +
  38666. + mutex = dwc_mutex_alloc(&usb3_dev->os_dep.mtxctx);
  38667. +
  38668. + dwc_mutex_free(&usb3_dev->os_dep.mtxctx, mutex);
  38669. +
  38670. +
  38671. +Same for dwc_spinlock_alloc() and dwc_spinlock_free(). Examples:
  38672. +
  38673. + lock = dwc_spinlock_alloc(&usb3_dev->osdep.splctx);
  38674. +
  38675. + dwc_spinlock_free(&usb3_dev->osdep.splctx, lock);
  38676. +
  38677. +
  38678. +Same for dwc_timer_alloc(). Example:
  38679. +
  38680. + timer = dwc_timer_alloc(&usb3_dev->os_dep.tmrctx, "dwc_usb3_tmr1",
  38681. + cb_func, cb_data);
  38682. +
  38683. +
  38684. +Same for dwc_waitq_alloc(). Example:
  38685. +
  38686. + waitq = dwc_waitq_alloc(&usb3_dev->os_dep.wtqctx);
  38687. +
  38688. +
  38689. +Same for dwc_thread_run(). Example:
  38690. +
  38691. + thread = dwc_thread_run(&usb3_dev->os_dep.thdctx, func,
  38692. + "dwc_usb3_thd1", data);
  38693. +
  38694. +
  38695. +Same for dwc_workq_alloc(). Example:
  38696. +
  38697. + workq = dwc_workq_alloc(&usb3_dev->osdep.wkqctx, "dwc_usb3_wkq1");
  38698. +
  38699. +
  38700. +Same for dwc_task_alloc(). Example:
  38701. +
  38702. + task = dwc_task_alloc(&usb3_dev->os_dep.tskctx, "dwc_usb3_tsk1",
  38703. + cb_func, cb_data);
  38704. +
  38705. +
  38706. +In addition to the context pointer additions, a few core functions have had
  38707. +other changes made to their parameters:
  38708. +
  38709. +The 'flags' parameter to dwc_spinlock_irqsave() and dwc_spinunlock_irqrestore()
  38710. +has been changed from a uint64_t to a dwc_irqflags_t.
  38711. +
  38712. +dwc_thread_should_stop() now takes a 'dwc_thread_t *' parameter, because the
  38713. +FreeBSD equivalent of that function requires it.
  38714. +
  38715. +And, in addition to the context pointer, dwc_task_alloc() also adds a
  38716. +'char *name' parameter, to be consistent with dwc_thread_run() and
  38717. +dwc_workq_alloc(), and because the FreeBSD equivalent of that function
  38718. +requires a unique name.
  38719. +
  38720. +
  38721. +Here is a complete list of the core functions that now take a pointer to a
  38722. +context as their first parameter:
  38723. +
  38724. + dwc_read_reg32
  38725. + dwc_read_reg64
  38726. + dwc_write_reg32
  38727. + dwc_write_reg64
  38728. + dwc_modify_reg32
  38729. + dwc_modify_reg64
  38730. + dwc_alloc
  38731. + dwc_alloc_atomic
  38732. + dwc_strdup
  38733. + dwc_free
  38734. + dwc_dma_alloc
  38735. + dwc_dma_free
  38736. + dwc_mutex_alloc
  38737. + dwc_mutex_free
  38738. + dwc_spinlock_alloc
  38739. + dwc_spinlock_free
  38740. + dwc_timer_alloc
  38741. + dwc_waitq_alloc
  38742. + dwc_thread_run
  38743. + dwc_workq_alloc
  38744. + dwc_task_alloc Also adds a 'char *name' as its 2nd parameter
  38745. +
  38746. +And here are the core functions that have other changes to their parameters:
  38747. +
  38748. + dwc_spinlock_irqsave 'flags' param is now a 'dwc_irqflags_t *'
  38749. + dwc_spinunlock_irqrestore 'flags' param is now a 'dwc_irqflags_t'
  38750. + dwc_thread_should_stop Adds a 'dwc_thread_t *' parameter
  38751. +
  38752. +
  38753. +
  38754. +The changes to the core functions also require some of the other library
  38755. +functions to change:
  38756. +
  38757. + dwc_cc_if_alloc() and dwc_cc_if_free() now take a 'void *memctx'
  38758. + (for memory allocation) as the 1st param and a 'void *mtxctx'
  38759. + (for mutex allocation) as the 2nd param.
  38760. +
  38761. + dwc_cc_clear(), dwc_cc_add(), dwc_cc_change(), dwc_cc_remove(),
  38762. + dwc_cc_data_for_save(), and dwc_cc_restore_from_data() now take a
  38763. + 'void *memctx' as the 1st param.
  38764. +
  38765. + dwc_dh_modpow(), dwc_dh_pk(), and dwc_dh_derive_keys() now take a
  38766. + 'void *memctx' as the 1st param.
  38767. +
  38768. + dwc_modpow() now takes a 'void *memctx' as the 1st param.
  38769. +
  38770. + dwc_alloc_notification_manager() now takes a 'void *memctx' as the
  38771. + 1st param and a 'void *wkqctx' (for work queue allocation) as the 2nd
  38772. + param, and also now returns an integer value that is non-zero if
  38773. + allocation of its data structures or work queue fails.
  38774. +
  38775. + dwc_register_notifier() now takes a 'void *memctx' as the 1st param.
  38776. +
  38777. + dwc_memory_debug_start() now takes a 'void *mem_ctx' as the first
  38778. + param, and also now returns an integer value that is non-zero if
  38779. + allocation of its data structures fails.
  38780. +
  38781. +
  38782. +
  38783. +Other miscellaneous changes:
  38784. +
  38785. +The DEBUG_MEMORY and DEBUG_REGS #define's have been renamed to
  38786. +DWC_DEBUG_MEMORY and DWC_DEBUG_REGS.
  38787. +
  38788. +The following #define's have been added to allow selectively compiling library
  38789. +features:
  38790. +
  38791. + DWC_CCLIB
  38792. + DWC_CRYPTOLIB
  38793. + DWC_NOTIFYLIB
  38794. + DWC_UTFLIB
  38795. +
  38796. +A DWC_LIBMODULE #define has also been added. If this is not defined, then the
  38797. +module code in dwc_common_linux.c is not compiled in. This allows linking the
  38798. +library code directly into a driver module, instead of as a standalone module.
  38799. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/doc/doxygen.cfg linux-3.12.11/drivers/usb/host/dwc_common_port/doc/doxygen.cfg
  38800. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  38801. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 2014-02-18 11:52:14.000000000 +0100
  38802. @@ -0,0 +1,270 @@
  38803. +# Doxyfile 1.4.5
  38804. +
  38805. +#---------------------------------------------------------------------------
  38806. +# Project related configuration options
  38807. +#---------------------------------------------------------------------------
  38808. +PROJECT_NAME = "Synopsys DWC Portability and Common Library for UWB"
  38809. +PROJECT_NUMBER =
  38810. +OUTPUT_DIRECTORY = doc
  38811. +CREATE_SUBDIRS = NO
  38812. +OUTPUT_LANGUAGE = English
  38813. +BRIEF_MEMBER_DESC = YES
  38814. +REPEAT_BRIEF = YES
  38815. +ABBREVIATE_BRIEF = "The $name class" \
  38816. + "The $name widget" \
  38817. + "The $name file" \
  38818. + is \
  38819. + provides \
  38820. + specifies \
  38821. + contains \
  38822. + represents \
  38823. + a \
  38824. + an \
  38825. + the
  38826. +ALWAYS_DETAILED_SEC = YES
  38827. +INLINE_INHERITED_MEMB = NO
  38828. +FULL_PATH_NAMES = NO
  38829. +STRIP_FROM_PATH = ..
  38830. +STRIP_FROM_INC_PATH =
  38831. +SHORT_NAMES = NO
  38832. +JAVADOC_AUTOBRIEF = YES
  38833. +MULTILINE_CPP_IS_BRIEF = NO
  38834. +DETAILS_AT_TOP = YES
  38835. +INHERIT_DOCS = YES
  38836. +SEPARATE_MEMBER_PAGES = NO
  38837. +TAB_SIZE = 8
  38838. +ALIASES =
  38839. +OPTIMIZE_OUTPUT_FOR_C = YES
  38840. +OPTIMIZE_OUTPUT_JAVA = NO
  38841. +BUILTIN_STL_SUPPORT = NO
  38842. +DISTRIBUTE_GROUP_DOC = NO
  38843. +SUBGROUPING = NO
  38844. +#---------------------------------------------------------------------------
  38845. +# Build related configuration options
  38846. +#---------------------------------------------------------------------------
  38847. +EXTRACT_ALL = NO
  38848. +EXTRACT_PRIVATE = NO
  38849. +EXTRACT_STATIC = YES
  38850. +EXTRACT_LOCAL_CLASSES = NO
  38851. +EXTRACT_LOCAL_METHODS = NO
  38852. +HIDE_UNDOC_MEMBERS = NO
  38853. +HIDE_UNDOC_CLASSES = NO
  38854. +HIDE_FRIEND_COMPOUNDS = NO
  38855. +HIDE_IN_BODY_DOCS = NO
  38856. +INTERNAL_DOCS = NO
  38857. +CASE_SENSE_NAMES = YES
  38858. +HIDE_SCOPE_NAMES = NO
  38859. +SHOW_INCLUDE_FILES = NO
  38860. +INLINE_INFO = YES
  38861. +SORT_MEMBER_DOCS = NO
  38862. +SORT_BRIEF_DOCS = NO
  38863. +SORT_BY_SCOPE_NAME = NO
  38864. +GENERATE_TODOLIST = YES
  38865. +GENERATE_TESTLIST = YES
  38866. +GENERATE_BUGLIST = YES
  38867. +GENERATE_DEPRECATEDLIST= YES
  38868. +ENABLED_SECTIONS =
  38869. +MAX_INITIALIZER_LINES = 30
  38870. +SHOW_USED_FILES = YES
  38871. +SHOW_DIRECTORIES = YES
  38872. +FILE_VERSION_FILTER =
  38873. +#---------------------------------------------------------------------------
  38874. +# configuration options related to warning and progress messages
  38875. +#---------------------------------------------------------------------------
  38876. +QUIET = YES
  38877. +WARNINGS = YES
  38878. +WARN_IF_UNDOCUMENTED = NO
  38879. +WARN_IF_DOC_ERROR = YES
  38880. +WARN_NO_PARAMDOC = YES
  38881. +WARN_FORMAT = "$file:$line: $text"
  38882. +WARN_LOGFILE =
  38883. +#---------------------------------------------------------------------------
  38884. +# configuration options related to the input files
  38885. +#---------------------------------------------------------------------------
  38886. +INPUT = .
  38887. +FILE_PATTERNS = *.c \
  38888. + *.cc \
  38889. + *.cxx \
  38890. + *.cpp \
  38891. + *.c++ \
  38892. + *.d \
  38893. + *.java \
  38894. + *.ii \
  38895. + *.ixx \
  38896. + *.ipp \
  38897. + *.i++ \
  38898. + *.inl \
  38899. + *.h \
  38900. + *.hh \
  38901. + *.hxx \
  38902. + *.hpp \
  38903. + *.h++ \
  38904. + *.idl \
  38905. + *.odl \
  38906. + *.cs \
  38907. + *.php \
  38908. + *.php3 \
  38909. + *.inc \
  38910. + *.m \
  38911. + *.mm \
  38912. + *.dox \
  38913. + *.py \
  38914. + *.C \
  38915. + *.CC \
  38916. + *.C++ \
  38917. + *.II \
  38918. + *.I++ \
  38919. + *.H \
  38920. + *.HH \
  38921. + *.H++ \
  38922. + *.CS \
  38923. + *.PHP \
  38924. + *.PHP3 \
  38925. + *.M \
  38926. + *.MM \
  38927. + *.PY
  38928. +RECURSIVE = NO
  38929. +EXCLUDE =
  38930. +EXCLUDE_SYMLINKS = NO
  38931. +EXCLUDE_PATTERNS =
  38932. +EXAMPLE_PATH =
  38933. +EXAMPLE_PATTERNS = *
  38934. +EXAMPLE_RECURSIVE = NO
  38935. +IMAGE_PATH =
  38936. +INPUT_FILTER =
  38937. +FILTER_PATTERNS =
  38938. +FILTER_SOURCE_FILES = NO
  38939. +#---------------------------------------------------------------------------
  38940. +# configuration options related to source browsing
  38941. +#---------------------------------------------------------------------------
  38942. +SOURCE_BROWSER = NO
  38943. +INLINE_SOURCES = NO
  38944. +STRIP_CODE_COMMENTS = YES
  38945. +REFERENCED_BY_RELATION = YES
  38946. +REFERENCES_RELATION = YES
  38947. +USE_HTAGS = NO
  38948. +VERBATIM_HEADERS = NO
  38949. +#---------------------------------------------------------------------------
  38950. +# configuration options related to the alphabetical class index
  38951. +#---------------------------------------------------------------------------
  38952. +ALPHABETICAL_INDEX = NO
  38953. +COLS_IN_ALPHA_INDEX = 5
  38954. +IGNORE_PREFIX =
  38955. +#---------------------------------------------------------------------------
  38956. +# configuration options related to the HTML output
  38957. +#---------------------------------------------------------------------------
  38958. +GENERATE_HTML = YES
  38959. +HTML_OUTPUT = html
  38960. +HTML_FILE_EXTENSION = .html
  38961. +HTML_HEADER =
  38962. +HTML_FOOTER =
  38963. +HTML_STYLESHEET =
  38964. +HTML_ALIGN_MEMBERS = YES
  38965. +GENERATE_HTMLHELP = NO
  38966. +CHM_FILE =
  38967. +HHC_LOCATION =
  38968. +GENERATE_CHI = NO
  38969. +BINARY_TOC = NO
  38970. +TOC_EXPAND = NO
  38971. +DISABLE_INDEX = NO
  38972. +ENUM_VALUES_PER_LINE = 4
  38973. +GENERATE_TREEVIEW = YES
  38974. +TREEVIEW_WIDTH = 250
  38975. +#---------------------------------------------------------------------------
  38976. +# configuration options related to the LaTeX output
  38977. +#---------------------------------------------------------------------------
  38978. +GENERATE_LATEX = NO
  38979. +LATEX_OUTPUT = latex
  38980. +LATEX_CMD_NAME = latex
  38981. +MAKEINDEX_CMD_NAME = makeindex
  38982. +COMPACT_LATEX = NO
  38983. +PAPER_TYPE = a4wide
  38984. +EXTRA_PACKAGES =
  38985. +LATEX_HEADER =
  38986. +PDF_HYPERLINKS = NO
  38987. +USE_PDFLATEX = NO
  38988. +LATEX_BATCHMODE = NO
  38989. +LATEX_HIDE_INDICES = NO
  38990. +#---------------------------------------------------------------------------
  38991. +# configuration options related to the RTF output
  38992. +#---------------------------------------------------------------------------
  38993. +GENERATE_RTF = NO
  38994. +RTF_OUTPUT = rtf
  38995. +COMPACT_RTF = NO
  38996. +RTF_HYPERLINKS = NO
  38997. +RTF_STYLESHEET_FILE =
  38998. +RTF_EXTENSIONS_FILE =
  38999. +#---------------------------------------------------------------------------
  39000. +# configuration options related to the man page output
  39001. +#---------------------------------------------------------------------------
  39002. +GENERATE_MAN = NO
  39003. +MAN_OUTPUT = man
  39004. +MAN_EXTENSION = .3
  39005. +MAN_LINKS = NO
  39006. +#---------------------------------------------------------------------------
  39007. +# configuration options related to the XML output
  39008. +#---------------------------------------------------------------------------
  39009. +GENERATE_XML = NO
  39010. +XML_OUTPUT = xml
  39011. +XML_SCHEMA =
  39012. +XML_DTD =
  39013. +XML_PROGRAMLISTING = YES
  39014. +#---------------------------------------------------------------------------
  39015. +# configuration options for the AutoGen Definitions output
  39016. +#---------------------------------------------------------------------------
  39017. +GENERATE_AUTOGEN_DEF = NO
  39018. +#---------------------------------------------------------------------------
  39019. +# configuration options related to the Perl module output
  39020. +#---------------------------------------------------------------------------
  39021. +GENERATE_PERLMOD = NO
  39022. +PERLMOD_LATEX = NO
  39023. +PERLMOD_PRETTY = YES
  39024. +PERLMOD_MAKEVAR_PREFIX =
  39025. +#---------------------------------------------------------------------------
  39026. +# Configuration options related to the preprocessor
  39027. +#---------------------------------------------------------------------------
  39028. +ENABLE_PREPROCESSING = YES
  39029. +MACRO_EXPANSION = NO
  39030. +EXPAND_ONLY_PREDEF = NO
  39031. +SEARCH_INCLUDES = YES
  39032. +INCLUDE_PATH =
  39033. +INCLUDE_FILE_PATTERNS =
  39034. +PREDEFINED = DEBUG DEBUG_MEMORY
  39035. +EXPAND_AS_DEFINED =
  39036. +SKIP_FUNCTION_MACROS = YES
  39037. +#---------------------------------------------------------------------------
  39038. +# Configuration::additions related to external references
  39039. +#---------------------------------------------------------------------------
  39040. +TAGFILES =
  39041. +GENERATE_TAGFILE =
  39042. +ALLEXTERNALS = NO
  39043. +EXTERNAL_GROUPS = YES
  39044. +PERL_PATH = /usr/bin/perl
  39045. +#---------------------------------------------------------------------------
  39046. +# Configuration options related to the dot tool
  39047. +#---------------------------------------------------------------------------
  39048. +CLASS_DIAGRAMS = YES
  39049. +HIDE_UNDOC_RELATIONS = YES
  39050. +HAVE_DOT = NO
  39051. +CLASS_GRAPH = YES
  39052. +COLLABORATION_GRAPH = YES
  39053. +GROUP_GRAPHS = YES
  39054. +UML_LOOK = NO
  39055. +TEMPLATE_RELATIONS = NO
  39056. +INCLUDE_GRAPH = NO
  39057. +INCLUDED_BY_GRAPH = YES
  39058. +CALL_GRAPH = NO
  39059. +GRAPHICAL_HIERARCHY = YES
  39060. +DIRECTORY_GRAPH = YES
  39061. +DOT_IMAGE_FORMAT = png
  39062. +DOT_PATH =
  39063. +DOTFILE_DIRS =
  39064. +MAX_DOT_GRAPH_DEPTH = 1000
  39065. +DOT_TRANSPARENT = NO
  39066. +DOT_MULTI_TARGETS = NO
  39067. +GENERATE_LEGEND = YES
  39068. +DOT_CLEANUP = YES
  39069. +#---------------------------------------------------------------------------
  39070. +# Configuration::additions related to the search engine
  39071. +#---------------------------------------------------------------------------
  39072. +SEARCHENGINE = NO
  39073. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_cc.c linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_cc.c
  39074. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_cc.c 1970-01-01 01:00:00.000000000 +0100
  39075. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_cc.c 2014-02-18 11:52:14.000000000 +0100
  39076. @@ -0,0 +1,532 @@
  39077. +/* =========================================================================
  39078. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.c $
  39079. + * $Revision: #4 $
  39080. + * $Date: 2010/11/04 $
  39081. + * $Change: 1621692 $
  39082. + *
  39083. + * Synopsys Portability Library Software and documentation
  39084. + * (hereinafter, "Software") is an Unsupported proprietary work of
  39085. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  39086. + * between Synopsys and you.
  39087. + *
  39088. + * The Software IS NOT an item of Licensed Software or Licensed Product
  39089. + * under any End User Software License Agreement or Agreement for
  39090. + * Licensed Product with Synopsys or any supplement thereto. You are
  39091. + * permitted to use and redistribute this Software in source and binary
  39092. + * forms, with or without modification, provided that redistributions
  39093. + * of source code must retain this notice. You may not view, use,
  39094. + * disclose, copy or distribute this file or any information contained
  39095. + * herein except pursuant to this license grant from Synopsys. If you
  39096. + * do not agree with this notice, including the disclaimer below, then
  39097. + * you are not authorized to use the Software.
  39098. + *
  39099. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  39100. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  39101. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  39102. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  39103. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  39104. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  39105. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  39106. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  39107. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  39108. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  39109. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  39110. + * DAMAGE.
  39111. + * ========================================================================= */
  39112. +#ifdef DWC_CCLIB
  39113. +
  39114. +#include "dwc_cc.h"
  39115. +
  39116. +typedef struct dwc_cc
  39117. +{
  39118. + uint32_t uid;
  39119. + uint8_t chid[16];
  39120. + uint8_t cdid[16];
  39121. + uint8_t ck[16];
  39122. + uint8_t *name;
  39123. + uint8_t length;
  39124. + DWC_CIRCLEQ_ENTRY(dwc_cc) list_entry;
  39125. +} dwc_cc_t;
  39126. +
  39127. +DWC_CIRCLEQ_HEAD(context_list, dwc_cc);
  39128. +
  39129. +/** The main structure for CC management. */
  39130. +struct dwc_cc_if
  39131. +{
  39132. + dwc_mutex_t *mutex;
  39133. + char *filename;
  39134. +
  39135. + unsigned is_host:1;
  39136. +
  39137. + dwc_notifier_t *notifier;
  39138. +
  39139. + struct context_list list;
  39140. +};
  39141. +
  39142. +#ifdef DEBUG
  39143. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  39144. +{
  39145. + int i;
  39146. + DWC_PRINTF("%s: ", name);
  39147. + for (i=0; i<len; i++) {
  39148. + DWC_PRINTF("%02x ", bytes[i]);
  39149. + }
  39150. + DWC_PRINTF("\n");
  39151. +}
  39152. +#else
  39153. +#define dump_bytes(x...)
  39154. +#endif
  39155. +
  39156. +static dwc_cc_t *alloc_cc(void *mem_ctx, uint8_t *name, uint32_t length)
  39157. +{
  39158. + dwc_cc_t *cc = dwc_alloc(mem_ctx, sizeof(dwc_cc_t));
  39159. + if (!cc) {
  39160. + return NULL;
  39161. + }
  39162. + DWC_MEMSET(cc, 0, sizeof(dwc_cc_t));
  39163. +
  39164. + if (name) {
  39165. + cc->length = length;
  39166. + cc->name = dwc_alloc(mem_ctx, length);
  39167. + if (!cc->name) {
  39168. + dwc_free(mem_ctx, cc);
  39169. + return NULL;
  39170. + }
  39171. +
  39172. + DWC_MEMCPY(cc->name, name, length);
  39173. + }
  39174. +
  39175. + return cc;
  39176. +}
  39177. +
  39178. +static void free_cc(void *mem_ctx, dwc_cc_t *cc)
  39179. +{
  39180. + if (cc->name) {
  39181. + dwc_free(mem_ctx, cc->name);
  39182. + }
  39183. + dwc_free(mem_ctx, cc);
  39184. +}
  39185. +
  39186. +static uint32_t next_uid(dwc_cc_if_t *cc_if)
  39187. +{
  39188. + uint32_t uid = 0;
  39189. + dwc_cc_t *cc;
  39190. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39191. + if (cc->uid > uid) {
  39192. + uid = cc->uid;
  39193. + }
  39194. + }
  39195. +
  39196. + if (uid == 0) {
  39197. + uid = 255;
  39198. + }
  39199. +
  39200. + return uid + 1;
  39201. +}
  39202. +
  39203. +static dwc_cc_t *cc_find(dwc_cc_if_t *cc_if, uint32_t uid)
  39204. +{
  39205. + dwc_cc_t *cc;
  39206. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39207. + if (cc->uid == uid) {
  39208. + return cc;
  39209. + }
  39210. + }
  39211. + return NULL;
  39212. +}
  39213. +
  39214. +static unsigned int cc_data_size(dwc_cc_if_t *cc_if)
  39215. +{
  39216. + unsigned int size = 0;
  39217. + dwc_cc_t *cc;
  39218. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39219. + size += (48 + 1);
  39220. + if (cc->name) {
  39221. + size += cc->length;
  39222. + }
  39223. + }
  39224. + return size;
  39225. +}
  39226. +
  39227. +static uint32_t cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  39228. +{
  39229. + uint32_t uid = 0;
  39230. + dwc_cc_t *cc;
  39231. +
  39232. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39233. + if (DWC_MEMCMP(cc->chid, chid, 16) == 0) {
  39234. + uid = cc->uid;
  39235. + break;
  39236. + }
  39237. + }
  39238. + return uid;
  39239. +}
  39240. +static uint32_t cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  39241. +{
  39242. + uint32_t uid = 0;
  39243. + dwc_cc_t *cc;
  39244. +
  39245. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39246. + if (DWC_MEMCMP(cc->cdid, cdid, 16) == 0) {
  39247. + uid = cc->uid;
  39248. + break;
  39249. + }
  39250. + }
  39251. + return uid;
  39252. +}
  39253. +
  39254. +/* Internal cc_add */
  39255. +static int32_t cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  39256. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  39257. +{
  39258. + dwc_cc_t *cc;
  39259. + uint32_t uid;
  39260. +
  39261. + if (cc_if->is_host) {
  39262. + uid = cc_match_cdid(cc_if, cdid);
  39263. + }
  39264. + else {
  39265. + uid = cc_match_chid(cc_if, chid);
  39266. + }
  39267. +
  39268. + if (uid) {
  39269. + DWC_DEBUGC("Replacing previous connection context id=%d name=%p name_len=%d", uid, name, length);
  39270. + cc = cc_find(cc_if, uid);
  39271. + }
  39272. + else {
  39273. + cc = alloc_cc(mem_ctx, name, length);
  39274. + cc->uid = next_uid(cc_if);
  39275. + DWC_CIRCLEQ_INSERT_TAIL(&cc_if->list, cc, list_entry);
  39276. + }
  39277. +
  39278. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  39279. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  39280. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  39281. +
  39282. + DWC_DEBUGC("Added connection context id=%d name=%p name_len=%d", cc->uid, name, length);
  39283. + dump_bytes("CHID", cc->chid, 16);
  39284. + dump_bytes("CDID", cc->cdid, 16);
  39285. + dump_bytes("CK", cc->ck, 16);
  39286. + return cc->uid;
  39287. +}
  39288. +
  39289. +/* Internal cc_clear */
  39290. +static void cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  39291. +{
  39292. + while (!DWC_CIRCLEQ_EMPTY(&cc_if->list)) {
  39293. + dwc_cc_t *cc = DWC_CIRCLEQ_FIRST(&cc_if->list);
  39294. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  39295. + free_cc(mem_ctx, cc);
  39296. + }
  39297. +}
  39298. +
  39299. +dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  39300. + dwc_notifier_t *notifier, unsigned is_host)
  39301. +{
  39302. + dwc_cc_if_t *cc_if = NULL;
  39303. +
  39304. + /* Allocate a common_cc_if structure */
  39305. + cc_if = dwc_alloc(mem_ctx, sizeof(dwc_cc_if_t));
  39306. +
  39307. + if (!cc_if)
  39308. + return NULL;
  39309. +
  39310. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  39311. + DWC_MUTEX_ALLOC_LINUX_DEBUG(cc_if->mutex);
  39312. +#else
  39313. + cc_if->mutex = dwc_mutex_alloc(mtx_ctx);
  39314. +#endif
  39315. + if (!cc_if->mutex) {
  39316. + dwc_free(mem_ctx, cc_if);
  39317. + return NULL;
  39318. + }
  39319. +
  39320. + DWC_CIRCLEQ_INIT(&cc_if->list);
  39321. + cc_if->is_host = is_host;
  39322. + cc_if->notifier = notifier;
  39323. + return cc_if;
  39324. +}
  39325. +
  39326. +void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if)
  39327. +{
  39328. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  39329. + DWC_MUTEX_FREE(cc_if->mutex);
  39330. +#else
  39331. + dwc_mutex_free(mtx_ctx, cc_if->mutex);
  39332. +#endif
  39333. + cc_clear(mem_ctx, cc_if);
  39334. + dwc_free(mem_ctx, cc_if);
  39335. +}
  39336. +
  39337. +static void cc_changed(dwc_cc_if_t *cc_if)
  39338. +{
  39339. + if (cc_if->notifier) {
  39340. + dwc_notify(cc_if->notifier, DWC_CC_LIST_CHANGED_NOTIFICATION, cc_if);
  39341. + }
  39342. +}
  39343. +
  39344. +void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  39345. +{
  39346. + DWC_MUTEX_LOCK(cc_if->mutex);
  39347. + cc_clear(mem_ctx, cc_if);
  39348. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39349. + cc_changed(cc_if);
  39350. +}
  39351. +
  39352. +int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  39353. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  39354. +{
  39355. + uint32_t uid;
  39356. +
  39357. + DWC_MUTEX_LOCK(cc_if->mutex);
  39358. + uid = cc_add(mem_ctx, cc_if, chid, cdid, ck, name, length);
  39359. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39360. + cc_changed(cc_if);
  39361. +
  39362. + return uid;
  39363. +}
  39364. +
  39365. +void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id, uint8_t *chid,
  39366. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  39367. +{
  39368. + dwc_cc_t* cc;
  39369. +
  39370. + DWC_DEBUGC("Change connection context %d", id);
  39371. +
  39372. + DWC_MUTEX_LOCK(cc_if->mutex);
  39373. + cc = cc_find(cc_if, id);
  39374. + if (!cc) {
  39375. + DWC_ERROR("Uid %d not found in cc list\n", id);
  39376. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39377. + return;
  39378. + }
  39379. +
  39380. + if (chid) {
  39381. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  39382. + }
  39383. + if (cdid) {
  39384. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  39385. + }
  39386. + if (ck) {
  39387. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  39388. + }
  39389. +
  39390. + if (name) {
  39391. + if (cc->name) {
  39392. + dwc_free(mem_ctx, cc->name);
  39393. + }
  39394. + cc->name = dwc_alloc(mem_ctx, length);
  39395. + if (!cc->name) {
  39396. + DWC_ERROR("Out of memory in dwc_cc_change()\n");
  39397. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39398. + return;
  39399. + }
  39400. + cc->length = length;
  39401. + DWC_MEMCPY(cc->name, name, length);
  39402. + }
  39403. +
  39404. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39405. +
  39406. + cc_changed(cc_if);
  39407. +
  39408. + DWC_DEBUGC("Changed connection context id=%d\n", id);
  39409. + dump_bytes("New CHID", cc->chid, 16);
  39410. + dump_bytes("New CDID", cc->cdid, 16);
  39411. + dump_bytes("New CK", cc->ck, 16);
  39412. +}
  39413. +
  39414. +void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id)
  39415. +{
  39416. + dwc_cc_t *cc;
  39417. +
  39418. + DWC_DEBUGC("Removing connection context %d", id);
  39419. +
  39420. + DWC_MUTEX_LOCK(cc_if->mutex);
  39421. + cc = cc_find(cc_if, id);
  39422. + if (!cc) {
  39423. + DWC_ERROR("Uid %d not found in cc list\n", id);
  39424. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39425. + return;
  39426. + }
  39427. +
  39428. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  39429. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39430. + free_cc(mem_ctx, cc);
  39431. +
  39432. + cc_changed(cc_if);
  39433. +}
  39434. +
  39435. +uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if, unsigned int *length)
  39436. +{
  39437. + uint8_t *buf, *x;
  39438. + uint8_t zero = 0;
  39439. + dwc_cc_t *cc;
  39440. +
  39441. + DWC_MUTEX_LOCK(cc_if->mutex);
  39442. + *length = cc_data_size(cc_if);
  39443. + if (!(*length)) {
  39444. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39445. + return NULL;
  39446. + }
  39447. +
  39448. + DWC_DEBUGC("Creating data for saving (length=%d)", *length);
  39449. +
  39450. + buf = dwc_alloc(mem_ctx, *length);
  39451. + if (!buf) {
  39452. + *length = 0;
  39453. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39454. + return NULL;
  39455. + }
  39456. +
  39457. + x = buf;
  39458. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39459. + DWC_MEMCPY(x, cc->chid, 16);
  39460. + x += 16;
  39461. + DWC_MEMCPY(x, cc->cdid, 16);
  39462. + x += 16;
  39463. + DWC_MEMCPY(x, cc->ck, 16);
  39464. + x += 16;
  39465. + if (cc->name) {
  39466. + DWC_MEMCPY(x, &cc->length, 1);
  39467. + x += 1;
  39468. + DWC_MEMCPY(x, cc->name, cc->length);
  39469. + x += cc->length;
  39470. + }
  39471. + else {
  39472. + DWC_MEMCPY(x, &zero, 1);
  39473. + x += 1;
  39474. + }
  39475. + }
  39476. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39477. +
  39478. + return buf;
  39479. +}
  39480. +
  39481. +void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *data, uint32_t length)
  39482. +{
  39483. + uint8_t name_length;
  39484. + uint8_t *name;
  39485. + uint8_t *chid;
  39486. + uint8_t *cdid;
  39487. + uint8_t *ck;
  39488. + uint32_t i = 0;
  39489. +
  39490. + DWC_MUTEX_LOCK(cc_if->mutex);
  39491. + cc_clear(mem_ctx, cc_if);
  39492. +
  39493. + while (i < length) {
  39494. + chid = &data[i];
  39495. + i += 16;
  39496. + cdid = &data[i];
  39497. + i += 16;
  39498. + ck = &data[i];
  39499. + i += 16;
  39500. +
  39501. + name_length = data[i];
  39502. + i ++;
  39503. +
  39504. + if (name_length) {
  39505. + name = &data[i];
  39506. + i += name_length;
  39507. + }
  39508. + else {
  39509. + name = NULL;
  39510. + }
  39511. +
  39512. + /* check to see if we haven't overflown the buffer */
  39513. + if (i > length) {
  39514. + DWC_ERROR("Data format error while attempting to load CCs "
  39515. + "(nlen=%d, iter=%d, buflen=%d).\n", name_length, i, length);
  39516. + break;
  39517. + }
  39518. +
  39519. + cc_add(mem_ctx, cc_if, chid, cdid, ck, name, name_length);
  39520. + }
  39521. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39522. +
  39523. + cc_changed(cc_if);
  39524. +}
  39525. +
  39526. +uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  39527. +{
  39528. + uint32_t uid = 0;
  39529. +
  39530. + DWC_MUTEX_LOCK(cc_if->mutex);
  39531. + uid = cc_match_chid(cc_if, chid);
  39532. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39533. + return uid;
  39534. +}
  39535. +uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  39536. +{
  39537. + uint32_t uid = 0;
  39538. +
  39539. + DWC_MUTEX_LOCK(cc_if->mutex);
  39540. + uid = cc_match_cdid(cc_if, cdid);
  39541. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39542. + return uid;
  39543. +}
  39544. +
  39545. +uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id)
  39546. +{
  39547. + uint8_t *ck = NULL;
  39548. + dwc_cc_t *cc;
  39549. +
  39550. + DWC_MUTEX_LOCK(cc_if->mutex);
  39551. + cc = cc_find(cc_if, id);
  39552. + if (cc) {
  39553. + ck = cc->ck;
  39554. + }
  39555. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39556. +
  39557. + return ck;
  39558. +
  39559. +}
  39560. +
  39561. +uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id)
  39562. +{
  39563. + uint8_t *retval = NULL;
  39564. + dwc_cc_t *cc;
  39565. +
  39566. + DWC_MUTEX_LOCK(cc_if->mutex);
  39567. + cc = cc_find(cc_if, id);
  39568. + if (cc) {
  39569. + retval = cc->chid;
  39570. + }
  39571. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39572. +
  39573. + return retval;
  39574. +}
  39575. +
  39576. +uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id)
  39577. +{
  39578. + uint8_t *retval = NULL;
  39579. + dwc_cc_t *cc;
  39580. +
  39581. + DWC_MUTEX_LOCK(cc_if->mutex);
  39582. + cc = cc_find(cc_if, id);
  39583. + if (cc) {
  39584. + retval = cc->cdid;
  39585. + }
  39586. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39587. +
  39588. + return retval;
  39589. +}
  39590. +
  39591. +uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length)
  39592. +{
  39593. + uint8_t *retval = NULL;
  39594. + dwc_cc_t *cc;
  39595. +
  39596. + DWC_MUTEX_LOCK(cc_if->mutex);
  39597. + *length = 0;
  39598. + cc = cc_find(cc_if, id);
  39599. + if (cc) {
  39600. + *length = cc->length;
  39601. + retval = cc->name;
  39602. + }
  39603. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39604. +
  39605. + return retval;
  39606. +}
  39607. +
  39608. +#endif /* DWC_CCLIB */
  39609. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_cc.h linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_cc.h
  39610. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_cc.h 1970-01-01 01:00:00.000000000 +0100
  39611. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_cc.h 2014-02-18 11:52:14.000000000 +0100
  39612. @@ -0,0 +1,224 @@
  39613. +/* =========================================================================
  39614. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.h $
  39615. + * $Revision: #4 $
  39616. + * $Date: 2010/09/28 $
  39617. + * $Change: 1596182 $
  39618. + *
  39619. + * Synopsys Portability Library Software and documentation
  39620. + * (hereinafter, "Software") is an Unsupported proprietary work of
  39621. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  39622. + * between Synopsys and you.
  39623. + *
  39624. + * The Software IS NOT an item of Licensed Software or Licensed Product
  39625. + * under any End User Software License Agreement or Agreement for
  39626. + * Licensed Product with Synopsys or any supplement thereto. You are
  39627. + * permitted to use and redistribute this Software in source and binary
  39628. + * forms, with or without modification, provided that redistributions
  39629. + * of source code must retain this notice. You may not view, use,
  39630. + * disclose, copy or distribute this file or any information contained
  39631. + * herein except pursuant to this license grant from Synopsys. If you
  39632. + * do not agree with this notice, including the disclaimer below, then
  39633. + * you are not authorized to use the Software.
  39634. + *
  39635. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  39636. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  39637. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  39638. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  39639. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  39640. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  39641. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  39642. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  39643. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  39644. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  39645. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  39646. + * DAMAGE.
  39647. + * ========================================================================= */
  39648. +#ifndef _DWC_CC_H_
  39649. +#define _DWC_CC_H_
  39650. +
  39651. +#ifdef __cplusplus
  39652. +extern "C" {
  39653. +#endif
  39654. +
  39655. +/** @file
  39656. + *
  39657. + * This file defines the Context Context library.
  39658. + *
  39659. + * The main data structure is dwc_cc_if_t which is returned by either the
  39660. + * dwc_cc_if_alloc function or returned by the module to the user via a provided
  39661. + * function. The data structure is opaque and should only be manipulated via the
  39662. + * functions provied in this API.
  39663. + *
  39664. + * It manages a list of connection contexts and operations can be performed to
  39665. + * add, remove, query, search, and change, those contexts. Additionally,
  39666. + * a dwc_notifier_t object can be requested from the manager so that
  39667. + * the user can be notified whenever the context list has changed.
  39668. + */
  39669. +
  39670. +#include "dwc_os.h"
  39671. +#include "dwc_list.h"
  39672. +#include "dwc_notifier.h"
  39673. +
  39674. +
  39675. +/* Notifications */
  39676. +#define DWC_CC_LIST_CHANGED_NOTIFICATION "DWC_CC_LIST_CHANGED_NOTIFICATION"
  39677. +
  39678. +struct dwc_cc_if;
  39679. +typedef struct dwc_cc_if dwc_cc_if_t;
  39680. +
  39681. +
  39682. +/** @name Connection Context Operations */
  39683. +/** @{ */
  39684. +
  39685. +/** This function allocates memory for a dwc_cc_if_t structure, initializes
  39686. + * fields to default values, and returns a pointer to the structure or NULL on
  39687. + * error. */
  39688. +extern dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  39689. + dwc_notifier_t *notifier, unsigned is_host);
  39690. +
  39691. +/** Frees the memory for the specified CC structure allocated from
  39692. + * dwc_cc_if_alloc(). */
  39693. +extern void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if);
  39694. +
  39695. +/** Removes all contexts from the connection context list */
  39696. +extern void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if);
  39697. +
  39698. +/** Adds a connection context (CHID, CK, CDID, Name) to the connection context list.
  39699. + * If a CHID already exists, the CK and name are overwritten. Statistics are
  39700. + * not overwritten.
  39701. + *
  39702. + * @param cc_if The cc_if structure.
  39703. + * @param chid A pointer to the 16-byte CHID. This value will be copied.
  39704. + * @param ck A pointer to the 16-byte CK. This value will be copied.
  39705. + * @param cdid A pointer to the 16-byte CDID. This value will be copied.
  39706. + * @param name An optional host friendly name as defined in the association model
  39707. + * spec. Must be a UTF16-LE unicode string. Can be NULL to indicated no name.
  39708. + * @param length The length othe unicode string.
  39709. + * @return A unique identifier used to refer to this context that is valid for
  39710. + * as long as this context is still in the list. */
  39711. +extern int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  39712. + uint8_t *cdid, uint8_t *ck, uint8_t *name,
  39713. + uint8_t length);
  39714. +
  39715. +/** Changes the CHID, CK, CDID, or Name values of a connection context in the
  39716. + * list, preserving any accumulated statistics. This would typically be called
  39717. + * if the host decideds to change the context with a SET_CONNECTION request.
  39718. + *
  39719. + * @param cc_if The cc_if structure.
  39720. + * @param id The identifier of the connection context.
  39721. + * @param chid A pointer to the 16-byte CHID. This value will be copied. NULL
  39722. + * indicates no change.
  39723. + * @param cdid A pointer to the 16-byte CDID. This value will be copied. NULL
  39724. + * indicates no change.
  39725. + * @param ck A pointer to the 16-byte CK. This value will be copied. NULL
  39726. + * indicates no change.
  39727. + * @param name Host friendly name UTF16-LE. NULL indicates no change.
  39728. + * @param length Length of name. */
  39729. +extern void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id,
  39730. + uint8_t *chid, uint8_t *cdid, uint8_t *ck,
  39731. + uint8_t *name, uint8_t length);
  39732. +
  39733. +/** Remove the specified connection context.
  39734. + * @param cc_if The cc_if structure.
  39735. + * @param id The identifier of the connection context to remove. */
  39736. +extern void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id);
  39737. +
  39738. +/** Get a binary block of data for the connection context list and attributes.
  39739. + * This data can be used by the OS specific driver to save the connection
  39740. + * context list into non-volatile memory.
  39741. + *
  39742. + * @param cc_if The cc_if structure.
  39743. + * @param length Return the length of the data buffer.
  39744. + * @return A pointer to the data buffer. The memory for this buffer should be
  39745. + * freed with DWC_FREE() after use. */
  39746. +extern uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if,
  39747. + unsigned int *length);
  39748. +
  39749. +/** Restore the connection context list from the binary data that was previously
  39750. + * returned from a call to dwc_cc_data_for_save. This can be used by the OS specific
  39751. + * driver to load a connection context list from non-volatile memory.
  39752. + *
  39753. + * @param cc_if The cc_if structure.
  39754. + * @param data The data bytes as returned from dwc_cc_data_for_save.
  39755. + * @param length The length of the data. */
  39756. +extern void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if,
  39757. + uint8_t *data, unsigned int length);
  39758. +
  39759. +/** Find the connection context from the specified CHID.
  39760. + *
  39761. + * @param cc_if The cc_if structure.
  39762. + * @param chid A pointer to the CHID data.
  39763. + * @return A non-zero identifier of the connection context if the CHID matches.
  39764. + * Otherwise returns 0. */
  39765. +extern uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid);
  39766. +
  39767. +/** Find the connection context from the specified CDID.
  39768. + *
  39769. + * @param cc_if The cc_if structure.
  39770. + * @param cdid A pointer to the CDID data.
  39771. + * @return A non-zero identifier of the connection context if the CHID matches.
  39772. + * Otherwise returns 0. */
  39773. +extern uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid);
  39774. +
  39775. +/** Retrieve the CK from the specified connection context.
  39776. + *
  39777. + * @param cc_if The cc_if structure.
  39778. + * @param id The identifier of the connection context.
  39779. + * @return A pointer to the CK data. The memory does not need to be freed. */
  39780. +extern uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id);
  39781. +
  39782. +/** Retrieve the CHID from the specified connection context.
  39783. + *
  39784. + * @param cc_if The cc_if structure.
  39785. + * @param id The identifier of the connection context.
  39786. + * @return A pointer to the CHID data. The memory does not need to be freed. */
  39787. +extern uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id);
  39788. +
  39789. +/** Retrieve the CDID from the specified connection context.
  39790. + *
  39791. + * @param cc_if The cc_if structure.
  39792. + * @param id The identifier of the connection context.
  39793. + * @return A pointer to the CDID data. The memory does not need to be freed. */
  39794. +extern uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id);
  39795. +
  39796. +extern uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length);
  39797. +
  39798. +/** Checks a buffer for non-zero.
  39799. + * @param id A pointer to a 16 byte buffer.
  39800. + * @return true if the 16 byte value is non-zero. */
  39801. +static inline unsigned dwc_assoc_is_not_zero_id(uint8_t *id) {
  39802. + int i;
  39803. + for (i=0; i<16; i++) {
  39804. + if (id[i]) return 1;
  39805. + }
  39806. + return 0;
  39807. +}
  39808. +
  39809. +/** Checks a buffer for zero.
  39810. + * @param id A pointer to a 16 byte buffer.
  39811. + * @return true if the 16 byte value is zero. */
  39812. +static inline unsigned dwc_assoc_is_zero_id(uint8_t *id) {
  39813. + return !dwc_assoc_is_not_zero_id(id);
  39814. +}
  39815. +
  39816. +/** Prints an ASCII representation for the 16-byte chid, cdid, or ck, into
  39817. + * buffer. */
  39818. +static inline int dwc_print_id_string(char *buffer, uint8_t *id) {
  39819. + char *ptr = buffer;
  39820. + int i;
  39821. + for (i=0; i<16; i++) {
  39822. + ptr += DWC_SPRINTF(ptr, "%02x", id[i]);
  39823. + if (i < 15) {
  39824. + ptr += DWC_SPRINTF(ptr, " ");
  39825. + }
  39826. + }
  39827. + return ptr - buffer;
  39828. +}
  39829. +
  39830. +/** @} */
  39831. +
  39832. +#ifdef __cplusplus
  39833. +}
  39834. +#endif
  39835. +
  39836. +#endif /* _DWC_CC_H_ */
  39837. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c
  39838. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 1970-01-01 01:00:00.000000000 +0100
  39839. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 2014-02-18 11:52:14.000000000 +0100
  39840. @@ -0,0 +1,1308 @@
  39841. +#include "dwc_os.h"
  39842. +#include "dwc_list.h"
  39843. +
  39844. +#ifdef DWC_CCLIB
  39845. +# include "dwc_cc.h"
  39846. +#endif
  39847. +
  39848. +#ifdef DWC_CRYPTOLIB
  39849. +# include "dwc_modpow.h"
  39850. +# include "dwc_dh.h"
  39851. +# include "dwc_crypto.h"
  39852. +#endif
  39853. +
  39854. +#ifdef DWC_NOTIFYLIB
  39855. +# include "dwc_notifier.h"
  39856. +#endif
  39857. +
  39858. +/* OS-Level Implementations */
  39859. +
  39860. +/* This is the FreeBSD 7.0 kernel implementation of the DWC platform library. */
  39861. +
  39862. +
  39863. +/* MISC */
  39864. +
  39865. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  39866. +{
  39867. + return memset(dest, byte, size);
  39868. +}
  39869. +
  39870. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  39871. +{
  39872. + return memcpy(dest, src, size);
  39873. +}
  39874. +
  39875. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  39876. +{
  39877. + bcopy(src, dest, size);
  39878. + return dest;
  39879. +}
  39880. +
  39881. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  39882. +{
  39883. + return memcmp(m1, m2, size);
  39884. +}
  39885. +
  39886. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  39887. +{
  39888. + return strncmp(s1, s2, size);
  39889. +}
  39890. +
  39891. +int DWC_STRCMP(void *s1, void *s2)
  39892. +{
  39893. + return strcmp(s1, s2);
  39894. +}
  39895. +
  39896. +int DWC_STRLEN(char const *str)
  39897. +{
  39898. + return strlen(str);
  39899. +}
  39900. +
  39901. +char *DWC_STRCPY(char *to, char const *from)
  39902. +{
  39903. + return strcpy(to, from);
  39904. +}
  39905. +
  39906. +char *DWC_STRDUP(char const *str)
  39907. +{
  39908. + int len = DWC_STRLEN(str) + 1;
  39909. + char *new = DWC_ALLOC_ATOMIC(len);
  39910. +
  39911. + if (!new) {
  39912. + return NULL;
  39913. + }
  39914. +
  39915. + DWC_MEMCPY(new, str, len);
  39916. + return new;
  39917. +}
  39918. +
  39919. +int DWC_ATOI(char *str, int32_t *value)
  39920. +{
  39921. + char *end = NULL;
  39922. +
  39923. + *value = strtol(str, &end, 0);
  39924. + if (*end == '\0') {
  39925. + return 0;
  39926. + }
  39927. +
  39928. + return -1;
  39929. +}
  39930. +
  39931. +int DWC_ATOUI(char *str, uint32_t *value)
  39932. +{
  39933. + char *end = NULL;
  39934. +
  39935. + *value = strtoul(str, &end, 0);
  39936. + if (*end == '\0') {
  39937. + return 0;
  39938. + }
  39939. +
  39940. + return -1;
  39941. +}
  39942. +
  39943. +
  39944. +#ifdef DWC_UTFLIB
  39945. +/* From usbstring.c */
  39946. +
  39947. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  39948. +{
  39949. + int count = 0;
  39950. + u8 c;
  39951. + u16 uchar;
  39952. +
  39953. + /* this insists on correct encodings, though not minimal ones.
  39954. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  39955. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  39956. + */
  39957. + while (len != 0 && (c = (u8) *s++) != 0) {
  39958. + if (unlikely(c & 0x80)) {
  39959. + // 2-byte sequence:
  39960. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  39961. + if ((c & 0xe0) == 0xc0) {
  39962. + uchar = (c & 0x1f) << 6;
  39963. +
  39964. + c = (u8) *s++;
  39965. + if ((c & 0xc0) != 0xc0)
  39966. + goto fail;
  39967. + c &= 0x3f;
  39968. + uchar |= c;
  39969. +
  39970. + // 3-byte sequence (most CJKV characters):
  39971. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  39972. + } else if ((c & 0xf0) == 0xe0) {
  39973. + uchar = (c & 0x0f) << 12;
  39974. +
  39975. + c = (u8) *s++;
  39976. + if ((c & 0xc0) != 0xc0)
  39977. + goto fail;
  39978. + c &= 0x3f;
  39979. + uchar |= c << 6;
  39980. +
  39981. + c = (u8) *s++;
  39982. + if ((c & 0xc0) != 0xc0)
  39983. + goto fail;
  39984. + c &= 0x3f;
  39985. + uchar |= c;
  39986. +
  39987. + /* no bogus surrogates */
  39988. + if (0xd800 <= uchar && uchar <= 0xdfff)
  39989. + goto fail;
  39990. +
  39991. + // 4-byte sequence (surrogate pairs, currently rare):
  39992. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  39993. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  39994. + // (uuuuu = wwww + 1)
  39995. + // FIXME accept the surrogate code points (only)
  39996. + } else
  39997. + goto fail;
  39998. + } else
  39999. + uchar = c;
  40000. + put_unaligned (cpu_to_le16 (uchar), cp++);
  40001. + count++;
  40002. + len--;
  40003. + }
  40004. + return count;
  40005. +fail:
  40006. + return -1;
  40007. +}
  40008. +
  40009. +#endif /* DWC_UTFLIB */
  40010. +
  40011. +
  40012. +/* dwc_debug.h */
  40013. +
  40014. +dwc_bool_t DWC_IN_IRQ(void)
  40015. +{
  40016. +// return in_irq();
  40017. + return 0;
  40018. +}
  40019. +
  40020. +dwc_bool_t DWC_IN_BH(void)
  40021. +{
  40022. +// return in_softirq();
  40023. + return 0;
  40024. +}
  40025. +
  40026. +void DWC_VPRINTF(char *format, va_list args)
  40027. +{
  40028. + vprintf(format, args);
  40029. +}
  40030. +
  40031. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  40032. +{
  40033. + return vsnprintf(str, size, format, args);
  40034. +}
  40035. +
  40036. +void DWC_PRINTF(char *format, ...)
  40037. +{
  40038. + va_list args;
  40039. +
  40040. + va_start(args, format);
  40041. + DWC_VPRINTF(format, args);
  40042. + va_end(args);
  40043. +}
  40044. +
  40045. +int DWC_SPRINTF(char *buffer, char *format, ...)
  40046. +{
  40047. + int retval;
  40048. + va_list args;
  40049. +
  40050. + va_start(args, format);
  40051. + retval = vsprintf(buffer, format, args);
  40052. + va_end(args);
  40053. + return retval;
  40054. +}
  40055. +
  40056. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  40057. +{
  40058. + int retval;
  40059. + va_list args;
  40060. +
  40061. + va_start(args, format);
  40062. + retval = vsnprintf(buffer, size, format, args);
  40063. + va_end(args);
  40064. + return retval;
  40065. +}
  40066. +
  40067. +void __DWC_WARN(char *format, ...)
  40068. +{
  40069. + va_list args;
  40070. +
  40071. + va_start(args, format);
  40072. + DWC_VPRINTF(format, args);
  40073. + va_end(args);
  40074. +}
  40075. +
  40076. +void __DWC_ERROR(char *format, ...)
  40077. +{
  40078. + va_list args;
  40079. +
  40080. + va_start(args, format);
  40081. + DWC_VPRINTF(format, args);
  40082. + va_end(args);
  40083. +}
  40084. +
  40085. +void DWC_EXCEPTION(char *format, ...)
  40086. +{
  40087. + va_list args;
  40088. +
  40089. + va_start(args, format);
  40090. + DWC_VPRINTF(format, args);
  40091. + va_end(args);
  40092. +// BUG_ON(1); ???
  40093. +}
  40094. +
  40095. +#ifdef DEBUG
  40096. +void __DWC_DEBUG(char *format, ...)
  40097. +{
  40098. + va_list args;
  40099. +
  40100. + va_start(args, format);
  40101. + DWC_VPRINTF(format, args);
  40102. + va_end(args);
  40103. +}
  40104. +#endif
  40105. +
  40106. +
  40107. +/* dwc_mem.h */
  40108. +
  40109. +#if 0
  40110. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  40111. + uint32_t align,
  40112. + uint32_t alloc)
  40113. +{
  40114. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  40115. + size, align, alloc);
  40116. + return (dwc_pool_t *)pool;
  40117. +}
  40118. +
  40119. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  40120. +{
  40121. + dma_pool_destroy((struct dma_pool *)pool);
  40122. +}
  40123. +
  40124. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  40125. +{
  40126. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  40127. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  40128. +}
  40129. +
  40130. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  40131. +{
  40132. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  40133. + memset(..);
  40134. +}
  40135. +
  40136. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  40137. +{
  40138. + dma_pool_free(pool, vaddr, daddr);
  40139. +}
  40140. +#endif
  40141. +
  40142. +static void dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
  40143. +{
  40144. + if (error)
  40145. + return;
  40146. + *(bus_addr_t *)arg = segs[0].ds_addr;
  40147. +}
  40148. +
  40149. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  40150. +{
  40151. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  40152. + int error;
  40153. +
  40154. + error = bus_dma_tag_create(
  40155. +#if __FreeBSD_version >= 700000
  40156. + bus_get_dma_tag(dma->dev), /* parent */
  40157. +#else
  40158. + NULL, /* parent */
  40159. +#endif
  40160. + 4, 0, /* alignment, bounds */
  40161. + BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
  40162. + BUS_SPACE_MAXADDR, /* highaddr */
  40163. + NULL, NULL, /* filter, filterarg */
  40164. + size, /* maxsize */
  40165. + 1, /* nsegments */
  40166. + size, /* maxsegsize */
  40167. + 0, /* flags */
  40168. + NULL, /* lockfunc */
  40169. + NULL, /* lockarg */
  40170. + &dma->dma_tag);
  40171. + if (error) {
  40172. + device_printf(dma->dev, "%s: bus_dma_tag_create failed: %d\n",
  40173. + __func__, error);
  40174. + goto fail_0;
  40175. + }
  40176. +
  40177. + error = bus_dmamem_alloc(dma->dma_tag, &dma->dma_vaddr,
  40178. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT, &dma->dma_map);
  40179. + if (error) {
  40180. + device_printf(dma->dev, "%s: bus_dmamem_alloc(%ju) failed: %d\n",
  40181. + __func__, (uintmax_t)size, error);
  40182. + goto fail_1;
  40183. + }
  40184. +
  40185. + dma->dma_paddr = 0;
  40186. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr, size,
  40187. + dmamap_cb, &dma->dma_paddr, BUS_DMA_NOWAIT);
  40188. + if (error || dma->dma_paddr == 0) {
  40189. + device_printf(dma->dev, "%s: bus_dmamap_load failed: %d\n",
  40190. + __func__, error);
  40191. + goto fail_2;
  40192. + }
  40193. +
  40194. + *dma_addr = dma->dma_paddr;
  40195. + return dma->dma_vaddr;
  40196. +
  40197. +fail_2:
  40198. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  40199. +fail_1:
  40200. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  40201. + bus_dma_tag_destroy(dma->dma_tag);
  40202. +fail_0:
  40203. + dma->dma_map = NULL;
  40204. + dma->dma_tag = NULL;
  40205. +
  40206. + return NULL;
  40207. +}
  40208. +
  40209. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  40210. +{
  40211. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  40212. +
  40213. + if (dma->dma_tag == NULL)
  40214. + return;
  40215. + if (dma->dma_map != NULL) {
  40216. + bus_dmamap_sync(dma->dma_tag, dma->dma_map,
  40217. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  40218. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  40219. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  40220. + dma->dma_map = NULL;
  40221. + }
  40222. +
  40223. + bus_dma_tag_destroy(dma->dma_tag);
  40224. + dma->dma_tag = NULL;
  40225. +}
  40226. +
  40227. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  40228. +{
  40229. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  40230. +}
  40231. +
  40232. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  40233. +{
  40234. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  40235. +}
  40236. +
  40237. +void __DWC_FREE(void *mem_ctx, void *addr)
  40238. +{
  40239. + free(addr, M_DEVBUF);
  40240. +}
  40241. +
  40242. +
  40243. +#ifdef DWC_CRYPTOLIB
  40244. +/* dwc_crypto.h */
  40245. +
  40246. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  40247. +{
  40248. + get_random_bytes(buffer, length);
  40249. +}
  40250. +
  40251. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  40252. +{
  40253. + struct crypto_blkcipher *tfm;
  40254. + struct blkcipher_desc desc;
  40255. + struct scatterlist sgd;
  40256. + struct scatterlist sgs;
  40257. +
  40258. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  40259. + if (tfm == NULL) {
  40260. + printk("failed to load transform for aes CBC\n");
  40261. + return -1;
  40262. + }
  40263. +
  40264. + crypto_blkcipher_setkey(tfm, key, keylen);
  40265. + crypto_blkcipher_set_iv(tfm, iv, 16);
  40266. +
  40267. + sg_init_one(&sgd, out, messagelen);
  40268. + sg_init_one(&sgs, message, messagelen);
  40269. +
  40270. + desc.tfm = tfm;
  40271. + desc.flags = 0;
  40272. +
  40273. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  40274. + crypto_free_blkcipher(tfm);
  40275. + DWC_ERROR("AES CBC encryption failed");
  40276. + return -1;
  40277. + }
  40278. +
  40279. + crypto_free_blkcipher(tfm);
  40280. + return 0;
  40281. +}
  40282. +
  40283. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  40284. +{
  40285. + struct crypto_hash *tfm;
  40286. + struct hash_desc desc;
  40287. + struct scatterlist sg;
  40288. +
  40289. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  40290. + if (IS_ERR(tfm)) {
  40291. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  40292. + return 0;
  40293. + }
  40294. + desc.tfm = tfm;
  40295. + desc.flags = 0;
  40296. +
  40297. + sg_init_one(&sg, message, len);
  40298. + crypto_hash_digest(&desc, &sg, len, out);
  40299. + crypto_free_hash(tfm);
  40300. +
  40301. + return 1;
  40302. +}
  40303. +
  40304. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  40305. + uint8_t *key, uint32_t keylen, uint8_t *out)
  40306. +{
  40307. + struct crypto_hash *tfm;
  40308. + struct hash_desc desc;
  40309. + struct scatterlist sg;
  40310. +
  40311. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  40312. + if (IS_ERR(tfm)) {
  40313. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  40314. + return 0;
  40315. + }
  40316. + desc.tfm = tfm;
  40317. + desc.flags = 0;
  40318. +
  40319. + sg_init_one(&sg, message, messagelen);
  40320. + crypto_hash_setkey(tfm, key, keylen);
  40321. + crypto_hash_digest(&desc, &sg, messagelen, out);
  40322. + crypto_free_hash(tfm);
  40323. +
  40324. + return 1;
  40325. +}
  40326. +
  40327. +#endif /* DWC_CRYPTOLIB */
  40328. +
  40329. +
  40330. +/* Byte Ordering Conversions */
  40331. +
  40332. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  40333. +{
  40334. +#ifdef __LITTLE_ENDIAN
  40335. + return *p;
  40336. +#else
  40337. + uint8_t *u_p = (uint8_t *)p;
  40338. +
  40339. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40340. +#endif
  40341. +}
  40342. +
  40343. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  40344. +{
  40345. +#ifdef __BIG_ENDIAN
  40346. + return *p;
  40347. +#else
  40348. + uint8_t *u_p = (uint8_t *)p;
  40349. +
  40350. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40351. +#endif
  40352. +}
  40353. +
  40354. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  40355. +{
  40356. +#ifdef __LITTLE_ENDIAN
  40357. + return *p;
  40358. +#else
  40359. + uint8_t *u_p = (uint8_t *)p;
  40360. +
  40361. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40362. +#endif
  40363. +}
  40364. +
  40365. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  40366. +{
  40367. +#ifdef __BIG_ENDIAN
  40368. + return *p;
  40369. +#else
  40370. + uint8_t *u_p = (uint8_t *)p;
  40371. +
  40372. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40373. +#endif
  40374. +}
  40375. +
  40376. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  40377. +{
  40378. +#ifdef __LITTLE_ENDIAN
  40379. + return *p;
  40380. +#else
  40381. + uint8_t *u_p = (uint8_t *)p;
  40382. + return (u_p[1] | (u_p[0] << 8));
  40383. +#endif
  40384. +}
  40385. +
  40386. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  40387. +{
  40388. +#ifdef __BIG_ENDIAN
  40389. + return *p;
  40390. +#else
  40391. + uint8_t *u_p = (uint8_t *)p;
  40392. + return (u_p[1] | (u_p[0] << 8));
  40393. +#endif
  40394. +}
  40395. +
  40396. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  40397. +{
  40398. +#ifdef __LITTLE_ENDIAN
  40399. + return *p;
  40400. +#else
  40401. + uint8_t *u_p = (uint8_t *)p;
  40402. + return (u_p[1] | (u_p[0] << 8));
  40403. +#endif
  40404. +}
  40405. +
  40406. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  40407. +{
  40408. +#ifdef __BIG_ENDIAN
  40409. + return *p;
  40410. +#else
  40411. + uint8_t *u_p = (uint8_t *)p;
  40412. + return (u_p[1] | (u_p[0] << 8));
  40413. +#endif
  40414. +}
  40415. +
  40416. +
  40417. +/* Registers */
  40418. +
  40419. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  40420. +{
  40421. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40422. + bus_size_t ior = (bus_size_t)reg;
  40423. +
  40424. + return bus_space_read_4(io->iot, io->ioh, ior);
  40425. +}
  40426. +
  40427. +#if 0
  40428. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  40429. +{
  40430. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40431. + bus_size_t ior = (bus_size_t)reg;
  40432. +
  40433. + return bus_space_read_8(io->iot, io->ioh, ior);
  40434. +}
  40435. +#endif
  40436. +
  40437. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  40438. +{
  40439. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40440. + bus_size_t ior = (bus_size_t)reg;
  40441. +
  40442. + bus_space_write_4(io->iot, io->ioh, ior, value);
  40443. +}
  40444. +
  40445. +#if 0
  40446. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  40447. +{
  40448. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40449. + bus_size_t ior = (bus_size_t)reg;
  40450. +
  40451. + bus_space_write_8(io->iot, io->ioh, ior, value);
  40452. +}
  40453. +#endif
  40454. +
  40455. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  40456. + uint32_t set_mask)
  40457. +{
  40458. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40459. + bus_size_t ior = (bus_size_t)reg;
  40460. +
  40461. + bus_space_write_4(io->iot, io->ioh, ior,
  40462. + (bus_space_read_4(io->iot, io->ioh, ior) &
  40463. + ~clear_mask) | set_mask);
  40464. +}
  40465. +
  40466. +#if 0
  40467. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  40468. + uint64_t set_mask)
  40469. +{
  40470. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40471. + bus_size_t ior = (bus_size_t)reg;
  40472. +
  40473. + bus_space_write_8(io->iot, io->ioh, ior,
  40474. + (bus_space_read_8(io->iot, io->ioh, ior) &
  40475. + ~clear_mask) | set_mask);
  40476. +}
  40477. +#endif
  40478. +
  40479. +
  40480. +/* Locking */
  40481. +
  40482. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  40483. +{
  40484. + struct mtx *sl = DWC_ALLOC(sizeof(*sl));
  40485. +
  40486. + if (!sl) {
  40487. + DWC_ERROR("Cannot allocate memory for spinlock");
  40488. + return NULL;
  40489. + }
  40490. +
  40491. + mtx_init(sl, "dw3spn", NULL, MTX_SPIN);
  40492. + return (dwc_spinlock_t *)sl;
  40493. +}
  40494. +
  40495. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  40496. +{
  40497. + struct mtx *sl = (struct mtx *)lock;
  40498. +
  40499. + mtx_destroy(sl);
  40500. + DWC_FREE(sl);
  40501. +}
  40502. +
  40503. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  40504. +{
  40505. + mtx_lock_spin((struct mtx *)lock); // ???
  40506. +}
  40507. +
  40508. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  40509. +{
  40510. + mtx_unlock_spin((struct mtx *)lock); // ???
  40511. +}
  40512. +
  40513. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  40514. +{
  40515. + mtx_lock_spin((struct mtx *)lock);
  40516. +}
  40517. +
  40518. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  40519. +{
  40520. + mtx_unlock_spin((struct mtx *)lock);
  40521. +}
  40522. +
  40523. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  40524. +{
  40525. + struct mtx *m;
  40526. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mtx));
  40527. +
  40528. + if (!mutex) {
  40529. + DWC_ERROR("Cannot allocate memory for mutex");
  40530. + return NULL;
  40531. + }
  40532. +
  40533. + m = (struct mtx *)mutex;
  40534. + mtx_init(m, "dw3mtx", NULL, MTX_DEF);
  40535. + return mutex;
  40536. +}
  40537. +
  40538. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  40539. +#else
  40540. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  40541. +{
  40542. + mtx_destroy((struct mtx *)mutex);
  40543. + DWC_FREE(mutex);
  40544. +}
  40545. +#endif
  40546. +
  40547. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  40548. +{
  40549. + struct mtx *m = (struct mtx *)mutex;
  40550. +
  40551. + mtx_lock(m);
  40552. +}
  40553. +
  40554. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  40555. +{
  40556. + struct mtx *m = (struct mtx *)mutex;
  40557. +
  40558. + return mtx_trylock(m);
  40559. +}
  40560. +
  40561. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  40562. +{
  40563. + struct mtx *m = (struct mtx *)mutex;
  40564. +
  40565. + mtx_unlock(m);
  40566. +}
  40567. +
  40568. +
  40569. +/* Timing */
  40570. +
  40571. +void DWC_UDELAY(uint32_t usecs)
  40572. +{
  40573. + DELAY(usecs);
  40574. +}
  40575. +
  40576. +void DWC_MDELAY(uint32_t msecs)
  40577. +{
  40578. + do {
  40579. + DELAY(1000);
  40580. + } while (--msecs);
  40581. +}
  40582. +
  40583. +void DWC_MSLEEP(uint32_t msecs)
  40584. +{
  40585. + struct timeval tv;
  40586. +
  40587. + tv.tv_sec = msecs / 1000;
  40588. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  40589. + pause("dw3slp", tvtohz(&tv));
  40590. +}
  40591. +
  40592. +uint32_t DWC_TIME(void)
  40593. +{
  40594. + struct timeval tv;
  40595. +
  40596. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  40597. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  40598. +}
  40599. +
  40600. +
  40601. +/* Timers */
  40602. +
  40603. +struct dwc_timer {
  40604. + struct callout t;
  40605. + char *name;
  40606. + dwc_spinlock_t *lock;
  40607. + dwc_timer_callback_t cb;
  40608. + void *data;
  40609. +};
  40610. +
  40611. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  40612. +{
  40613. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  40614. +
  40615. + if (!t) {
  40616. + DWC_ERROR("Cannot allocate memory for timer");
  40617. + return NULL;
  40618. + }
  40619. +
  40620. + callout_init(&t->t, 1);
  40621. +
  40622. + t->name = DWC_STRDUP(name);
  40623. + if (!t->name) {
  40624. + DWC_ERROR("Cannot allocate memory for timer->name");
  40625. + goto no_name;
  40626. + }
  40627. +
  40628. + t->lock = DWC_SPINLOCK_ALLOC();
  40629. + if (!t->lock) {
  40630. + DWC_ERROR("Cannot allocate memory for lock");
  40631. + goto no_lock;
  40632. + }
  40633. +
  40634. + t->cb = cb;
  40635. + t->data = data;
  40636. +
  40637. + return t;
  40638. +
  40639. + no_lock:
  40640. + DWC_FREE(t->name);
  40641. + no_name:
  40642. + DWC_FREE(t);
  40643. +
  40644. + return NULL;
  40645. +}
  40646. +
  40647. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  40648. +{
  40649. + callout_stop(&timer->t);
  40650. + DWC_SPINLOCK_FREE(timer->lock);
  40651. + DWC_FREE(timer->name);
  40652. + DWC_FREE(timer);
  40653. +}
  40654. +
  40655. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  40656. +{
  40657. + struct timeval tv;
  40658. +
  40659. + tv.tv_sec = time / 1000;
  40660. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  40661. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  40662. +}
  40663. +
  40664. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  40665. +{
  40666. + callout_stop(&timer->t);
  40667. +}
  40668. +
  40669. +
  40670. +/* Wait Queues */
  40671. +
  40672. +struct dwc_waitq {
  40673. + struct mtx lock;
  40674. + int abort;
  40675. +};
  40676. +
  40677. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  40678. +{
  40679. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  40680. +
  40681. + if (!wq) {
  40682. + DWC_ERROR("Cannot allocate memory for waitqueue");
  40683. + return NULL;
  40684. + }
  40685. +
  40686. + mtx_init(&wq->lock, "dw3wtq", NULL, MTX_DEF);
  40687. + wq->abort = 0;
  40688. +
  40689. + return wq;
  40690. +}
  40691. +
  40692. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  40693. +{
  40694. + mtx_destroy(&wq->lock);
  40695. + DWC_FREE(wq);
  40696. +}
  40697. +
  40698. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  40699. +{
  40700. +// intrmask_t ipl;
  40701. + int result = 0;
  40702. +
  40703. + mtx_lock(&wq->lock);
  40704. +// ipl = splbio();
  40705. +
  40706. + /* Skip the sleep if already aborted or triggered */
  40707. + if (!wq->abort && !cond(data)) {
  40708. +// splx(ipl);
  40709. + result = msleep(wq, &wq->lock, PCATCH, "dw3wat", 0); // infinite timeout
  40710. +// ipl = splbio();
  40711. + }
  40712. +
  40713. + if (result == ERESTART) { // signaled - restart
  40714. + result = -DWC_E_RESTART;
  40715. +
  40716. + } else if (result == EINTR) { // signaled - interrupt
  40717. + result = -DWC_E_ABORT;
  40718. +
  40719. + } else if (wq->abort) {
  40720. + result = -DWC_E_ABORT;
  40721. +
  40722. + } else {
  40723. + result = 0;
  40724. + }
  40725. +
  40726. + wq->abort = 0;
  40727. +// splx(ipl);
  40728. + mtx_unlock(&wq->lock);
  40729. + return result;
  40730. +}
  40731. +
  40732. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  40733. + void *data, int32_t msecs)
  40734. +{
  40735. + struct timeval tv, tv1, tv2;
  40736. +// intrmask_t ipl;
  40737. + int result = 0;
  40738. +
  40739. + tv.tv_sec = msecs / 1000;
  40740. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  40741. +
  40742. + mtx_lock(&wq->lock);
  40743. +// ipl = splbio();
  40744. +
  40745. + /* Skip the sleep if already aborted or triggered */
  40746. + if (!wq->abort && !cond(data)) {
  40747. +// splx(ipl);
  40748. + getmicrouptime(&tv1);
  40749. + result = msleep(wq, &wq->lock, PCATCH, "dw3wto", tvtohz(&tv));
  40750. + getmicrouptime(&tv2);
  40751. +// ipl = splbio();
  40752. + }
  40753. +
  40754. + if (result == 0) { // awoken
  40755. + if (wq->abort) {
  40756. + result = -DWC_E_ABORT;
  40757. + } else {
  40758. + tv2.tv_usec -= tv1.tv_usec;
  40759. + if (tv2.tv_usec < 0) {
  40760. + tv2.tv_usec += 1000000;
  40761. + tv2.tv_sec--;
  40762. + }
  40763. +
  40764. + tv2.tv_sec -= tv1.tv_sec;
  40765. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  40766. + result = msecs - result;
  40767. + if (result <= 0)
  40768. + result = 1;
  40769. + }
  40770. + } else if (result == ERESTART) { // signaled - restart
  40771. + result = -DWC_E_RESTART;
  40772. +
  40773. + } else if (result == EINTR) { // signaled - interrupt
  40774. + result = -DWC_E_ABORT;
  40775. +
  40776. + } else { // timed out
  40777. + result = -DWC_E_TIMEOUT;
  40778. + }
  40779. +
  40780. + wq->abort = 0;
  40781. +// splx(ipl);
  40782. + mtx_unlock(&wq->lock);
  40783. + return result;
  40784. +}
  40785. +
  40786. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  40787. +{
  40788. + wakeup(wq);
  40789. +}
  40790. +
  40791. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  40792. +{
  40793. +// intrmask_t ipl;
  40794. +
  40795. + mtx_lock(&wq->lock);
  40796. +// ipl = splbio();
  40797. + wq->abort = 1;
  40798. + wakeup(wq);
  40799. +// splx(ipl);
  40800. + mtx_unlock(&wq->lock);
  40801. +}
  40802. +
  40803. +
  40804. +/* Threading */
  40805. +
  40806. +struct dwc_thread {
  40807. + struct proc *proc;
  40808. + int abort;
  40809. +};
  40810. +
  40811. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  40812. +{
  40813. + int retval;
  40814. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  40815. +
  40816. + if (!thread) {
  40817. + return NULL;
  40818. + }
  40819. +
  40820. + thread->abort = 0;
  40821. + retval = kthread_create((void (*)(void *))func, data, &thread->proc,
  40822. + RFPROC | RFNOWAIT, 0, "%s", name);
  40823. + if (retval) {
  40824. + DWC_FREE(thread);
  40825. + return NULL;
  40826. + }
  40827. +
  40828. + return thread;
  40829. +}
  40830. +
  40831. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  40832. +{
  40833. + int retval;
  40834. +
  40835. + thread->abort = 1;
  40836. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  40837. +
  40838. + if (retval == 0) {
  40839. + /* DWC_THREAD_EXIT() will free the thread struct */
  40840. + return 0;
  40841. + }
  40842. +
  40843. + /* NOTE: We leak the thread struct if thread doesn't die */
  40844. +
  40845. + if (retval == EWOULDBLOCK) {
  40846. + return -DWC_E_TIMEOUT;
  40847. + }
  40848. +
  40849. + return -DWC_E_UNKNOWN;
  40850. +}
  40851. +
  40852. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  40853. +{
  40854. + return thread->abort;
  40855. +}
  40856. +
  40857. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  40858. +{
  40859. + wakeup(&thread->abort);
  40860. + DWC_FREE(thread);
  40861. + kthread_exit(0);
  40862. +}
  40863. +
  40864. +
  40865. +/* tasklets
  40866. + - Runs in interrupt context (cannot sleep)
  40867. + - Each tasklet runs on a single CPU [ How can we ensure this on FreeBSD? Does it matter? ]
  40868. + - Different tasklets can be running simultaneously on different CPUs [ shouldn't matter ]
  40869. + */
  40870. +struct dwc_tasklet {
  40871. + struct task t;
  40872. + dwc_tasklet_callback_t cb;
  40873. + void *data;
  40874. +};
  40875. +
  40876. +static void tasklet_callback(void *data, int pending) // what to do with pending ???
  40877. +{
  40878. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  40879. +
  40880. + task->cb(task->data);
  40881. +}
  40882. +
  40883. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  40884. +{
  40885. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  40886. +
  40887. + if (task) {
  40888. + task->cb = cb;
  40889. + task->data = data;
  40890. + TASK_INIT(&task->t, 0, tasklet_callback, task);
  40891. + } else {
  40892. + DWC_ERROR("Cannot allocate memory for tasklet");
  40893. + }
  40894. +
  40895. + return task;
  40896. +}
  40897. +
  40898. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  40899. +{
  40900. + taskqueue_drain(taskqueue_fast, &task->t); // ???
  40901. + DWC_FREE(task);
  40902. +}
  40903. +
  40904. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  40905. +{
  40906. + /* Uses predefined system queue */
  40907. + taskqueue_enqueue_fast(taskqueue_fast, &task->t);
  40908. +}
  40909. +
  40910. +
  40911. +/* workqueues
  40912. + - Runs in process context (can sleep)
  40913. + */
  40914. +typedef struct work_container {
  40915. + dwc_work_callback_t cb;
  40916. + void *data;
  40917. + dwc_workq_t *wq;
  40918. + char *name;
  40919. + int hz;
  40920. +
  40921. +#ifdef DEBUG
  40922. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  40923. +#endif
  40924. + struct task task;
  40925. +} work_container_t;
  40926. +
  40927. +#ifdef DEBUG
  40928. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  40929. +#endif
  40930. +
  40931. +struct dwc_workq {
  40932. + struct taskqueue *taskq;
  40933. + dwc_spinlock_t *lock;
  40934. + dwc_waitq_t *waitq;
  40935. + int pending;
  40936. +
  40937. +#ifdef DEBUG
  40938. + struct work_container_queue entries;
  40939. +#endif
  40940. +};
  40941. +
  40942. +static void do_work(void *data, int pending) // what to do with pending ???
  40943. +{
  40944. + work_container_t *container = (work_container_t *)data;
  40945. + dwc_workq_t *wq = container->wq;
  40946. + dwc_irqflags_t flags;
  40947. +
  40948. + if (container->hz) {
  40949. + pause("dw3wrk", container->hz);
  40950. + }
  40951. +
  40952. + container->cb(container->data);
  40953. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  40954. +
  40955. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  40956. +
  40957. +#ifdef DEBUG
  40958. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  40959. +#endif
  40960. + if (container->name)
  40961. + DWC_FREE(container->name);
  40962. + DWC_FREE(container);
  40963. + wq->pending--;
  40964. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  40965. + DWC_WAITQ_TRIGGER(wq->waitq);
  40966. +}
  40967. +
  40968. +static int work_done(void *data)
  40969. +{
  40970. + dwc_workq_t *workq = (dwc_workq_t *)data;
  40971. +
  40972. + return workq->pending == 0;
  40973. +}
  40974. +
  40975. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  40976. +{
  40977. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  40978. +}
  40979. +
  40980. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  40981. +{
  40982. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  40983. +
  40984. + if (!wq) {
  40985. + DWC_ERROR("Cannot allocate memory for workqueue");
  40986. + return NULL;
  40987. + }
  40988. +
  40989. + wq->taskq = taskqueue_create(name, M_NOWAIT, taskqueue_thread_enqueue, &wq->taskq);
  40990. + if (!wq->taskq) {
  40991. + DWC_ERROR("Cannot allocate memory for taskqueue");
  40992. + goto no_taskq;
  40993. + }
  40994. +
  40995. + wq->pending = 0;
  40996. +
  40997. + wq->lock = DWC_SPINLOCK_ALLOC();
  40998. + if (!wq->lock) {
  40999. + DWC_ERROR("Cannot allocate memory for spinlock");
  41000. + goto no_lock;
  41001. + }
  41002. +
  41003. + wq->waitq = DWC_WAITQ_ALLOC();
  41004. + if (!wq->waitq) {
  41005. + DWC_ERROR("Cannot allocate memory for waitqueue");
  41006. + goto no_waitq;
  41007. + }
  41008. +
  41009. + taskqueue_start_threads(&wq->taskq, 1, PWAIT, "%s taskq", "dw3tsk");
  41010. +
  41011. +#ifdef DEBUG
  41012. + DWC_CIRCLEQ_INIT(&wq->entries);
  41013. +#endif
  41014. + return wq;
  41015. +
  41016. + no_waitq:
  41017. + DWC_SPINLOCK_FREE(wq->lock);
  41018. + no_lock:
  41019. + taskqueue_free(wq->taskq);
  41020. + no_taskq:
  41021. + DWC_FREE(wq);
  41022. +
  41023. + return NULL;
  41024. +}
  41025. +
  41026. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  41027. +{
  41028. +#ifdef DEBUG
  41029. + dwc_irqflags_t flags;
  41030. +
  41031. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41032. +
  41033. + if (wq->pending != 0) {
  41034. + struct work_container *container;
  41035. +
  41036. + DWC_ERROR("Destroying work queue with pending work");
  41037. +
  41038. + DWC_CIRCLEQ_FOREACH(container, &wq->entries, entry) {
  41039. + DWC_ERROR("Work %s still pending", container->name);
  41040. + }
  41041. + }
  41042. +
  41043. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41044. +#endif
  41045. + DWC_WAITQ_FREE(wq->waitq);
  41046. + DWC_SPINLOCK_FREE(wq->lock);
  41047. + taskqueue_free(wq->taskq);
  41048. + DWC_FREE(wq);
  41049. +}
  41050. +
  41051. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  41052. + char *format, ...)
  41053. +{
  41054. + dwc_irqflags_t flags;
  41055. + work_container_t *container;
  41056. + static char name[128];
  41057. + va_list args;
  41058. +
  41059. + va_start(args, format);
  41060. + DWC_VSNPRINTF(name, 128, format, args);
  41061. + va_end(args);
  41062. +
  41063. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41064. + wq->pending++;
  41065. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41066. + DWC_WAITQ_TRIGGER(wq->waitq);
  41067. +
  41068. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  41069. + if (!container) {
  41070. + DWC_ERROR("Cannot allocate memory for container");
  41071. + return;
  41072. + }
  41073. +
  41074. + container->name = DWC_STRDUP(name);
  41075. + if (!container->name) {
  41076. + DWC_ERROR("Cannot allocate memory for container->name");
  41077. + DWC_FREE(container);
  41078. + return;
  41079. + }
  41080. +
  41081. + container->cb = cb;
  41082. + container->data = data;
  41083. + container->wq = wq;
  41084. + container->hz = 0;
  41085. +
  41086. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  41087. +
  41088. + TASK_INIT(&container->task, 0, do_work, container);
  41089. +
  41090. +#ifdef DEBUG
  41091. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  41092. +#endif
  41093. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  41094. +}
  41095. +
  41096. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  41097. + void *data, uint32_t time, char *format, ...)
  41098. +{
  41099. + dwc_irqflags_t flags;
  41100. + work_container_t *container;
  41101. + static char name[128];
  41102. + struct timeval tv;
  41103. + va_list args;
  41104. +
  41105. + va_start(args, format);
  41106. + DWC_VSNPRINTF(name, 128, format, args);
  41107. + va_end(args);
  41108. +
  41109. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41110. + wq->pending++;
  41111. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41112. + DWC_WAITQ_TRIGGER(wq->waitq);
  41113. +
  41114. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  41115. + if (!container) {
  41116. + DWC_ERROR("Cannot allocate memory for container");
  41117. + return;
  41118. + }
  41119. +
  41120. + container->name = DWC_STRDUP(name);
  41121. + if (!container->name) {
  41122. + DWC_ERROR("Cannot allocate memory for container->name");
  41123. + DWC_FREE(container);
  41124. + return;
  41125. + }
  41126. +
  41127. + container->cb = cb;
  41128. + container->data = data;
  41129. + container->wq = wq;
  41130. +
  41131. + tv.tv_sec = time / 1000;
  41132. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  41133. + container->hz = tvtohz(&tv);
  41134. +
  41135. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  41136. +
  41137. + TASK_INIT(&container->task, 0, do_work, container);
  41138. +
  41139. +#ifdef DEBUG
  41140. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  41141. +#endif
  41142. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  41143. +}
  41144. +
  41145. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  41146. +{
  41147. + return wq->pending;
  41148. +}
  41149. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_common_linux.c linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_common_linux.c
  41150. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_common_linux.c 1970-01-01 01:00:00.000000000 +0100
  41151. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_common_linux.c 2014-02-18 11:52:14.000000000 +0100
  41152. @@ -0,0 +1,1431 @@
  41153. +#include <linux/kernel.h>
  41154. +#include <linux/init.h>
  41155. +#include <linux/module.h>
  41156. +#include <linux/kthread.h>
  41157. +
  41158. +#ifdef DWC_CCLIB
  41159. +# include "dwc_cc.h"
  41160. +#endif
  41161. +
  41162. +#ifdef DWC_CRYPTOLIB
  41163. +# include "dwc_modpow.h"
  41164. +# include "dwc_dh.h"
  41165. +# include "dwc_crypto.h"
  41166. +#endif
  41167. +
  41168. +#ifdef DWC_NOTIFYLIB
  41169. +# include "dwc_notifier.h"
  41170. +#endif
  41171. +
  41172. +/* OS-Level Implementations */
  41173. +
  41174. +/* This is the Linux kernel implementation of the DWC platform library. */
  41175. +#include <linux/moduleparam.h>
  41176. +#include <linux/ctype.h>
  41177. +#include <linux/crypto.h>
  41178. +#include <linux/delay.h>
  41179. +#include <linux/device.h>
  41180. +#include <linux/dma-mapping.h>
  41181. +#include <linux/cdev.h>
  41182. +#include <linux/errno.h>
  41183. +#include <linux/interrupt.h>
  41184. +#include <linux/jiffies.h>
  41185. +#include <linux/list.h>
  41186. +#include <linux/pci.h>
  41187. +#include <linux/random.h>
  41188. +#include <linux/scatterlist.h>
  41189. +#include <linux/slab.h>
  41190. +#include <linux/stat.h>
  41191. +#include <linux/string.h>
  41192. +#include <linux/timer.h>
  41193. +#include <linux/usb.h>
  41194. +
  41195. +#include <linux/version.h>
  41196. +
  41197. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  41198. +# include <linux/usb/gadget.h>
  41199. +#else
  41200. +# include <linux/usb_gadget.h>
  41201. +#endif
  41202. +
  41203. +#include <asm/io.h>
  41204. +#include <asm/page.h>
  41205. +#include <asm/uaccess.h>
  41206. +#include <asm/unaligned.h>
  41207. +
  41208. +#include "dwc_os.h"
  41209. +#include "dwc_list.h"
  41210. +
  41211. +
  41212. +/* MISC */
  41213. +
  41214. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  41215. +{
  41216. + return memset(dest, byte, size);
  41217. +}
  41218. +
  41219. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  41220. +{
  41221. + return memcpy(dest, src, size);
  41222. +}
  41223. +
  41224. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  41225. +{
  41226. + return memmove(dest, src, size);
  41227. +}
  41228. +
  41229. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  41230. +{
  41231. + return memcmp(m1, m2, size);
  41232. +}
  41233. +
  41234. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  41235. +{
  41236. + return strncmp(s1, s2, size);
  41237. +}
  41238. +
  41239. +int DWC_STRCMP(void *s1, void *s2)
  41240. +{
  41241. + return strcmp(s1, s2);
  41242. +}
  41243. +
  41244. +int DWC_STRLEN(char const *str)
  41245. +{
  41246. + return strlen(str);
  41247. +}
  41248. +
  41249. +char *DWC_STRCPY(char *to, char const *from)
  41250. +{
  41251. + return strcpy(to, from);
  41252. +}
  41253. +
  41254. +char *DWC_STRDUP(char const *str)
  41255. +{
  41256. + int len = DWC_STRLEN(str) + 1;
  41257. + char *new = DWC_ALLOC_ATOMIC(len);
  41258. +
  41259. + if (!new) {
  41260. + return NULL;
  41261. + }
  41262. +
  41263. + DWC_MEMCPY(new, str, len);
  41264. + return new;
  41265. +}
  41266. +
  41267. +int DWC_ATOI(const char *str, int32_t *value)
  41268. +{
  41269. + char *end = NULL;
  41270. +
  41271. + *value = simple_strtol(str, &end, 0);
  41272. + if (*end == '\0') {
  41273. + return 0;
  41274. + }
  41275. +
  41276. + return -1;
  41277. +}
  41278. +
  41279. +int DWC_ATOUI(const char *str, uint32_t *value)
  41280. +{
  41281. + char *end = NULL;
  41282. +
  41283. + *value = simple_strtoul(str, &end, 0);
  41284. + if (*end == '\0') {
  41285. + return 0;
  41286. + }
  41287. +
  41288. + return -1;
  41289. +}
  41290. +
  41291. +
  41292. +#ifdef DWC_UTFLIB
  41293. +/* From usbstring.c */
  41294. +
  41295. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  41296. +{
  41297. + int count = 0;
  41298. + u8 c;
  41299. + u16 uchar;
  41300. +
  41301. + /* this insists on correct encodings, though not minimal ones.
  41302. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  41303. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  41304. + */
  41305. + while (len != 0 && (c = (u8) *s++) != 0) {
  41306. + if (unlikely(c & 0x80)) {
  41307. + // 2-byte sequence:
  41308. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  41309. + if ((c & 0xe0) == 0xc0) {
  41310. + uchar = (c & 0x1f) << 6;
  41311. +
  41312. + c = (u8) *s++;
  41313. + if ((c & 0xc0) != 0xc0)
  41314. + goto fail;
  41315. + c &= 0x3f;
  41316. + uchar |= c;
  41317. +
  41318. + // 3-byte sequence (most CJKV characters):
  41319. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  41320. + } else if ((c & 0xf0) == 0xe0) {
  41321. + uchar = (c & 0x0f) << 12;
  41322. +
  41323. + c = (u8) *s++;
  41324. + if ((c & 0xc0) != 0xc0)
  41325. + goto fail;
  41326. + c &= 0x3f;
  41327. + uchar |= c << 6;
  41328. +
  41329. + c = (u8) *s++;
  41330. + if ((c & 0xc0) != 0xc0)
  41331. + goto fail;
  41332. + c &= 0x3f;
  41333. + uchar |= c;
  41334. +
  41335. + /* no bogus surrogates */
  41336. + if (0xd800 <= uchar && uchar <= 0xdfff)
  41337. + goto fail;
  41338. +
  41339. + // 4-byte sequence (surrogate pairs, currently rare):
  41340. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  41341. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  41342. + // (uuuuu = wwww + 1)
  41343. + // FIXME accept the surrogate code points (only)
  41344. + } else
  41345. + goto fail;
  41346. + } else
  41347. + uchar = c;
  41348. + put_unaligned (cpu_to_le16 (uchar), cp++);
  41349. + count++;
  41350. + len--;
  41351. + }
  41352. + return count;
  41353. +fail:
  41354. + return -1;
  41355. +}
  41356. +#endif /* DWC_UTFLIB */
  41357. +
  41358. +
  41359. +/* dwc_debug.h */
  41360. +
  41361. +dwc_bool_t DWC_IN_IRQ(void)
  41362. +{
  41363. + return in_irq();
  41364. +}
  41365. +
  41366. +dwc_bool_t DWC_IN_BH(void)
  41367. +{
  41368. + return in_softirq();
  41369. +}
  41370. +
  41371. +void DWC_VPRINTF(char *format, va_list args)
  41372. +{
  41373. + vprintk(format, args);
  41374. +}
  41375. +
  41376. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  41377. +{
  41378. + return vsnprintf(str, size, format, args);
  41379. +}
  41380. +
  41381. +void DWC_PRINTF(char *format, ...)
  41382. +{
  41383. + va_list args;
  41384. +
  41385. + va_start(args, format);
  41386. + DWC_VPRINTF(format, args);
  41387. + va_end(args);
  41388. +}
  41389. +
  41390. +int DWC_SPRINTF(char *buffer, char *format, ...)
  41391. +{
  41392. + int retval;
  41393. + va_list args;
  41394. +
  41395. + va_start(args, format);
  41396. + retval = vsprintf(buffer, format, args);
  41397. + va_end(args);
  41398. + return retval;
  41399. +}
  41400. +
  41401. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  41402. +{
  41403. + int retval;
  41404. + va_list args;
  41405. +
  41406. + va_start(args, format);
  41407. + retval = vsnprintf(buffer, size, format, args);
  41408. + va_end(args);
  41409. + return retval;
  41410. +}
  41411. +
  41412. +void __DWC_WARN(char *format, ...)
  41413. +{
  41414. + va_list args;
  41415. +
  41416. + va_start(args, format);
  41417. + DWC_PRINTF(KERN_WARNING);
  41418. + DWC_VPRINTF(format, args);
  41419. + va_end(args);
  41420. +}
  41421. +
  41422. +void __DWC_ERROR(char *format, ...)
  41423. +{
  41424. + va_list args;
  41425. +
  41426. + va_start(args, format);
  41427. + DWC_PRINTF(KERN_ERR);
  41428. + DWC_VPRINTF(format, args);
  41429. + va_end(args);
  41430. +}
  41431. +
  41432. +void DWC_EXCEPTION(char *format, ...)
  41433. +{
  41434. + va_list args;
  41435. +
  41436. + va_start(args, format);
  41437. + DWC_PRINTF(KERN_ERR);
  41438. + DWC_VPRINTF(format, args);
  41439. + va_end(args);
  41440. + BUG_ON(1);
  41441. +}
  41442. +
  41443. +#ifdef DEBUG
  41444. +void __DWC_DEBUG(char *format, ...)
  41445. +{
  41446. + va_list args;
  41447. +
  41448. + va_start(args, format);
  41449. + DWC_PRINTF(KERN_DEBUG);
  41450. + DWC_VPRINTF(format, args);
  41451. + va_end(args);
  41452. +}
  41453. +#endif
  41454. +
  41455. +
  41456. +/* dwc_mem.h */
  41457. +
  41458. +#if 0
  41459. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  41460. + uint32_t align,
  41461. + uint32_t alloc)
  41462. +{
  41463. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  41464. + size, align, alloc);
  41465. + return (dwc_pool_t *)pool;
  41466. +}
  41467. +
  41468. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  41469. +{
  41470. + dma_pool_destroy((struct dma_pool *)pool);
  41471. +}
  41472. +
  41473. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  41474. +{
  41475. + return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  41476. +}
  41477. +
  41478. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  41479. +{
  41480. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  41481. + memset(..);
  41482. +}
  41483. +
  41484. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  41485. +{
  41486. + dma_pool_free(pool, vaddr, daddr);
  41487. +}
  41488. +#endif
  41489. +
  41490. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  41491. +{
  41492. +#ifdef xxCOSIM /* Only works for 32-bit cosim */
  41493. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL);
  41494. +#else
  41495. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL | GFP_DMA32);
  41496. +#endif
  41497. + if (!buf) {
  41498. + return NULL;
  41499. + }
  41500. +
  41501. + memset(buf, 0, (size_t)size);
  41502. + return buf;
  41503. +}
  41504. +
  41505. +void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  41506. +{
  41507. + void *buf = dma_alloc_coherent(NULL, (size_t)size, dma_addr, GFP_ATOMIC);
  41508. + if (!buf) {
  41509. + return NULL;
  41510. + }
  41511. + memset(buf, 0, (size_t)size);
  41512. + return buf;
  41513. +}
  41514. +
  41515. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  41516. +{
  41517. + dma_free_coherent(dma_ctx, size, virt_addr, dma_addr);
  41518. +}
  41519. +
  41520. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  41521. +{
  41522. + return kzalloc(size, GFP_KERNEL);
  41523. +}
  41524. +
  41525. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  41526. +{
  41527. + return kzalloc(size, GFP_ATOMIC);
  41528. +}
  41529. +
  41530. +void __DWC_FREE(void *mem_ctx, void *addr)
  41531. +{
  41532. + kfree(addr);
  41533. +}
  41534. +
  41535. +
  41536. +#ifdef DWC_CRYPTOLIB
  41537. +/* dwc_crypto.h */
  41538. +
  41539. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  41540. +{
  41541. + get_random_bytes(buffer, length);
  41542. +}
  41543. +
  41544. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  41545. +{
  41546. + struct crypto_blkcipher *tfm;
  41547. + struct blkcipher_desc desc;
  41548. + struct scatterlist sgd;
  41549. + struct scatterlist sgs;
  41550. +
  41551. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  41552. + if (tfm == NULL) {
  41553. + printk("failed to load transform for aes CBC\n");
  41554. + return -1;
  41555. + }
  41556. +
  41557. + crypto_blkcipher_setkey(tfm, key, keylen);
  41558. + crypto_blkcipher_set_iv(tfm, iv, 16);
  41559. +
  41560. + sg_init_one(&sgd, out, messagelen);
  41561. + sg_init_one(&sgs, message, messagelen);
  41562. +
  41563. + desc.tfm = tfm;
  41564. + desc.flags = 0;
  41565. +
  41566. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  41567. + crypto_free_blkcipher(tfm);
  41568. + DWC_ERROR("AES CBC encryption failed");
  41569. + return -1;
  41570. + }
  41571. +
  41572. + crypto_free_blkcipher(tfm);
  41573. + return 0;
  41574. +}
  41575. +
  41576. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  41577. +{
  41578. + struct crypto_hash *tfm;
  41579. + struct hash_desc desc;
  41580. + struct scatterlist sg;
  41581. +
  41582. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  41583. + if (IS_ERR(tfm)) {
  41584. + DWC_ERROR("Failed to load transform for sha256: %ld\n", PTR_ERR(tfm));
  41585. + return 0;
  41586. + }
  41587. + desc.tfm = tfm;
  41588. + desc.flags = 0;
  41589. +
  41590. + sg_init_one(&sg, message, len);
  41591. + crypto_hash_digest(&desc, &sg, len, out);
  41592. + crypto_free_hash(tfm);
  41593. +
  41594. + return 1;
  41595. +}
  41596. +
  41597. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  41598. + uint8_t *key, uint32_t keylen, uint8_t *out)
  41599. +{
  41600. + struct crypto_hash *tfm;
  41601. + struct hash_desc desc;
  41602. + struct scatterlist sg;
  41603. +
  41604. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  41605. + if (IS_ERR(tfm)) {
  41606. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld\n", PTR_ERR(tfm));
  41607. + return 0;
  41608. + }
  41609. + desc.tfm = tfm;
  41610. + desc.flags = 0;
  41611. +
  41612. + sg_init_one(&sg, message, messagelen);
  41613. + crypto_hash_setkey(tfm, key, keylen);
  41614. + crypto_hash_digest(&desc, &sg, messagelen, out);
  41615. + crypto_free_hash(tfm);
  41616. +
  41617. + return 1;
  41618. +}
  41619. +#endif /* DWC_CRYPTOLIB */
  41620. +
  41621. +
  41622. +/* Byte Ordering Conversions */
  41623. +
  41624. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  41625. +{
  41626. +#ifdef __LITTLE_ENDIAN
  41627. + return *p;
  41628. +#else
  41629. + uint8_t *u_p = (uint8_t *)p;
  41630. +
  41631. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41632. +#endif
  41633. +}
  41634. +
  41635. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  41636. +{
  41637. +#ifdef __BIG_ENDIAN
  41638. + return *p;
  41639. +#else
  41640. + uint8_t *u_p = (uint8_t *)p;
  41641. +
  41642. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41643. +#endif
  41644. +}
  41645. +
  41646. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  41647. +{
  41648. +#ifdef __LITTLE_ENDIAN
  41649. + return *p;
  41650. +#else
  41651. + uint8_t *u_p = (uint8_t *)p;
  41652. +
  41653. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41654. +#endif
  41655. +}
  41656. +
  41657. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  41658. +{
  41659. +#ifdef __BIG_ENDIAN
  41660. + return *p;
  41661. +#else
  41662. + uint8_t *u_p = (uint8_t *)p;
  41663. +
  41664. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41665. +#endif
  41666. +}
  41667. +
  41668. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  41669. +{
  41670. +#ifdef __LITTLE_ENDIAN
  41671. + return *p;
  41672. +#else
  41673. + uint8_t *u_p = (uint8_t *)p;
  41674. + return (u_p[1] | (u_p[0] << 8));
  41675. +#endif
  41676. +}
  41677. +
  41678. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  41679. +{
  41680. +#ifdef __BIG_ENDIAN
  41681. + return *p;
  41682. +#else
  41683. + uint8_t *u_p = (uint8_t *)p;
  41684. + return (u_p[1] | (u_p[0] << 8));
  41685. +#endif
  41686. +}
  41687. +
  41688. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  41689. +{
  41690. +#ifdef __LITTLE_ENDIAN
  41691. + return *p;
  41692. +#else
  41693. + uint8_t *u_p = (uint8_t *)p;
  41694. + return (u_p[1] | (u_p[0] << 8));
  41695. +#endif
  41696. +}
  41697. +
  41698. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  41699. +{
  41700. +#ifdef __BIG_ENDIAN
  41701. + return *p;
  41702. +#else
  41703. + uint8_t *u_p = (uint8_t *)p;
  41704. + return (u_p[1] | (u_p[0] << 8));
  41705. +#endif
  41706. +}
  41707. +
  41708. +
  41709. +/* Registers */
  41710. +
  41711. +uint32_t DWC_READ_REG32(uint32_t volatile *reg)
  41712. +{
  41713. + return readl(reg);
  41714. +}
  41715. +
  41716. +#if 0
  41717. +uint64_t DWC_READ_REG64(uint64_t volatile *reg)
  41718. +{
  41719. +}
  41720. +#endif
  41721. +
  41722. +void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value)
  41723. +{
  41724. + writel(value, reg);
  41725. +}
  41726. +
  41727. +#if 0
  41728. +void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value)
  41729. +{
  41730. +}
  41731. +#endif
  41732. +
  41733. +void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask)
  41734. +{
  41735. + unsigned long flags;
  41736. +
  41737. + local_irq_save(flags);
  41738. + local_fiq_disable();
  41739. + writel((readl(reg) & ~clear_mask) | set_mask, reg);
  41740. + local_irq_restore(flags);
  41741. +}
  41742. +
  41743. +#if 0
  41744. +void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask)
  41745. +{
  41746. +}
  41747. +#endif
  41748. +
  41749. +
  41750. +/* Locking */
  41751. +
  41752. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  41753. +{
  41754. + spinlock_t *sl = (spinlock_t *)1;
  41755. +
  41756. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41757. + sl = DWC_ALLOC(sizeof(*sl));
  41758. + if (!sl) {
  41759. + DWC_ERROR("Cannot allocate memory for spinlock\n");
  41760. + return NULL;
  41761. + }
  41762. +
  41763. + spin_lock_init(sl);
  41764. +#endif
  41765. + return (dwc_spinlock_t *)sl;
  41766. +}
  41767. +
  41768. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  41769. +{
  41770. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41771. + DWC_FREE(lock);
  41772. +#endif
  41773. +}
  41774. +
  41775. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  41776. +{
  41777. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41778. + spin_lock((spinlock_t *)lock);
  41779. +#endif
  41780. +}
  41781. +
  41782. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  41783. +{
  41784. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41785. + spin_unlock((spinlock_t *)lock);
  41786. +#endif
  41787. +}
  41788. +
  41789. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  41790. +{
  41791. + dwc_irqflags_t f;
  41792. +
  41793. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41794. + spin_lock_irqsave((spinlock_t *)lock, f);
  41795. +#else
  41796. + local_irq_save(f);
  41797. +#endif
  41798. + *flags = f;
  41799. +}
  41800. +
  41801. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  41802. +{
  41803. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41804. + spin_unlock_irqrestore((spinlock_t *)lock, flags);
  41805. +#else
  41806. + local_irq_restore(flags);
  41807. +#endif
  41808. +}
  41809. +
  41810. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  41811. +{
  41812. + struct mutex *m;
  41813. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex));
  41814. +
  41815. + if (!mutex) {
  41816. + DWC_ERROR("Cannot allocate memory for mutex\n");
  41817. + return NULL;
  41818. + }
  41819. +
  41820. + m = (struct mutex *)mutex;
  41821. + mutex_init(m);
  41822. + return mutex;
  41823. +}
  41824. +
  41825. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  41826. +#else
  41827. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  41828. +{
  41829. + mutex_destroy((struct mutex *)mutex);
  41830. + DWC_FREE(mutex);
  41831. +}
  41832. +#endif
  41833. +
  41834. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  41835. +{
  41836. + struct mutex *m = (struct mutex *)mutex;
  41837. + mutex_lock(m);
  41838. +}
  41839. +
  41840. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  41841. +{
  41842. + struct mutex *m = (struct mutex *)mutex;
  41843. + return mutex_trylock(m);
  41844. +}
  41845. +
  41846. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  41847. +{
  41848. + struct mutex *m = (struct mutex *)mutex;
  41849. + mutex_unlock(m);
  41850. +}
  41851. +
  41852. +
  41853. +/* Timing */
  41854. +
  41855. +void DWC_UDELAY(uint32_t usecs)
  41856. +{
  41857. + udelay(usecs);
  41858. +}
  41859. +
  41860. +void DWC_MDELAY(uint32_t msecs)
  41861. +{
  41862. + mdelay(msecs);
  41863. +}
  41864. +
  41865. +void DWC_MSLEEP(uint32_t msecs)
  41866. +{
  41867. + msleep(msecs);
  41868. +}
  41869. +
  41870. +uint32_t DWC_TIME(void)
  41871. +{
  41872. + return jiffies_to_msecs(jiffies);
  41873. +}
  41874. +
  41875. +
  41876. +/* Timers */
  41877. +
  41878. +struct dwc_timer {
  41879. + struct timer_list *t;
  41880. + char *name;
  41881. + dwc_timer_callback_t cb;
  41882. + void *data;
  41883. + uint8_t scheduled;
  41884. + dwc_spinlock_t *lock;
  41885. +};
  41886. +
  41887. +static void timer_callback(unsigned long data)
  41888. +{
  41889. + dwc_timer_t *timer = (dwc_timer_t *)data;
  41890. + dwc_irqflags_t flags;
  41891. +
  41892. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  41893. + timer->scheduled = 0;
  41894. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  41895. + DWC_DEBUGC("Timer %s callback", timer->name);
  41896. + timer->cb(timer->data);
  41897. +}
  41898. +
  41899. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  41900. +{
  41901. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  41902. +
  41903. + if (!t) {
  41904. + DWC_ERROR("Cannot allocate memory for timer");
  41905. + return NULL;
  41906. + }
  41907. +
  41908. + t->t = DWC_ALLOC(sizeof(*t->t));
  41909. + if (!t->t) {
  41910. + DWC_ERROR("Cannot allocate memory for timer->t");
  41911. + goto no_timer;
  41912. + }
  41913. +
  41914. + t->name = DWC_STRDUP(name);
  41915. + if (!t->name) {
  41916. + DWC_ERROR("Cannot allocate memory for timer->name");
  41917. + goto no_name;
  41918. + }
  41919. +
  41920. + t->lock = DWC_SPINLOCK_ALLOC();
  41921. + if (!t->lock) {
  41922. + DWC_ERROR("Cannot allocate memory for lock");
  41923. + goto no_lock;
  41924. + }
  41925. +
  41926. + t->scheduled = 0;
  41927. + t->t->base = &boot_tvec_bases;
  41928. + t->t->expires = jiffies;
  41929. + setup_timer(t->t, timer_callback, (unsigned long)t);
  41930. +
  41931. + t->cb = cb;
  41932. + t->data = data;
  41933. +
  41934. + return t;
  41935. +
  41936. + no_lock:
  41937. + DWC_FREE(t->name);
  41938. + no_name:
  41939. + DWC_FREE(t->t);
  41940. + no_timer:
  41941. + DWC_FREE(t);
  41942. + return NULL;
  41943. +}
  41944. +
  41945. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  41946. +{
  41947. + dwc_irqflags_t flags;
  41948. +
  41949. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  41950. +
  41951. + if (timer->scheduled) {
  41952. + del_timer(timer->t);
  41953. + timer->scheduled = 0;
  41954. + }
  41955. +
  41956. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  41957. + DWC_SPINLOCK_FREE(timer->lock);
  41958. + DWC_FREE(timer->t);
  41959. + DWC_FREE(timer->name);
  41960. + DWC_FREE(timer);
  41961. +}
  41962. +
  41963. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  41964. +{
  41965. + dwc_irqflags_t flags;
  41966. +
  41967. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  41968. +
  41969. + if (!timer->scheduled) {
  41970. + timer->scheduled = 1;
  41971. + DWC_DEBUGC("Scheduling timer %s to expire in +%d msec", timer->name, time);
  41972. + timer->t->expires = jiffies + msecs_to_jiffies(time);
  41973. + add_timer(timer->t);
  41974. + } else {
  41975. + DWC_DEBUGC("Modifying timer %s to expire in +%d msec", timer->name, time);
  41976. + mod_timer(timer->t, jiffies + msecs_to_jiffies(time));
  41977. + }
  41978. +
  41979. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  41980. +}
  41981. +
  41982. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  41983. +{
  41984. + del_timer(timer->t);
  41985. +}
  41986. +
  41987. +
  41988. +/* Wait Queues */
  41989. +
  41990. +struct dwc_waitq {
  41991. + wait_queue_head_t queue;
  41992. + int abort;
  41993. +};
  41994. +
  41995. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  41996. +{
  41997. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  41998. +
  41999. + if (!wq) {
  42000. + DWC_ERROR("Cannot allocate memory for waitqueue\n");
  42001. + return NULL;
  42002. + }
  42003. +
  42004. + init_waitqueue_head(&wq->queue);
  42005. + wq->abort = 0;
  42006. + return wq;
  42007. +}
  42008. +
  42009. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  42010. +{
  42011. + DWC_FREE(wq);
  42012. +}
  42013. +
  42014. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  42015. +{
  42016. + int result = wait_event_interruptible(wq->queue,
  42017. + cond(data) || wq->abort);
  42018. + if (result == -ERESTARTSYS) {
  42019. + wq->abort = 0;
  42020. + return -DWC_E_RESTART;
  42021. + }
  42022. +
  42023. + if (wq->abort == 1) {
  42024. + wq->abort = 0;
  42025. + return -DWC_E_ABORT;
  42026. + }
  42027. +
  42028. + wq->abort = 0;
  42029. +
  42030. + if (result == 0) {
  42031. + return 0;
  42032. + }
  42033. +
  42034. + return -DWC_E_UNKNOWN;
  42035. +}
  42036. +
  42037. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  42038. + void *data, int32_t msecs)
  42039. +{
  42040. + int32_t tmsecs;
  42041. + int result = wait_event_interruptible_timeout(wq->queue,
  42042. + cond(data) || wq->abort,
  42043. + msecs_to_jiffies(msecs));
  42044. + if (result == -ERESTARTSYS) {
  42045. + wq->abort = 0;
  42046. + return -DWC_E_RESTART;
  42047. + }
  42048. +
  42049. + if (wq->abort == 1) {
  42050. + wq->abort = 0;
  42051. + return -DWC_E_ABORT;
  42052. + }
  42053. +
  42054. + wq->abort = 0;
  42055. +
  42056. + if (result > 0) {
  42057. + tmsecs = jiffies_to_msecs(result);
  42058. + if (!tmsecs) {
  42059. + return 1;
  42060. + }
  42061. +
  42062. + return tmsecs;
  42063. + }
  42064. +
  42065. + if (result == 0) {
  42066. + return -DWC_E_TIMEOUT;
  42067. + }
  42068. +
  42069. + return -DWC_E_UNKNOWN;
  42070. +}
  42071. +
  42072. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  42073. +{
  42074. + wq->abort = 0;
  42075. + wake_up_interruptible(&wq->queue);
  42076. +}
  42077. +
  42078. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  42079. +{
  42080. + wq->abort = 1;
  42081. + wake_up_interruptible(&wq->queue);
  42082. +}
  42083. +
  42084. +
  42085. +/* Threading */
  42086. +
  42087. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  42088. +{
  42089. + struct task_struct *thread = kthread_run(func, data, name);
  42090. +
  42091. + if (thread == ERR_PTR(-ENOMEM)) {
  42092. + return NULL;
  42093. + }
  42094. +
  42095. + return (dwc_thread_t *)thread;
  42096. +}
  42097. +
  42098. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  42099. +{
  42100. + return kthread_stop((struct task_struct *)thread);
  42101. +}
  42102. +
  42103. +dwc_bool_t DWC_THREAD_SHOULD_STOP(void)
  42104. +{
  42105. + return kthread_should_stop();
  42106. +}
  42107. +
  42108. +
  42109. +/* tasklets
  42110. + - run in interrupt context (cannot sleep)
  42111. + - each tasklet runs on a single CPU
  42112. + - different tasklets can be running simultaneously on different CPUs
  42113. + */
  42114. +struct dwc_tasklet {
  42115. + struct tasklet_struct t;
  42116. + dwc_tasklet_callback_t cb;
  42117. + void *data;
  42118. +};
  42119. +
  42120. +static void tasklet_callback(unsigned long data)
  42121. +{
  42122. + dwc_tasklet_t *t = (dwc_tasklet_t *)data;
  42123. + t->cb(t->data);
  42124. +}
  42125. +
  42126. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  42127. +{
  42128. + dwc_tasklet_t *t = DWC_ALLOC(sizeof(*t));
  42129. +
  42130. + if (t) {
  42131. + t->cb = cb;
  42132. + t->data = data;
  42133. + tasklet_init(&t->t, tasklet_callback, (unsigned long)t);
  42134. + } else {
  42135. + DWC_ERROR("Cannot allocate memory for tasklet\n");
  42136. + }
  42137. +
  42138. + return t;
  42139. +}
  42140. +
  42141. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  42142. +{
  42143. + DWC_FREE(task);
  42144. +}
  42145. +
  42146. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  42147. +{
  42148. + tasklet_schedule(&task->t);
  42149. +}
  42150. +
  42151. +void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task)
  42152. +{
  42153. + tasklet_hi_schedule(&task->t);
  42154. +}
  42155. +
  42156. +
  42157. +/* workqueues
  42158. + - run in process context (can sleep)
  42159. + */
  42160. +typedef struct work_container {
  42161. + dwc_work_callback_t cb;
  42162. + void *data;
  42163. + dwc_workq_t *wq;
  42164. + char *name;
  42165. +
  42166. +#ifdef DEBUG
  42167. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  42168. +#endif
  42169. + struct delayed_work work;
  42170. +} work_container_t;
  42171. +
  42172. +#ifdef DEBUG
  42173. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  42174. +#endif
  42175. +
  42176. +struct dwc_workq {
  42177. + struct workqueue_struct *wq;
  42178. + dwc_spinlock_t *lock;
  42179. + dwc_waitq_t *waitq;
  42180. + int pending;
  42181. +
  42182. +#ifdef DEBUG
  42183. + struct work_container_queue entries;
  42184. +#endif
  42185. +};
  42186. +
  42187. +static void do_work(struct work_struct *work)
  42188. +{
  42189. + dwc_irqflags_t flags;
  42190. + struct delayed_work *dw = container_of(work, struct delayed_work, work);
  42191. + work_container_t *container = container_of(dw, struct work_container, work);
  42192. + dwc_workq_t *wq = container->wq;
  42193. +
  42194. + container->cb(container->data);
  42195. +
  42196. +#ifdef DEBUG
  42197. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  42198. +#endif
  42199. + DWC_DEBUGC("Work done: %s, container=%p", container->name, container);
  42200. + if (container->name) {
  42201. + DWC_FREE(container->name);
  42202. + }
  42203. + DWC_FREE(container);
  42204. +
  42205. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42206. + wq->pending--;
  42207. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42208. + DWC_WAITQ_TRIGGER(wq->waitq);
  42209. +}
  42210. +
  42211. +static int work_done(void *data)
  42212. +{
  42213. + dwc_workq_t *workq = (dwc_workq_t *)data;
  42214. + return workq->pending == 0;
  42215. +}
  42216. +
  42217. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  42218. +{
  42219. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  42220. +}
  42221. +
  42222. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  42223. +{
  42224. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  42225. +
  42226. + if (!wq) {
  42227. + return NULL;
  42228. + }
  42229. +
  42230. + wq->wq = create_singlethread_workqueue(name);
  42231. + if (!wq->wq) {
  42232. + goto no_wq;
  42233. + }
  42234. +
  42235. + wq->pending = 0;
  42236. +
  42237. + wq->lock = DWC_SPINLOCK_ALLOC();
  42238. + if (!wq->lock) {
  42239. + goto no_lock;
  42240. + }
  42241. +
  42242. + wq->waitq = DWC_WAITQ_ALLOC();
  42243. + if (!wq->waitq) {
  42244. + goto no_waitq;
  42245. + }
  42246. +
  42247. +#ifdef DEBUG
  42248. + DWC_CIRCLEQ_INIT(&wq->entries);
  42249. +#endif
  42250. + return wq;
  42251. +
  42252. + no_waitq:
  42253. + DWC_SPINLOCK_FREE(wq->lock);
  42254. + no_lock:
  42255. + destroy_workqueue(wq->wq);
  42256. + no_wq:
  42257. + DWC_FREE(wq);
  42258. +
  42259. + return NULL;
  42260. +}
  42261. +
  42262. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  42263. +{
  42264. +#ifdef DEBUG
  42265. + if (wq->pending != 0) {
  42266. + struct work_container *wc;
  42267. + DWC_ERROR("Destroying work queue with pending work");
  42268. + DWC_CIRCLEQ_FOREACH(wc, &wq->entries, entry) {
  42269. + DWC_ERROR("Work %s still pending", wc->name);
  42270. + }
  42271. + }
  42272. +#endif
  42273. + destroy_workqueue(wq->wq);
  42274. + DWC_SPINLOCK_FREE(wq->lock);
  42275. + DWC_WAITQ_FREE(wq->waitq);
  42276. + DWC_FREE(wq);
  42277. +}
  42278. +
  42279. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  42280. + char *format, ...)
  42281. +{
  42282. + dwc_irqflags_t flags;
  42283. + work_container_t *container;
  42284. + static char name[128];
  42285. + va_list args;
  42286. +
  42287. + va_start(args, format);
  42288. + DWC_VSNPRINTF(name, 128, format, args);
  42289. + va_end(args);
  42290. +
  42291. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42292. + wq->pending++;
  42293. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42294. + DWC_WAITQ_TRIGGER(wq->waitq);
  42295. +
  42296. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  42297. + if (!container) {
  42298. + DWC_ERROR("Cannot allocate memory for container\n");
  42299. + return;
  42300. + }
  42301. +
  42302. + container->name = DWC_STRDUP(name);
  42303. + if (!container->name) {
  42304. + DWC_ERROR("Cannot allocate memory for container->name\n");
  42305. + DWC_FREE(container);
  42306. + return;
  42307. + }
  42308. +
  42309. + container->cb = cb;
  42310. + container->data = data;
  42311. + container->wq = wq;
  42312. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  42313. + INIT_WORK(&container->work.work, do_work);
  42314. +
  42315. +#ifdef DEBUG
  42316. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  42317. +#endif
  42318. + queue_work(wq->wq, &container->work.work);
  42319. +}
  42320. +
  42321. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  42322. + void *data, uint32_t time, char *format, ...)
  42323. +{
  42324. + dwc_irqflags_t flags;
  42325. + work_container_t *container;
  42326. + static char name[128];
  42327. + va_list args;
  42328. +
  42329. + va_start(args, format);
  42330. + DWC_VSNPRINTF(name, 128, format, args);
  42331. + va_end(args);
  42332. +
  42333. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  42334. + wq->pending++;
  42335. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  42336. + DWC_WAITQ_TRIGGER(wq->waitq);
  42337. +
  42338. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  42339. + if (!container) {
  42340. + DWC_ERROR("Cannot allocate memory for container\n");
  42341. + return;
  42342. + }
  42343. +
  42344. + container->name = DWC_STRDUP(name);
  42345. + if (!container->name) {
  42346. + DWC_ERROR("Cannot allocate memory for container->name\n");
  42347. + DWC_FREE(container);
  42348. + return;
  42349. + }
  42350. +
  42351. + container->cb = cb;
  42352. + container->data = data;
  42353. + container->wq = wq;
  42354. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  42355. + INIT_DELAYED_WORK(&container->work, do_work);
  42356. +
  42357. +#ifdef DEBUG
  42358. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  42359. +#endif
  42360. + queue_delayed_work(wq->wq, &container->work, msecs_to_jiffies(time));
  42361. +}
  42362. +
  42363. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  42364. +{
  42365. + return wq->pending;
  42366. +}
  42367. +
  42368. +
  42369. +#ifdef DWC_LIBMODULE
  42370. +
  42371. +#ifdef DWC_CCLIB
  42372. +/* CC */
  42373. +EXPORT_SYMBOL(dwc_cc_if_alloc);
  42374. +EXPORT_SYMBOL(dwc_cc_if_free);
  42375. +EXPORT_SYMBOL(dwc_cc_clear);
  42376. +EXPORT_SYMBOL(dwc_cc_add);
  42377. +EXPORT_SYMBOL(dwc_cc_remove);
  42378. +EXPORT_SYMBOL(dwc_cc_change);
  42379. +EXPORT_SYMBOL(dwc_cc_data_for_save);
  42380. +EXPORT_SYMBOL(dwc_cc_restore_from_data);
  42381. +EXPORT_SYMBOL(dwc_cc_match_chid);
  42382. +EXPORT_SYMBOL(dwc_cc_match_cdid);
  42383. +EXPORT_SYMBOL(dwc_cc_ck);
  42384. +EXPORT_SYMBOL(dwc_cc_chid);
  42385. +EXPORT_SYMBOL(dwc_cc_cdid);
  42386. +EXPORT_SYMBOL(dwc_cc_name);
  42387. +#endif /* DWC_CCLIB */
  42388. +
  42389. +#ifdef DWC_CRYPTOLIB
  42390. +# ifndef CONFIG_MACH_IPMATE
  42391. +/* Modpow */
  42392. +EXPORT_SYMBOL(dwc_modpow);
  42393. +
  42394. +/* DH */
  42395. +EXPORT_SYMBOL(dwc_dh_modpow);
  42396. +EXPORT_SYMBOL(dwc_dh_derive_keys);
  42397. +EXPORT_SYMBOL(dwc_dh_pk);
  42398. +# endif /* CONFIG_MACH_IPMATE */
  42399. +
  42400. +/* Crypto */
  42401. +EXPORT_SYMBOL(dwc_wusb_aes_encrypt);
  42402. +EXPORT_SYMBOL(dwc_wusb_cmf);
  42403. +EXPORT_SYMBOL(dwc_wusb_prf);
  42404. +EXPORT_SYMBOL(dwc_wusb_fill_ccm_nonce);
  42405. +EXPORT_SYMBOL(dwc_wusb_gen_nonce);
  42406. +EXPORT_SYMBOL(dwc_wusb_gen_key);
  42407. +EXPORT_SYMBOL(dwc_wusb_gen_mic);
  42408. +#endif /* DWC_CRYPTOLIB */
  42409. +
  42410. +/* Notification */
  42411. +#ifdef DWC_NOTIFYLIB
  42412. +EXPORT_SYMBOL(dwc_alloc_notification_manager);
  42413. +EXPORT_SYMBOL(dwc_free_notification_manager);
  42414. +EXPORT_SYMBOL(dwc_register_notifier);
  42415. +EXPORT_SYMBOL(dwc_unregister_notifier);
  42416. +EXPORT_SYMBOL(dwc_add_observer);
  42417. +EXPORT_SYMBOL(dwc_remove_observer);
  42418. +EXPORT_SYMBOL(dwc_notify);
  42419. +#endif
  42420. +
  42421. +/* Memory Debugging Routines */
  42422. +#ifdef DWC_DEBUG_MEMORY
  42423. +EXPORT_SYMBOL(dwc_alloc_debug);
  42424. +EXPORT_SYMBOL(dwc_alloc_atomic_debug);
  42425. +EXPORT_SYMBOL(dwc_free_debug);
  42426. +EXPORT_SYMBOL(dwc_dma_alloc_debug);
  42427. +EXPORT_SYMBOL(dwc_dma_free_debug);
  42428. +#endif
  42429. +
  42430. +EXPORT_SYMBOL(DWC_MEMSET);
  42431. +EXPORT_SYMBOL(DWC_MEMCPY);
  42432. +EXPORT_SYMBOL(DWC_MEMMOVE);
  42433. +EXPORT_SYMBOL(DWC_MEMCMP);
  42434. +EXPORT_SYMBOL(DWC_STRNCMP);
  42435. +EXPORT_SYMBOL(DWC_STRCMP);
  42436. +EXPORT_SYMBOL(DWC_STRLEN);
  42437. +EXPORT_SYMBOL(DWC_STRCPY);
  42438. +EXPORT_SYMBOL(DWC_STRDUP);
  42439. +EXPORT_SYMBOL(DWC_ATOI);
  42440. +EXPORT_SYMBOL(DWC_ATOUI);
  42441. +
  42442. +#ifdef DWC_UTFLIB
  42443. +EXPORT_SYMBOL(DWC_UTF8_TO_UTF16LE);
  42444. +#endif /* DWC_UTFLIB */
  42445. +
  42446. +EXPORT_SYMBOL(DWC_IN_IRQ);
  42447. +EXPORT_SYMBOL(DWC_IN_BH);
  42448. +EXPORT_SYMBOL(DWC_VPRINTF);
  42449. +EXPORT_SYMBOL(DWC_VSNPRINTF);
  42450. +EXPORT_SYMBOL(DWC_PRINTF);
  42451. +EXPORT_SYMBOL(DWC_SPRINTF);
  42452. +EXPORT_SYMBOL(DWC_SNPRINTF);
  42453. +EXPORT_SYMBOL(__DWC_WARN);
  42454. +EXPORT_SYMBOL(__DWC_ERROR);
  42455. +EXPORT_SYMBOL(DWC_EXCEPTION);
  42456. +
  42457. +#ifdef DEBUG
  42458. +EXPORT_SYMBOL(__DWC_DEBUG);
  42459. +#endif
  42460. +
  42461. +EXPORT_SYMBOL(__DWC_DMA_ALLOC);
  42462. +EXPORT_SYMBOL(__DWC_DMA_ALLOC_ATOMIC);
  42463. +EXPORT_SYMBOL(__DWC_DMA_FREE);
  42464. +EXPORT_SYMBOL(__DWC_ALLOC);
  42465. +EXPORT_SYMBOL(__DWC_ALLOC_ATOMIC);
  42466. +EXPORT_SYMBOL(__DWC_FREE);
  42467. +
  42468. +#ifdef DWC_CRYPTOLIB
  42469. +EXPORT_SYMBOL(DWC_RANDOM_BYTES);
  42470. +EXPORT_SYMBOL(DWC_AES_CBC);
  42471. +EXPORT_SYMBOL(DWC_SHA256);
  42472. +EXPORT_SYMBOL(DWC_HMAC_SHA256);
  42473. +#endif
  42474. +
  42475. +EXPORT_SYMBOL(DWC_CPU_TO_LE32);
  42476. +EXPORT_SYMBOL(DWC_CPU_TO_BE32);
  42477. +EXPORT_SYMBOL(DWC_LE32_TO_CPU);
  42478. +EXPORT_SYMBOL(DWC_BE32_TO_CPU);
  42479. +EXPORT_SYMBOL(DWC_CPU_TO_LE16);
  42480. +EXPORT_SYMBOL(DWC_CPU_TO_BE16);
  42481. +EXPORT_SYMBOL(DWC_LE16_TO_CPU);
  42482. +EXPORT_SYMBOL(DWC_BE16_TO_CPU);
  42483. +EXPORT_SYMBOL(DWC_READ_REG32);
  42484. +EXPORT_SYMBOL(DWC_WRITE_REG32);
  42485. +EXPORT_SYMBOL(DWC_MODIFY_REG32);
  42486. +
  42487. +#if 0
  42488. +EXPORT_SYMBOL(DWC_READ_REG64);
  42489. +EXPORT_SYMBOL(DWC_WRITE_REG64);
  42490. +EXPORT_SYMBOL(DWC_MODIFY_REG64);
  42491. +#endif
  42492. +
  42493. +EXPORT_SYMBOL(DWC_SPINLOCK_ALLOC);
  42494. +EXPORT_SYMBOL(DWC_SPINLOCK_FREE);
  42495. +EXPORT_SYMBOL(DWC_SPINLOCK);
  42496. +EXPORT_SYMBOL(DWC_SPINUNLOCK);
  42497. +EXPORT_SYMBOL(DWC_SPINLOCK_IRQSAVE);
  42498. +EXPORT_SYMBOL(DWC_SPINUNLOCK_IRQRESTORE);
  42499. +EXPORT_SYMBOL(DWC_MUTEX_ALLOC);
  42500. +
  42501. +#if (!defined(DWC_LINUX) || !defined(CONFIG_DEBUG_MUTEXES))
  42502. +EXPORT_SYMBOL(DWC_MUTEX_FREE);
  42503. +#endif
  42504. +
  42505. +EXPORT_SYMBOL(DWC_MUTEX_LOCK);
  42506. +EXPORT_SYMBOL(DWC_MUTEX_TRYLOCK);
  42507. +EXPORT_SYMBOL(DWC_MUTEX_UNLOCK);
  42508. +EXPORT_SYMBOL(DWC_UDELAY);
  42509. +EXPORT_SYMBOL(DWC_MDELAY);
  42510. +EXPORT_SYMBOL(DWC_MSLEEP);
  42511. +EXPORT_SYMBOL(DWC_TIME);
  42512. +EXPORT_SYMBOL(DWC_TIMER_ALLOC);
  42513. +EXPORT_SYMBOL(DWC_TIMER_FREE);
  42514. +EXPORT_SYMBOL(DWC_TIMER_SCHEDULE);
  42515. +EXPORT_SYMBOL(DWC_TIMER_CANCEL);
  42516. +EXPORT_SYMBOL(DWC_WAITQ_ALLOC);
  42517. +EXPORT_SYMBOL(DWC_WAITQ_FREE);
  42518. +EXPORT_SYMBOL(DWC_WAITQ_WAIT);
  42519. +EXPORT_SYMBOL(DWC_WAITQ_WAIT_TIMEOUT);
  42520. +EXPORT_SYMBOL(DWC_WAITQ_TRIGGER);
  42521. +EXPORT_SYMBOL(DWC_WAITQ_ABORT);
  42522. +EXPORT_SYMBOL(DWC_THREAD_RUN);
  42523. +EXPORT_SYMBOL(DWC_THREAD_STOP);
  42524. +EXPORT_SYMBOL(DWC_THREAD_SHOULD_STOP);
  42525. +EXPORT_SYMBOL(DWC_TASK_ALLOC);
  42526. +EXPORT_SYMBOL(DWC_TASK_FREE);
  42527. +EXPORT_SYMBOL(DWC_TASK_SCHEDULE);
  42528. +EXPORT_SYMBOL(DWC_WORKQ_WAIT_WORK_DONE);
  42529. +EXPORT_SYMBOL(DWC_WORKQ_ALLOC);
  42530. +EXPORT_SYMBOL(DWC_WORKQ_FREE);
  42531. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE);
  42532. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE_DELAYED);
  42533. +EXPORT_SYMBOL(DWC_WORKQ_PENDING);
  42534. +
  42535. +static int dwc_common_port_init_module(void)
  42536. +{
  42537. + int result = 0;
  42538. +
  42539. + printk(KERN_DEBUG "Module dwc_common_port init\n" );
  42540. +
  42541. +#ifdef DWC_DEBUG_MEMORY
  42542. + result = dwc_memory_debug_start(NULL);
  42543. + if (result) {
  42544. + printk(KERN_ERR
  42545. + "dwc_memory_debug_start() failed with error %d\n",
  42546. + result);
  42547. + return result;
  42548. + }
  42549. +#endif
  42550. +
  42551. +#ifdef DWC_NOTIFYLIB
  42552. + result = dwc_alloc_notification_manager(NULL, NULL);
  42553. + if (result) {
  42554. + printk(KERN_ERR
  42555. + "dwc_alloc_notification_manager() failed with error %d\n",
  42556. + result);
  42557. + return result;
  42558. + }
  42559. +#endif
  42560. + return result;
  42561. +}
  42562. +
  42563. +static void dwc_common_port_exit_module(void)
  42564. +{
  42565. + printk(KERN_DEBUG "Module dwc_common_port exit\n" );
  42566. +
  42567. +#ifdef DWC_NOTIFYLIB
  42568. + dwc_free_notification_manager();
  42569. +#endif
  42570. +
  42571. +#ifdef DWC_DEBUG_MEMORY
  42572. + dwc_memory_debug_stop();
  42573. +#endif
  42574. +}
  42575. +
  42576. +module_init(dwc_common_port_init_module);
  42577. +module_exit(dwc_common_port_exit_module);
  42578. +
  42579. +MODULE_DESCRIPTION("DWC Common Library - Portable version");
  42580. +MODULE_AUTHOR("Synopsys Inc.");
  42581. +MODULE_LICENSE ("GPL");
  42582. +
  42583. +#endif /* DWC_LIBMODULE */
  42584. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c
  42585. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 1970-01-01 01:00:00.000000000 +0100
  42586. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 2014-02-18 11:52:14.000000000 +0100
  42587. @@ -0,0 +1,1275 @@
  42588. +#include "dwc_os.h"
  42589. +#include "dwc_list.h"
  42590. +
  42591. +#ifdef DWC_CCLIB
  42592. +# include "dwc_cc.h"
  42593. +#endif
  42594. +
  42595. +#ifdef DWC_CRYPTOLIB
  42596. +# include "dwc_modpow.h"
  42597. +# include "dwc_dh.h"
  42598. +# include "dwc_crypto.h"
  42599. +#endif
  42600. +
  42601. +#ifdef DWC_NOTIFYLIB
  42602. +# include "dwc_notifier.h"
  42603. +#endif
  42604. +
  42605. +/* OS-Level Implementations */
  42606. +
  42607. +/* This is the NetBSD 4.0.1 kernel implementation of the DWC platform library. */
  42608. +
  42609. +
  42610. +/* MISC */
  42611. +
  42612. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  42613. +{
  42614. + return memset(dest, byte, size);
  42615. +}
  42616. +
  42617. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  42618. +{
  42619. + return memcpy(dest, src, size);
  42620. +}
  42621. +
  42622. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  42623. +{
  42624. + bcopy(src, dest, size);
  42625. + return dest;
  42626. +}
  42627. +
  42628. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  42629. +{
  42630. + return memcmp(m1, m2, size);
  42631. +}
  42632. +
  42633. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  42634. +{
  42635. + return strncmp(s1, s2, size);
  42636. +}
  42637. +
  42638. +int DWC_STRCMP(void *s1, void *s2)
  42639. +{
  42640. + return strcmp(s1, s2);
  42641. +}
  42642. +
  42643. +int DWC_STRLEN(char const *str)
  42644. +{
  42645. + return strlen(str);
  42646. +}
  42647. +
  42648. +char *DWC_STRCPY(char *to, char const *from)
  42649. +{
  42650. + return strcpy(to, from);
  42651. +}
  42652. +
  42653. +char *DWC_STRDUP(char const *str)
  42654. +{
  42655. + int len = DWC_STRLEN(str) + 1;
  42656. + char *new = DWC_ALLOC_ATOMIC(len);
  42657. +
  42658. + if (!new) {
  42659. + return NULL;
  42660. + }
  42661. +
  42662. + DWC_MEMCPY(new, str, len);
  42663. + return new;
  42664. +}
  42665. +
  42666. +int DWC_ATOI(char *str, int32_t *value)
  42667. +{
  42668. + char *end = NULL;
  42669. +
  42670. + /* NetBSD doesn't have 'strtol' in the kernel, but 'strtoul'
  42671. + * should be equivalent on 2's complement machines
  42672. + */
  42673. + *value = strtoul(str, &end, 0);
  42674. + if (*end == '\0') {
  42675. + return 0;
  42676. + }
  42677. +
  42678. + return -1;
  42679. +}
  42680. +
  42681. +int DWC_ATOUI(char *str, uint32_t *value)
  42682. +{
  42683. + char *end = NULL;
  42684. +
  42685. + *value = strtoul(str, &end, 0);
  42686. + if (*end == '\0') {
  42687. + return 0;
  42688. + }
  42689. +
  42690. + return -1;
  42691. +}
  42692. +
  42693. +
  42694. +#ifdef DWC_UTFLIB
  42695. +/* From usbstring.c */
  42696. +
  42697. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  42698. +{
  42699. + int count = 0;
  42700. + u8 c;
  42701. + u16 uchar;
  42702. +
  42703. + /* this insists on correct encodings, though not minimal ones.
  42704. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  42705. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  42706. + */
  42707. + while (len != 0 && (c = (u8) *s++) != 0) {
  42708. + if (unlikely(c & 0x80)) {
  42709. + // 2-byte sequence:
  42710. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  42711. + if ((c & 0xe0) == 0xc0) {
  42712. + uchar = (c & 0x1f) << 6;
  42713. +
  42714. + c = (u8) *s++;
  42715. + if ((c & 0xc0) != 0xc0)
  42716. + goto fail;
  42717. + c &= 0x3f;
  42718. + uchar |= c;
  42719. +
  42720. + // 3-byte sequence (most CJKV characters):
  42721. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  42722. + } else if ((c & 0xf0) == 0xe0) {
  42723. + uchar = (c & 0x0f) << 12;
  42724. +
  42725. + c = (u8) *s++;
  42726. + if ((c & 0xc0) != 0xc0)
  42727. + goto fail;
  42728. + c &= 0x3f;
  42729. + uchar |= c << 6;
  42730. +
  42731. + c = (u8) *s++;
  42732. + if ((c & 0xc0) != 0xc0)
  42733. + goto fail;
  42734. + c &= 0x3f;
  42735. + uchar |= c;
  42736. +
  42737. + /* no bogus surrogates */
  42738. + if (0xd800 <= uchar && uchar <= 0xdfff)
  42739. + goto fail;
  42740. +
  42741. + // 4-byte sequence (surrogate pairs, currently rare):
  42742. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  42743. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  42744. + // (uuuuu = wwww + 1)
  42745. + // FIXME accept the surrogate code points (only)
  42746. + } else
  42747. + goto fail;
  42748. + } else
  42749. + uchar = c;
  42750. + put_unaligned (cpu_to_le16 (uchar), cp++);
  42751. + count++;
  42752. + len--;
  42753. + }
  42754. + return count;
  42755. +fail:
  42756. + return -1;
  42757. +}
  42758. +
  42759. +#endif /* DWC_UTFLIB */
  42760. +
  42761. +
  42762. +/* dwc_debug.h */
  42763. +
  42764. +dwc_bool_t DWC_IN_IRQ(void)
  42765. +{
  42766. +// return in_irq();
  42767. + return 0;
  42768. +}
  42769. +
  42770. +dwc_bool_t DWC_IN_BH(void)
  42771. +{
  42772. +// return in_softirq();
  42773. + return 0;
  42774. +}
  42775. +
  42776. +void DWC_VPRINTF(char *format, va_list args)
  42777. +{
  42778. + vprintf(format, args);
  42779. +}
  42780. +
  42781. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  42782. +{
  42783. + return vsnprintf(str, size, format, args);
  42784. +}
  42785. +
  42786. +void DWC_PRINTF(char *format, ...)
  42787. +{
  42788. + va_list args;
  42789. +
  42790. + va_start(args, format);
  42791. + DWC_VPRINTF(format, args);
  42792. + va_end(args);
  42793. +}
  42794. +
  42795. +int DWC_SPRINTF(char *buffer, char *format, ...)
  42796. +{
  42797. + int retval;
  42798. + va_list args;
  42799. +
  42800. + va_start(args, format);
  42801. + retval = vsprintf(buffer, format, args);
  42802. + va_end(args);
  42803. + return retval;
  42804. +}
  42805. +
  42806. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  42807. +{
  42808. + int retval;
  42809. + va_list args;
  42810. +
  42811. + va_start(args, format);
  42812. + retval = vsnprintf(buffer, size, format, args);
  42813. + va_end(args);
  42814. + return retval;
  42815. +}
  42816. +
  42817. +void __DWC_WARN(char *format, ...)
  42818. +{
  42819. + va_list args;
  42820. +
  42821. + va_start(args, format);
  42822. + DWC_VPRINTF(format, args);
  42823. + va_end(args);
  42824. +}
  42825. +
  42826. +void __DWC_ERROR(char *format, ...)
  42827. +{
  42828. + va_list args;
  42829. +
  42830. + va_start(args, format);
  42831. + DWC_VPRINTF(format, args);
  42832. + va_end(args);
  42833. +}
  42834. +
  42835. +void DWC_EXCEPTION(char *format, ...)
  42836. +{
  42837. + va_list args;
  42838. +
  42839. + va_start(args, format);
  42840. + DWC_VPRINTF(format, args);
  42841. + va_end(args);
  42842. +// BUG_ON(1); ???
  42843. +}
  42844. +
  42845. +#ifdef DEBUG
  42846. +void __DWC_DEBUG(char *format, ...)
  42847. +{
  42848. + va_list args;
  42849. +
  42850. + va_start(args, format);
  42851. + DWC_VPRINTF(format, args);
  42852. + va_end(args);
  42853. +}
  42854. +#endif
  42855. +
  42856. +
  42857. +/* dwc_mem.h */
  42858. +
  42859. +#if 0
  42860. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  42861. + uint32_t align,
  42862. + uint32_t alloc)
  42863. +{
  42864. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  42865. + size, align, alloc);
  42866. + return (dwc_pool_t *)pool;
  42867. +}
  42868. +
  42869. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  42870. +{
  42871. + dma_pool_destroy((struct dma_pool *)pool);
  42872. +}
  42873. +
  42874. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  42875. +{
  42876. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  42877. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  42878. +}
  42879. +
  42880. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  42881. +{
  42882. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  42883. + memset(..);
  42884. +}
  42885. +
  42886. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  42887. +{
  42888. + dma_pool_free(pool, vaddr, daddr);
  42889. +}
  42890. +#endif
  42891. +
  42892. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  42893. +{
  42894. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  42895. + int error;
  42896. +
  42897. + error = bus_dmamem_alloc(dma->dma_tag, size, 1, size, dma->segs,
  42898. + sizeof(dma->segs) / sizeof(dma->segs[0]),
  42899. + &dma->nsegs, BUS_DMA_NOWAIT);
  42900. + if (error) {
  42901. + printf("%s: bus_dmamem_alloc(%ju) failed: %d\n", __func__,
  42902. + (uintmax_t)size, error);
  42903. + goto fail_0;
  42904. + }
  42905. +
  42906. + error = bus_dmamem_map(dma->dma_tag, dma->segs, dma->nsegs, size,
  42907. + (caddr_t *)&dma->dma_vaddr,
  42908. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
  42909. + if (error) {
  42910. + printf("%s: bus_dmamem_map failed: %d\n", __func__, error);
  42911. + goto fail_1;
  42912. + }
  42913. +
  42914. + error = bus_dmamap_create(dma->dma_tag, size, 1, size, 0,
  42915. + BUS_DMA_NOWAIT, &dma->dma_map);
  42916. + if (error) {
  42917. + printf("%s: bus_dmamap_create failed: %d\n", __func__, error);
  42918. + goto fail_2;
  42919. + }
  42920. +
  42921. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
  42922. + size, NULL, BUS_DMA_NOWAIT);
  42923. + if (error) {
  42924. + printf("%s: bus_dmamap_load failed: %d\n", __func__, error);
  42925. + goto fail_3;
  42926. + }
  42927. +
  42928. + dma->dma_paddr = (bus_addr_t)dma->segs[0].ds_addr;
  42929. + *dma_addr = dma->dma_paddr;
  42930. + return dma->dma_vaddr;
  42931. +
  42932. +fail_3:
  42933. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  42934. +fail_2:
  42935. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  42936. +fail_1:
  42937. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  42938. +fail_0:
  42939. + dma->dma_map = NULL;
  42940. + dma->dma_vaddr = NULL;
  42941. + dma->nsegs = 0;
  42942. +
  42943. + return NULL;
  42944. +}
  42945. +
  42946. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  42947. +{
  42948. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  42949. +
  42950. + if (dma->dma_map != NULL) {
  42951. + bus_dmamap_sync(dma->dma_tag, dma->dma_map, 0, size,
  42952. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  42953. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  42954. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  42955. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  42956. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  42957. + dma->dma_paddr = 0;
  42958. + dma->dma_map = NULL;
  42959. + dma->dma_vaddr = NULL;
  42960. + dma->nsegs = 0;
  42961. + }
  42962. +}
  42963. +
  42964. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  42965. +{
  42966. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  42967. +}
  42968. +
  42969. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  42970. +{
  42971. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  42972. +}
  42973. +
  42974. +void __DWC_FREE(void *mem_ctx, void *addr)
  42975. +{
  42976. + free(addr, M_DEVBUF);
  42977. +}
  42978. +
  42979. +
  42980. +#ifdef DWC_CRYPTOLIB
  42981. +/* dwc_crypto.h */
  42982. +
  42983. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  42984. +{
  42985. + get_random_bytes(buffer, length);
  42986. +}
  42987. +
  42988. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  42989. +{
  42990. + struct crypto_blkcipher *tfm;
  42991. + struct blkcipher_desc desc;
  42992. + struct scatterlist sgd;
  42993. + struct scatterlist sgs;
  42994. +
  42995. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  42996. + if (tfm == NULL) {
  42997. + printk("failed to load transform for aes CBC\n");
  42998. + return -1;
  42999. + }
  43000. +
  43001. + crypto_blkcipher_setkey(tfm, key, keylen);
  43002. + crypto_blkcipher_set_iv(tfm, iv, 16);
  43003. +
  43004. + sg_init_one(&sgd, out, messagelen);
  43005. + sg_init_one(&sgs, message, messagelen);
  43006. +
  43007. + desc.tfm = tfm;
  43008. + desc.flags = 0;
  43009. +
  43010. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  43011. + crypto_free_blkcipher(tfm);
  43012. + DWC_ERROR("AES CBC encryption failed");
  43013. + return -1;
  43014. + }
  43015. +
  43016. + crypto_free_blkcipher(tfm);
  43017. + return 0;
  43018. +}
  43019. +
  43020. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  43021. +{
  43022. + struct crypto_hash *tfm;
  43023. + struct hash_desc desc;
  43024. + struct scatterlist sg;
  43025. +
  43026. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  43027. + if (IS_ERR(tfm)) {
  43028. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  43029. + return 0;
  43030. + }
  43031. + desc.tfm = tfm;
  43032. + desc.flags = 0;
  43033. +
  43034. + sg_init_one(&sg, message, len);
  43035. + crypto_hash_digest(&desc, &sg, len, out);
  43036. + crypto_free_hash(tfm);
  43037. +
  43038. + return 1;
  43039. +}
  43040. +
  43041. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  43042. + uint8_t *key, uint32_t keylen, uint8_t *out)
  43043. +{
  43044. + struct crypto_hash *tfm;
  43045. + struct hash_desc desc;
  43046. + struct scatterlist sg;
  43047. +
  43048. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  43049. + if (IS_ERR(tfm)) {
  43050. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  43051. + return 0;
  43052. + }
  43053. + desc.tfm = tfm;
  43054. + desc.flags = 0;
  43055. +
  43056. + sg_init_one(&sg, message, messagelen);
  43057. + crypto_hash_setkey(tfm, key, keylen);
  43058. + crypto_hash_digest(&desc, &sg, messagelen, out);
  43059. + crypto_free_hash(tfm);
  43060. +
  43061. + return 1;
  43062. +}
  43063. +
  43064. +#endif /* DWC_CRYPTOLIB */
  43065. +
  43066. +
  43067. +/* Byte Ordering Conversions */
  43068. +
  43069. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  43070. +{
  43071. +#ifdef __LITTLE_ENDIAN
  43072. + return *p;
  43073. +#else
  43074. + uint8_t *u_p = (uint8_t *)p;
  43075. +
  43076. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  43077. +#endif
  43078. +}
  43079. +
  43080. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  43081. +{
  43082. +#ifdef __BIG_ENDIAN
  43083. + return *p;
  43084. +#else
  43085. + uint8_t *u_p = (uint8_t *)p;
  43086. +
  43087. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  43088. +#endif
  43089. +}
  43090. +
  43091. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  43092. +{
  43093. +#ifdef __LITTLE_ENDIAN
  43094. + return *p;
  43095. +#else
  43096. + uint8_t *u_p = (uint8_t *)p;
  43097. +
  43098. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  43099. +#endif
  43100. +}
  43101. +
  43102. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  43103. +{
  43104. +#ifdef __BIG_ENDIAN
  43105. + return *p;
  43106. +#else
  43107. + uint8_t *u_p = (uint8_t *)p;
  43108. +
  43109. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  43110. +#endif
  43111. +}
  43112. +
  43113. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  43114. +{
  43115. +#ifdef __LITTLE_ENDIAN
  43116. + return *p;
  43117. +#else
  43118. + uint8_t *u_p = (uint8_t *)p;
  43119. + return (u_p[1] | (u_p[0] << 8));
  43120. +#endif
  43121. +}
  43122. +
  43123. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  43124. +{
  43125. +#ifdef __BIG_ENDIAN
  43126. + return *p;
  43127. +#else
  43128. + uint8_t *u_p = (uint8_t *)p;
  43129. + return (u_p[1] | (u_p[0] << 8));
  43130. +#endif
  43131. +}
  43132. +
  43133. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  43134. +{
  43135. +#ifdef __LITTLE_ENDIAN
  43136. + return *p;
  43137. +#else
  43138. + uint8_t *u_p = (uint8_t *)p;
  43139. + return (u_p[1] | (u_p[0] << 8));
  43140. +#endif
  43141. +}
  43142. +
  43143. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  43144. +{
  43145. +#ifdef __BIG_ENDIAN
  43146. + return *p;
  43147. +#else
  43148. + uint8_t *u_p = (uint8_t *)p;
  43149. + return (u_p[1] | (u_p[0] << 8));
  43150. +#endif
  43151. +}
  43152. +
  43153. +
  43154. +/* Registers */
  43155. +
  43156. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  43157. +{
  43158. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43159. + bus_size_t ior = (bus_size_t)reg;
  43160. +
  43161. + return bus_space_read_4(io->iot, io->ioh, ior);
  43162. +}
  43163. +
  43164. +#if 0
  43165. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  43166. +{
  43167. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43168. + bus_size_t ior = (bus_size_t)reg;
  43169. +
  43170. + return bus_space_read_8(io->iot, io->ioh, ior);
  43171. +}
  43172. +#endif
  43173. +
  43174. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  43175. +{
  43176. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43177. + bus_size_t ior = (bus_size_t)reg;
  43178. +
  43179. + bus_space_write_4(io->iot, io->ioh, ior, value);
  43180. +}
  43181. +
  43182. +#if 0
  43183. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  43184. +{
  43185. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43186. + bus_size_t ior = (bus_size_t)reg;
  43187. +
  43188. + bus_space_write_8(io->iot, io->ioh, ior, value);
  43189. +}
  43190. +#endif
  43191. +
  43192. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  43193. + uint32_t set_mask)
  43194. +{
  43195. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43196. + bus_size_t ior = (bus_size_t)reg;
  43197. +
  43198. + bus_space_write_4(io->iot, io->ioh, ior,
  43199. + (bus_space_read_4(io->iot, io->ioh, ior) &
  43200. + ~clear_mask) | set_mask);
  43201. +}
  43202. +
  43203. +#if 0
  43204. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  43205. + uint64_t set_mask)
  43206. +{
  43207. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  43208. + bus_size_t ior = (bus_size_t)reg;
  43209. +
  43210. + bus_space_write_8(io->iot, io->ioh, ior,
  43211. + (bus_space_read_8(io->iot, io->ioh, ior) &
  43212. + ~clear_mask) | set_mask);
  43213. +}
  43214. +#endif
  43215. +
  43216. +
  43217. +/* Locking */
  43218. +
  43219. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  43220. +{
  43221. + struct simplelock *sl = DWC_ALLOC(sizeof(*sl));
  43222. +
  43223. + if (!sl) {
  43224. + DWC_ERROR("Cannot allocate memory for spinlock");
  43225. + return NULL;
  43226. + }
  43227. +
  43228. + simple_lock_init(sl);
  43229. + return (dwc_spinlock_t *)sl;
  43230. +}
  43231. +
  43232. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  43233. +{
  43234. + struct simplelock *sl = (struct simplelock *)lock;
  43235. +
  43236. + DWC_FREE(sl);
  43237. +}
  43238. +
  43239. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  43240. +{
  43241. + simple_lock((struct simplelock *)lock);
  43242. +}
  43243. +
  43244. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  43245. +{
  43246. + simple_unlock((struct simplelock *)lock);
  43247. +}
  43248. +
  43249. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  43250. +{
  43251. + simple_lock((struct simplelock *)lock);
  43252. + *flags = splbio();
  43253. +}
  43254. +
  43255. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  43256. +{
  43257. + splx(flags);
  43258. + simple_unlock((struct simplelock *)lock);
  43259. +}
  43260. +
  43261. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  43262. +{
  43263. + dwc_mutex_t *mutex = DWC_ALLOC(sizeof(struct lock));
  43264. +
  43265. + if (!mutex) {
  43266. + DWC_ERROR("Cannot allocate memory for mutex");
  43267. + return NULL;
  43268. + }
  43269. +
  43270. + lockinit((struct lock *)mutex, 0, "dw3mtx", 0, 0);
  43271. + return mutex;
  43272. +}
  43273. +
  43274. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  43275. +#else
  43276. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  43277. +{
  43278. + DWC_FREE(mutex);
  43279. +}
  43280. +#endif
  43281. +
  43282. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  43283. +{
  43284. + lockmgr((struct lock *)mutex, LK_EXCLUSIVE, NULL);
  43285. +}
  43286. +
  43287. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  43288. +{
  43289. + int status;
  43290. +
  43291. + status = lockmgr((struct lock *)mutex, LK_EXCLUSIVE | LK_NOWAIT, NULL);
  43292. + return status == 0;
  43293. +}
  43294. +
  43295. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  43296. +{
  43297. + lockmgr((struct lock *)mutex, LK_RELEASE, NULL);
  43298. +}
  43299. +
  43300. +
  43301. +/* Timing */
  43302. +
  43303. +void DWC_UDELAY(uint32_t usecs)
  43304. +{
  43305. + DELAY(usecs);
  43306. +}
  43307. +
  43308. +void DWC_MDELAY(uint32_t msecs)
  43309. +{
  43310. + do {
  43311. + DELAY(1000);
  43312. + } while (--msecs);
  43313. +}
  43314. +
  43315. +void DWC_MSLEEP(uint32_t msecs)
  43316. +{
  43317. + struct timeval tv;
  43318. +
  43319. + tv.tv_sec = msecs / 1000;
  43320. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  43321. + tsleep(&tv, 0, "dw3slp", tvtohz(&tv));
  43322. +}
  43323. +
  43324. +uint32_t DWC_TIME(void)
  43325. +{
  43326. + struct timeval tv;
  43327. +
  43328. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  43329. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  43330. +}
  43331. +
  43332. +
  43333. +/* Timers */
  43334. +
  43335. +struct dwc_timer {
  43336. + struct callout t;
  43337. + char *name;
  43338. + dwc_spinlock_t *lock;
  43339. + dwc_timer_callback_t cb;
  43340. + void *data;
  43341. +};
  43342. +
  43343. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  43344. +{
  43345. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  43346. +
  43347. + if (!t) {
  43348. + DWC_ERROR("Cannot allocate memory for timer");
  43349. + return NULL;
  43350. + }
  43351. +
  43352. + callout_init(&t->t);
  43353. +
  43354. + t->name = DWC_STRDUP(name);
  43355. + if (!t->name) {
  43356. + DWC_ERROR("Cannot allocate memory for timer->name");
  43357. + goto no_name;
  43358. + }
  43359. +
  43360. + t->lock = DWC_SPINLOCK_ALLOC();
  43361. + if (!t->lock) {
  43362. + DWC_ERROR("Cannot allocate memory for timer->lock");
  43363. + goto no_lock;
  43364. + }
  43365. +
  43366. + t->cb = cb;
  43367. + t->data = data;
  43368. +
  43369. + return t;
  43370. +
  43371. + no_lock:
  43372. + DWC_FREE(t->name);
  43373. + no_name:
  43374. + DWC_FREE(t);
  43375. +
  43376. + return NULL;
  43377. +}
  43378. +
  43379. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  43380. +{
  43381. + callout_stop(&timer->t);
  43382. + DWC_SPINLOCK_FREE(timer->lock);
  43383. + DWC_FREE(timer->name);
  43384. + DWC_FREE(timer);
  43385. +}
  43386. +
  43387. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  43388. +{
  43389. + struct timeval tv;
  43390. +
  43391. + tv.tv_sec = time / 1000;
  43392. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  43393. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  43394. +}
  43395. +
  43396. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  43397. +{
  43398. + callout_stop(&timer->t);
  43399. +}
  43400. +
  43401. +
  43402. +/* Wait Queues */
  43403. +
  43404. +struct dwc_waitq {
  43405. + struct simplelock lock;
  43406. + int abort;
  43407. +};
  43408. +
  43409. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  43410. +{
  43411. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  43412. +
  43413. + if (!wq) {
  43414. + DWC_ERROR("Cannot allocate memory for waitqueue");
  43415. + return NULL;
  43416. + }
  43417. +
  43418. + simple_lock_init(&wq->lock);
  43419. + wq->abort = 0;
  43420. +
  43421. + return wq;
  43422. +}
  43423. +
  43424. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  43425. +{
  43426. + DWC_FREE(wq);
  43427. +}
  43428. +
  43429. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  43430. +{
  43431. + int ipl;
  43432. + int result = 0;
  43433. +
  43434. + simple_lock(&wq->lock);
  43435. + ipl = splbio();
  43436. +
  43437. + /* Skip the sleep if already aborted or triggered */
  43438. + if (!wq->abort && !cond(data)) {
  43439. + splx(ipl);
  43440. + result = ltsleep(wq, PCATCH, "dw3wat", 0, &wq->lock); // infinite timeout
  43441. + ipl = splbio();
  43442. + }
  43443. +
  43444. + if (result == 0) { // awoken
  43445. + if (wq->abort) {
  43446. + wq->abort = 0;
  43447. + result = -DWC_E_ABORT;
  43448. + } else {
  43449. + result = 0;
  43450. + }
  43451. +
  43452. + splx(ipl);
  43453. + simple_unlock(&wq->lock);
  43454. + } else {
  43455. + wq->abort = 0;
  43456. + splx(ipl);
  43457. + simple_unlock(&wq->lock);
  43458. +
  43459. + if (result == ERESTART) { // signaled - restart
  43460. + result = -DWC_E_RESTART;
  43461. + } else { // signaled - must be EINTR
  43462. + result = -DWC_E_ABORT;
  43463. + }
  43464. + }
  43465. +
  43466. + return result;
  43467. +}
  43468. +
  43469. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  43470. + void *data, int32_t msecs)
  43471. +{
  43472. + struct timeval tv, tv1, tv2;
  43473. + int ipl;
  43474. + int result = 0;
  43475. +
  43476. + tv.tv_sec = msecs / 1000;
  43477. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  43478. +
  43479. + simple_lock(&wq->lock);
  43480. + ipl = splbio();
  43481. +
  43482. + /* Skip the sleep if already aborted or triggered */
  43483. + if (!wq->abort && !cond(data)) {
  43484. + splx(ipl);
  43485. + getmicrouptime(&tv1);
  43486. + result = ltsleep(wq, PCATCH, "dw3wto", tvtohz(&tv), &wq->lock);
  43487. + getmicrouptime(&tv2);
  43488. + ipl = splbio();
  43489. + }
  43490. +
  43491. + if (result == 0) { // awoken
  43492. + if (wq->abort) {
  43493. + wq->abort = 0;
  43494. + splx(ipl);
  43495. + simple_unlock(&wq->lock);
  43496. + result = -DWC_E_ABORT;
  43497. + } else {
  43498. + splx(ipl);
  43499. + simple_unlock(&wq->lock);
  43500. +
  43501. + tv2.tv_usec -= tv1.tv_usec;
  43502. + if (tv2.tv_usec < 0) {
  43503. + tv2.tv_usec += 1000000;
  43504. + tv2.tv_sec--;
  43505. + }
  43506. +
  43507. + tv2.tv_sec -= tv1.tv_sec;
  43508. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  43509. + result = msecs - result;
  43510. + if (result <= 0)
  43511. + result = 1;
  43512. + }
  43513. + } else {
  43514. + wq->abort = 0;
  43515. + splx(ipl);
  43516. + simple_unlock(&wq->lock);
  43517. +
  43518. + if (result == ERESTART) { // signaled - restart
  43519. + result = -DWC_E_RESTART;
  43520. +
  43521. + } else if (result == EINTR) { // signaled - interrupt
  43522. + result = -DWC_E_ABORT;
  43523. +
  43524. + } else { // timed out
  43525. + result = -DWC_E_TIMEOUT;
  43526. + }
  43527. + }
  43528. +
  43529. + return result;
  43530. +}
  43531. +
  43532. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  43533. +{
  43534. + wakeup(wq);
  43535. +}
  43536. +
  43537. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  43538. +{
  43539. + int ipl;
  43540. +
  43541. + simple_lock(&wq->lock);
  43542. + ipl = splbio();
  43543. + wq->abort = 1;
  43544. + wakeup(wq);
  43545. + splx(ipl);
  43546. + simple_unlock(&wq->lock);
  43547. +}
  43548. +
  43549. +
  43550. +/* Threading */
  43551. +
  43552. +struct dwc_thread {
  43553. + struct proc *proc;
  43554. + int abort;
  43555. +};
  43556. +
  43557. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  43558. +{
  43559. + int retval;
  43560. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  43561. +
  43562. + if (!thread) {
  43563. + return NULL;
  43564. + }
  43565. +
  43566. + thread->abort = 0;
  43567. + retval = kthread_create1((void (*)(void *))func, data, &thread->proc,
  43568. + "%s", name);
  43569. + if (retval) {
  43570. + DWC_FREE(thread);
  43571. + return NULL;
  43572. + }
  43573. +
  43574. + return thread;
  43575. +}
  43576. +
  43577. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  43578. +{
  43579. + int retval;
  43580. +
  43581. + thread->abort = 1;
  43582. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  43583. +
  43584. + if (retval == 0) {
  43585. + /* DWC_THREAD_EXIT() will free the thread struct */
  43586. + return 0;
  43587. + }
  43588. +
  43589. + /* NOTE: We leak the thread struct if thread doesn't die */
  43590. +
  43591. + if (retval == EWOULDBLOCK) {
  43592. + return -DWC_E_TIMEOUT;
  43593. + }
  43594. +
  43595. + return -DWC_E_UNKNOWN;
  43596. +}
  43597. +
  43598. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  43599. +{
  43600. + return thread->abort;
  43601. +}
  43602. +
  43603. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  43604. +{
  43605. + wakeup(&thread->abort);
  43606. + DWC_FREE(thread);
  43607. + kthread_exit(0);
  43608. +}
  43609. +
  43610. +/* tasklets
  43611. + - Runs in interrupt context (cannot sleep)
  43612. + - Each tasklet runs on a single CPU
  43613. + - Different tasklets can be running simultaneously on different CPUs
  43614. + [ On NetBSD there is no corresponding mechanism, drivers don't have bottom-
  43615. + halves. So we just call the callback directly from DWC_TASK_SCHEDULE() ]
  43616. + */
  43617. +struct dwc_tasklet {
  43618. + dwc_tasklet_callback_t cb;
  43619. + void *data;
  43620. +};
  43621. +
  43622. +static void tasklet_callback(void *data)
  43623. +{
  43624. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  43625. +
  43626. + task->cb(task->data);
  43627. +}
  43628. +
  43629. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  43630. +{
  43631. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  43632. +
  43633. + if (task) {
  43634. + task->cb = cb;
  43635. + task->data = data;
  43636. + } else {
  43637. + DWC_ERROR("Cannot allocate memory for tasklet");
  43638. + }
  43639. +
  43640. + return task;
  43641. +}
  43642. +
  43643. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  43644. +{
  43645. + DWC_FREE(task);
  43646. +}
  43647. +
  43648. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  43649. +{
  43650. + tasklet_callback(task);
  43651. +}
  43652. +
  43653. +
  43654. +/* workqueues
  43655. + - Runs in process context (can sleep)
  43656. + */
  43657. +typedef struct work_container {
  43658. + dwc_work_callback_t cb;
  43659. + void *data;
  43660. + dwc_workq_t *wq;
  43661. + char *name;
  43662. + int hz;
  43663. + struct work task;
  43664. +} work_container_t;
  43665. +
  43666. +struct dwc_workq {
  43667. + struct workqueue *taskq;
  43668. + dwc_spinlock_t *lock;
  43669. + dwc_waitq_t *waitq;
  43670. + int pending;
  43671. + struct work_container *container;
  43672. +};
  43673. +
  43674. +static void do_work(struct work *task, void *data)
  43675. +{
  43676. + dwc_workq_t *wq = (dwc_workq_t *)data;
  43677. + work_container_t *container = wq->container;
  43678. + dwc_irqflags_t flags;
  43679. +
  43680. + if (container->hz) {
  43681. + tsleep(container, 0, "dw3wrk", container->hz);
  43682. + }
  43683. +
  43684. + container->cb(container->data);
  43685. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  43686. +
  43687. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  43688. + if (container->name)
  43689. + DWC_FREE(container->name);
  43690. + DWC_FREE(container);
  43691. + wq->pending--;
  43692. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  43693. + DWC_WAITQ_TRIGGER(wq->waitq);
  43694. +}
  43695. +
  43696. +static int work_done(void *data)
  43697. +{
  43698. + dwc_workq_t *workq = (dwc_workq_t *)data;
  43699. +
  43700. + return workq->pending == 0;
  43701. +}
  43702. +
  43703. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  43704. +{
  43705. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  43706. +}
  43707. +
  43708. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  43709. +{
  43710. + int result;
  43711. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  43712. +
  43713. + if (!wq) {
  43714. + DWC_ERROR("Cannot allocate memory for workqueue");
  43715. + return NULL;
  43716. + }
  43717. +
  43718. + result = workqueue_create(&wq->taskq, name, do_work, wq, 0 /*PWAIT*/,
  43719. + IPL_BIO, 0);
  43720. + if (result) {
  43721. + DWC_ERROR("Cannot create workqueue");
  43722. + goto no_taskq;
  43723. + }
  43724. +
  43725. + wq->pending = 0;
  43726. +
  43727. + wq->lock = DWC_SPINLOCK_ALLOC();
  43728. + if (!wq->lock) {
  43729. + DWC_ERROR("Cannot allocate memory for spinlock");
  43730. + goto no_lock;
  43731. + }
  43732. +
  43733. + wq->waitq = DWC_WAITQ_ALLOC();
  43734. + if (!wq->waitq) {
  43735. + DWC_ERROR("Cannot allocate memory for waitqueue");
  43736. + goto no_waitq;
  43737. + }
  43738. +
  43739. + return wq;
  43740. +
  43741. + no_waitq:
  43742. + DWC_SPINLOCK_FREE(wq->lock);
  43743. + no_lock:
  43744. + workqueue_destroy(wq->taskq);
  43745. + no_taskq:
  43746. + DWC_FREE(wq);
  43747. +
  43748. + return NULL;
  43749. +}
  43750. +
  43751. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  43752. +{
  43753. +#ifdef DEBUG
  43754. + dwc_irqflags_t flags;
  43755. +
  43756. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  43757. +
  43758. + if (wq->pending != 0) {
  43759. + struct work_container *container = wq->container;
  43760. +
  43761. + DWC_ERROR("Destroying work queue with pending work");
  43762. +
  43763. + if (container && container->name) {
  43764. + DWC_ERROR("Work %s still pending", container->name);
  43765. + }
  43766. + }
  43767. +
  43768. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  43769. +#endif
  43770. + DWC_WAITQ_FREE(wq->waitq);
  43771. + DWC_SPINLOCK_FREE(wq->lock);
  43772. + workqueue_destroy(wq->taskq);
  43773. + DWC_FREE(wq);
  43774. +}
  43775. +
  43776. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  43777. + char *format, ...)
  43778. +{
  43779. + dwc_irqflags_t flags;
  43780. + work_container_t *container;
  43781. + static char name[128];
  43782. + va_list args;
  43783. +
  43784. + va_start(args, format);
  43785. + DWC_VSNPRINTF(name, 128, format, args);
  43786. + va_end(args);
  43787. +
  43788. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  43789. + wq->pending++;
  43790. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  43791. + DWC_WAITQ_TRIGGER(wq->waitq);
  43792. +
  43793. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  43794. + if (!container) {
  43795. + DWC_ERROR("Cannot allocate memory for container");
  43796. + return;
  43797. + }
  43798. +
  43799. + container->name = DWC_STRDUP(name);
  43800. + if (!container->name) {
  43801. + DWC_ERROR("Cannot allocate memory for container->name");
  43802. + DWC_FREE(container);
  43803. + return;
  43804. + }
  43805. +
  43806. + container->cb = cb;
  43807. + container->data = data;
  43808. + container->wq = wq;
  43809. + container->hz = 0;
  43810. + wq->container = container;
  43811. +
  43812. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  43813. + workqueue_enqueue(wq->taskq, &container->task);
  43814. +}
  43815. +
  43816. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  43817. + void *data, uint32_t time, char *format, ...)
  43818. +{
  43819. + dwc_irqflags_t flags;
  43820. + work_container_t *container;
  43821. + static char name[128];
  43822. + struct timeval tv;
  43823. + va_list args;
  43824. +
  43825. + va_start(args, format);
  43826. + DWC_VSNPRINTF(name, 128, format, args);
  43827. + va_end(args);
  43828. +
  43829. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  43830. + wq->pending++;
  43831. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  43832. + DWC_WAITQ_TRIGGER(wq->waitq);
  43833. +
  43834. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  43835. + if (!container) {
  43836. + DWC_ERROR("Cannot allocate memory for container");
  43837. + return;
  43838. + }
  43839. +
  43840. + container->name = DWC_STRDUP(name);
  43841. + if (!container->name) {
  43842. + DWC_ERROR("Cannot allocate memory for container->name");
  43843. + DWC_FREE(container);
  43844. + return;
  43845. + }
  43846. +
  43847. + container->cb = cb;
  43848. + container->data = data;
  43849. + container->wq = wq;
  43850. + tv.tv_sec = time / 1000;
  43851. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  43852. + container->hz = tvtohz(&tv);
  43853. + wq->container = container;
  43854. +
  43855. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  43856. + workqueue_enqueue(wq->taskq, &container->task);
  43857. +}
  43858. +
  43859. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  43860. +{
  43861. + return wq->pending;
  43862. +}
  43863. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_crypto.c linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_crypto.c
  43864. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_crypto.c 1970-01-01 01:00:00.000000000 +0100
  43865. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_crypto.c 2014-02-18 11:52:14.000000000 +0100
  43866. @@ -0,0 +1,308 @@
  43867. +/* =========================================================================
  43868. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.c $
  43869. + * $Revision: #5 $
  43870. + * $Date: 2010/09/28 $
  43871. + * $Change: 1596182 $
  43872. + *
  43873. + * Synopsys Portability Library Software and documentation
  43874. + * (hereinafter, "Software") is an Unsupported proprietary work of
  43875. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  43876. + * between Synopsys and you.
  43877. + *
  43878. + * The Software IS NOT an item of Licensed Software or Licensed Product
  43879. + * under any End User Software License Agreement or Agreement for
  43880. + * Licensed Product with Synopsys or any supplement thereto. You are
  43881. + * permitted to use and redistribute this Software in source and binary
  43882. + * forms, with or without modification, provided that redistributions
  43883. + * of source code must retain this notice. You may not view, use,
  43884. + * disclose, copy or distribute this file or any information contained
  43885. + * herein except pursuant to this license grant from Synopsys. If you
  43886. + * do not agree with this notice, including the disclaimer below, then
  43887. + * you are not authorized to use the Software.
  43888. + *
  43889. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  43890. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  43891. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  43892. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  43893. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  43894. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  43895. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  43896. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  43897. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43898. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  43899. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  43900. + * DAMAGE.
  43901. + * ========================================================================= */
  43902. +
  43903. +/** @file
  43904. + * This file contains the WUSB cryptographic routines.
  43905. + */
  43906. +
  43907. +#ifdef DWC_CRYPTOLIB
  43908. +
  43909. +#include "dwc_crypto.h"
  43910. +#include "usb.h"
  43911. +
  43912. +#ifdef DEBUG
  43913. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  43914. +{
  43915. + int i;
  43916. + DWC_PRINTF("%s: ", name);
  43917. + for (i=0; i<len; i++) {
  43918. + DWC_PRINTF("%02x ", bytes[i]);
  43919. + }
  43920. + DWC_PRINTF("\n");
  43921. +}
  43922. +#else
  43923. +#define dump_bytes(x...)
  43924. +#endif
  43925. +
  43926. +/* Display a block */
  43927. +void show_block(const u8 *blk, const char *prefix, const char *suffix, int a)
  43928. +{
  43929. +#ifdef DWC_DEBUG_CRYPTO
  43930. + int i, blksize = 16;
  43931. +
  43932. + DWC_DEBUG("%s", prefix);
  43933. +
  43934. + if (suffix == NULL) {
  43935. + suffix = "\n";
  43936. + blksize = a;
  43937. + }
  43938. +
  43939. + for (i = 0; i < blksize; i++)
  43940. + DWC_PRINT("%02x%s", *blk++, ((i & 3) == 3) ? " " : " ");
  43941. + DWC_PRINT(suffix);
  43942. +#endif
  43943. +}
  43944. +
  43945. +/**
  43946. + * Encrypts an array of bytes using the AES encryption engine.
  43947. + * If <code>dst</code> == <code>src</code>, then the bytes will be encrypted
  43948. + * in-place.
  43949. + *
  43950. + * @return 0 on success, negative error code on error.
  43951. + */
  43952. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst)
  43953. +{
  43954. + u8 block_t[16];
  43955. + DWC_MEMSET(block_t, 0, 16);
  43956. +
  43957. + return DWC_AES_CBC(src, 16, key, 16, block_t, dst);
  43958. +}
  43959. +
  43960. +/**
  43961. + * The CCM-MAC-FUNCTION described in section 6.5 of the WUSB spec.
  43962. + * This function takes a data string and returns the encrypted CBC
  43963. + * Counter-mode MIC.
  43964. + *
  43965. + * @param key The 128-bit symmetric key.
  43966. + * @param nonce The CCM nonce.
  43967. + * @param label The unique 14-byte ASCII text label.
  43968. + * @param bytes The byte array to be encrypted.
  43969. + * @param len Length of the byte array.
  43970. + * @param result Byte array to receive the 8-byte encrypted MIC.
  43971. + */
  43972. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  43973. + char *label, u8 *bytes, int len, u8 *result)
  43974. +{
  43975. + u8 block_m[16];
  43976. + u8 block_x[16];
  43977. + u8 block_t[8];
  43978. + int idx, blkNum;
  43979. + u16 la = (u16)(len + 14);
  43980. +
  43981. + /* Set the AES-128 key */
  43982. + //dwc_aes_setkey(tfm, key, 16);
  43983. +
  43984. + /* Fill block B0 from flags = 0x59, N, and l(m) = 0 */
  43985. + block_m[0] = 0x59;
  43986. + for (idx = 0; idx < 13; idx++)
  43987. + block_m[idx + 1] = nonce[idx];
  43988. + block_m[14] = 0;
  43989. + block_m[15] = 0;
  43990. +
  43991. + /* Produce the CBC IV */
  43992. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  43993. + show_block(block_m, "CBC IV in: ", "\n", 0);
  43994. + show_block(block_x, "CBC IV out:", "\n", 0);
  43995. +
  43996. + /* Fill block B1 from l(a) = Blen + 14, and A */
  43997. + block_x[0] ^= (u8)(la >> 8);
  43998. + block_x[1] ^= (u8)la;
  43999. + for (idx = 0; idx < 14; idx++)
  44000. + block_x[idx + 2] ^= label[idx];
  44001. + show_block(block_x, "After xor: ", "b1\n", 16);
  44002. +
  44003. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  44004. + show_block(block_x, "After AES: ", "b1\n", 16);
  44005. +
  44006. + idx = 0;
  44007. + blkNum = 0;
  44008. +
  44009. + /* Fill remaining blocks with B */
  44010. + while (len-- > 0) {
  44011. + block_x[idx] ^= *bytes++;
  44012. + if (++idx >= 16) {
  44013. + idx = 0;
  44014. + show_block(block_x, "After xor: ", "\n", blkNum);
  44015. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  44016. + show_block(block_x, "After AES: ", "\n", blkNum);
  44017. + blkNum++;
  44018. + }
  44019. + }
  44020. +
  44021. + /* Handle partial last block */
  44022. + if (idx > 0) {
  44023. + show_block(block_x, "After xor: ", "\n", blkNum);
  44024. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  44025. + show_block(block_x, "After AES: ", "\n", blkNum);
  44026. + }
  44027. +
  44028. + /* Save the MIC tag */
  44029. + DWC_MEMCPY(block_t, block_x, 8);
  44030. + show_block(block_t, "MIC tag : ", NULL, 8);
  44031. +
  44032. + /* Fill block A0 from flags = 0x01, N, and counter = 0 */
  44033. + block_m[0] = 0x01;
  44034. + block_m[14] = 0;
  44035. + block_m[15] = 0;
  44036. +
  44037. + /* Encrypt the counter */
  44038. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  44039. + show_block(block_x, "CTR[MIC] : ", NULL, 8);
  44040. +
  44041. + /* XOR with MIC tag */
  44042. + for (idx = 0; idx < 8; idx++) {
  44043. + block_t[idx] ^= block_x[idx];
  44044. + }
  44045. +
  44046. + /* Return result to caller */
  44047. + DWC_MEMCPY(result, block_t, 8);
  44048. + show_block(result, "CCM-MIC : ", NULL, 8);
  44049. +
  44050. +}
  44051. +
  44052. +/**
  44053. + * The PRF function described in section 6.5 of the WUSB spec. This function
  44054. + * concatenates MIC values returned from dwc_cmf() to create a value of
  44055. + * the requested length.
  44056. + *
  44057. + * @param prf_len Length of the PRF function in bits (64, 128, or 256).
  44058. + * @param key, nonce, label, bytes, len Same as for dwc_cmf().
  44059. + * @param result Byte array to receive the result.
  44060. + */
  44061. +void dwc_wusb_prf(int prf_len, u8 *key,
  44062. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result)
  44063. +{
  44064. + int i;
  44065. +
  44066. + nonce[0] = 0;
  44067. + for (i = 0; i < prf_len >> 6; i++, nonce[0]++) {
  44068. + dwc_wusb_cmf(key, nonce, label, bytes, len, result);
  44069. + result += 8;
  44070. + }
  44071. +}
  44072. +
  44073. +/**
  44074. + * Fills in CCM Nonce per the WUSB spec.
  44075. + *
  44076. + * @param[in] haddr Host address.
  44077. + * @param[in] daddr Device address.
  44078. + * @param[in] tkid Session Key(PTK) identifier.
  44079. + * @param[out] nonce Pointer to where the CCM Nonce output is to be written.
  44080. + */
  44081. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  44082. + uint8_t *nonce)
  44083. +{
  44084. +
  44085. + DWC_DEBUG("%s %x %x\n", __func__, daddr, haddr);
  44086. +
  44087. + DWC_MEMSET(&nonce[0], 0, 16);
  44088. +
  44089. + DWC_MEMCPY(&nonce[6], tkid, 3);
  44090. + nonce[9] = daddr & 0xFF;
  44091. + nonce[10] = (daddr >> 8) & 0xFF;
  44092. + nonce[11] = haddr & 0xFF;
  44093. + nonce[12] = (haddr >> 8) & 0xFF;
  44094. +
  44095. + dump_bytes("CCM nonce", nonce, 16);
  44096. +}
  44097. +
  44098. +/**
  44099. + * Generates a 16-byte cryptographic-grade random number for the Host/Device
  44100. + * Nonce.
  44101. + */
  44102. +void dwc_wusb_gen_nonce(uint16_t addr, uint8_t *nonce)
  44103. +{
  44104. + uint8_t inonce[16];
  44105. + uint32_t temp[4];
  44106. +
  44107. + /* Fill in the Nonce */
  44108. + DWC_MEMSET(&inonce[0], 0, sizeof(inonce));
  44109. + inonce[9] = addr & 0xFF;
  44110. + inonce[10] = (addr >> 8) & 0xFF;
  44111. + inonce[11] = inonce[9];
  44112. + inonce[12] = inonce[10];
  44113. +
  44114. + /* Collect "randomness samples" */
  44115. + DWC_RANDOM_BYTES((uint8_t *)temp, 16);
  44116. +
  44117. + dwc_wusb_prf_128((uint8_t *)temp, nonce,
  44118. + "Random Numbers", (uint8_t *)temp, sizeof(temp),
  44119. + nonce);
  44120. +}
  44121. +
  44122. +/**
  44123. + * Generates the Session Key (PTK) and Key Confirmation Key (KCK) per the
  44124. + * WUSB spec.
  44125. + *
  44126. + * @param[in] ccm_nonce Pointer to CCM Nonce.
  44127. + * @param[in] mk Master Key to derive the session from
  44128. + * @param[in] hnonce Pointer to Host Nonce.
  44129. + * @param[in] dnonce Pointer to Device Nonce.
  44130. + * @param[out] kck Pointer to where the KCK output is to be written.
  44131. + * @param[out] ptk Pointer to where the PTK output is to be written.
  44132. + */
  44133. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk, uint8_t *hnonce,
  44134. + uint8_t *dnonce, uint8_t *kck, uint8_t *ptk)
  44135. +{
  44136. + uint8_t idata[32];
  44137. + uint8_t odata[32];
  44138. +
  44139. + dump_bytes("ck", mk, 16);
  44140. + dump_bytes("hnonce", hnonce, 16);
  44141. + dump_bytes("dnonce", dnonce, 16);
  44142. +
  44143. + /* The data is the HNonce and DNonce concatenated */
  44144. + DWC_MEMCPY(&idata[0], hnonce, 16);
  44145. + DWC_MEMCPY(&idata[16], dnonce, 16);
  44146. +
  44147. + dwc_wusb_prf_256(mk, ccm_nonce, "Pair-wise keys", idata, 32, odata);
  44148. +
  44149. + /* Low 16 bytes of the result is the KCK, high 16 is the PTK */
  44150. + DWC_MEMCPY(kck, &odata[0], 16);
  44151. + DWC_MEMCPY(ptk, &odata[16], 16);
  44152. +
  44153. + dump_bytes("kck", kck, 16);
  44154. + dump_bytes("ptk", ptk, 16);
  44155. +}
  44156. +
  44157. +/**
  44158. + * Generates the Message Integrity Code over the Handshake data per the
  44159. + * WUSB spec.
  44160. + *
  44161. + * @param ccm_nonce Pointer to CCM Nonce.
  44162. + * @param kck Pointer to Key Confirmation Key.
  44163. + * @param data Pointer to Handshake data to be checked.
  44164. + * @param mic Pointer to where the MIC output is to be written.
  44165. + */
  44166. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t *kck,
  44167. + uint8_t *data, uint8_t *mic)
  44168. +{
  44169. +
  44170. + dwc_wusb_prf_64(kck, ccm_nonce, "out-of-bandMIC",
  44171. + data, WUSB_HANDSHAKE_LEN_FOR_MIC, mic);
  44172. +}
  44173. +
  44174. +#endif /* DWC_CRYPTOLIB */
  44175. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_crypto.h linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_crypto.h
  44176. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_crypto.h 1970-01-01 01:00:00.000000000 +0100
  44177. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_crypto.h 2014-02-18 11:52:14.000000000 +0100
  44178. @@ -0,0 +1,111 @@
  44179. +/* =========================================================================
  44180. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.h $
  44181. + * $Revision: #3 $
  44182. + * $Date: 2010/09/28 $
  44183. + * $Change: 1596182 $
  44184. + *
  44185. + * Synopsys Portability Library Software and documentation
  44186. + * (hereinafter, "Software") is an Unsupported proprietary work of
  44187. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  44188. + * between Synopsys and you.
  44189. + *
  44190. + * The Software IS NOT an item of Licensed Software or Licensed Product
  44191. + * under any End User Software License Agreement or Agreement for
  44192. + * Licensed Product with Synopsys or any supplement thereto. You are
  44193. + * permitted to use and redistribute this Software in source and binary
  44194. + * forms, with or without modification, provided that redistributions
  44195. + * of source code must retain this notice. You may not view, use,
  44196. + * disclose, copy or distribute this file or any information contained
  44197. + * herein except pursuant to this license grant from Synopsys. If you
  44198. + * do not agree with this notice, including the disclaimer below, then
  44199. + * you are not authorized to use the Software.
  44200. + *
  44201. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  44202. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  44203. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  44204. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  44205. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44206. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44207. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44208. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  44209. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44210. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  44211. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  44212. + * DAMAGE.
  44213. + * ========================================================================= */
  44214. +
  44215. +#ifndef _DWC_CRYPTO_H_
  44216. +#define _DWC_CRYPTO_H_
  44217. +
  44218. +#ifdef __cplusplus
  44219. +extern "C" {
  44220. +#endif
  44221. +
  44222. +/** @file
  44223. + *
  44224. + * This file contains declarations for the WUSB Cryptographic routines as
  44225. + * defined in the WUSB spec. They are only to be used internally by the DWC UWB
  44226. + * modules.
  44227. + */
  44228. +
  44229. +#include "dwc_os.h"
  44230. +
  44231. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst);
  44232. +
  44233. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  44234. + char *label, u8 *bytes, int len, u8 *result);
  44235. +void dwc_wusb_prf(int prf_len, u8 *key,
  44236. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result);
  44237. +
  44238. +/**
  44239. + * The PRF-64 function described in section 6.5 of the WUSB spec.
  44240. + *
  44241. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  44242. + */
  44243. +static inline void dwc_wusb_prf_64(u8 *key, u8 *nonce,
  44244. + char *label, u8 *bytes, int len, u8 *result)
  44245. +{
  44246. + dwc_wusb_prf(64, key, nonce, label, bytes, len, result);
  44247. +}
  44248. +
  44249. +/**
  44250. + * The PRF-128 function described in section 6.5 of the WUSB spec.
  44251. + *
  44252. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  44253. + */
  44254. +static inline void dwc_wusb_prf_128(u8 *key, u8 *nonce,
  44255. + char *label, u8 *bytes, int len, u8 *result)
  44256. +{
  44257. + dwc_wusb_prf(128, key, nonce, label, bytes, len, result);
  44258. +}
  44259. +
  44260. +/**
  44261. + * The PRF-256 function described in section 6.5 of the WUSB spec.
  44262. + *
  44263. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  44264. + */
  44265. +static inline void dwc_wusb_prf_256(u8 *key, u8 *nonce,
  44266. + char *label, u8 *bytes, int len, u8 *result)
  44267. +{
  44268. + dwc_wusb_prf(256, key, nonce, label, bytes, len, result);
  44269. +}
  44270. +
  44271. +
  44272. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  44273. + uint8_t *nonce);
  44274. +void dwc_wusb_gen_nonce(uint16_t addr,
  44275. + uint8_t *nonce);
  44276. +
  44277. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk,
  44278. + uint8_t *hnonce, uint8_t *dnonce,
  44279. + uint8_t *kck, uint8_t *ptk);
  44280. +
  44281. +
  44282. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t
  44283. + *kck, uint8_t *data, uint8_t *mic);
  44284. +
  44285. +#ifdef __cplusplus
  44286. +}
  44287. +#endif
  44288. +
  44289. +#endif /* _DWC_CRYPTO_H_ */
  44290. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_dh.c linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_dh.c
  44291. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_dh.c 1970-01-01 01:00:00.000000000 +0100
  44292. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_dh.c 2014-02-18 11:52:14.000000000 +0100
  44293. @@ -0,0 +1,291 @@
  44294. +/* =========================================================================
  44295. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.c $
  44296. + * $Revision: #3 $
  44297. + * $Date: 2010/09/28 $
  44298. + * $Change: 1596182 $
  44299. + *
  44300. + * Synopsys Portability Library Software and documentation
  44301. + * (hereinafter, "Software") is an Unsupported proprietary work of
  44302. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  44303. + * between Synopsys and you.
  44304. + *
  44305. + * The Software IS NOT an item of Licensed Software or Licensed Product
  44306. + * under any End User Software License Agreement or Agreement for
  44307. + * Licensed Product with Synopsys or any supplement thereto. You are
  44308. + * permitted to use and redistribute this Software in source and binary
  44309. + * forms, with or without modification, provided that redistributions
  44310. + * of source code must retain this notice. You may not view, use,
  44311. + * disclose, copy or distribute this file or any information contained
  44312. + * herein except pursuant to this license grant from Synopsys. If you
  44313. + * do not agree with this notice, including the disclaimer below, then
  44314. + * you are not authorized to use the Software.
  44315. + *
  44316. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  44317. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  44318. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  44319. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  44320. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44321. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44322. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44323. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  44324. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44325. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  44326. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  44327. + * DAMAGE.
  44328. + * ========================================================================= */
  44329. +#ifdef DWC_CRYPTOLIB
  44330. +
  44331. +#ifndef CONFIG_MACH_IPMATE
  44332. +
  44333. +#include "dwc_dh.h"
  44334. +#include "dwc_modpow.h"
  44335. +
  44336. +#ifdef DEBUG
  44337. +/* This function prints out a buffer in the format described in the Association
  44338. + * Model specification. */
  44339. +static void dh_dump(char *str, void *_num, int len)
  44340. +{
  44341. + uint8_t *num = _num;
  44342. + int i;
  44343. + DWC_PRINTF("%s\n", str);
  44344. + for (i = 0; i < len; i ++) {
  44345. + DWC_PRINTF("%02x", num[i]);
  44346. + if (((i + 1) % 2) == 0) DWC_PRINTF(" ");
  44347. + if (((i + 1) % 26) == 0) DWC_PRINTF("\n");
  44348. + }
  44349. +
  44350. + DWC_PRINTF("\n");
  44351. +}
  44352. +#else
  44353. +#define dh_dump(_x...) do {; } while(0)
  44354. +#endif
  44355. +
  44356. +/* Constant g value */
  44357. +static __u32 dh_g[] = {
  44358. + 0x02000000,
  44359. +};
  44360. +
  44361. +/* Constant p value */
  44362. +static __u32 dh_p[] = {
  44363. + 0xFFFFFFFF, 0xFFFFFFFF, 0xA2DA0FC9, 0x34C26821, 0x8B62C6C4, 0xD11CDC80, 0x084E0229, 0x74CC678A,
  44364. + 0xA6BE0B02, 0x229B133B, 0x79084A51, 0xDD04348E, 0xB31995EF, 0x1B433ACD, 0x6D0A2B30, 0x37145FF2,
  44365. + 0x6D35E14F, 0x45C2516D, 0x76B585E4, 0xC67E5E62, 0xE9424CF4, 0x6BED37A6, 0xB65CFF0B, 0xEDB706F4,
  44366. + 0xFB6B38EE, 0xA59F895A, 0x11249FAE, 0xE61F4B7C, 0x51662849, 0x3D5BE4EC, 0xB87C00C2, 0x05BF63A1,
  44367. + 0x3648DA98, 0x9AD3551C, 0xA83F1669, 0x5FCF24FD, 0x235D6583, 0x96ADA3DC, 0x56F3621C, 0xBB528520,
  44368. + 0x0729D59E, 0x6D969670, 0x4E350C67, 0x0498BC4A, 0x086C74F1, 0x7C2118CA, 0x465E9032, 0x3BCE362E,
  44369. + 0x2C779EE3, 0x03860E18, 0xA283279B, 0x8FA207EC, 0xF05DC5B5, 0xC9524C6F, 0xF6CB2BDE, 0x18175895,
  44370. + 0x7C499539, 0xE56A95EA, 0x1826D215, 0x1005FA98, 0x5A8E7215, 0x2DC4AA8A, 0x0D1733AD, 0x337A5004,
  44371. + 0xAB2155A8, 0x64BA1CDF, 0x0485FBEC, 0x0AEFDB58, 0x5771EA8A, 0x7D0C065D, 0x850F97B3, 0xC7E4E1A6,
  44372. + 0x8CAEF5AB, 0xD73309DB, 0xE0948C1E, 0x9D61254A, 0x26D2E3CE, 0x6BEED21A, 0x06FA2FF1, 0x64088AD9,
  44373. + 0x730276D8, 0x646AC83E, 0x182B1F52, 0x0C207B17, 0x5717E1BB, 0x6C5D617A, 0xC0880977, 0xE246D9BA,
  44374. + 0xA04FE208, 0x31ABE574, 0xFC5BDB43, 0x8E10FDE0, 0x20D1824B, 0xCAD23AA9, 0xFFFFFFFF, 0xFFFFFFFF,
  44375. +};
  44376. +
  44377. +static void dh_swap_bytes(void *_in, void *_out, uint32_t len)
  44378. +{
  44379. + uint8_t *in = _in;
  44380. + uint8_t *out = _out;
  44381. + int i;
  44382. + for (i=0; i<len; i++) {
  44383. + out[i] = in[len-1-i];
  44384. + }
  44385. +}
  44386. +
  44387. +/* Computes the modular exponentiation (num^exp % mod). num, exp, and mod are
  44388. + * big endian numbers of size len, in bytes. Each len value must be a multiple
  44389. + * of 4. */
  44390. +int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  44391. + void *exp, uint32_t exp_len,
  44392. + void *mod, uint32_t mod_len,
  44393. + void *out)
  44394. +{
  44395. + /* modpow() takes little endian numbers. AM uses big-endian. This
  44396. + * function swaps bytes of numbers before passing onto modpow. */
  44397. +
  44398. + int retval = 0;
  44399. + uint32_t *result;
  44400. +
  44401. + uint32_t *bignum_num = dwc_alloc(mem_ctx, num_len + 4);
  44402. + uint32_t *bignum_exp = dwc_alloc(mem_ctx, exp_len + 4);
  44403. + uint32_t *bignum_mod = dwc_alloc(mem_ctx, mod_len + 4);
  44404. +
  44405. + dh_swap_bytes(num, &bignum_num[1], num_len);
  44406. + bignum_num[0] = num_len / 4;
  44407. +
  44408. + dh_swap_bytes(exp, &bignum_exp[1], exp_len);
  44409. + bignum_exp[0] = exp_len / 4;
  44410. +
  44411. + dh_swap_bytes(mod, &bignum_mod[1], mod_len);
  44412. + bignum_mod[0] = mod_len / 4;
  44413. +
  44414. + result = dwc_modpow(mem_ctx, bignum_num, bignum_exp, bignum_mod);
  44415. + if (!result) {
  44416. + retval = -1;
  44417. + goto dh_modpow_nomem;
  44418. + }
  44419. +
  44420. + dh_swap_bytes(&result[1], out, result[0] * 4);
  44421. + dwc_free(mem_ctx, result);
  44422. +
  44423. + dh_modpow_nomem:
  44424. + dwc_free(mem_ctx, bignum_num);
  44425. + dwc_free(mem_ctx, bignum_exp);
  44426. + dwc_free(mem_ctx, bignum_mod);
  44427. + return retval;
  44428. +}
  44429. +
  44430. +
  44431. +int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pk, uint8_t *hash)
  44432. +{
  44433. + int retval;
  44434. + uint8_t m3[385];
  44435. +
  44436. +#ifndef DH_TEST_VECTORS
  44437. + DWC_RANDOM_BYTES(exp, 32);
  44438. +#endif
  44439. +
  44440. + /* Compute the pkd */
  44441. + if ((retval = dwc_dh_modpow(mem_ctx, dh_g, 4,
  44442. + exp, 32,
  44443. + dh_p, 384, pk))) {
  44444. + return retval;
  44445. + }
  44446. +
  44447. + m3[384] = nd;
  44448. + DWC_MEMCPY(&m3[0], pk, 384);
  44449. + DWC_SHA256(m3, 385, hash);
  44450. +
  44451. + dh_dump("PK", pk, 384);
  44452. + dh_dump("SHA-256(M3)", hash, 32);
  44453. + return 0;
  44454. +}
  44455. +
  44456. +int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  44457. + uint8_t *exp, int is_host,
  44458. + char *dd, uint8_t *ck, uint8_t *kdk)
  44459. +{
  44460. + int retval;
  44461. + uint8_t mv[784];
  44462. + uint8_t sha_result[32];
  44463. + uint8_t dhkey[384];
  44464. + uint8_t shared_secret[384];
  44465. + char *message;
  44466. + uint32_t vd;
  44467. +
  44468. + uint8_t *pk;
  44469. +
  44470. + if (is_host) {
  44471. + pk = pkd;
  44472. + }
  44473. + else {
  44474. + pk = pkh;
  44475. + }
  44476. +
  44477. + if ((retval = dwc_dh_modpow(mem_ctx, pk, 384,
  44478. + exp, 32,
  44479. + dh_p, 384, shared_secret))) {
  44480. + return retval;
  44481. + }
  44482. + dh_dump("Shared Secret", shared_secret, 384);
  44483. +
  44484. + DWC_SHA256(shared_secret, 384, dhkey);
  44485. + dh_dump("DHKEY", dhkey, 384);
  44486. +
  44487. + DWC_MEMCPY(&mv[0], pkd, 384);
  44488. + DWC_MEMCPY(&mv[384], pkh, 384);
  44489. + DWC_MEMCPY(&mv[768], "displayed digest", 16);
  44490. + dh_dump("MV", mv, 784);
  44491. +
  44492. + DWC_SHA256(mv, 784, sha_result);
  44493. + dh_dump("SHA-256(MV)", sha_result, 32);
  44494. + dh_dump("First 32-bits of SHA-256(MV)", sha_result, 4);
  44495. +
  44496. + dh_swap_bytes(sha_result, &vd, 4);
  44497. +#ifdef DEBUG
  44498. + DWC_PRINTF("Vd (decimal) = %d\n", vd);
  44499. +#endif
  44500. +
  44501. + switch (nd) {
  44502. + case 2:
  44503. + vd = vd % 100;
  44504. + DWC_SPRINTF(dd, "%02d", vd);
  44505. + break;
  44506. + case 3:
  44507. + vd = vd % 1000;
  44508. + DWC_SPRINTF(dd, "%03d", vd);
  44509. + break;
  44510. + case 4:
  44511. + vd = vd % 10000;
  44512. + DWC_SPRINTF(dd, "%04d", vd);
  44513. + break;
  44514. + }
  44515. +#ifdef DEBUG
  44516. + DWC_PRINTF("Display Digits: %s\n", dd);
  44517. +#endif
  44518. +
  44519. + message = "connection key";
  44520. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  44521. + dh_dump("HMAC(SHA-256, DHKey, connection key)", sha_result, 32);
  44522. + DWC_MEMCPY(ck, sha_result, 16);
  44523. +
  44524. + message = "key derivation key";
  44525. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  44526. + dh_dump("HMAC(SHA-256, DHKey, key derivation key)", sha_result, 32);
  44527. + DWC_MEMCPY(kdk, sha_result, 32);
  44528. +
  44529. + return 0;
  44530. +}
  44531. +
  44532. +
  44533. +#ifdef DH_TEST_VECTORS
  44534. +
  44535. +static __u8 dh_a[] = {
  44536. + 0x44, 0x00, 0x51, 0xd6,
  44537. + 0xf0, 0xb5, 0x5e, 0xa9,
  44538. + 0x67, 0xab, 0x31, 0xc6,
  44539. + 0x8a, 0x8b, 0x5e, 0x37,
  44540. + 0xd9, 0x10, 0xda, 0xe0,
  44541. + 0xe2, 0xd4, 0x59, 0xa4,
  44542. + 0x86, 0x45, 0x9c, 0xaa,
  44543. + 0xdf, 0x36, 0x75, 0x16,
  44544. +};
  44545. +
  44546. +static __u8 dh_b[] = {
  44547. + 0x5d, 0xae, 0xc7, 0x86,
  44548. + 0x79, 0x80, 0xa3, 0x24,
  44549. + 0x8c, 0xe3, 0x57, 0x8f,
  44550. + 0xc7, 0x5f, 0x1b, 0x0f,
  44551. + 0x2d, 0xf8, 0x9d, 0x30,
  44552. + 0x6f, 0xa4, 0x52, 0xcd,
  44553. + 0xe0, 0x7a, 0x04, 0x8a,
  44554. + 0xde, 0xd9, 0x26, 0x56,
  44555. +};
  44556. +
  44557. +void dwc_run_dh_test_vectors(void *mem_ctx)
  44558. +{
  44559. + uint8_t pkd[384];
  44560. + uint8_t pkh[384];
  44561. + uint8_t hashd[32];
  44562. + uint8_t hashh[32];
  44563. + uint8_t ck[16];
  44564. + uint8_t kdk[32];
  44565. + char dd[5];
  44566. +
  44567. + DWC_PRINTF("\n\n\nDH_TEST_VECTORS\n\n");
  44568. +
  44569. + /* compute the PKd and SHA-256(PKd || Nd) */
  44570. + DWC_PRINTF("Computing PKd\n");
  44571. + dwc_dh_pk(mem_ctx, 2, dh_a, pkd, hashd);
  44572. +
  44573. + /* compute the PKd and SHA-256(PKh || Nd) */
  44574. + DWC_PRINTF("Computing PKh\n");
  44575. + dwc_dh_pk(mem_ctx, 2, dh_b, pkh, hashh);
  44576. +
  44577. + /* compute the dhkey */
  44578. + dwc_dh_derive_keys(mem_ctx, 2, pkh, pkd, dh_a, 0, dd, ck, kdk);
  44579. +}
  44580. +#endif /* DH_TEST_VECTORS */
  44581. +
  44582. +#endif /* !CONFIG_MACH_IPMATE */
  44583. +
  44584. +#endif /* DWC_CRYPTOLIB */
  44585. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_dh.h linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_dh.h
  44586. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_dh.h 1970-01-01 01:00:00.000000000 +0100
  44587. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_dh.h 2014-02-18 11:52:14.000000000 +0100
  44588. @@ -0,0 +1,106 @@
  44589. +/* =========================================================================
  44590. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.h $
  44591. + * $Revision: #4 $
  44592. + * $Date: 2010/09/28 $
  44593. + * $Change: 1596182 $
  44594. + *
  44595. + * Synopsys Portability Library Software and documentation
  44596. + * (hereinafter, "Software") is an Unsupported proprietary work of
  44597. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  44598. + * between Synopsys and you.
  44599. + *
  44600. + * The Software IS NOT an item of Licensed Software or Licensed Product
  44601. + * under any End User Software License Agreement or Agreement for
  44602. + * Licensed Product with Synopsys or any supplement thereto. You are
  44603. + * permitted to use and redistribute this Software in source and binary
  44604. + * forms, with or without modification, provided that redistributions
  44605. + * of source code must retain this notice. You may not view, use,
  44606. + * disclose, copy or distribute this file or any information contained
  44607. + * herein except pursuant to this license grant from Synopsys. If you
  44608. + * do not agree with this notice, including the disclaimer below, then
  44609. + * you are not authorized to use the Software.
  44610. + *
  44611. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  44612. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  44613. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  44614. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  44615. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44616. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44617. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44618. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  44619. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44620. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  44621. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  44622. + * DAMAGE.
  44623. + * ========================================================================= */
  44624. +#ifndef _DWC_DH_H_
  44625. +#define _DWC_DH_H_
  44626. +
  44627. +#ifdef __cplusplus
  44628. +extern "C" {
  44629. +#endif
  44630. +
  44631. +#include "dwc_os.h"
  44632. +
  44633. +/** @file
  44634. + *
  44635. + * This file defines the common functions on device and host for performing
  44636. + * numeric association as defined in the WUSB spec. They are only to be
  44637. + * used internally by the DWC UWB modules. */
  44638. +
  44639. +extern int dwc_dh_sha256(uint8_t *message, uint32_t len, uint8_t *out);
  44640. +extern int dwc_dh_hmac_sha256(uint8_t *message, uint32_t messagelen,
  44641. + uint8_t *key, uint32_t keylen,
  44642. + uint8_t *out);
  44643. +extern int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  44644. + void *exp, uint32_t exp_len,
  44645. + void *mod, uint32_t mod_len,
  44646. + void *out);
  44647. +
  44648. +/** Computes PKD or PKH, and SHA-256(PKd || Nd)
  44649. + *
  44650. + * PK = g^exp mod p.
  44651. + *
  44652. + * Input:
  44653. + * Nd = Number of digits on the device.
  44654. + *
  44655. + * Output:
  44656. + * exp = A 32-byte buffer to be filled with a randomly generated number.
  44657. + * used as either A or B.
  44658. + * pk = A 384-byte buffer to be filled with the PKH or PKD.
  44659. + * hash = A 32-byte buffer to be filled with SHA-256(PK || ND).
  44660. + */
  44661. +extern int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pkd, uint8_t *hash);
  44662. +
  44663. +/** Computes the DHKEY, and VD.
  44664. + *
  44665. + * If called from host, then it will comput DHKEY=PKD^exp % p.
  44666. + * If called from device, then it will comput DHKEY=PKH^exp % p.
  44667. + *
  44668. + * Input:
  44669. + * pkd = The PKD value.
  44670. + * pkh = The PKH value.
  44671. + * exp = The A value (if device) or B value (if host) generated in dwc_wudev_dh_pk.
  44672. + * is_host = Set to non zero if a WUSB host is calling this function.
  44673. + *
  44674. + * Output:
  44675. +
  44676. + * dd = A pointer to an buffer to be set to the displayed digits string to be shown
  44677. + * to the user. This buffer should be at 5 bytes long to hold 4 digits plus a
  44678. + * null termination character. This buffer can be used directly for display.
  44679. + * ck = A 16-byte buffer to be filled with the CK.
  44680. + * kdk = A 32-byte buffer to be filled with the KDK.
  44681. + */
  44682. +extern int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  44683. + uint8_t *exp, int is_host,
  44684. + char *dd, uint8_t *ck, uint8_t *kdk);
  44685. +
  44686. +#ifdef DH_TEST_VECTORS
  44687. +extern void dwc_run_dh_test_vectors(void);
  44688. +#endif
  44689. +
  44690. +#ifdef __cplusplus
  44691. +}
  44692. +#endif
  44693. +
  44694. +#endif /* _DWC_DH_H_ */
  44695. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_list.h linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_list.h
  44696. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_list.h 1970-01-01 01:00:00.000000000 +0100
  44697. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_list.h 2014-02-18 11:52:14.000000000 +0100
  44698. @@ -0,0 +1,594 @@
  44699. +/* $OpenBSD: queue.h,v 1.26 2004/05/04 16:59:32 grange Exp $ */
  44700. +/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
  44701. +
  44702. +/*
  44703. + * Copyright (c) 1991, 1993
  44704. + * The Regents of the University of California. All rights reserved.
  44705. + *
  44706. + * Redistribution and use in source and binary forms, with or without
  44707. + * modification, are permitted provided that the following conditions
  44708. + * are met:
  44709. + * 1. Redistributions of source code must retain the above copyright
  44710. + * notice, this list of conditions and the following disclaimer.
  44711. + * 2. Redistributions in binary form must reproduce the above copyright
  44712. + * notice, this list of conditions and the following disclaimer in the
  44713. + * documentation and/or other materials provided with the distribution.
  44714. + * 3. Neither the name of the University nor the names of its contributors
  44715. + * may be used to endorse or promote products derived from this software
  44716. + * without specific prior written permission.
  44717. + *
  44718. + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  44719. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  44720. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  44721. + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  44722. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  44723. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  44724. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  44725. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  44726. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  44727. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  44728. + * SUCH DAMAGE.
  44729. + *
  44730. + * @(#)queue.h 8.5 (Berkeley) 8/20/94
  44731. + */
  44732. +
  44733. +#ifndef _DWC_LIST_H_
  44734. +#define _DWC_LIST_H_
  44735. +
  44736. +#ifdef __cplusplus
  44737. +extern "C" {
  44738. +#endif
  44739. +
  44740. +/** @file
  44741. + *
  44742. + * This file defines linked list operations. It is derived from BSD with
  44743. + * only the MACRO names being prefixed with DWC_. This is because a few of
  44744. + * these names conflict with those on Linux. For documentation on use, see the
  44745. + * inline comments in the source code. The original license for this source
  44746. + * code applies and is preserved in the dwc_list.h source file.
  44747. + */
  44748. +
  44749. +/*
  44750. + * This file defines five types of data structures: singly-linked lists,
  44751. + * lists, simple queues, tail queues, and circular queues.
  44752. + *
  44753. + *
  44754. + * A singly-linked list is headed by a single forward pointer. The elements
  44755. + * are singly linked for minimum space and pointer manipulation overhead at
  44756. + * the expense of O(n) removal for arbitrary elements. New elements can be
  44757. + * added to the list after an existing element or at the head of the list.
  44758. + * Elements being removed from the head of the list should use the explicit
  44759. + * macro for this purpose for optimum efficiency. A singly-linked list may
  44760. + * only be traversed in the forward direction. Singly-linked lists are ideal
  44761. + * for applications with large datasets and few or no removals or for
  44762. + * implementing a LIFO queue.
  44763. + *
  44764. + * A list is headed by a single forward pointer (or an array of forward
  44765. + * pointers for a hash table header). The elements are doubly linked
  44766. + * so that an arbitrary element can be removed without a need to
  44767. + * traverse the list. New elements can be added to the list before
  44768. + * or after an existing element or at the head of the list. A list
  44769. + * may only be traversed in the forward direction.
  44770. + *
  44771. + * A simple queue is headed by a pair of pointers, one the head of the
  44772. + * list and the other to the tail of the list. The elements are singly
  44773. + * linked to save space, so elements can only be removed from the
  44774. + * head of the list. New elements can be added to the list before or after
  44775. + * an existing element, at the head of the list, or at the end of the
  44776. + * list. A simple queue may only be traversed in the forward direction.
  44777. + *
  44778. + * A tail queue is headed by a pair of pointers, one to the head of the
  44779. + * list and the other to the tail of the list. The elements are doubly
  44780. + * linked so that an arbitrary element can be removed without a need to
  44781. + * traverse the list. New elements can be added to the list before or
  44782. + * after an existing element, at the head of the list, or at the end of
  44783. + * the list. A tail queue may be traversed in either direction.
  44784. + *
  44785. + * A circle queue is headed by a pair of pointers, one to the head of the
  44786. + * list and the other to the tail of the list. The elements are doubly
  44787. + * linked so that an arbitrary element can be removed without a need to
  44788. + * traverse the list. New elements can be added to the list before or after
  44789. + * an existing element, at the head of the list, or at the end of the list.
  44790. + * A circle queue may be traversed in either direction, but has a more
  44791. + * complex end of list detection.
  44792. + *
  44793. + * For details on the use of these macros, see the queue(3) manual page.
  44794. + */
  44795. +
  44796. +/*
  44797. + * Double-linked List.
  44798. + */
  44799. +
  44800. +typedef struct dwc_list_link {
  44801. + struct dwc_list_link *next;
  44802. + struct dwc_list_link *prev;
  44803. +} dwc_list_link_t;
  44804. +
  44805. +#define DWC_LIST_INIT(link) do { \
  44806. + (link)->next = (link); \
  44807. + (link)->prev = (link); \
  44808. +} while (0)
  44809. +
  44810. +#define DWC_LIST_FIRST(link) ((link)->next)
  44811. +#define DWC_LIST_LAST(link) ((link)->prev)
  44812. +#define DWC_LIST_END(link) (link)
  44813. +#define DWC_LIST_NEXT(link) ((link)->next)
  44814. +#define DWC_LIST_PREV(link) ((link)->prev)
  44815. +#define DWC_LIST_EMPTY(link) \
  44816. + (DWC_LIST_FIRST(link) == DWC_LIST_END(link))
  44817. +#define DWC_LIST_ENTRY(link, type, field) \
  44818. + (type *)((uint8_t *)(link) - (size_t)(&((type *)0)->field))
  44819. +
  44820. +#if 0
  44821. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  44822. + (link)->next = (list)->next; \
  44823. + (link)->prev = (list); \
  44824. + (list)->next->prev = (link); \
  44825. + (list)->next = (link); \
  44826. +} while (0)
  44827. +
  44828. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  44829. + (link)->next = (list); \
  44830. + (link)->prev = (list)->prev; \
  44831. + (list)->prev->next = (link); \
  44832. + (list)->prev = (link); \
  44833. +} while (0)
  44834. +#else
  44835. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  44836. + dwc_list_link_t *__next__ = (list)->next; \
  44837. + __next__->prev = (link); \
  44838. + (link)->next = __next__; \
  44839. + (link)->prev = (list); \
  44840. + (list)->next = (link); \
  44841. +} while (0)
  44842. +
  44843. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  44844. + dwc_list_link_t *__prev__ = (list)->prev; \
  44845. + (list)->prev = (link); \
  44846. + (link)->next = (list); \
  44847. + (link)->prev = __prev__; \
  44848. + __prev__->next = (link); \
  44849. +} while (0)
  44850. +#endif
  44851. +
  44852. +#if 0
  44853. +static inline void __list_add(struct list_head *new,
  44854. + struct list_head *prev,
  44855. + struct list_head *next)
  44856. +{
  44857. + next->prev = new;
  44858. + new->next = next;
  44859. + new->prev = prev;
  44860. + prev->next = new;
  44861. +}
  44862. +
  44863. +static inline void list_add(struct list_head *new, struct list_head *head)
  44864. +{
  44865. + __list_add(new, head, head->next);
  44866. +}
  44867. +
  44868. +static inline void list_add_tail(struct list_head *new, struct list_head *head)
  44869. +{
  44870. + __list_add(new, head->prev, head);
  44871. +}
  44872. +
  44873. +static inline void __list_del(struct list_head * prev, struct list_head * next)
  44874. +{
  44875. + next->prev = prev;
  44876. + prev->next = next;
  44877. +}
  44878. +
  44879. +static inline void list_del(struct list_head *entry)
  44880. +{
  44881. + __list_del(entry->prev, entry->next);
  44882. + entry->next = LIST_POISON1;
  44883. + entry->prev = LIST_POISON2;
  44884. +}
  44885. +#endif
  44886. +
  44887. +#define DWC_LIST_REMOVE(link) do { \
  44888. + (link)->next->prev = (link)->prev; \
  44889. + (link)->prev->next = (link)->next; \
  44890. +} while (0)
  44891. +
  44892. +#define DWC_LIST_REMOVE_INIT(link) do { \
  44893. + DWC_LIST_REMOVE(link); \
  44894. + DWC_LIST_INIT(link); \
  44895. +} while (0)
  44896. +
  44897. +#define DWC_LIST_MOVE_HEAD(list, link) do { \
  44898. + DWC_LIST_REMOVE(link); \
  44899. + DWC_LIST_INSERT_HEAD(list, link); \
  44900. +} while (0)
  44901. +
  44902. +#define DWC_LIST_MOVE_TAIL(list, link) do { \
  44903. + DWC_LIST_REMOVE(link); \
  44904. + DWC_LIST_INSERT_TAIL(list, link); \
  44905. +} while (0)
  44906. +
  44907. +#define DWC_LIST_FOREACH(var, list) \
  44908. + for((var) = DWC_LIST_FIRST(list); \
  44909. + (var) != DWC_LIST_END(list); \
  44910. + (var) = DWC_LIST_NEXT(var))
  44911. +
  44912. +#define DWC_LIST_FOREACH_SAFE(var, var2, list) \
  44913. + for((var) = DWC_LIST_FIRST(list), (var2) = DWC_LIST_NEXT(var); \
  44914. + (var) != DWC_LIST_END(list); \
  44915. + (var) = (var2), (var2) = DWC_LIST_NEXT(var2))
  44916. +
  44917. +#define DWC_LIST_FOREACH_REVERSE(var, list) \
  44918. + for((var) = DWC_LIST_LAST(list); \
  44919. + (var) != DWC_LIST_END(list); \
  44920. + (var) = DWC_LIST_PREV(var))
  44921. +
  44922. +/*
  44923. + * Singly-linked List definitions.
  44924. + */
  44925. +#define DWC_SLIST_HEAD(name, type) \
  44926. +struct name { \
  44927. + struct type *slh_first; /* first element */ \
  44928. +}
  44929. +
  44930. +#define DWC_SLIST_HEAD_INITIALIZER(head) \
  44931. + { NULL }
  44932. +
  44933. +#define DWC_SLIST_ENTRY(type) \
  44934. +struct { \
  44935. + struct type *sle_next; /* next element */ \
  44936. +}
  44937. +
  44938. +/*
  44939. + * Singly-linked List access methods.
  44940. + */
  44941. +#define DWC_SLIST_FIRST(head) ((head)->slh_first)
  44942. +#define DWC_SLIST_END(head) NULL
  44943. +#define DWC_SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
  44944. +#define DWC_SLIST_NEXT(elm, field) ((elm)->field.sle_next)
  44945. +
  44946. +#define DWC_SLIST_FOREACH(var, head, field) \
  44947. + for((var) = SLIST_FIRST(head); \
  44948. + (var) != SLIST_END(head); \
  44949. + (var) = SLIST_NEXT(var, field))
  44950. +
  44951. +#define DWC_SLIST_FOREACH_PREVPTR(var, varp, head, field) \
  44952. + for((varp) = &SLIST_FIRST((head)); \
  44953. + ((var) = *(varp)) != SLIST_END(head); \
  44954. + (varp) = &SLIST_NEXT((var), field))
  44955. +
  44956. +/*
  44957. + * Singly-linked List functions.
  44958. + */
  44959. +#define DWC_SLIST_INIT(head) { \
  44960. + SLIST_FIRST(head) = SLIST_END(head); \
  44961. +}
  44962. +
  44963. +#define DWC_SLIST_INSERT_AFTER(slistelm, elm, field) do { \
  44964. + (elm)->field.sle_next = (slistelm)->field.sle_next; \
  44965. + (slistelm)->field.sle_next = (elm); \
  44966. +} while (0)
  44967. +
  44968. +#define DWC_SLIST_INSERT_HEAD(head, elm, field) do { \
  44969. + (elm)->field.sle_next = (head)->slh_first; \
  44970. + (head)->slh_first = (elm); \
  44971. +} while (0)
  44972. +
  44973. +#define DWC_SLIST_REMOVE_NEXT(head, elm, field) do { \
  44974. + (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
  44975. +} while (0)
  44976. +
  44977. +#define DWC_SLIST_REMOVE_HEAD(head, field) do { \
  44978. + (head)->slh_first = (head)->slh_first->field.sle_next; \
  44979. +} while (0)
  44980. +
  44981. +#define DWC_SLIST_REMOVE(head, elm, type, field) do { \
  44982. + if ((head)->slh_first == (elm)) { \
  44983. + SLIST_REMOVE_HEAD((head), field); \
  44984. + } \
  44985. + else { \
  44986. + struct type *curelm = (head)->slh_first; \
  44987. + while( curelm->field.sle_next != (elm) ) \
  44988. + curelm = curelm->field.sle_next; \
  44989. + curelm->field.sle_next = \
  44990. + curelm->field.sle_next->field.sle_next; \
  44991. + } \
  44992. +} while (0)
  44993. +
  44994. +/*
  44995. + * Simple queue definitions.
  44996. + */
  44997. +#define DWC_SIMPLEQ_HEAD(name, type) \
  44998. +struct name { \
  44999. + struct type *sqh_first; /* first element */ \
  45000. + struct type **sqh_last; /* addr of last next element */ \
  45001. +}
  45002. +
  45003. +#define DWC_SIMPLEQ_HEAD_INITIALIZER(head) \
  45004. + { NULL, &(head).sqh_first }
  45005. +
  45006. +#define DWC_SIMPLEQ_ENTRY(type) \
  45007. +struct { \
  45008. + struct type *sqe_next; /* next element */ \
  45009. +}
  45010. +
  45011. +/*
  45012. + * Simple queue access methods.
  45013. + */
  45014. +#define DWC_SIMPLEQ_FIRST(head) ((head)->sqh_first)
  45015. +#define DWC_SIMPLEQ_END(head) NULL
  45016. +#define DWC_SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
  45017. +#define DWC_SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
  45018. +
  45019. +#define DWC_SIMPLEQ_FOREACH(var, head, field) \
  45020. + for((var) = SIMPLEQ_FIRST(head); \
  45021. + (var) != SIMPLEQ_END(head); \
  45022. + (var) = SIMPLEQ_NEXT(var, field))
  45023. +
  45024. +/*
  45025. + * Simple queue functions.
  45026. + */
  45027. +#define DWC_SIMPLEQ_INIT(head) do { \
  45028. + (head)->sqh_first = NULL; \
  45029. + (head)->sqh_last = &(head)->sqh_first; \
  45030. +} while (0)
  45031. +
  45032. +#define DWC_SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
  45033. + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
  45034. + (head)->sqh_last = &(elm)->field.sqe_next; \
  45035. + (head)->sqh_first = (elm); \
  45036. +} while (0)
  45037. +
  45038. +#define DWC_SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
  45039. + (elm)->field.sqe_next = NULL; \
  45040. + *(head)->sqh_last = (elm); \
  45041. + (head)->sqh_last = &(elm)->field.sqe_next; \
  45042. +} while (0)
  45043. +
  45044. +#define DWC_SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  45045. + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
  45046. + (head)->sqh_last = &(elm)->field.sqe_next; \
  45047. + (listelm)->field.sqe_next = (elm); \
  45048. +} while (0)
  45049. +
  45050. +#define DWC_SIMPLEQ_REMOVE_HEAD(head, field) do { \
  45051. + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
  45052. + (head)->sqh_last = &(head)->sqh_first; \
  45053. +} while (0)
  45054. +
  45055. +/*
  45056. + * Tail queue definitions.
  45057. + */
  45058. +#define DWC_TAILQ_HEAD(name, type) \
  45059. +struct name { \
  45060. + struct type *tqh_first; /* first element */ \
  45061. + struct type **tqh_last; /* addr of last next element */ \
  45062. +}
  45063. +
  45064. +#define DWC_TAILQ_HEAD_INITIALIZER(head) \
  45065. + { NULL, &(head).tqh_first }
  45066. +
  45067. +#define DWC_TAILQ_ENTRY(type) \
  45068. +struct { \
  45069. + struct type *tqe_next; /* next element */ \
  45070. + struct type **tqe_prev; /* address of previous next element */ \
  45071. +}
  45072. +
  45073. +/*
  45074. + * tail queue access methods
  45075. + */
  45076. +#define DWC_TAILQ_FIRST(head) ((head)->tqh_first)
  45077. +#define DWC_TAILQ_END(head) NULL
  45078. +#define DWC_TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
  45079. +#define DWC_TAILQ_LAST(head, headname) \
  45080. + (*(((struct headname *)((head)->tqh_last))->tqh_last))
  45081. +/* XXX */
  45082. +#define DWC_TAILQ_PREV(elm, headname, field) \
  45083. + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
  45084. +#define DWC_TAILQ_EMPTY(head) \
  45085. + (DWC_TAILQ_FIRST(head) == DWC_TAILQ_END(head))
  45086. +
  45087. +#define DWC_TAILQ_FOREACH(var, head, field) \
  45088. + for ((var) = DWC_TAILQ_FIRST(head); \
  45089. + (var) != DWC_TAILQ_END(head); \
  45090. + (var) = DWC_TAILQ_NEXT(var, field))
  45091. +
  45092. +#define DWC_TAILQ_FOREACH_REVERSE(var, head, headname, field) \
  45093. + for ((var) = DWC_TAILQ_LAST(head, headname); \
  45094. + (var) != DWC_TAILQ_END(head); \
  45095. + (var) = DWC_TAILQ_PREV(var, headname, field))
  45096. +
  45097. +/*
  45098. + * Tail queue functions.
  45099. + */
  45100. +#define DWC_TAILQ_INIT(head) do { \
  45101. + (head)->tqh_first = NULL; \
  45102. + (head)->tqh_last = &(head)->tqh_first; \
  45103. +} while (0)
  45104. +
  45105. +#define DWC_TAILQ_INSERT_HEAD(head, elm, field) do { \
  45106. + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
  45107. + (head)->tqh_first->field.tqe_prev = \
  45108. + &(elm)->field.tqe_next; \
  45109. + else \
  45110. + (head)->tqh_last = &(elm)->field.tqe_next; \
  45111. + (head)->tqh_first = (elm); \
  45112. + (elm)->field.tqe_prev = &(head)->tqh_first; \
  45113. +} while (0)
  45114. +
  45115. +#define DWC_TAILQ_INSERT_TAIL(head, elm, field) do { \
  45116. + (elm)->field.tqe_next = NULL; \
  45117. + (elm)->field.tqe_prev = (head)->tqh_last; \
  45118. + *(head)->tqh_last = (elm); \
  45119. + (head)->tqh_last = &(elm)->field.tqe_next; \
  45120. +} while (0)
  45121. +
  45122. +#define DWC_TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
  45123. + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
  45124. + (elm)->field.tqe_next->field.tqe_prev = \
  45125. + &(elm)->field.tqe_next; \
  45126. + else \
  45127. + (head)->tqh_last = &(elm)->field.tqe_next; \
  45128. + (listelm)->field.tqe_next = (elm); \
  45129. + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
  45130. +} while (0)
  45131. +
  45132. +#define DWC_TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
  45133. + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
  45134. + (elm)->field.tqe_next = (listelm); \
  45135. + *(listelm)->field.tqe_prev = (elm); \
  45136. + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
  45137. +} while (0)
  45138. +
  45139. +#define DWC_TAILQ_REMOVE(head, elm, field) do { \
  45140. + if (((elm)->field.tqe_next) != NULL) \
  45141. + (elm)->field.tqe_next->field.tqe_prev = \
  45142. + (elm)->field.tqe_prev; \
  45143. + else \
  45144. + (head)->tqh_last = (elm)->field.tqe_prev; \
  45145. + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
  45146. +} while (0)
  45147. +
  45148. +#define DWC_TAILQ_REPLACE(head, elm, elm2, field) do { \
  45149. + if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
  45150. + (elm2)->field.tqe_next->field.tqe_prev = \
  45151. + &(elm2)->field.tqe_next; \
  45152. + else \
  45153. + (head)->tqh_last = &(elm2)->field.tqe_next; \
  45154. + (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
  45155. + *(elm2)->field.tqe_prev = (elm2); \
  45156. +} while (0)
  45157. +
  45158. +/*
  45159. + * Circular queue definitions.
  45160. + */
  45161. +#define DWC_CIRCLEQ_HEAD(name, type) \
  45162. +struct name { \
  45163. + struct type *cqh_first; /* first element */ \
  45164. + struct type *cqh_last; /* last element */ \
  45165. +}
  45166. +
  45167. +#define DWC_CIRCLEQ_HEAD_INITIALIZER(head) \
  45168. + { DWC_CIRCLEQ_END(&head), DWC_CIRCLEQ_END(&head) }
  45169. +
  45170. +#define DWC_CIRCLEQ_ENTRY(type) \
  45171. +struct { \
  45172. + struct type *cqe_next; /* next element */ \
  45173. + struct type *cqe_prev; /* previous element */ \
  45174. +}
  45175. +
  45176. +/*
  45177. + * Circular queue access methods
  45178. + */
  45179. +#define DWC_CIRCLEQ_FIRST(head) ((head)->cqh_first)
  45180. +#define DWC_CIRCLEQ_LAST(head) ((head)->cqh_last)
  45181. +#define DWC_CIRCLEQ_END(head) ((void *)(head))
  45182. +#define DWC_CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
  45183. +#define DWC_CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
  45184. +#define DWC_CIRCLEQ_EMPTY(head) \
  45185. + (DWC_CIRCLEQ_FIRST(head) == DWC_CIRCLEQ_END(head))
  45186. +
  45187. +#define DWC_CIRCLEQ_EMPTY_ENTRY(elm, field) (((elm)->field.cqe_next == NULL) && ((elm)->field.cqe_prev == NULL))
  45188. +
  45189. +#define DWC_CIRCLEQ_FOREACH(var, head, field) \
  45190. + for((var) = DWC_CIRCLEQ_FIRST(head); \
  45191. + (var) != DWC_CIRCLEQ_END(head); \
  45192. + (var) = DWC_CIRCLEQ_NEXT(var, field))
  45193. +
  45194. +#define DWC_CIRCLEQ_FOREACH_SAFE(var, var2, head, field) \
  45195. + for((var) = DWC_CIRCLEQ_FIRST(head), var2 = DWC_CIRCLEQ_NEXT(var, field); \
  45196. + (var) != DWC_CIRCLEQ_END(head); \
  45197. + (var) = var2, var2 = DWC_CIRCLEQ_NEXT(var, field))
  45198. +
  45199. +#define DWC_CIRCLEQ_FOREACH_REVERSE(var, head, field) \
  45200. + for((var) = DWC_CIRCLEQ_LAST(head); \
  45201. + (var) != DWC_CIRCLEQ_END(head); \
  45202. + (var) = DWC_CIRCLEQ_PREV(var, field))
  45203. +
  45204. +/*
  45205. + * Circular queue functions.
  45206. + */
  45207. +#define DWC_CIRCLEQ_INIT(head) do { \
  45208. + (head)->cqh_first = DWC_CIRCLEQ_END(head); \
  45209. + (head)->cqh_last = DWC_CIRCLEQ_END(head); \
  45210. +} while (0)
  45211. +
  45212. +#define DWC_CIRCLEQ_INIT_ENTRY(elm, field) do { \
  45213. + (elm)->field.cqe_next = NULL; \
  45214. + (elm)->field.cqe_prev = NULL; \
  45215. +} while (0)
  45216. +
  45217. +#define DWC_CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  45218. + (elm)->field.cqe_next = (listelm)->field.cqe_next; \
  45219. + (elm)->field.cqe_prev = (listelm); \
  45220. + if ((listelm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  45221. + (head)->cqh_last = (elm); \
  45222. + else \
  45223. + (listelm)->field.cqe_next->field.cqe_prev = (elm); \
  45224. + (listelm)->field.cqe_next = (elm); \
  45225. +} while (0)
  45226. +
  45227. +#define DWC_CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
  45228. + (elm)->field.cqe_next = (listelm); \
  45229. + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
  45230. + if ((listelm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  45231. + (head)->cqh_first = (elm); \
  45232. + else \
  45233. + (listelm)->field.cqe_prev->field.cqe_next = (elm); \
  45234. + (listelm)->field.cqe_prev = (elm); \
  45235. +} while (0)
  45236. +
  45237. +#define DWC_CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
  45238. + (elm)->field.cqe_next = (head)->cqh_first; \
  45239. + (elm)->field.cqe_prev = DWC_CIRCLEQ_END(head); \
  45240. + if ((head)->cqh_last == DWC_CIRCLEQ_END(head)) \
  45241. + (head)->cqh_last = (elm); \
  45242. + else \
  45243. + (head)->cqh_first->field.cqe_prev = (elm); \
  45244. + (head)->cqh_first = (elm); \
  45245. +} while (0)
  45246. +
  45247. +#define DWC_CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
  45248. + (elm)->field.cqe_next = DWC_CIRCLEQ_END(head); \
  45249. + (elm)->field.cqe_prev = (head)->cqh_last; \
  45250. + if ((head)->cqh_first == DWC_CIRCLEQ_END(head)) \
  45251. + (head)->cqh_first = (elm); \
  45252. + else \
  45253. + (head)->cqh_last->field.cqe_next = (elm); \
  45254. + (head)->cqh_last = (elm); \
  45255. +} while (0)
  45256. +
  45257. +#define DWC_CIRCLEQ_REMOVE(head, elm, field) do { \
  45258. + if ((elm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  45259. + (head)->cqh_last = (elm)->field.cqe_prev; \
  45260. + else \
  45261. + (elm)->field.cqe_next->field.cqe_prev = \
  45262. + (elm)->field.cqe_prev; \
  45263. + if ((elm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  45264. + (head)->cqh_first = (elm)->field.cqe_next; \
  45265. + else \
  45266. + (elm)->field.cqe_prev->field.cqe_next = \
  45267. + (elm)->field.cqe_next; \
  45268. +} while (0)
  45269. +
  45270. +#define DWC_CIRCLEQ_REMOVE_INIT(head, elm, field) do { \
  45271. + DWC_CIRCLEQ_REMOVE(head, elm, field); \
  45272. + DWC_CIRCLEQ_INIT_ENTRY(elm, field); \
  45273. +} while (0)
  45274. +
  45275. +#define DWC_CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
  45276. + if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
  45277. + DWC_CIRCLEQ_END(head)) \
  45278. + (head).cqh_last = (elm2); \
  45279. + else \
  45280. + (elm2)->field.cqe_next->field.cqe_prev = (elm2); \
  45281. + if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
  45282. + DWC_CIRCLEQ_END(head)) \
  45283. + (head).cqh_first = (elm2); \
  45284. + else \
  45285. + (elm2)->field.cqe_prev->field.cqe_next = (elm2); \
  45286. +} while (0)
  45287. +
  45288. +#ifdef __cplusplus
  45289. +}
  45290. +#endif
  45291. +
  45292. +#endif /* _DWC_LIST_H_ */
  45293. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_mem.c linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_mem.c
  45294. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_mem.c 1970-01-01 01:00:00.000000000 +0100
  45295. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_mem.c 2014-02-18 11:52:14.000000000 +0100
  45296. @@ -0,0 +1,245 @@
  45297. +/* Memory Debugging */
  45298. +#ifdef DWC_DEBUG_MEMORY
  45299. +
  45300. +#include "dwc_os.h"
  45301. +#include "dwc_list.h"
  45302. +
  45303. +struct allocation {
  45304. + void *addr;
  45305. + void *ctx;
  45306. + char *func;
  45307. + int line;
  45308. + uint32_t size;
  45309. + int dma;
  45310. + DWC_CIRCLEQ_ENTRY(allocation) entry;
  45311. +};
  45312. +
  45313. +DWC_CIRCLEQ_HEAD(allocation_queue, allocation);
  45314. +
  45315. +struct allocation_manager {
  45316. + void *mem_ctx;
  45317. + struct allocation_queue allocations;
  45318. +
  45319. + /* statistics */
  45320. + int num;
  45321. + int num_freed;
  45322. + int num_active;
  45323. + uint32_t total;
  45324. + uint32_t cur;
  45325. + uint32_t max;
  45326. +};
  45327. +
  45328. +static struct allocation_manager *manager = NULL;
  45329. +
  45330. +static int add_allocation(void *ctx, uint32_t size, char const *func, int line, void *addr,
  45331. + int dma)
  45332. +{
  45333. + struct allocation *a;
  45334. +
  45335. + DWC_ASSERT(manager != NULL, "manager not allocated");
  45336. +
  45337. + a = __DWC_ALLOC_ATOMIC(manager->mem_ctx, sizeof(*a));
  45338. + if (!a) {
  45339. + return -DWC_E_NO_MEMORY;
  45340. + }
  45341. +
  45342. + a->func = __DWC_ALLOC_ATOMIC(manager->mem_ctx, DWC_STRLEN(func) + 1);
  45343. + if (!a->func) {
  45344. + __DWC_FREE(manager->mem_ctx, a);
  45345. + return -DWC_E_NO_MEMORY;
  45346. + }
  45347. +
  45348. + DWC_MEMCPY(a->func, func, DWC_STRLEN(func) + 1);
  45349. + a->addr = addr;
  45350. + a->ctx = ctx;
  45351. + a->line = line;
  45352. + a->size = size;
  45353. + a->dma = dma;
  45354. + DWC_CIRCLEQ_INSERT_TAIL(&manager->allocations, a, entry);
  45355. +
  45356. + /* Update stats */
  45357. + manager->num++;
  45358. + manager->num_active++;
  45359. + manager->total += size;
  45360. + manager->cur += size;
  45361. +
  45362. + if (manager->max < manager->cur) {
  45363. + manager->max = manager->cur;
  45364. + }
  45365. +
  45366. + return 0;
  45367. +}
  45368. +
  45369. +static struct allocation *find_allocation(void *ctx, void *addr)
  45370. +{
  45371. + struct allocation *a;
  45372. +
  45373. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  45374. + if (a->ctx == ctx && a->addr == addr) {
  45375. + return a;
  45376. + }
  45377. + }
  45378. +
  45379. + return NULL;
  45380. +}
  45381. +
  45382. +static void free_allocation(void *ctx, void *addr, char const *func, int line)
  45383. +{
  45384. + struct allocation *a = find_allocation(ctx, addr);
  45385. +
  45386. + if (!a) {
  45387. + DWC_ASSERT(0,
  45388. + "Free of address %p that was never allocated or already freed %s:%d",
  45389. + addr, func, line);
  45390. + return;
  45391. + }
  45392. +
  45393. + DWC_CIRCLEQ_REMOVE(&manager->allocations, a, entry);
  45394. +
  45395. + manager->num_active--;
  45396. + manager->num_freed++;
  45397. + manager->cur -= a->size;
  45398. + __DWC_FREE(manager->mem_ctx, a->func);
  45399. + __DWC_FREE(manager->mem_ctx, a);
  45400. +}
  45401. +
  45402. +int dwc_memory_debug_start(void *mem_ctx)
  45403. +{
  45404. + DWC_ASSERT(manager == NULL, "Memory debugging has already started\n");
  45405. +
  45406. + if (manager) {
  45407. + return -DWC_E_BUSY;
  45408. + }
  45409. +
  45410. + manager = __DWC_ALLOC(mem_ctx, sizeof(*manager));
  45411. + if (!manager) {
  45412. + return -DWC_E_NO_MEMORY;
  45413. + }
  45414. +
  45415. + DWC_CIRCLEQ_INIT(&manager->allocations);
  45416. + manager->mem_ctx = mem_ctx;
  45417. + manager->num = 0;
  45418. + manager->num_freed = 0;
  45419. + manager->num_active = 0;
  45420. + manager->total = 0;
  45421. + manager->cur = 0;
  45422. + manager->max = 0;
  45423. +
  45424. + return 0;
  45425. +}
  45426. +
  45427. +void dwc_memory_debug_stop(void)
  45428. +{
  45429. + struct allocation *a;
  45430. +
  45431. + dwc_memory_debug_report();
  45432. +
  45433. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  45434. + DWC_ERROR("Memory leaked from %s:%d\n", a->func, a->line);
  45435. + free_allocation(a->ctx, a->addr, NULL, -1);
  45436. + }
  45437. +
  45438. + __DWC_FREE(manager->mem_ctx, manager);
  45439. +}
  45440. +
  45441. +void dwc_memory_debug_report(void)
  45442. +{
  45443. + struct allocation *a;
  45444. +
  45445. + DWC_PRINTF("\n\n\n----------------- Memory Debugging Report -----------------\n\n");
  45446. + DWC_PRINTF("Num Allocations = %d\n", manager->num);
  45447. + DWC_PRINTF("Freed = %d\n", manager->num_freed);
  45448. + DWC_PRINTF("Active = %d\n", manager->num_active);
  45449. + DWC_PRINTF("Current Memory Used = %d\n", manager->cur);
  45450. + DWC_PRINTF("Total Memory Used = %d\n", manager->total);
  45451. + DWC_PRINTF("Maximum Memory Used at Once = %d\n", manager->max);
  45452. + DWC_PRINTF("Unfreed allocations:\n");
  45453. +
  45454. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  45455. + DWC_PRINTF(" addr=%p, size=%d from %s:%d, DMA=%d\n",
  45456. + a->addr, a->size, a->func, a->line, a->dma);
  45457. + }
  45458. +}
  45459. +
  45460. +/* The replacement functions */
  45461. +void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line)
  45462. +{
  45463. + void *addr = __DWC_ALLOC(mem_ctx, size);
  45464. +
  45465. + if (!addr) {
  45466. + return NULL;
  45467. + }
  45468. +
  45469. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  45470. + __DWC_FREE(mem_ctx, addr);
  45471. + return NULL;
  45472. + }
  45473. +
  45474. + return addr;
  45475. +}
  45476. +
  45477. +void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func,
  45478. + int line)
  45479. +{
  45480. + void *addr = __DWC_ALLOC_ATOMIC(mem_ctx, size);
  45481. +
  45482. + if (!addr) {
  45483. + return NULL;
  45484. + }
  45485. +
  45486. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  45487. + __DWC_FREE(mem_ctx, addr);
  45488. + return NULL;
  45489. + }
  45490. +
  45491. + return addr;
  45492. +}
  45493. +
  45494. +void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line)
  45495. +{
  45496. + free_allocation(mem_ctx, addr, func, line);
  45497. + __DWC_FREE(mem_ctx, addr);
  45498. +}
  45499. +
  45500. +void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  45501. + char const *func, int line)
  45502. +{
  45503. + void *addr = __DWC_DMA_ALLOC(dma_ctx, size, dma_addr);
  45504. +
  45505. + if (!addr) {
  45506. + return NULL;
  45507. + }
  45508. +
  45509. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  45510. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  45511. + return NULL;
  45512. + }
  45513. +
  45514. + return addr;
  45515. +}
  45516. +
  45517. +void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size,
  45518. + dwc_dma_t *dma_addr, char const *func, int line)
  45519. +{
  45520. + void *addr = __DWC_DMA_ALLOC_ATOMIC(dma_ctx, size, dma_addr);
  45521. +
  45522. + if (!addr) {
  45523. + return NULL;
  45524. + }
  45525. +
  45526. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  45527. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  45528. + return NULL;
  45529. + }
  45530. +
  45531. + return addr;
  45532. +}
  45533. +
  45534. +void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  45535. + dwc_dma_t dma_addr, char const *func, int line)
  45536. +{
  45537. + free_allocation(dma_ctx, virt_addr, func, line);
  45538. + __DWC_DMA_FREE(dma_ctx, size, virt_addr, dma_addr);
  45539. +}
  45540. +
  45541. +#endif /* DWC_DEBUG_MEMORY */
  45542. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_modpow.c linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_modpow.c
  45543. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_modpow.c 1970-01-01 01:00:00.000000000 +0100
  45544. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_modpow.c 2014-02-18 11:52:14.000000000 +0100
  45545. @@ -0,0 +1,636 @@
  45546. +/* Bignum routines adapted from PUTTY sources. PuTTY copyright notice follows.
  45547. + *
  45548. + * PuTTY is copyright 1997-2007 Simon Tatham.
  45549. + *
  45550. + * Portions copyright Robert de Bath, Joris van Rantwijk, Delian
  45551. + * Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas Barry,
  45552. + * Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, Markus
  45553. + * Kuhn, and CORE SDI S.A.
  45554. + *
  45555. + * Permission is hereby granted, free of charge, to any person
  45556. + * obtaining a copy of this software and associated documentation files
  45557. + * (the "Software"), to deal in the Software without restriction,
  45558. + * including without limitation the rights to use, copy, modify, merge,
  45559. + * publish, distribute, sublicense, and/or sell copies of the Software,
  45560. + * and to permit persons to whom the Software is furnished to do so,
  45561. + * subject to the following conditions:
  45562. + *
  45563. + * The above copyright notice and this permission notice shall be
  45564. + * included in all copies or substantial portions of the Software.
  45565. +
  45566. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  45567. + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  45568. + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  45569. + * NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
  45570. + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  45571. + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  45572. + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  45573. + *
  45574. + */
  45575. +#ifdef DWC_CRYPTOLIB
  45576. +
  45577. +#ifndef CONFIG_MACH_IPMATE
  45578. +
  45579. +#include "dwc_modpow.h"
  45580. +
  45581. +#define BIGNUM_INT_MASK 0xFFFFFFFFUL
  45582. +#define BIGNUM_TOP_BIT 0x80000000UL
  45583. +#define BIGNUM_INT_BITS 32
  45584. +
  45585. +
  45586. +static void *snmalloc(void *mem_ctx, size_t n, size_t size)
  45587. +{
  45588. + void *p;
  45589. + size *= n;
  45590. + if (size == 0) size = 1;
  45591. + p = dwc_alloc(mem_ctx, size);
  45592. + return p;
  45593. +}
  45594. +
  45595. +#define snewn(ctx, n, type) ((type *)snmalloc((ctx), (n), sizeof(type)))
  45596. +#define sfree dwc_free
  45597. +
  45598. +/*
  45599. + * Usage notes:
  45600. + * * Do not call the DIVMOD_WORD macro with expressions such as array
  45601. + * subscripts, as some implementations object to this (see below).
  45602. + * * Note that none of the division methods below will cope if the
  45603. + * quotient won't fit into BIGNUM_INT_BITS. Callers should be careful
  45604. + * to avoid this case.
  45605. + * If this condition occurs, in the case of the x86 DIV instruction,
  45606. + * an overflow exception will occur, which (according to a correspondent)
  45607. + * will manifest on Windows as something like
  45608. + * 0xC0000095: Integer overflow
  45609. + * The C variant won't give the right answer, either.
  45610. + */
  45611. +
  45612. +#define MUL_WORD(w1, w2) ((BignumDblInt)w1 * w2)
  45613. +
  45614. +#if defined __GNUC__ && defined __i386__
  45615. +#define DIVMOD_WORD(q, r, hi, lo, w) \
  45616. + __asm__("div %2" : \
  45617. + "=d" (r), "=a" (q) : \
  45618. + "r" (w), "d" (hi), "a" (lo))
  45619. +#else
  45620. +#define DIVMOD_WORD(q, r, hi, lo, w) do { \
  45621. + BignumDblInt n = (((BignumDblInt)hi) << BIGNUM_INT_BITS) | lo; \
  45622. + q = n / w; \
  45623. + r = n % w; \
  45624. +} while (0)
  45625. +#endif
  45626. +
  45627. +// q = n / w;
  45628. +// r = n % w;
  45629. +
  45630. +#define BIGNUM_INT_BYTES (BIGNUM_INT_BITS / 8)
  45631. +
  45632. +#define BIGNUM_INTERNAL
  45633. +
  45634. +static Bignum newbn(void *mem_ctx, int length)
  45635. +{
  45636. + Bignum b = snewn(mem_ctx, length + 1, BignumInt);
  45637. + //if (!b)
  45638. + //abort(); /* FIXME */
  45639. + DWC_MEMSET(b, 0, (length + 1) * sizeof(*b));
  45640. + b[0] = length;
  45641. + return b;
  45642. +}
  45643. +
  45644. +void freebn(void *mem_ctx, Bignum b)
  45645. +{
  45646. + /*
  45647. + * Burn the evidence, just in case.
  45648. + */
  45649. + DWC_MEMSET(b, 0, sizeof(b[0]) * (b[0] + 1));
  45650. + sfree(mem_ctx, b);
  45651. +}
  45652. +
  45653. +/*
  45654. + * Compute c = a * b.
  45655. + * Input is in the first len words of a and b.
  45656. + * Result is returned in the first 2*len words of c.
  45657. + */
  45658. +static void internal_mul(BignumInt *a, BignumInt *b,
  45659. + BignumInt *c, int len)
  45660. +{
  45661. + int i, j;
  45662. + BignumDblInt t;
  45663. +
  45664. + for (j = 0; j < 2 * len; j++)
  45665. + c[j] = 0;
  45666. +
  45667. + for (i = len - 1; i >= 0; i--) {
  45668. + t = 0;
  45669. + for (j = len - 1; j >= 0; j--) {
  45670. + t += MUL_WORD(a[i], (BignumDblInt) b[j]);
  45671. + t += (BignumDblInt) c[i + j + 1];
  45672. + c[i + j + 1] = (BignumInt) t;
  45673. + t = t >> BIGNUM_INT_BITS;
  45674. + }
  45675. + c[i] = (BignumInt) t;
  45676. + }
  45677. +}
  45678. +
  45679. +static void internal_add_shifted(BignumInt *number,
  45680. + unsigned n, int shift)
  45681. +{
  45682. + int word = 1 + (shift / BIGNUM_INT_BITS);
  45683. + int bshift = shift % BIGNUM_INT_BITS;
  45684. + BignumDblInt addend;
  45685. +
  45686. + addend = (BignumDblInt)n << bshift;
  45687. +
  45688. + while (addend) {
  45689. + addend += number[word];
  45690. + number[word] = (BignumInt) addend & BIGNUM_INT_MASK;
  45691. + addend >>= BIGNUM_INT_BITS;
  45692. + word++;
  45693. + }
  45694. +}
  45695. +
  45696. +/*
  45697. + * Compute a = a % m.
  45698. + * Input in first alen words of a and first mlen words of m.
  45699. + * Output in first alen words of a
  45700. + * (of which first alen-mlen words will be zero).
  45701. + * The MSW of m MUST have its high bit set.
  45702. + * Quotient is accumulated in the `quotient' array, which is a Bignum
  45703. + * rather than the internal bigendian format. Quotient parts are shifted
  45704. + * left by `qshift' before adding into quot.
  45705. + */
  45706. +static void internal_mod(BignumInt *a, int alen,
  45707. + BignumInt *m, int mlen,
  45708. + BignumInt *quot, int qshift)
  45709. +{
  45710. + BignumInt m0, m1;
  45711. + unsigned int h;
  45712. + int i, k;
  45713. +
  45714. + m0 = m[0];
  45715. + if (mlen > 1)
  45716. + m1 = m[1];
  45717. + else
  45718. + m1 = 0;
  45719. +
  45720. + for (i = 0; i <= alen - mlen; i++) {
  45721. + BignumDblInt t;
  45722. + unsigned int q, r, c, ai1;
  45723. +
  45724. + if (i == 0) {
  45725. + h = 0;
  45726. + } else {
  45727. + h = a[i - 1];
  45728. + a[i - 1] = 0;
  45729. + }
  45730. +
  45731. + if (i == alen - 1)
  45732. + ai1 = 0;
  45733. + else
  45734. + ai1 = a[i + 1];
  45735. +
  45736. + /* Find q = h:a[i] / m0 */
  45737. + if (h >= m0) {
  45738. + /*
  45739. + * Special case.
  45740. + *
  45741. + * To illustrate it, suppose a BignumInt is 8 bits, and
  45742. + * we are dividing (say) A1:23:45:67 by A1:B2:C3. Then
  45743. + * our initial division will be 0xA123 / 0xA1, which
  45744. + * will give a quotient of 0x100 and a divide overflow.
  45745. + * However, the invariants in this division algorithm
  45746. + * are not violated, since the full number A1:23:... is
  45747. + * _less_ than the quotient prefix A1:B2:... and so the
  45748. + * following correction loop would have sorted it out.
  45749. + *
  45750. + * In this situation we set q to be the largest
  45751. + * quotient we _can_ stomach (0xFF, of course).
  45752. + */
  45753. + q = BIGNUM_INT_MASK;
  45754. + } else {
  45755. + /* Macro doesn't want an array subscript expression passed
  45756. + * into it (see definition), so use a temporary. */
  45757. + BignumInt tmplo = a[i];
  45758. + DIVMOD_WORD(q, r, h, tmplo, m0);
  45759. +
  45760. + /* Refine our estimate of q by looking at
  45761. + h:a[i]:a[i+1] / m0:m1 */
  45762. + t = MUL_WORD(m1, q);
  45763. + if (t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) {
  45764. + q--;
  45765. + t -= m1;
  45766. + r = (r + m0) & BIGNUM_INT_MASK; /* overflow? */
  45767. + if (r >= (BignumDblInt) m0 &&
  45768. + t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) q--;
  45769. + }
  45770. + }
  45771. +
  45772. + /* Subtract q * m from a[i...] */
  45773. + c = 0;
  45774. + for (k = mlen - 1; k >= 0; k--) {
  45775. + t = MUL_WORD(q, m[k]);
  45776. + t += c;
  45777. + c = (unsigned)(t >> BIGNUM_INT_BITS);
  45778. + if ((BignumInt) t > a[i + k])
  45779. + c++;
  45780. + a[i + k] -= (BignumInt) t;
  45781. + }
  45782. +
  45783. + /* Add back m in case of borrow */
  45784. + if (c != h) {
  45785. + t = 0;
  45786. + for (k = mlen - 1; k >= 0; k--) {
  45787. + t += m[k];
  45788. + t += a[i + k];
  45789. + a[i + k] = (BignumInt) t;
  45790. + t = t >> BIGNUM_INT_BITS;
  45791. + }
  45792. + q--;
  45793. + }
  45794. + if (quot)
  45795. + internal_add_shifted(quot, q, qshift + BIGNUM_INT_BITS * (alen - mlen - i));
  45796. + }
  45797. +}
  45798. +
  45799. +/*
  45800. + * Compute p % mod.
  45801. + * The most significant word of mod MUST be non-zero.
  45802. + * We assume that the result array is the same size as the mod array.
  45803. + * We optionally write out a quotient if `quotient' is non-NULL.
  45804. + * We can avoid writing out the result if `result' is NULL.
  45805. + */
  45806. +void bigdivmod(void *mem_ctx, Bignum p, Bignum mod, Bignum result, Bignum quotient)
  45807. +{
  45808. + BignumInt *n, *m;
  45809. + int mshift;
  45810. + int plen, mlen, i, j;
  45811. +
  45812. + /* Allocate m of size mlen, copy mod to m */
  45813. + /* We use big endian internally */
  45814. + mlen = mod[0];
  45815. + m = snewn(mem_ctx, mlen, BignumInt);
  45816. + //if (!m)
  45817. + //abort(); /* FIXME */
  45818. + for (j = 0; j < mlen; j++)
  45819. + m[j] = mod[mod[0] - j];
  45820. +
  45821. + /* Shift m left to make msb bit set */
  45822. + for (mshift = 0; mshift < BIGNUM_INT_BITS-1; mshift++)
  45823. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  45824. + break;
  45825. + if (mshift) {
  45826. + for (i = 0; i < mlen - 1; i++)
  45827. + m[i] = (m[i] << mshift) | (m[i + 1] >> (BIGNUM_INT_BITS - mshift));
  45828. + m[mlen - 1] = m[mlen - 1] << mshift;
  45829. + }
  45830. +
  45831. + plen = p[0];
  45832. + /* Ensure plen > mlen */
  45833. + if (plen <= mlen)
  45834. + plen = mlen + 1;
  45835. +
  45836. + /* Allocate n of size plen, copy p to n */
  45837. + n = snewn(mem_ctx, plen, BignumInt);
  45838. + //if (!n)
  45839. + //abort(); /* FIXME */
  45840. + for (j = 0; j < plen; j++)
  45841. + n[j] = 0;
  45842. + for (j = 1; j <= (int)p[0]; j++)
  45843. + n[plen - j] = p[j];
  45844. +
  45845. + /* Main computation */
  45846. + internal_mod(n, plen, m, mlen, quotient, mshift);
  45847. +
  45848. + /* Fixup result in case the modulus was shifted */
  45849. + if (mshift) {
  45850. + for (i = plen - mlen - 1; i < plen - 1; i++)
  45851. + n[i] = (n[i] << mshift) | (n[i + 1] >> (BIGNUM_INT_BITS - mshift));
  45852. + n[plen - 1] = n[plen - 1] << mshift;
  45853. + internal_mod(n, plen, m, mlen, quotient, 0);
  45854. + for (i = plen - 1; i >= plen - mlen; i--)
  45855. + n[i] = (n[i] >> mshift) | (n[i - 1] << (BIGNUM_INT_BITS - mshift));
  45856. + }
  45857. +
  45858. + /* Copy result to buffer */
  45859. + if (result) {
  45860. + for (i = 1; i <= (int)result[0]; i++) {
  45861. + int j = plen - i;
  45862. + result[i] = j >= 0 ? n[j] : 0;
  45863. + }
  45864. + }
  45865. +
  45866. + /* Free temporary arrays */
  45867. + for (i = 0; i < mlen; i++)
  45868. + m[i] = 0;
  45869. + sfree(mem_ctx, m);
  45870. + for (i = 0; i < plen; i++)
  45871. + n[i] = 0;
  45872. + sfree(mem_ctx, n);
  45873. +}
  45874. +
  45875. +/*
  45876. + * Simple remainder.
  45877. + */
  45878. +Bignum bigmod(void *mem_ctx, Bignum a, Bignum b)
  45879. +{
  45880. + Bignum r = newbn(mem_ctx, b[0]);
  45881. + bigdivmod(mem_ctx, a, b, r, NULL);
  45882. + return r;
  45883. +}
  45884. +
  45885. +/*
  45886. + * Compute (base ^ exp) % mod.
  45887. + */
  45888. +Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod)
  45889. +{
  45890. + BignumInt *a, *b, *n, *m;
  45891. + int mshift;
  45892. + int mlen, i, j;
  45893. + Bignum base, result;
  45894. +
  45895. + /*
  45896. + * The most significant word of mod needs to be non-zero. It
  45897. + * should already be, but let's make sure.
  45898. + */
  45899. + //assert(mod[mod[0]] != 0);
  45900. +
  45901. + /*
  45902. + * Make sure the base is smaller than the modulus, by reducing
  45903. + * it modulo the modulus if not.
  45904. + */
  45905. + base = bigmod(mem_ctx, base_in, mod);
  45906. +
  45907. + /* Allocate m of size mlen, copy mod to m */
  45908. + /* We use big endian internally */
  45909. + mlen = mod[0];
  45910. + m = snewn(mem_ctx, mlen, BignumInt);
  45911. + //if (!m)
  45912. + //abort(); /* FIXME */
  45913. + for (j = 0; j < mlen; j++)
  45914. + m[j] = mod[mod[0] - j];
  45915. +
  45916. + /* Shift m left to make msb bit set */
  45917. + for (mshift = 0; mshift < BIGNUM_INT_BITS - 1; mshift++)
  45918. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  45919. + break;
  45920. + if (mshift) {
  45921. + for (i = 0; i < mlen - 1; i++)
  45922. + m[i] =
  45923. + (m[i] << mshift) | (m[i + 1] >>
  45924. + (BIGNUM_INT_BITS - mshift));
  45925. + m[mlen - 1] = m[mlen - 1] << mshift;
  45926. + }
  45927. +
  45928. + /* Allocate n of size mlen, copy base to n */
  45929. + n = snewn(mem_ctx, mlen, BignumInt);
  45930. + //if (!n)
  45931. + //abort(); /* FIXME */
  45932. + i = mlen - base[0];
  45933. + for (j = 0; j < i; j++)
  45934. + n[j] = 0;
  45935. + for (j = 0; j < base[0]; j++)
  45936. + n[i + j] = base[base[0] - j];
  45937. +
  45938. + /* Allocate a and b of size 2*mlen. Set a = 1 */
  45939. + a = snewn(mem_ctx, 2 * mlen, BignumInt);
  45940. + //if (!a)
  45941. + //abort(); /* FIXME */
  45942. + b = snewn(mem_ctx, 2 * mlen, BignumInt);
  45943. + //if (!b)
  45944. + //abort(); /* FIXME */
  45945. + for (i = 0; i < 2 * mlen; i++)
  45946. + a[i] = 0;
  45947. + a[2 * mlen - 1] = 1;
  45948. +
  45949. + /* Skip leading zero bits of exp. */
  45950. + i = 0;
  45951. + j = BIGNUM_INT_BITS - 1;
  45952. + while (i < exp[0] && (exp[exp[0] - i] & (1 << j)) == 0) {
  45953. + j--;
  45954. + if (j < 0) {
  45955. + i++;
  45956. + j = BIGNUM_INT_BITS - 1;
  45957. + }
  45958. + }
  45959. +
  45960. + /* Main computation */
  45961. + while (i < exp[0]) {
  45962. + while (j >= 0) {
  45963. + internal_mul(a + mlen, a + mlen, b, mlen);
  45964. + internal_mod(b, mlen * 2, m, mlen, NULL, 0);
  45965. + if ((exp[exp[0] - i] & (1 << j)) != 0) {
  45966. + internal_mul(b + mlen, n, a, mlen);
  45967. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  45968. + } else {
  45969. + BignumInt *t;
  45970. + t = a;
  45971. + a = b;
  45972. + b = t;
  45973. + }
  45974. + j--;
  45975. + }
  45976. + i++;
  45977. + j = BIGNUM_INT_BITS - 1;
  45978. + }
  45979. +
  45980. + /* Fixup result in case the modulus was shifted */
  45981. + if (mshift) {
  45982. + for (i = mlen - 1; i < 2 * mlen - 1; i++)
  45983. + a[i] =
  45984. + (a[i] << mshift) | (a[i + 1] >>
  45985. + (BIGNUM_INT_BITS - mshift));
  45986. + a[2 * mlen - 1] = a[2 * mlen - 1] << mshift;
  45987. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  45988. + for (i = 2 * mlen - 1; i >= mlen; i--)
  45989. + a[i] =
  45990. + (a[i] >> mshift) | (a[i - 1] <<
  45991. + (BIGNUM_INT_BITS - mshift));
  45992. + }
  45993. +
  45994. + /* Copy result to buffer */
  45995. + result = newbn(mem_ctx, mod[0]);
  45996. + for (i = 0; i < mlen; i++)
  45997. + result[result[0] - i] = a[i + mlen];
  45998. + while (result[0] > 1 && result[result[0]] == 0)
  45999. + result[0]--;
  46000. +
  46001. + /* Free temporary arrays */
  46002. + for (i = 0; i < 2 * mlen; i++)
  46003. + a[i] = 0;
  46004. + sfree(mem_ctx, a);
  46005. + for (i = 0; i < 2 * mlen; i++)
  46006. + b[i] = 0;
  46007. + sfree(mem_ctx, b);
  46008. + for (i = 0; i < mlen; i++)
  46009. + m[i] = 0;
  46010. + sfree(mem_ctx, m);
  46011. + for (i = 0; i < mlen; i++)
  46012. + n[i] = 0;
  46013. + sfree(mem_ctx, n);
  46014. +
  46015. + freebn(mem_ctx, base);
  46016. +
  46017. + return result;
  46018. +}
  46019. +
  46020. +
  46021. +#ifdef UNITTEST
  46022. +
  46023. +static __u32 dh_p[] = {
  46024. + 96,
  46025. + 0xFFFFFFFF,
  46026. + 0xFFFFFFFF,
  46027. + 0xA93AD2CA,
  46028. + 0x4B82D120,
  46029. + 0xE0FD108E,
  46030. + 0x43DB5BFC,
  46031. + 0x74E5AB31,
  46032. + 0x08E24FA0,
  46033. + 0xBAD946E2,
  46034. + 0x770988C0,
  46035. + 0x7A615D6C,
  46036. + 0xBBE11757,
  46037. + 0x177B200C,
  46038. + 0x521F2B18,
  46039. + 0x3EC86A64,
  46040. + 0xD8760273,
  46041. + 0xD98A0864,
  46042. + 0xF12FFA06,
  46043. + 0x1AD2EE6B,
  46044. + 0xCEE3D226,
  46045. + 0x4A25619D,
  46046. + 0x1E8C94E0,
  46047. + 0xDB0933D7,
  46048. + 0xABF5AE8C,
  46049. + 0xA6E1E4C7,
  46050. + 0xB3970F85,
  46051. + 0x5D060C7D,
  46052. + 0x8AEA7157,
  46053. + 0x58DBEF0A,
  46054. + 0xECFB8504,
  46055. + 0xDF1CBA64,
  46056. + 0xA85521AB,
  46057. + 0x04507A33,
  46058. + 0xAD33170D,
  46059. + 0x8AAAC42D,
  46060. + 0x15728E5A,
  46061. + 0x98FA0510,
  46062. + 0x15D22618,
  46063. + 0xEA956AE5,
  46064. + 0x3995497C,
  46065. + 0x95581718,
  46066. + 0xDE2BCBF6,
  46067. + 0x6F4C52C9,
  46068. + 0xB5C55DF0,
  46069. + 0xEC07A28F,
  46070. + 0x9B2783A2,
  46071. + 0x180E8603,
  46072. + 0xE39E772C,
  46073. + 0x2E36CE3B,
  46074. + 0x32905E46,
  46075. + 0xCA18217C,
  46076. + 0xF1746C08,
  46077. + 0x4ABC9804,
  46078. + 0x670C354E,
  46079. + 0x7096966D,
  46080. + 0x9ED52907,
  46081. + 0x208552BB,
  46082. + 0x1C62F356,
  46083. + 0xDCA3AD96,
  46084. + 0x83655D23,
  46085. + 0xFD24CF5F,
  46086. + 0x69163FA8,
  46087. + 0x1C55D39A,
  46088. + 0x98DA4836,
  46089. + 0xA163BF05,
  46090. + 0xC2007CB8,
  46091. + 0xECE45B3D,
  46092. + 0x49286651,
  46093. + 0x7C4B1FE6,
  46094. + 0xAE9F2411,
  46095. + 0x5A899FA5,
  46096. + 0xEE386BFB,
  46097. + 0xF406B7ED,
  46098. + 0x0BFF5CB6,
  46099. + 0xA637ED6B,
  46100. + 0xF44C42E9,
  46101. + 0x625E7EC6,
  46102. + 0xE485B576,
  46103. + 0x6D51C245,
  46104. + 0x4FE1356D,
  46105. + 0xF25F1437,
  46106. + 0x302B0A6D,
  46107. + 0xCD3A431B,
  46108. + 0xEF9519B3,
  46109. + 0x8E3404DD,
  46110. + 0x514A0879,
  46111. + 0x3B139B22,
  46112. + 0x020BBEA6,
  46113. + 0x8A67CC74,
  46114. + 0x29024E08,
  46115. + 0x80DC1CD1,
  46116. + 0xC4C6628B,
  46117. + 0x2168C234,
  46118. + 0xC90FDAA2,
  46119. + 0xFFFFFFFF,
  46120. + 0xFFFFFFFF,
  46121. +};
  46122. +
  46123. +static __u32 dh_a[] = {
  46124. + 8,
  46125. + 0xdf367516,
  46126. + 0x86459caa,
  46127. + 0xe2d459a4,
  46128. + 0xd910dae0,
  46129. + 0x8a8b5e37,
  46130. + 0x67ab31c6,
  46131. + 0xf0b55ea9,
  46132. + 0x440051d6,
  46133. +};
  46134. +
  46135. +static __u32 dh_b[] = {
  46136. + 8,
  46137. + 0xded92656,
  46138. + 0xe07a048a,
  46139. + 0x6fa452cd,
  46140. + 0x2df89d30,
  46141. + 0xc75f1b0f,
  46142. + 0x8ce3578f,
  46143. + 0x7980a324,
  46144. + 0x5daec786,
  46145. +};
  46146. +
  46147. +static __u32 dh_g[] = {
  46148. + 1,
  46149. + 2,
  46150. +};
  46151. +
  46152. +int main(void)
  46153. +{
  46154. + int i;
  46155. + __u32 *k;
  46156. + k = dwc_modpow(NULL, dh_g, dh_a, dh_p);
  46157. +
  46158. + printf("\n\n");
  46159. + for (i=0; i<k[0]; i++) {
  46160. + __u32 word32 = k[k[0] - i];
  46161. + __u16 l = word32 & 0xffff;
  46162. + __u16 m = (word32 & 0xffff0000) >> 16;
  46163. + printf("%04x %04x ", m, l);
  46164. + if (!((i + 1)%13)) printf("\n");
  46165. + }
  46166. + printf("\n\n");
  46167. +
  46168. + if ((k[0] == 0x60) && (k[1] == 0x28e490e5) && (k[0x60] == 0x5a0d3d4e)) {
  46169. + printf("PASS\n\n");
  46170. + }
  46171. + else {
  46172. + printf("FAIL\n\n");
  46173. + }
  46174. +
  46175. +}
  46176. +
  46177. +#endif /* UNITTEST */
  46178. +
  46179. +#endif /* CONFIG_MACH_IPMATE */
  46180. +
  46181. +#endif /*DWC_CRYPTOLIB */
  46182. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_modpow.h linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_modpow.h
  46183. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_modpow.h 1970-01-01 01:00:00.000000000 +0100
  46184. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_modpow.h 2014-02-18 11:52:14.000000000 +0100
  46185. @@ -0,0 +1,34 @@
  46186. +/*
  46187. + * dwc_modpow.h
  46188. + * See dwc_modpow.c for license and changes
  46189. + */
  46190. +#ifndef _DWC_MODPOW_H
  46191. +#define _DWC_MODPOW_H
  46192. +
  46193. +#ifdef __cplusplus
  46194. +extern "C" {
  46195. +#endif
  46196. +
  46197. +#include "dwc_os.h"
  46198. +
  46199. +/** @file
  46200. + *
  46201. + * This file defines the module exponentiation function which is only used
  46202. + * internally by the DWC UWB modules for calculation of PKs during numeric
  46203. + * association. The routine is taken from the PUTTY, an open source terminal
  46204. + * emulator. The PUTTY License is preserved in the dwc_modpow.c file.
  46205. + *
  46206. + */
  46207. +
  46208. +typedef uint32_t BignumInt;
  46209. +typedef uint64_t BignumDblInt;
  46210. +typedef BignumInt *Bignum;
  46211. +
  46212. +/* Compute modular exponentiaion */
  46213. +extern Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod);
  46214. +
  46215. +#ifdef __cplusplus
  46216. +}
  46217. +#endif
  46218. +
  46219. +#endif /* _LINUX_BIGNUM_H */
  46220. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_notifier.c linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_notifier.c
  46221. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_notifier.c 1970-01-01 01:00:00.000000000 +0100
  46222. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_notifier.c 2014-02-18 11:52:14.000000000 +0100
  46223. @@ -0,0 +1,319 @@
  46224. +#ifdef DWC_NOTIFYLIB
  46225. +
  46226. +#include "dwc_notifier.h"
  46227. +#include "dwc_list.h"
  46228. +
  46229. +typedef struct dwc_observer {
  46230. + void *observer;
  46231. + dwc_notifier_callback_t callback;
  46232. + void *data;
  46233. + char *notification;
  46234. + DWC_CIRCLEQ_ENTRY(dwc_observer) list_entry;
  46235. +} observer_t;
  46236. +
  46237. +DWC_CIRCLEQ_HEAD(observer_queue, dwc_observer);
  46238. +
  46239. +typedef struct dwc_notifier {
  46240. + void *mem_ctx;
  46241. + void *object;
  46242. + struct observer_queue observers;
  46243. + DWC_CIRCLEQ_ENTRY(dwc_notifier) list_entry;
  46244. +} notifier_t;
  46245. +
  46246. +DWC_CIRCLEQ_HEAD(notifier_queue, dwc_notifier);
  46247. +
  46248. +typedef struct manager {
  46249. + void *mem_ctx;
  46250. + void *wkq_ctx;
  46251. + dwc_workq_t *wq;
  46252. +// dwc_mutex_t *mutex;
  46253. + struct notifier_queue notifiers;
  46254. +} manager_t;
  46255. +
  46256. +static manager_t *manager = NULL;
  46257. +
  46258. +static int create_manager(void *mem_ctx, void *wkq_ctx)
  46259. +{
  46260. + manager = dwc_alloc(mem_ctx, sizeof(manager_t));
  46261. + if (!manager) {
  46262. + return -DWC_E_NO_MEMORY;
  46263. + }
  46264. +
  46265. + DWC_CIRCLEQ_INIT(&manager->notifiers);
  46266. +
  46267. + manager->wq = dwc_workq_alloc(wkq_ctx, "DWC Notification WorkQ");
  46268. + if (!manager->wq) {
  46269. + return -DWC_E_NO_MEMORY;
  46270. + }
  46271. +
  46272. + return 0;
  46273. +}
  46274. +
  46275. +static void free_manager(void)
  46276. +{
  46277. + dwc_workq_free(manager->wq);
  46278. +
  46279. + /* All notifiers must have unregistered themselves before this module
  46280. + * can be removed. Hitting this assertion indicates a programmer
  46281. + * error. */
  46282. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&manager->notifiers),
  46283. + "Notification manager being freed before all notifiers have been removed");
  46284. + dwc_free(manager->mem_ctx, manager);
  46285. +}
  46286. +
  46287. +#ifdef DEBUG
  46288. +static void dump_manager(void)
  46289. +{
  46290. + notifier_t *n;
  46291. + observer_t *o;
  46292. +
  46293. + DWC_ASSERT(manager, "Notification manager not found");
  46294. +
  46295. + DWC_DEBUG("List of all notifiers and observers:\n");
  46296. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  46297. + DWC_DEBUG("Notifier %p has observers:\n", n->object);
  46298. + DWC_CIRCLEQ_FOREACH(o, &n->observers, list_entry) {
  46299. + DWC_DEBUG(" %p watching %s\n", o->observer, o->notification);
  46300. + }
  46301. + }
  46302. +}
  46303. +#else
  46304. +#define dump_manager(...)
  46305. +#endif
  46306. +
  46307. +static observer_t *alloc_observer(void *mem_ctx, void *observer, char *notification,
  46308. + dwc_notifier_callback_t callback, void *data)
  46309. +{
  46310. + observer_t *new_observer = dwc_alloc(mem_ctx, sizeof(observer_t));
  46311. +
  46312. + if (!new_observer) {
  46313. + return NULL;
  46314. + }
  46315. +
  46316. + DWC_CIRCLEQ_INIT_ENTRY(new_observer, list_entry);
  46317. + new_observer->observer = observer;
  46318. + new_observer->notification = notification;
  46319. + new_observer->callback = callback;
  46320. + new_observer->data = data;
  46321. + return new_observer;
  46322. +}
  46323. +
  46324. +static void free_observer(void *mem_ctx, observer_t *observer)
  46325. +{
  46326. + dwc_free(mem_ctx, observer);
  46327. +}
  46328. +
  46329. +static notifier_t *alloc_notifier(void *mem_ctx, void *object)
  46330. +{
  46331. + notifier_t *notifier;
  46332. +
  46333. + if (!object) {
  46334. + return NULL;
  46335. + }
  46336. +
  46337. + notifier = dwc_alloc(mem_ctx, sizeof(notifier_t));
  46338. + if (!notifier) {
  46339. + return NULL;
  46340. + }
  46341. +
  46342. + DWC_CIRCLEQ_INIT(&notifier->observers);
  46343. + DWC_CIRCLEQ_INIT_ENTRY(notifier, list_entry);
  46344. +
  46345. + notifier->mem_ctx = mem_ctx;
  46346. + notifier->object = object;
  46347. + return notifier;
  46348. +}
  46349. +
  46350. +static void free_notifier(notifier_t *notifier)
  46351. +{
  46352. + observer_t *observer;
  46353. +
  46354. + DWC_CIRCLEQ_FOREACH(observer, &notifier->observers, list_entry) {
  46355. + free_observer(notifier->mem_ctx, observer);
  46356. + }
  46357. +
  46358. + dwc_free(notifier->mem_ctx, notifier);
  46359. +}
  46360. +
  46361. +static notifier_t *find_notifier(void *object)
  46362. +{
  46363. + notifier_t *notifier;
  46364. +
  46365. + DWC_ASSERT(manager, "Notification manager not found");
  46366. +
  46367. + if (!object) {
  46368. + return NULL;
  46369. + }
  46370. +
  46371. + DWC_CIRCLEQ_FOREACH(notifier, &manager->notifiers, list_entry) {
  46372. + if (notifier->object == object) {
  46373. + return notifier;
  46374. + }
  46375. + }
  46376. +
  46377. + return NULL;
  46378. +}
  46379. +
  46380. +int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx)
  46381. +{
  46382. + return create_manager(mem_ctx, wkq_ctx);
  46383. +}
  46384. +
  46385. +void dwc_free_notification_manager(void)
  46386. +{
  46387. + free_manager();
  46388. +}
  46389. +
  46390. +dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object)
  46391. +{
  46392. + notifier_t *notifier;
  46393. +
  46394. + DWC_ASSERT(manager, "Notification manager not found");
  46395. +
  46396. + notifier = find_notifier(object);
  46397. + if (notifier) {
  46398. + DWC_ERROR("Notifier %p is already registered\n", object);
  46399. + return NULL;
  46400. + }
  46401. +
  46402. + notifier = alloc_notifier(mem_ctx, object);
  46403. + if (!notifier) {
  46404. + return NULL;
  46405. + }
  46406. +
  46407. + DWC_CIRCLEQ_INSERT_TAIL(&manager->notifiers, notifier, list_entry);
  46408. +
  46409. + DWC_INFO("Notifier %p registered", object);
  46410. + dump_manager();
  46411. +
  46412. + return notifier;
  46413. +}
  46414. +
  46415. +void dwc_unregister_notifier(dwc_notifier_t *notifier)
  46416. +{
  46417. + DWC_ASSERT(manager, "Notification manager not found");
  46418. +
  46419. + if (!DWC_CIRCLEQ_EMPTY(&notifier->observers)) {
  46420. + observer_t *o;
  46421. +
  46422. + DWC_ERROR("Notifier %p has active observers when removing\n", notifier->object);
  46423. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  46424. + DWC_DEBUGC(" %p watching %s\n", o->observer, o->notification);
  46425. + }
  46426. +
  46427. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&notifier->observers),
  46428. + "Notifier %p has active observers when removing", notifier);
  46429. + }
  46430. +
  46431. + DWC_CIRCLEQ_REMOVE_INIT(&manager->notifiers, notifier, list_entry);
  46432. + free_notifier(notifier);
  46433. +
  46434. + DWC_INFO("Notifier unregistered");
  46435. + dump_manager();
  46436. +}
  46437. +
  46438. +/* Add an observer to observe the notifier for a particular state, event, or notification. */
  46439. +int dwc_add_observer(void *observer, void *object, char *notification,
  46440. + dwc_notifier_callback_t callback, void *data)
  46441. +{
  46442. + notifier_t *notifier = find_notifier(object);
  46443. + observer_t *new_observer;
  46444. +
  46445. + if (!notifier) {
  46446. + DWC_ERROR("Notifier %p is not found when adding observer\n", object);
  46447. + return -DWC_E_INVALID;
  46448. + }
  46449. +
  46450. + new_observer = alloc_observer(notifier->mem_ctx, observer, notification, callback, data);
  46451. + if (!new_observer) {
  46452. + return -DWC_E_NO_MEMORY;
  46453. + }
  46454. +
  46455. + DWC_CIRCLEQ_INSERT_TAIL(&notifier->observers, new_observer, list_entry);
  46456. +
  46457. + DWC_INFO("Added observer %p to notifier %p observing notification %s, callback=%p, data=%p",
  46458. + observer, object, notification, callback, data);
  46459. +
  46460. + dump_manager();
  46461. + return 0;
  46462. +}
  46463. +
  46464. +int dwc_remove_observer(void *observer)
  46465. +{
  46466. + notifier_t *n;
  46467. +
  46468. + DWC_ASSERT(manager, "Notification manager not found");
  46469. +
  46470. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  46471. + observer_t *o;
  46472. + observer_t *o2;
  46473. +
  46474. + DWC_CIRCLEQ_FOREACH_SAFE(o, o2, &n->observers, list_entry) {
  46475. + if (o->observer == observer) {
  46476. + DWC_CIRCLEQ_REMOVE_INIT(&n->observers, o, list_entry);
  46477. + DWC_INFO("Removing observer %p from notifier %p watching notification %s:",
  46478. + o->observer, n->object, o->notification);
  46479. + free_observer(n->mem_ctx, o);
  46480. + }
  46481. + }
  46482. + }
  46483. +
  46484. + dump_manager();
  46485. + return 0;
  46486. +}
  46487. +
  46488. +typedef struct callback_data {
  46489. + void *mem_ctx;
  46490. + dwc_notifier_callback_t cb;
  46491. + void *observer;
  46492. + void *data;
  46493. + void *object;
  46494. + char *notification;
  46495. + void *notification_data;
  46496. +} cb_data_t;
  46497. +
  46498. +static void cb_task(void *data)
  46499. +{
  46500. + cb_data_t *cb = (cb_data_t *)data;
  46501. +
  46502. + cb->cb(cb->object, cb->notification, cb->observer, cb->notification_data, cb->data);
  46503. + dwc_free(cb->mem_ctx, cb);
  46504. +}
  46505. +
  46506. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data)
  46507. +{
  46508. + observer_t *o;
  46509. +
  46510. + DWC_ASSERT(manager, "Notification manager not found");
  46511. +
  46512. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  46513. + int len = DWC_STRLEN(notification);
  46514. +
  46515. + if (DWC_STRLEN(o->notification) != len) {
  46516. + continue;
  46517. + }
  46518. +
  46519. + if (DWC_STRNCMP(o->notification, notification, len) == 0) {
  46520. + cb_data_t *cb_data = dwc_alloc(notifier->mem_ctx, sizeof(cb_data_t));
  46521. +
  46522. + if (!cb_data) {
  46523. + DWC_ERROR("Failed to allocate callback data\n");
  46524. + return;
  46525. + }
  46526. +
  46527. + cb_data->mem_ctx = notifier->mem_ctx;
  46528. + cb_data->cb = o->callback;
  46529. + cb_data->observer = o->observer;
  46530. + cb_data->data = o->data;
  46531. + cb_data->object = notifier->object;
  46532. + cb_data->notification = notification;
  46533. + cb_data->notification_data = notification_data;
  46534. + DWC_DEBUGC("Observer found %p for notification %s\n", o->observer, notification);
  46535. + DWC_WORKQ_SCHEDULE(manager->wq, cb_task, cb_data,
  46536. + "Notify callback from %p for Notification %s, to observer %p",
  46537. + cb_data->object, notification, cb_data->observer);
  46538. + }
  46539. + }
  46540. +}
  46541. +
  46542. +#endif /* DWC_NOTIFYLIB */
  46543. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_notifier.h linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_notifier.h
  46544. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_notifier.h 1970-01-01 01:00:00.000000000 +0100
  46545. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_notifier.h 2014-02-18 11:52:14.000000000 +0100
  46546. @@ -0,0 +1,122 @@
  46547. +
  46548. +#ifndef __DWC_NOTIFIER_H__
  46549. +#define __DWC_NOTIFIER_H__
  46550. +
  46551. +#ifdef __cplusplus
  46552. +extern "C" {
  46553. +#endif
  46554. +
  46555. +#include "dwc_os.h"
  46556. +
  46557. +/** @file
  46558. + *
  46559. + * A simple implementation of the Observer pattern. Any "module" can
  46560. + * register as an observer or notifier. The notion of "module" is abstract and
  46561. + * can mean anything used to identify either an observer or notifier. Usually
  46562. + * it will be a pointer to a data structure which contains some state, ie an
  46563. + * object.
  46564. + *
  46565. + * Before any notifiers can be added, the global notification manager must be
  46566. + * brought up with dwc_alloc_notification_manager().
  46567. + * dwc_free_notification_manager() will bring it down and free all resources.
  46568. + * These would typically be called upon module load and unload. The
  46569. + * notification manager is a single global instance that handles all registered
  46570. + * observable modules and observers so this should be done only once.
  46571. + *
  46572. + * A module can be observable by using Notifications to publicize some general
  46573. + * information about it's state or operation. It does not care who listens, or
  46574. + * even if anyone listens, or what they do with the information. The observable
  46575. + * modules do not need to know any information about it's observers or their
  46576. + * interface, or their state or data.
  46577. + *
  46578. + * Any module can register to emit Notifications. It should publish a list of
  46579. + * notifications that it can emit and their behavior, such as when they will get
  46580. + * triggered, and what information will be provided to the observer. Then it
  46581. + * should register itself as an observable module. See dwc_register_notifier().
  46582. + *
  46583. + * Any module can observe any observable, registered module, provided it has a
  46584. + * handle to the other module and knows what notifications to observe. See
  46585. + * dwc_add_observer().
  46586. + *
  46587. + * A function of type dwc_notifier_callback_t is called whenever a notification
  46588. + * is triggered with one or more observers observing it. This function is
  46589. + * called in it's own process so it may sleep or block if needed. It is
  46590. + * guaranteed to be called sometime after the notification has occurred and will
  46591. + * be called once per each time the notification is triggered. It will NOT be
  46592. + * called in the same process context used to trigger the notification.
  46593. + *
  46594. + * @section Limitiations
  46595. + *
  46596. + * Keep in mind that Notifications that can be triggered in rapid sucession may
  46597. + * schedule too many processes too handle. Be aware of this limitation when
  46598. + * designing to use notifications, and only add notifications for appropriate
  46599. + * observable information.
  46600. + *
  46601. + * Also Notification callbacks are not synchronous. If you need to synchronize
  46602. + * the behavior between module/observer you must use other means. And perhaps
  46603. + * that will mean Notifications are not the proper solution.
  46604. + */
  46605. +
  46606. +struct dwc_notifier;
  46607. +typedef struct dwc_notifier dwc_notifier_t;
  46608. +
  46609. +/** The callback function must be of this type.
  46610. + *
  46611. + * @param object This is the object that is being observed.
  46612. + * @param notification This is the notification that was triggered.
  46613. + * @param observer This is the observer
  46614. + * @param notification_data This is notification-specific data that the notifier
  46615. + * has included in this notification. The value of this should be published in
  46616. + * the documentation of the observable module with the notifications.
  46617. + * @param user_data This is any custom data that the observer provided when
  46618. + * adding itself as an observer to the notification. */
  46619. +typedef void (*dwc_notifier_callback_t)(void *object, char *notification, void *observer,
  46620. + void *notification_data, void *user_data);
  46621. +
  46622. +/** Brings up the notification manager. */
  46623. +extern int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx);
  46624. +/** Brings down the notification manager. */
  46625. +extern void dwc_free_notification_manager(void);
  46626. +
  46627. +/** This function registers an observable module. A dwc_notifier_t object is
  46628. + * returned to the observable module. This is an opaque object that is used by
  46629. + * the observable module to trigger notifications. This object should only be
  46630. + * accessible to functions that are authorized to trigger notifications for this
  46631. + * module. Observers do not need this object. */
  46632. +extern dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object);
  46633. +
  46634. +/** This function unregisters an observable module. All observers have to be
  46635. + * removed prior to unregistration. */
  46636. +extern void dwc_unregister_notifier(dwc_notifier_t *notifier);
  46637. +
  46638. +/** Add a module as an observer to the observable module. The observable module
  46639. + * needs to have previously registered with the notification manager.
  46640. + *
  46641. + * @param observer The observer module
  46642. + * @param object The module to observe
  46643. + * @param notification The notification to observe
  46644. + * @param callback The callback function to call
  46645. + * @param user_data Any additional user data to pass into the callback function */
  46646. +extern int dwc_add_observer(void *observer, void *object, char *notification,
  46647. + dwc_notifier_callback_t callback, void *user_data);
  46648. +
  46649. +/** Removes the specified observer from all notifications that it is currently
  46650. + * observing. */
  46651. +extern int dwc_remove_observer(void *observer);
  46652. +
  46653. +/** This function triggers a Notification. It should be called by the
  46654. + * observable module, or any module or library which the observable module
  46655. + * allows to trigger notification on it's behalf. Such as the dwc_cc_t.
  46656. + *
  46657. + * dwc_notify is a non-blocking function. Callbacks are scheduled called in
  46658. + * their own process context for each trigger. Callbacks can be blocking.
  46659. + * dwc_notify can be called from interrupt context if needed.
  46660. + *
  46661. + */
  46662. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data);
  46663. +
  46664. +#ifdef __cplusplus
  46665. +}
  46666. +#endif
  46667. +
  46668. +#endif /* __DWC_NOTIFIER_H__ */
  46669. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_os.h linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_os.h
  46670. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/dwc_os.h 1970-01-01 01:00:00.000000000 +0100
  46671. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/dwc_os.h 2014-02-18 11:52:14.000000000 +0100
  46672. @@ -0,0 +1,1262 @@
  46673. +/* =========================================================================
  46674. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_os.h $
  46675. + * $Revision: #14 $
  46676. + * $Date: 2010/11/04 $
  46677. + * $Change: 1621695 $
  46678. + *
  46679. + * Synopsys Portability Library Software and documentation
  46680. + * (hereinafter, "Software") is an Unsupported proprietary work of
  46681. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  46682. + * between Synopsys and you.
  46683. + *
  46684. + * The Software IS NOT an item of Licensed Software or Licensed Product
  46685. + * under any End User Software License Agreement or Agreement for
  46686. + * Licensed Product with Synopsys or any supplement thereto. You are
  46687. + * permitted to use and redistribute this Software in source and binary
  46688. + * forms, with or without modification, provided that redistributions
  46689. + * of source code must retain this notice. You may not view, use,
  46690. + * disclose, copy or distribute this file or any information contained
  46691. + * herein except pursuant to this license grant from Synopsys. If you
  46692. + * do not agree with this notice, including the disclaimer below, then
  46693. + * you are not authorized to use the Software.
  46694. + *
  46695. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  46696. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  46697. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  46698. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  46699. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  46700. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  46701. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  46702. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  46703. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  46704. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  46705. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  46706. + * DAMAGE.
  46707. + * ========================================================================= */
  46708. +#ifndef _DWC_OS_H_
  46709. +#define _DWC_OS_H_
  46710. +
  46711. +#ifdef __cplusplus
  46712. +extern "C" {
  46713. +#endif
  46714. +
  46715. +/** @file
  46716. + *
  46717. + * DWC portability library, low level os-wrapper functions
  46718. + *
  46719. + */
  46720. +
  46721. +/* These basic types need to be defined by some OS header file or custom header
  46722. + * file for your specific target architecture.
  46723. + *
  46724. + * uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t
  46725. + *
  46726. + * Any custom or alternate header file must be added and enabled here.
  46727. + */
  46728. +
  46729. +#ifdef DWC_LINUX
  46730. +# include <linux/types.h>
  46731. +# ifdef CONFIG_DEBUG_MUTEXES
  46732. +# include <linux/mutex.h>
  46733. +# endif
  46734. +# include <linux/errno.h>
  46735. +# include <stdarg.h>
  46736. +#endif
  46737. +
  46738. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46739. +# include <os_dep.h>
  46740. +#endif
  46741. +
  46742. +
  46743. +/** @name Primitive Types and Values */
  46744. +
  46745. +/** We define a boolean type for consistency. Can be either YES or NO */
  46746. +typedef uint8_t dwc_bool_t;
  46747. +#define YES 1
  46748. +#define NO 0
  46749. +
  46750. +#ifdef DWC_LINUX
  46751. +
  46752. +/** @name Error Codes */
  46753. +#define DWC_E_INVALID EINVAL
  46754. +#define DWC_E_NO_MEMORY ENOMEM
  46755. +#define DWC_E_NO_DEVICE ENODEV
  46756. +#define DWC_E_NOT_SUPPORTED EOPNOTSUPP
  46757. +#define DWC_E_TIMEOUT ETIMEDOUT
  46758. +#define DWC_E_BUSY EBUSY
  46759. +#define DWC_E_AGAIN EAGAIN
  46760. +#define DWC_E_RESTART ERESTART
  46761. +#define DWC_E_ABORT ECONNABORTED
  46762. +#define DWC_E_SHUTDOWN ESHUTDOWN
  46763. +#define DWC_E_NO_DATA ENODATA
  46764. +#define DWC_E_DISCONNECT ECONNRESET
  46765. +#define DWC_E_UNKNOWN EINVAL
  46766. +#define DWC_E_NO_STREAM_RES ENOSR
  46767. +#define DWC_E_COMMUNICATION ECOMM
  46768. +#define DWC_E_OVERFLOW EOVERFLOW
  46769. +#define DWC_E_PROTOCOL EPROTO
  46770. +#define DWC_E_IN_PROGRESS EINPROGRESS
  46771. +#define DWC_E_PIPE EPIPE
  46772. +#define DWC_E_IO EIO
  46773. +#define DWC_E_NO_SPACE ENOSPC
  46774. +
  46775. +#else
  46776. +
  46777. +/** @name Error Codes */
  46778. +#define DWC_E_INVALID 1001
  46779. +#define DWC_E_NO_MEMORY 1002
  46780. +#define DWC_E_NO_DEVICE 1003
  46781. +#define DWC_E_NOT_SUPPORTED 1004
  46782. +#define DWC_E_TIMEOUT 1005
  46783. +#define DWC_E_BUSY 1006
  46784. +#define DWC_E_AGAIN 1007
  46785. +#define DWC_E_RESTART 1008
  46786. +#define DWC_E_ABORT 1009
  46787. +#define DWC_E_SHUTDOWN 1010
  46788. +#define DWC_E_NO_DATA 1011
  46789. +#define DWC_E_DISCONNECT 2000
  46790. +#define DWC_E_UNKNOWN 3000
  46791. +#define DWC_E_NO_STREAM_RES 4001
  46792. +#define DWC_E_COMMUNICATION 4002
  46793. +#define DWC_E_OVERFLOW 4003
  46794. +#define DWC_E_PROTOCOL 4004
  46795. +#define DWC_E_IN_PROGRESS 4005
  46796. +#define DWC_E_PIPE 4006
  46797. +#define DWC_E_IO 4007
  46798. +#define DWC_E_NO_SPACE 4008
  46799. +
  46800. +#endif
  46801. +
  46802. +
  46803. +/** @name Tracing/Logging Functions
  46804. + *
  46805. + * These function provide the capability to add tracing, debugging, and error
  46806. + * messages, as well exceptions as assertions. The WUDEV uses these
  46807. + * extensively. These could be logged to the main console, the serial port, an
  46808. + * internal buffer, etc. These functions could also be no-op if they are too
  46809. + * expensive on your system. By default undefining the DEBUG macro already
  46810. + * no-ops some of these functions. */
  46811. +
  46812. +/** Returns non-zero if in interrupt context. */
  46813. +extern dwc_bool_t DWC_IN_IRQ(void);
  46814. +#define dwc_in_irq DWC_IN_IRQ
  46815. +
  46816. +/** Returns "IRQ" if DWC_IN_IRQ is true. */
  46817. +static inline char *dwc_irq(void) {
  46818. + return DWC_IN_IRQ() ? "IRQ" : "";
  46819. +}
  46820. +
  46821. +/** Returns non-zero if in bottom-half context. */
  46822. +extern dwc_bool_t DWC_IN_BH(void);
  46823. +#define dwc_in_bh DWC_IN_BH
  46824. +
  46825. +/** Returns "BH" if DWC_IN_BH is true. */
  46826. +static inline char *dwc_bh(void) {
  46827. + return DWC_IN_BH() ? "BH" : "";
  46828. +}
  46829. +
  46830. +/**
  46831. + * A vprintf() clone. Just call vprintf if you've got it.
  46832. + */
  46833. +extern void DWC_VPRINTF(char *format, va_list args);
  46834. +#define dwc_vprintf DWC_VPRINTF
  46835. +
  46836. +/**
  46837. + * A vsnprintf() clone. Just call vprintf if you've got it.
  46838. + */
  46839. +extern int DWC_VSNPRINTF(char *str, int size, char *format, va_list args);
  46840. +#define dwc_vsnprintf DWC_VSNPRINTF
  46841. +
  46842. +/**
  46843. + * printf() clone. Just call printf if you've go it.
  46844. + */
  46845. +extern void DWC_PRINTF(char *format, ...)
  46846. +/* This provides compiler level static checking of the parameters if you're
  46847. + * using GCC. */
  46848. +#ifdef __GNUC__
  46849. + __attribute__ ((format(printf, 1, 2)));
  46850. +#else
  46851. + ;
  46852. +#endif
  46853. +#define dwc_printf DWC_PRINTF
  46854. +
  46855. +/**
  46856. + * sprintf() clone. Just call sprintf if you've got it.
  46857. + */
  46858. +extern int DWC_SPRINTF(char *string, char *format, ...)
  46859. +#ifdef __GNUC__
  46860. + __attribute__ ((format(printf, 2, 3)));
  46861. +#else
  46862. + ;
  46863. +#endif
  46864. +#define dwc_sprintf DWC_SPRINTF
  46865. +
  46866. +/**
  46867. + * snprintf() clone. Just call snprintf if you've got it.
  46868. + */
  46869. +extern int DWC_SNPRINTF(char *string, int size, char *format, ...)
  46870. +#ifdef __GNUC__
  46871. + __attribute__ ((format(printf, 3, 4)));
  46872. +#else
  46873. + ;
  46874. +#endif
  46875. +#define dwc_snprintf DWC_SNPRINTF
  46876. +
  46877. +/**
  46878. + * Prints a WARNING message. On systems that don't differentiate between
  46879. + * warnings and regular log messages, just print it. Indicates that something
  46880. + * may be wrong with the driver. Works like printf().
  46881. + *
  46882. + * Use the DWC_WARN macro to call this function.
  46883. + */
  46884. +extern void __DWC_WARN(char *format, ...)
  46885. +#ifdef __GNUC__
  46886. + __attribute__ ((format(printf, 1, 2)));
  46887. +#else
  46888. + ;
  46889. +#endif
  46890. +
  46891. +/**
  46892. + * Prints an error message. On systems that don't differentiate between errors
  46893. + * and regular log messages, just print it. Indicates that something went wrong
  46894. + * with the driver. Works like printf().
  46895. + *
  46896. + * Use the DWC_ERROR macro to call this function.
  46897. + */
  46898. +extern void __DWC_ERROR(char *format, ...)
  46899. +#ifdef __GNUC__
  46900. + __attribute__ ((format(printf, 1, 2)));
  46901. +#else
  46902. + ;
  46903. +#endif
  46904. +
  46905. +/**
  46906. + * Prints an exception error message and takes some user-defined action such as
  46907. + * print out a backtrace or trigger a breakpoint. Indicates that something went
  46908. + * abnormally wrong with the driver such as programmer error, or other
  46909. + * exceptional condition. It should not be ignored so even on systems without
  46910. + * printing capability, some action should be taken to notify the developer of
  46911. + * it. Works like printf().
  46912. + */
  46913. +extern void DWC_EXCEPTION(char *format, ...)
  46914. +#ifdef __GNUC__
  46915. + __attribute__ ((format(printf, 1, 2)));
  46916. +#else
  46917. + ;
  46918. +#endif
  46919. +#define dwc_exception DWC_EXCEPTION
  46920. +
  46921. +#ifndef DWC_OTG_DEBUG_LEV
  46922. +#define DWC_OTG_DEBUG_LEV 0
  46923. +#endif
  46924. +
  46925. +#ifdef DEBUG
  46926. +/**
  46927. + * Prints out a debug message. Used for logging/trace messages.
  46928. + *
  46929. + * Use the DWC_DEBUG macro to call this function
  46930. + */
  46931. +extern void __DWC_DEBUG(char *format, ...)
  46932. +#ifdef __GNUC__
  46933. + __attribute__ ((format(printf, 1, 2)));
  46934. +#else
  46935. + ;
  46936. +#endif
  46937. +#else
  46938. +#define __DWC_DEBUG printk
  46939. +#endif
  46940. +
  46941. +/**
  46942. + * Prints out a Debug message.
  46943. + */
  46944. +#define DWC_DEBUG(_format, _args...) __DWC_DEBUG("DEBUG:%s:%s: " _format "\n", \
  46945. + __func__, dwc_irq(), ## _args)
  46946. +#define dwc_debug DWC_DEBUG
  46947. +/**
  46948. + * Prints out a Debug message if enabled at compile time.
  46949. + */
  46950. +#if DWC_OTG_DEBUG_LEV > 0
  46951. +#define DWC_DEBUGC(_format, _args...) DWC_DEBUG(_format, ##_args )
  46952. +#else
  46953. +#define DWC_DEBUGC(_format, _args...)
  46954. +#endif
  46955. +#define dwc_debugc DWC_DEBUGC
  46956. +/**
  46957. + * Prints out an informative message.
  46958. + */
  46959. +#define DWC_INFO(_format, _args...) DWC_PRINTF("INFO:%s: " _format "\n", \
  46960. + dwc_irq(), ## _args)
  46961. +#define dwc_info DWC_INFO
  46962. +/**
  46963. + * Prints out an informative message if enabled at compile time.
  46964. + */
  46965. +#if DWC_OTG_DEBUG_LEV > 1
  46966. +#define DWC_INFOC(_format, _args...) DWC_INFO(_format, ##_args )
  46967. +#else
  46968. +#define DWC_INFOC(_format, _args...)
  46969. +#endif
  46970. +#define dwc_infoc DWC_INFOC
  46971. +/**
  46972. + * Prints out a warning message.
  46973. + */
  46974. +#define DWC_WARN(_format, _args...) __DWC_WARN("WARN:%s:%s:%d: " _format "\n", \
  46975. + dwc_irq(), __func__, __LINE__, ## _args)
  46976. +#define dwc_warn DWC_WARN
  46977. +/**
  46978. + * Prints out an error message.
  46979. + */
  46980. +#define DWC_ERROR(_format, _args...) __DWC_ERROR("ERROR:%s:%s:%d: " _format "\n", \
  46981. + dwc_irq(), __func__, __LINE__, ## _args)
  46982. +#define dwc_error DWC_ERROR
  46983. +
  46984. +#define DWC_PROTO_ERROR(_format, _args...) __DWC_WARN("ERROR:%s:%s:%d: " _format "\n", \
  46985. + dwc_irq(), __func__, __LINE__, ## _args)
  46986. +#define dwc_proto_error DWC_PROTO_ERROR
  46987. +
  46988. +#ifdef DEBUG
  46989. +/** Prints out a exception error message if the _expr expression fails. Disabled
  46990. + * if DEBUG is not enabled. */
  46991. +#define DWC_ASSERT(_expr, _format, _args...) do { \
  46992. + if (!(_expr)) { DWC_EXCEPTION("%s:%s:%d: " _format "\n", dwc_irq(), \
  46993. + __FILE__, __LINE__, ## _args); } \
  46994. + } while (0)
  46995. +#else
  46996. +#define DWC_ASSERT(_x...)
  46997. +#endif
  46998. +#define dwc_assert DWC_ASSERT
  46999. +
  47000. +
  47001. +/** @name Byte Ordering
  47002. + * The following functions are for conversions between processor's byte ordering
  47003. + * and specific ordering you want.
  47004. + */
  47005. +
  47006. +/** Converts 32 bit data in CPU byte ordering to little endian. */
  47007. +extern uint32_t DWC_CPU_TO_LE32(uint32_t *p);
  47008. +#define dwc_cpu_to_le32 DWC_CPU_TO_LE32
  47009. +
  47010. +/** Converts 32 bit data in CPU byte orderint to big endian. */
  47011. +extern uint32_t DWC_CPU_TO_BE32(uint32_t *p);
  47012. +#define dwc_cpu_to_be32 DWC_CPU_TO_BE32
  47013. +
  47014. +/** Converts 32 bit little endian data to CPU byte ordering. */
  47015. +extern uint32_t DWC_LE32_TO_CPU(uint32_t *p);
  47016. +#define dwc_le32_to_cpu DWC_LE32_TO_CPU
  47017. +
  47018. +/** Converts 32 bit big endian data to CPU byte ordering. */
  47019. +extern uint32_t DWC_BE32_TO_CPU(uint32_t *p);
  47020. +#define dwc_be32_to_cpu DWC_BE32_TO_CPU
  47021. +
  47022. +/** Converts 16 bit data in CPU byte ordering to little endian. */
  47023. +extern uint16_t DWC_CPU_TO_LE16(uint16_t *p);
  47024. +#define dwc_cpu_to_le16 DWC_CPU_TO_LE16
  47025. +
  47026. +/** Converts 16 bit data in CPU byte orderint to big endian. */
  47027. +extern uint16_t DWC_CPU_TO_BE16(uint16_t *p);
  47028. +#define dwc_cpu_to_be16 DWC_CPU_TO_BE16
  47029. +
  47030. +/** Converts 16 bit little endian data to CPU byte ordering. */
  47031. +extern uint16_t DWC_LE16_TO_CPU(uint16_t *p);
  47032. +#define dwc_le16_to_cpu DWC_LE16_TO_CPU
  47033. +
  47034. +/** Converts 16 bit bi endian data to CPU byte ordering. */
  47035. +extern uint16_t DWC_BE16_TO_CPU(uint16_t *p);
  47036. +#define dwc_be16_to_cpu DWC_BE16_TO_CPU
  47037. +
  47038. +
  47039. +/** @name Register Read/Write
  47040. + *
  47041. + * The following six functions should be implemented to read/write registers of
  47042. + * 32-bit and 64-bit sizes. All modules use this to read/write register values.
  47043. + * The reg value is a pointer to the register calculated from the void *base
  47044. + * variable passed into the driver when it is started. */
  47045. +
  47046. +#ifdef DWC_LINUX
  47047. +/* Linux doesn't need any extra parameters for register read/write, so we
  47048. + * just throw away the IO context parameter.
  47049. + */
  47050. +/** Reads the content of a 32-bit register. */
  47051. +extern uint32_t DWC_READ_REG32(uint32_t volatile *reg);
  47052. +#define dwc_read_reg32(_ctx_,_reg_) DWC_READ_REG32(_reg_)
  47053. +
  47054. +/** Reads the content of a 64-bit register. */
  47055. +extern uint64_t DWC_READ_REG64(uint64_t volatile *reg);
  47056. +#define dwc_read_reg64(_ctx_,_reg_) DWC_READ_REG64(_reg_)
  47057. +
  47058. +/** Writes to a 32-bit register. */
  47059. +extern void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value);
  47060. +#define dwc_write_reg32(_ctx_,_reg_,_val_) DWC_WRITE_REG32(_reg_, _val_)
  47061. +
  47062. +/** Writes to a 64-bit register. */
  47063. +extern void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value);
  47064. +#define dwc_write_reg64(_ctx_,_reg_,_val_) DWC_WRITE_REG64(_reg_, _val_)
  47065. +
  47066. +/**
  47067. + * Modify bit values in a register. Using the
  47068. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  47069. + */
  47070. +extern void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  47071. +#define dwc_modify_reg32(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG32(_reg_,_cmsk_,_smsk_)
  47072. +extern void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  47073. +#define dwc_modify_reg64(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG64(_reg_,_cmsk_,_smsk_)
  47074. +
  47075. +#endif /* DWC_LINUX */
  47076. +
  47077. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47078. +typedef struct dwc_ioctx {
  47079. + struct device *dev;
  47080. + bus_space_tag_t iot;
  47081. + bus_space_handle_t ioh;
  47082. +} dwc_ioctx_t;
  47083. +
  47084. +/** BSD needs two extra parameters for register read/write, so we pass
  47085. + * them in using the IO context parameter.
  47086. + */
  47087. +/** Reads the content of a 32-bit register. */
  47088. +extern uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg);
  47089. +#define dwc_read_reg32 DWC_READ_REG32
  47090. +
  47091. +/** Reads the content of a 64-bit register. */
  47092. +extern uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg);
  47093. +#define dwc_read_reg64 DWC_READ_REG64
  47094. +
  47095. +/** Writes to a 32-bit register. */
  47096. +extern void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value);
  47097. +#define dwc_write_reg32 DWC_WRITE_REG32
  47098. +
  47099. +/** Writes to a 64-bit register. */
  47100. +extern void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value);
  47101. +#define dwc_write_reg64 DWC_WRITE_REG64
  47102. +
  47103. +/**
  47104. + * Modify bit values in a register. Using the
  47105. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  47106. + */
  47107. +extern void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  47108. +#define dwc_modify_reg32 DWC_MODIFY_REG32
  47109. +extern void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  47110. +#define dwc_modify_reg64 DWC_MODIFY_REG64
  47111. +
  47112. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  47113. +
  47114. +/** @cond */
  47115. +
  47116. +/** @name Some convenience MACROS used internally. Define DWC_DEBUG_REGS to log the
  47117. + * register writes. */
  47118. +
  47119. +#ifdef DWC_LINUX
  47120. +
  47121. +# ifdef DWC_DEBUG_REGS
  47122. +
  47123. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  47124. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  47125. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  47126. +} \
  47127. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  47128. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  47129. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  47130. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  47131. +}
  47132. +
  47133. +#define dwc_define_read_write_reg(_reg,_container_type) \
  47134. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  47135. + return DWC_READ_REG32(&container->regs->_reg); \
  47136. +} \
  47137. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  47138. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  47139. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  47140. +}
  47141. +
  47142. +# else /* DWC_DEBUG_REGS */
  47143. +
  47144. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  47145. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  47146. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  47147. +} \
  47148. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  47149. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  47150. +}
  47151. +
  47152. +#define dwc_define_read_write_reg(_reg,_container_type) \
  47153. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  47154. + return DWC_READ_REG32(&container->regs->_reg); \
  47155. +} \
  47156. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  47157. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  47158. +}
  47159. +
  47160. +# endif /* DWC_DEBUG_REGS */
  47161. +
  47162. +#endif /* DWC_LINUX */
  47163. +
  47164. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47165. +
  47166. +# ifdef DWC_DEBUG_REGS
  47167. +
  47168. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  47169. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  47170. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  47171. +} \
  47172. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  47173. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  47174. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  47175. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  47176. +}
  47177. +
  47178. +#define dwc_define_read_write_reg(_reg,_container_type) \
  47179. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  47180. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  47181. +} \
  47182. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  47183. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  47184. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  47185. +}
  47186. +
  47187. +# else /* DWC_DEBUG_REGS */
  47188. +
  47189. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  47190. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  47191. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  47192. +} \
  47193. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  47194. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  47195. +}
  47196. +
  47197. +#define dwc_define_read_write_reg(_reg,_container_type) \
  47198. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  47199. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  47200. +} \
  47201. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  47202. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  47203. +}
  47204. +
  47205. +# endif /* DWC_DEBUG_REGS */
  47206. +
  47207. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  47208. +
  47209. +/** @endcond */
  47210. +
  47211. +
  47212. +#ifdef DWC_CRYPTOLIB
  47213. +/** @name Crypto Functions
  47214. + *
  47215. + * These are the low-level cryptographic functions used by the driver. */
  47216. +
  47217. +/** Perform AES CBC */
  47218. +extern int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out);
  47219. +#define dwc_aes_cbc DWC_AES_CBC
  47220. +
  47221. +/** Fill the provided buffer with random bytes. These should be cryptographic grade random numbers. */
  47222. +extern void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length);
  47223. +#define dwc_random_bytes DWC_RANDOM_BYTES
  47224. +
  47225. +/** Perform the SHA-256 hash function */
  47226. +extern int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out);
  47227. +#define dwc_sha256 DWC_SHA256
  47228. +
  47229. +/** Calculated the HMAC-SHA256 */
  47230. +extern int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t *out);
  47231. +#define dwc_hmac_sha256 DWC_HMAC_SHA256
  47232. +
  47233. +#endif /* DWC_CRYPTOLIB */
  47234. +
  47235. +
  47236. +/** @name Memory Allocation
  47237. + *
  47238. + * These function provide access to memory allocation. There are only 2 DMA
  47239. + * functions and 3 Regular memory functions that need to be implemented. None
  47240. + * of the memory debugging routines need to be implemented. The allocation
  47241. + * routines all ZERO the contents of the memory.
  47242. + *
  47243. + * Defining DWC_DEBUG_MEMORY turns on memory debugging and statistic gathering.
  47244. + * This checks for memory leaks, keeping track of alloc/free pairs. It also
  47245. + * keeps track of how much memory the driver is using at any given time. */
  47246. +
  47247. +#define DWC_PAGE_SIZE 4096
  47248. +#define DWC_PAGE_OFFSET(addr) (((uint32_t)addr) & 0xfff)
  47249. +#define DWC_PAGE_ALIGNED(addr) ((((uint32_t)addr) & 0xfff) == 0)
  47250. +
  47251. +#define DWC_INVALID_DMA_ADDR 0x0
  47252. +
  47253. +#ifdef DWC_LINUX
  47254. +/** Type for a DMA address */
  47255. +typedef dma_addr_t dwc_dma_t;
  47256. +#endif
  47257. +
  47258. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47259. +typedef bus_addr_t dwc_dma_t;
  47260. +#endif
  47261. +
  47262. +#ifdef DWC_FREEBSD
  47263. +typedef struct dwc_dmactx {
  47264. + struct device *dev;
  47265. + bus_dma_tag_t dma_tag;
  47266. + bus_dmamap_t dma_map;
  47267. + bus_addr_t dma_paddr;
  47268. + void *dma_vaddr;
  47269. +} dwc_dmactx_t;
  47270. +#endif
  47271. +
  47272. +#ifdef DWC_NETBSD
  47273. +typedef struct dwc_dmactx {
  47274. + struct device *dev;
  47275. + bus_dma_tag_t dma_tag;
  47276. + bus_dmamap_t dma_map;
  47277. + bus_dma_segment_t segs[1];
  47278. + int nsegs;
  47279. + bus_addr_t dma_paddr;
  47280. + void *dma_vaddr;
  47281. +} dwc_dmactx_t;
  47282. +#endif
  47283. +
  47284. +/* @todo these functions will be added in the future */
  47285. +#if 0
  47286. +/**
  47287. + * Creates a DMA pool from which you can allocate DMA buffers. Buffers
  47288. + * allocated from this pool will be guaranteed to meet the size, alignment, and
  47289. + * boundary requirements specified.
  47290. + *
  47291. + * @param[in] size Specifies the size of the buffers that will be allocated from
  47292. + * this pool.
  47293. + * @param[in] align Specifies the byte alignment requirements of the buffers
  47294. + * allocated from this pool. Must be a power of 2.
  47295. + * @param[in] boundary Specifies the N-byte boundary that buffers allocated from
  47296. + * this pool must not cross.
  47297. + *
  47298. + * @returns A pointer to an internal opaque structure which is not to be
  47299. + * accessed outside of these library functions. Use this handle to specify
  47300. + * which pools to allocate/free DMA buffers from and also to destroy the pool,
  47301. + * when you are done with it.
  47302. + */
  47303. +extern dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size, uint32_t align, uint32_t boundary);
  47304. +
  47305. +/**
  47306. + * Destroy a DMA pool. All buffers allocated from that pool must be freed first.
  47307. + */
  47308. +extern void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool);
  47309. +
  47310. +/**
  47311. + * Allocate a buffer from the specified DMA pool and zeros its contents.
  47312. + */
  47313. +extern void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr);
  47314. +
  47315. +/**
  47316. + * Free a previously allocated buffer from the DMA pool.
  47317. + */
  47318. +extern void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr);
  47319. +#endif
  47320. +
  47321. +/** Allocates a DMA capable buffer and zeroes its contents. */
  47322. +extern void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  47323. +
  47324. +/** Allocates a DMA capable buffer and zeroes its contents in atomic contest */
  47325. +extern void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  47326. +
  47327. +/** Frees a previously allocated buffer. */
  47328. +extern void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr);
  47329. +
  47330. +/** Allocates a block of memory and zeroes its contents. */
  47331. +extern void *__DWC_ALLOC(void *mem_ctx, uint32_t size);
  47332. +
  47333. +/** Allocates a block of memory and zeroes its contents, in an atomic manner
  47334. + * which can be used inside interrupt context. The size should be sufficiently
  47335. + * small, a few KB at most, such that failures are not likely to occur. Can just call
  47336. + * __DWC_ALLOC if it is atomic. */
  47337. +extern void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size);
  47338. +
  47339. +/** Frees a previously allocated buffer. */
  47340. +extern void __DWC_FREE(void *mem_ctx, void *addr);
  47341. +
  47342. +#ifndef DWC_DEBUG_MEMORY
  47343. +
  47344. +#define DWC_ALLOC(_size_) __DWC_ALLOC(NULL, _size_)
  47345. +#define DWC_ALLOC_ATOMIC(_size_) __DWC_ALLOC_ATOMIC(NULL, _size_)
  47346. +#define DWC_FREE(_addr_) __DWC_FREE(NULL, _addr_)
  47347. +
  47348. +# ifdef DWC_LINUX
  47349. +#define DWC_DMA_ALLOC(_size_,_dma_) __DWC_DMA_ALLOC(NULL, _size_, _dma_)
  47350. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) __DWC_DMA_ALLOC_ATOMIC(NULL, _size_,_dma_)
  47351. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) __DWC_DMA_FREE(NULL, _size_, _virt_, _dma_)
  47352. +# endif
  47353. +
  47354. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47355. +#define DWC_DMA_ALLOC __DWC_DMA_ALLOC
  47356. +#define DWC_DMA_FREE __DWC_DMA_FREE
  47357. +# endif
  47358. +extern void *dwc_dma_alloc_atomic_debug(uint32_t size, dwc_dma_t *dma_addr, char const *func, int line);
  47359. +
  47360. +#else /* DWC_DEBUG_MEMORY */
  47361. +
  47362. +extern void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  47363. +extern void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  47364. +extern void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line);
  47365. +extern void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  47366. + char const *func, int line);
  47367. +extern void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  47368. + char const *func, int line);
  47369. +extern void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  47370. + dwc_dma_t dma_addr, char const *func, int line);
  47371. +
  47372. +extern int dwc_memory_debug_start(void *mem_ctx);
  47373. +extern void dwc_memory_debug_stop(void);
  47374. +extern void dwc_memory_debug_report(void);
  47375. +
  47376. +#define DWC_ALLOC(_size_) dwc_alloc_debug(NULL, _size_, __func__, __LINE__)
  47377. +#define DWC_ALLOC_ATOMIC(_size_) dwc_alloc_atomic_debug(NULL, _size_, \
  47378. + __func__, __LINE__)
  47379. +#define DWC_FREE(_addr_) dwc_free_debug(NULL, _addr_, __func__, __LINE__)
  47380. +
  47381. +# ifdef DWC_LINUX
  47382. +#define DWC_DMA_ALLOC(_size_,_dma_) dwc_dma_alloc_debug(NULL, _size_, \
  47383. + _dma_, __func__, __LINE__)
  47384. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) dwc_dma_alloc_atomic_debug(NULL, _size_, \
  47385. + _dma_, __func__, __LINE__)
  47386. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) dwc_dma_free_debug(NULL, _size_, \
  47387. + _virt_, _dma_, __func__, __LINE__)
  47388. +# endif
  47389. +
  47390. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47391. +#define DWC_DMA_ALLOC(_ctx_,_size_,_dma_) dwc_dma_alloc_debug(_ctx_, _size_, \
  47392. + _dma_, __func__, __LINE__)
  47393. +#define DWC_DMA_FREE(_ctx_,_size_,_virt_,_dma_) dwc_dma_free_debug(_ctx_, _size_, \
  47394. + _virt_, _dma_, __func__, __LINE__)
  47395. +# endif
  47396. +
  47397. +#endif /* DWC_DEBUG_MEMORY */
  47398. +
  47399. +#define dwc_alloc(_ctx_,_size_) DWC_ALLOC(_size_)
  47400. +#define dwc_alloc_atomic(_ctx_,_size_) DWC_ALLOC_ATOMIC(_size_)
  47401. +#define dwc_free(_ctx_,_addr_) DWC_FREE(_addr_)
  47402. +
  47403. +#ifdef DWC_LINUX
  47404. +/* Linux doesn't need any extra parameters for DMA buffer allocation, so we
  47405. + * just throw away the DMA context parameter.
  47406. + */
  47407. +#define dwc_dma_alloc(_ctx_,_size_,_dma_) DWC_DMA_ALLOC(_size_, _dma_)
  47408. +#define dwc_dma_alloc_atomic(_ctx_,_size_,_dma_) DWC_DMA_ALLOC_ATOMIC(_size_, _dma_)
  47409. +#define dwc_dma_free(_ctx_,_size_,_virt_,_dma_) DWC_DMA_FREE(_size_, _virt_, _dma_)
  47410. +#endif
  47411. +
  47412. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47413. +/** BSD needs several extra parameters for DMA buffer allocation, so we pass
  47414. + * them in using the DMA context parameter.
  47415. + */
  47416. +#define dwc_dma_alloc DWC_DMA_ALLOC
  47417. +#define dwc_dma_free DWC_DMA_FREE
  47418. +#endif
  47419. +
  47420. +
  47421. +/** @name Memory and String Processing */
  47422. +
  47423. +/** memset() clone */
  47424. +extern void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size);
  47425. +#define dwc_memset DWC_MEMSET
  47426. +
  47427. +/** memcpy() clone */
  47428. +extern void *DWC_MEMCPY(void *dest, void const *src, uint32_t size);
  47429. +#define dwc_memcpy DWC_MEMCPY
  47430. +
  47431. +/** memmove() clone */
  47432. +extern void *DWC_MEMMOVE(void *dest, void *src, uint32_t size);
  47433. +#define dwc_memmove DWC_MEMMOVE
  47434. +
  47435. +/** memcmp() clone */
  47436. +extern int DWC_MEMCMP(void *m1, void *m2, uint32_t size);
  47437. +#define dwc_memcmp DWC_MEMCMP
  47438. +
  47439. +/** strcmp() clone */
  47440. +extern int DWC_STRCMP(void *s1, void *s2);
  47441. +#define dwc_strcmp DWC_STRCMP
  47442. +
  47443. +/** strncmp() clone */
  47444. +extern int DWC_STRNCMP(void *s1, void *s2, uint32_t size);
  47445. +#define dwc_strncmp DWC_STRNCMP
  47446. +
  47447. +/** strlen() clone, for NULL terminated ASCII strings */
  47448. +extern int DWC_STRLEN(char const *str);
  47449. +#define dwc_strlen DWC_STRLEN
  47450. +
  47451. +/** strcpy() clone, for NULL terminated ASCII strings */
  47452. +extern char *DWC_STRCPY(char *to, const char *from);
  47453. +#define dwc_strcpy DWC_STRCPY
  47454. +
  47455. +/** strdup() clone. If you wish to use memory allocation debugging, this
  47456. + * implementation of strdup should use the DWC_* memory routines instead of
  47457. + * calling a predefined strdup. Otherwise the memory allocated by this routine
  47458. + * will not be seen by the debugging routines. */
  47459. +extern char *DWC_STRDUP(char const *str);
  47460. +#define dwc_strdup(_ctx_,_str_) DWC_STRDUP(_str_)
  47461. +
  47462. +/** NOT an atoi() clone. Read the description carefully. Returns an integer
  47463. + * converted from the string str in base 10 unless the string begins with a "0x"
  47464. + * in which case it is base 16. String must be a NULL terminated sequence of
  47465. + * ASCII characters and may optionally begin with whitespace, a + or -, and a
  47466. + * "0x" prefix if base 16. The remaining characters must be valid digits for
  47467. + * the number and end with a NULL character. If any invalid characters are
  47468. + * encountered or it returns with a negative error code and the results of the
  47469. + * conversion are undefined. On sucess it returns 0. Overflow conditions are
  47470. + * undefined. An example implementation using atoi() can be referenced from the
  47471. + * Linux implementation. */
  47472. +extern int DWC_ATOI(const char *str, int32_t *value);
  47473. +#define dwc_atoi DWC_ATOI
  47474. +
  47475. +/** Same as above but for unsigned. */
  47476. +extern int DWC_ATOUI(const char *str, uint32_t *value);
  47477. +#define dwc_atoui DWC_ATOUI
  47478. +
  47479. +#ifdef DWC_UTFLIB
  47480. +/** This routine returns a UTF16LE unicode encoded string from a UTF8 string. */
  47481. +extern int DWC_UTF8_TO_UTF16LE(uint8_t const *utf8string, uint16_t *utf16string, unsigned len);
  47482. +#define dwc_utf8_to_utf16le DWC_UTF8_TO_UTF16LE
  47483. +#endif
  47484. +
  47485. +
  47486. +/** @name Wait queues
  47487. + *
  47488. + * Wait queues provide a means of synchronizing between threads or processes. A
  47489. + * process can block on a waitq if some condition is not true, waiting for it to
  47490. + * become true. When the waitq is triggered all waiting process will get
  47491. + * unblocked and the condition will be check again. Waitqs should be triggered
  47492. + * every time a condition can potentially change.*/
  47493. +struct dwc_waitq;
  47494. +
  47495. +/** Type for a waitq */
  47496. +typedef struct dwc_waitq dwc_waitq_t;
  47497. +
  47498. +/** The type of waitq condition callback function. This is called every time
  47499. + * condition is evaluated. */
  47500. +typedef int (*dwc_waitq_condition_t)(void *data);
  47501. +
  47502. +/** Allocate a waitq */
  47503. +extern dwc_waitq_t *DWC_WAITQ_ALLOC(void);
  47504. +#define dwc_waitq_alloc(_ctx_) DWC_WAITQ_ALLOC()
  47505. +
  47506. +/** Free a waitq */
  47507. +extern void DWC_WAITQ_FREE(dwc_waitq_t *wq);
  47508. +#define dwc_waitq_free DWC_WAITQ_FREE
  47509. +
  47510. +/** Check the condition and if it is false, block on the waitq. When unblocked, check the
  47511. + * condition again. The function returns when the condition becomes true. The return value
  47512. + * is 0 on condition true, DWC_WAITQ_ABORTED on abort or killed, or DWC_WAITQ_UNKNOWN on error. */
  47513. +extern int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data);
  47514. +#define dwc_waitq_wait DWC_WAITQ_WAIT
  47515. +
  47516. +/** Check the condition and if it is false, block on the waitq. When unblocked,
  47517. + * check the condition again. The function returns when the condition become
  47518. + * true or the timeout has passed. The return value is 0 on condition true or
  47519. + * DWC_TIMED_OUT on timeout, or DWC_WAITQ_ABORTED, or DWC_WAITQ_UNKNOWN on
  47520. + * error. */
  47521. +extern int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  47522. + void *data, int32_t msecs);
  47523. +#define dwc_waitq_wait_timeout DWC_WAITQ_WAIT_TIMEOUT
  47524. +
  47525. +/** Trigger a waitq, unblocking all processes. This should be called whenever a condition
  47526. + * has potentially changed. */
  47527. +extern void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq);
  47528. +#define dwc_waitq_trigger DWC_WAITQ_TRIGGER
  47529. +
  47530. +/** Unblock all processes waiting on the waitq with an ABORTED result. */
  47531. +extern void DWC_WAITQ_ABORT(dwc_waitq_t *wq);
  47532. +#define dwc_waitq_abort DWC_WAITQ_ABORT
  47533. +
  47534. +
  47535. +/** @name Threads
  47536. + *
  47537. + * A thread must be explicitly stopped. It must check DWC_THREAD_SHOULD_STOP
  47538. + * whenever it is woken up, and then return. The DWC_THREAD_STOP function
  47539. + * returns the value from the thread.
  47540. + */
  47541. +
  47542. +struct dwc_thread;
  47543. +
  47544. +/** Type for a thread */
  47545. +typedef struct dwc_thread dwc_thread_t;
  47546. +
  47547. +/** The thread function */
  47548. +typedef int (*dwc_thread_function_t)(void *data);
  47549. +
  47550. +/** Create a thread and start it running the thread_function. Returns a handle
  47551. + * to the thread */
  47552. +extern dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data);
  47553. +#define dwc_thread_run(_ctx_,_func_,_name_,_data_) DWC_THREAD_RUN(_func_, _name_, _data_)
  47554. +
  47555. +/** Stops a thread. Return the value returned by the thread. Or will return
  47556. + * DWC_ABORT if the thread never started. */
  47557. +extern int DWC_THREAD_STOP(dwc_thread_t *thread);
  47558. +#define dwc_thread_stop DWC_THREAD_STOP
  47559. +
  47560. +/** Signifies to the thread that it must stop. */
  47561. +#ifdef DWC_LINUX
  47562. +/* Linux doesn't need any parameters for kthread_should_stop() */
  47563. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(void);
  47564. +#define dwc_thread_should_stop(_thrd_) DWC_THREAD_SHOULD_STOP()
  47565. +
  47566. +/* No thread_exit function in Linux */
  47567. +#define dwc_thread_exit(_thrd_)
  47568. +#endif
  47569. +
  47570. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47571. +/** BSD needs the thread pointer for kthread_suspend_check() */
  47572. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread);
  47573. +#define dwc_thread_should_stop DWC_THREAD_SHOULD_STOP
  47574. +
  47575. +/** The thread must call this to exit. */
  47576. +extern void DWC_THREAD_EXIT(dwc_thread_t *thread);
  47577. +#define dwc_thread_exit DWC_THREAD_EXIT
  47578. +#endif
  47579. +
  47580. +
  47581. +/** @name Work queues
  47582. + *
  47583. + * Workqs are used to queue a callback function to be called at some later time,
  47584. + * in another thread. */
  47585. +struct dwc_workq;
  47586. +
  47587. +/** Type for a workq */
  47588. +typedef struct dwc_workq dwc_workq_t;
  47589. +
  47590. +/** The type of the callback function to be called. */
  47591. +typedef void (*dwc_work_callback_t)(void *data);
  47592. +
  47593. +/** Allocate a workq */
  47594. +extern dwc_workq_t *DWC_WORKQ_ALLOC(char *name);
  47595. +#define dwc_workq_alloc(_ctx_,_name_) DWC_WORKQ_ALLOC(_name_)
  47596. +
  47597. +/** Free a workq. All work must be completed before being freed. */
  47598. +extern void DWC_WORKQ_FREE(dwc_workq_t *workq);
  47599. +#define dwc_workq_free DWC_WORKQ_FREE
  47600. +
  47601. +/** Schedule a callback on the workq, passing in data. The function will be
  47602. + * scheduled at some later time. */
  47603. +extern void DWC_WORKQ_SCHEDULE(dwc_workq_t *workq, dwc_work_callback_t cb,
  47604. + void *data, char *format, ...)
  47605. +#ifdef __GNUC__
  47606. + __attribute__ ((format(printf, 4, 5)));
  47607. +#else
  47608. + ;
  47609. +#endif
  47610. +#define dwc_workq_schedule DWC_WORKQ_SCHEDULE
  47611. +
  47612. +/** Schedule a callback on the workq, that will be called until at least
  47613. + * given number miliseconds have passed. */
  47614. +extern void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *workq, dwc_work_callback_t cb,
  47615. + void *data, uint32_t time, char *format, ...)
  47616. +#ifdef __GNUC__
  47617. + __attribute__ ((format(printf, 5, 6)));
  47618. +#else
  47619. + ;
  47620. +#endif
  47621. +#define dwc_workq_schedule_delayed DWC_WORKQ_SCHEDULE_DELAYED
  47622. +
  47623. +/** The number of processes in the workq */
  47624. +extern int DWC_WORKQ_PENDING(dwc_workq_t *workq);
  47625. +#define dwc_workq_pending DWC_WORKQ_PENDING
  47626. +
  47627. +/** Blocks until all the work in the workq is complete or timed out. Returns <
  47628. + * 0 on timeout. */
  47629. +extern int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout);
  47630. +#define dwc_workq_wait_work_done DWC_WORKQ_WAIT_WORK_DONE
  47631. +
  47632. +
  47633. +/** @name Tasklets
  47634. + *
  47635. + */
  47636. +struct dwc_tasklet;
  47637. +
  47638. +/** Type for a tasklet */
  47639. +typedef struct dwc_tasklet dwc_tasklet_t;
  47640. +
  47641. +/** The type of the callback function to be called */
  47642. +typedef void (*dwc_tasklet_callback_t)(void *data);
  47643. +
  47644. +/** Allocates a tasklet */
  47645. +extern dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data);
  47646. +#define dwc_task_alloc(_ctx_,_name_,_cb_,_data_) DWC_TASK_ALLOC(_name_, _cb_, _data_)
  47647. +
  47648. +/** Frees a tasklet */
  47649. +extern void DWC_TASK_FREE(dwc_tasklet_t *task);
  47650. +#define dwc_task_free DWC_TASK_FREE
  47651. +
  47652. +/** Schedules a tasklet to run */
  47653. +extern void DWC_TASK_SCHEDULE(dwc_tasklet_t *task);
  47654. +#define dwc_task_schedule DWC_TASK_SCHEDULE
  47655. +
  47656. +extern void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task);
  47657. +#define dwc_task_hi_schedule DWC_TASK_HI_SCHEDULE
  47658. +
  47659. +/** @name Timer
  47660. + *
  47661. + * Callbacks must be small and atomic.
  47662. + */
  47663. +struct dwc_timer;
  47664. +
  47665. +/** Type for a timer */
  47666. +typedef struct dwc_timer dwc_timer_t;
  47667. +
  47668. +/** The type of the callback function to be called */
  47669. +typedef void (*dwc_timer_callback_t)(void *data);
  47670. +
  47671. +/** Allocates a timer */
  47672. +extern dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data);
  47673. +#define dwc_timer_alloc(_ctx_,_name_,_cb_,_data_) DWC_TIMER_ALLOC(_name_,_cb_,_data_)
  47674. +
  47675. +/** Frees a timer */
  47676. +extern void DWC_TIMER_FREE(dwc_timer_t *timer);
  47677. +#define dwc_timer_free DWC_TIMER_FREE
  47678. +
  47679. +/** Schedules the timer to run at time ms from now. And will repeat at every
  47680. + * repeat_interval msec therafter
  47681. + *
  47682. + * Modifies a timer that is still awaiting execution to a new expiration time.
  47683. + * The mod_time is added to the old time. */
  47684. +extern void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time);
  47685. +#define dwc_timer_schedule DWC_TIMER_SCHEDULE
  47686. +
  47687. +/** Disables the timer from execution. */
  47688. +extern void DWC_TIMER_CANCEL(dwc_timer_t *timer);
  47689. +#define dwc_timer_cancel DWC_TIMER_CANCEL
  47690. +
  47691. +
  47692. +/** @name Spinlocks
  47693. + *
  47694. + * These locks are used when the work between the lock/unlock is atomic and
  47695. + * short. Interrupts are also disabled during the lock/unlock and thus they are
  47696. + * suitable to lock between interrupt/non-interrupt context. They also lock
  47697. + * between processes if you have multiple CPUs or Preemption. If you don't have
  47698. + * multiple CPUS or Preemption, then the you can simply implement the
  47699. + * DWC_SPINLOCK and DWC_SPINUNLOCK to disable and enable interrupts. Because
  47700. + * the work between the lock/unlock is atomic, the process context will never
  47701. + * change, and so you never have to lock between processes. */
  47702. +
  47703. +struct dwc_spinlock;
  47704. +
  47705. +/** Type for a spinlock */
  47706. +typedef struct dwc_spinlock dwc_spinlock_t;
  47707. +
  47708. +/** Type for the 'flags' argument to spinlock funtions */
  47709. +typedef unsigned long dwc_irqflags_t;
  47710. +
  47711. +/** Returns an initialized lock variable. This function should allocate and
  47712. + * initialize the OS-specific data structure used for locking. This data
  47713. + * structure is to be used for the DWC_LOCK and DWC_UNLOCK functions and should
  47714. + * be freed by the DWC_FREE_LOCK when it is no longer used. */
  47715. +extern dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void);
  47716. +#define dwc_spinlock_alloc(_ctx_) DWC_SPINLOCK_ALLOC()
  47717. +
  47718. +/** Frees an initialized lock variable. */
  47719. +extern void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock);
  47720. +#define dwc_spinlock_free(_ctx_,_lock_) DWC_SPINLOCK_FREE(_lock_)
  47721. +
  47722. +/** Disables interrupts and blocks until it acquires the lock.
  47723. + *
  47724. + * @param lock Pointer to the spinlock.
  47725. + * @param flags Unsigned long for irq flags storage.
  47726. + */
  47727. +extern void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags);
  47728. +#define dwc_spinlock_irqsave DWC_SPINLOCK_IRQSAVE
  47729. +
  47730. +/** Re-enables the interrupt and releases the lock.
  47731. + *
  47732. + * @param lock Pointer to the spinlock.
  47733. + * @param flags Unsigned long for irq flags storage. Must be the same as was
  47734. + * passed into DWC_LOCK.
  47735. + */
  47736. +extern void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags);
  47737. +#define dwc_spinunlock_irqrestore DWC_SPINUNLOCK_IRQRESTORE
  47738. +
  47739. +/** Blocks until it acquires the lock.
  47740. + *
  47741. + * @param lock Pointer to the spinlock.
  47742. + */
  47743. +extern void DWC_SPINLOCK(dwc_spinlock_t *lock);
  47744. +#define dwc_spinlock DWC_SPINLOCK
  47745. +
  47746. +/** Releases the lock.
  47747. + *
  47748. + * @param lock Pointer to the spinlock.
  47749. + */
  47750. +extern void DWC_SPINUNLOCK(dwc_spinlock_t *lock);
  47751. +#define dwc_spinunlock DWC_SPINUNLOCK
  47752. +
  47753. +
  47754. +/** @name Mutexes
  47755. + *
  47756. + * Unlike spinlocks Mutexes lock only between processes and the work between the
  47757. + * lock/unlock CAN block, therefore it CANNOT be called from interrupt context.
  47758. + */
  47759. +
  47760. +struct dwc_mutex;
  47761. +
  47762. +/** Type for a mutex */
  47763. +typedef struct dwc_mutex dwc_mutex_t;
  47764. +
  47765. +/* For Linux Mutex Debugging make it inline because the debugging routines use
  47766. + * the symbol to determine recursive locking. This makes it falsely think
  47767. + * recursive locking occurs. */
  47768. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  47769. +#define DWC_MUTEX_ALLOC_LINUX_DEBUG(__mutexp) ({ \
  47770. + __mutexp = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex)); \
  47771. + mutex_init((struct mutex *)__mutexp); \
  47772. +})
  47773. +#endif
  47774. +
  47775. +/** Allocate a mutex */
  47776. +extern dwc_mutex_t *DWC_MUTEX_ALLOC(void);
  47777. +#define dwc_mutex_alloc(_ctx_) DWC_MUTEX_ALLOC()
  47778. +
  47779. +/* For memory leak debugging when using Linux Mutex Debugging */
  47780. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  47781. +#define DWC_MUTEX_FREE(__mutexp) do { \
  47782. + mutex_destroy((struct mutex *)__mutexp); \
  47783. + DWC_FREE(__mutexp); \
  47784. +} while(0)
  47785. +#else
  47786. +/** Free a mutex */
  47787. +extern void DWC_MUTEX_FREE(dwc_mutex_t *mutex);
  47788. +#define dwc_mutex_free(_ctx_,_mutex_) DWC_MUTEX_FREE(_mutex_)
  47789. +#endif
  47790. +
  47791. +/** Lock a mutex */
  47792. +extern void DWC_MUTEX_LOCK(dwc_mutex_t *mutex);
  47793. +#define dwc_mutex_lock DWC_MUTEX_LOCK
  47794. +
  47795. +/** Non-blocking lock returns 1 on successful lock. */
  47796. +extern int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex);
  47797. +#define dwc_mutex_trylock DWC_MUTEX_TRYLOCK
  47798. +
  47799. +/** Unlock a mutex */
  47800. +extern void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex);
  47801. +#define dwc_mutex_unlock DWC_MUTEX_UNLOCK
  47802. +
  47803. +
  47804. +/** @name Time */
  47805. +
  47806. +/** Microsecond delay.
  47807. + *
  47808. + * @param usecs Microseconds to delay.
  47809. + */
  47810. +extern void DWC_UDELAY(uint32_t usecs);
  47811. +#define dwc_udelay DWC_UDELAY
  47812. +
  47813. +/** Millisecond delay.
  47814. + *
  47815. + * @param msecs Milliseconds to delay.
  47816. + */
  47817. +extern void DWC_MDELAY(uint32_t msecs);
  47818. +#define dwc_mdelay DWC_MDELAY
  47819. +
  47820. +/** Non-busy waiting.
  47821. + * Sleeps for specified number of milliseconds.
  47822. + *
  47823. + * @param msecs Milliseconds to sleep.
  47824. + */
  47825. +extern void DWC_MSLEEP(uint32_t msecs);
  47826. +#define dwc_msleep DWC_MSLEEP
  47827. +
  47828. +/**
  47829. + * Returns number of milliseconds since boot.
  47830. + */
  47831. +extern uint32_t DWC_TIME(void);
  47832. +#define dwc_time DWC_TIME
  47833. +
  47834. +
  47835. +
  47836. +
  47837. +/* @mainpage DWC Portability and Common Library
  47838. + *
  47839. + * This is the documentation for the DWC Portability and Common Library.
  47840. + *
  47841. + * @section intro Introduction
  47842. + *
  47843. + * The DWC Portability library consists of wrapper calls and data structures to
  47844. + * all low-level functions which are typically provided by the OS. The WUDEV
  47845. + * driver uses only these functions. In order to port the WUDEV driver, only
  47846. + * the functions in this library need to be re-implemented, with the same
  47847. + * behavior as documented here.
  47848. + *
  47849. + * The Common library consists of higher level functions, which rely only on
  47850. + * calling the functions from the DWC Portability library. These common
  47851. + * routines are shared across modules. Some of the common libraries need to be
  47852. + * used directly by the driver programmer when porting WUDEV. Such as the
  47853. + * parameter and notification libraries.
  47854. + *
  47855. + * @section low Portability Library OS Wrapper Functions
  47856. + *
  47857. + * Any function starting with DWC and in all CAPS is a low-level OS-wrapper that
  47858. + * needs to be implemented when porting, for example DWC_MUTEX_ALLOC(). All of
  47859. + * these functions are included in the dwc_os.h file.
  47860. + *
  47861. + * There are many functions here covering a wide array of OS services. Please
  47862. + * see dwc_os.h for details, and implementation notes for each function.
  47863. + *
  47864. + * @section common Common Library Functions
  47865. + *
  47866. + * Any function starting with dwc and in all lowercase is a common library
  47867. + * routine. These functions have a portable implementation and do not need to
  47868. + * be reimplemented when porting. The common routines can be used by any
  47869. + * driver, and some must be used by the end user to control the drivers. For
  47870. + * example, you must use the Parameter common library in order to set the
  47871. + * parameters in the WUDEV module.
  47872. + *
  47873. + * The common libraries consist of the following:
  47874. + *
  47875. + * - Connection Contexts - Used internally and can be used by end-user. See dwc_cc.h
  47876. + * - Parameters - Used internally and can be used by end-user. See dwc_params.h
  47877. + * - Notifications - Used internally and can be used by end-user. See dwc_notifier.h
  47878. + * - Lists - Used internally and can be used by end-user. See dwc_list.h
  47879. + * - Memory Debugging - Used internally and can be used by end-user. See dwc_os.h
  47880. + * - Modpow - Used internally only. See dwc_modpow.h
  47881. + * - DH - Used internally only. See dwc_dh.h
  47882. + * - Crypto - Used internally only. See dwc_crypto.h
  47883. + *
  47884. + *
  47885. + * @section prereq Prerequistes For dwc_os.h
  47886. + * @subsection types Data Types
  47887. + *
  47888. + * The dwc_os.h file assumes that several low-level data types are pre defined for the
  47889. + * compilation environment. These data types are:
  47890. + *
  47891. + * - uint8_t - unsigned 8-bit data type
  47892. + * - int8_t - signed 8-bit data type
  47893. + * - uint16_t - unsigned 16-bit data type
  47894. + * - int16_t - signed 16-bit data type
  47895. + * - uint32_t - unsigned 32-bit data type
  47896. + * - int32_t - signed 32-bit data type
  47897. + * - uint64_t - unsigned 64-bit data type
  47898. + * - int64_t - signed 64-bit data type
  47899. + *
  47900. + * Ensure that these are defined before using dwc_os.h. The easiest way to do
  47901. + * that is to modify the top of the file to include the appropriate header.
  47902. + * This is already done for the Linux environment. If the DWC_LINUX macro is
  47903. + * defined, the correct header will be added. A standard header <stdint.h> is
  47904. + * also used for environments where standard C headers are available.
  47905. + *
  47906. + * @subsection stdarg Variable Arguments
  47907. + *
  47908. + * Variable arguments are provided by a standard C header <stdarg.h>. it is
  47909. + * available in Both the Linux and ANSI C enviornment. An equivalent must be
  47910. + * provided in your enviornment in order to use dwc_os.h with the debug and
  47911. + * tracing message functionality.
  47912. + *
  47913. + * @subsection thread Threading
  47914. + *
  47915. + * WUDEV Core must be run on an operating system that provides for multiple
  47916. + * threads/processes. Threading can be implemented in many ways, even in
  47917. + * embedded systems without an operating system. At the bare minimum, the
  47918. + * system should be able to start any number of processes at any time to handle
  47919. + * special work. It need not be a pre-emptive system. Process context can
  47920. + * change upon a call to a blocking function. The hardware interrupt context
  47921. + * that calls the module's ISR() function must be differentiable from process
  47922. + * context, even if your processes are impemented via a hardware interrupt.
  47923. + * Further locking mechanism between process must exist (or be implemented), and
  47924. + * process context must have a way to disable interrupts for a period of time to
  47925. + * lock them out. If all of this exists, the functions in dwc_os.h related to
  47926. + * threading should be able to be implemented with the defined behavior.
  47927. + *
  47928. + */
  47929. +
  47930. +#ifdef __cplusplus
  47931. +}
  47932. +#endif
  47933. +
  47934. +#endif /* _DWC_OS_H_ */
  47935. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/Makefile linux-3.12.11/drivers/usb/host/dwc_common_port/Makefile
  47936. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/Makefile 1970-01-01 01:00:00.000000000 +0100
  47937. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/Makefile 2014-02-18 11:52:14.000000000 +0100
  47938. @@ -0,0 +1,58 @@
  47939. +#
  47940. +# Makefile for DWC_common library
  47941. +#
  47942. +
  47943. +ifneq ($(KERNELRELEASE),)
  47944. +
  47945. +EXTRA_CFLAGS += -DDWC_LINUX
  47946. +#EXTRA_CFLAGS += -DDEBUG
  47947. +#EXTRA_CFLAGS += -DDWC_DEBUG_REGS
  47948. +#EXTRA_CFLAGS += -DDWC_DEBUG_MEMORY
  47949. +
  47950. +EXTRA_CFLAGS += -DDWC_LIBMODULE
  47951. +EXTRA_CFLAGS += -DDWC_CCLIB
  47952. +#EXTRA_CFLAGS += -DDWC_CRYPTOLIB
  47953. +EXTRA_CFLAGS += -DDWC_NOTIFYLIB
  47954. +EXTRA_CFLAGS += -DDWC_UTFLIB
  47955. +
  47956. +obj-$(CONFIG_USB_DWCOTG) += dwc_common_port_lib.o
  47957. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  47958. + dwc_crypto.o dwc_notifier.o \
  47959. + dwc_common_linux.o dwc_mem.o
  47960. +
  47961. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  47962. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  47963. +
  47964. +ifneq ($(kernrel3),2.6.20)
  47965. +# grayg - I only know that we use EXTRA_CFLAGS in 2.6.31 actually
  47966. +EXTRA_CFLAGS += $(CPPFLAGS)
  47967. +endif
  47968. +
  47969. +else
  47970. +
  47971. +#ifeq ($(KDIR),)
  47972. +#$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  47973. +#endif
  47974. +
  47975. +ifeq ($(ARCH),)
  47976. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  47977. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  47978. +endif
  47979. +
  47980. +ifeq ($(DOXYGEN),)
  47981. +DOXYGEN := doxygen
  47982. +endif
  47983. +
  47984. +default:
  47985. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  47986. +
  47987. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  47988. + $(DOXYGEN) doc/doxygen.cfg
  47989. +
  47990. +tags: $(wildcard *.[hc])
  47991. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  47992. +
  47993. +endif
  47994. +
  47995. +clean:
  47996. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  47997. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/Makefile.fbsd linux-3.12.11/drivers/usb/host/dwc_common_port/Makefile.fbsd
  47998. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/Makefile.fbsd 1970-01-01 01:00:00.000000000 +0100
  47999. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/Makefile.fbsd 2014-02-18 11:52:14.000000000 +0100
  48000. @@ -0,0 +1,17 @@
  48001. +CFLAGS += -I/sys/i386/compile/GENERIC -I/sys/i386/include -I/usr/include
  48002. +CFLAGS += -DDWC_FREEBSD
  48003. +CFLAGS += -DDEBUG
  48004. +#CFLAGS += -DDWC_DEBUG_REGS
  48005. +#CFLAGS += -DDWC_DEBUG_MEMORY
  48006. +
  48007. +#CFLAGS += -DDWC_LIBMODULE
  48008. +#CFLAGS += -DDWC_CCLIB
  48009. +#CFLAGS += -DDWC_CRYPTOLIB
  48010. +#CFLAGS += -DDWC_NOTIFYLIB
  48011. +#CFLAGS += -DDWC_UTFLIB
  48012. +
  48013. +KMOD = dwc_common_port_lib
  48014. +SRCS = dwc_cc.c dwc_modpow.c dwc_dh.c dwc_crypto.c dwc_notifier.c \
  48015. + dwc_common_fbsd.c dwc_mem.c
  48016. +
  48017. +.include <bsd.kmod.mk>
  48018. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/Makefile.linux linux-3.12.11/drivers/usb/host/dwc_common_port/Makefile.linux
  48019. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/Makefile.linux 1970-01-01 01:00:00.000000000 +0100
  48020. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/Makefile.linux 2014-02-18 11:52:14.000000000 +0100
  48021. @@ -0,0 +1,49 @@
  48022. +#
  48023. +# Makefile for DWC_common library
  48024. +#
  48025. +ifneq ($(KERNELRELEASE),)
  48026. +
  48027. +EXTRA_CFLAGS += -DDWC_LINUX
  48028. +#EXTRA_CFLAGS += -DDEBUG
  48029. +#EXTRA_CFLAGS += -DDWC_DEBUG_REGS
  48030. +#EXTRA_CFLAGS += -DDWC_DEBUG_MEMORY
  48031. +
  48032. +EXTRA_CFLAGS += -DDWC_LIBMODULE
  48033. +EXTRA_CFLAGS += -DDWC_CCLIB
  48034. +EXTRA_CFLAGS += -DDWC_CRYPTOLIB
  48035. +EXTRA_CFLAGS += -DDWC_NOTIFYLIB
  48036. +EXTRA_CFLAGS += -DDWC_UTFLIB
  48037. +
  48038. +obj-m := dwc_common_port_lib.o
  48039. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  48040. + dwc_crypto.o dwc_notifier.o \
  48041. + dwc_common_linux.o dwc_mem.o
  48042. +
  48043. +else
  48044. +
  48045. +ifeq ($(KDIR),)
  48046. +$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  48047. +endif
  48048. +
  48049. +ifeq ($(ARCH),)
  48050. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  48051. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  48052. +endif
  48053. +
  48054. +ifeq ($(DOXYGEN),)
  48055. +DOXYGEN := doxygen
  48056. +endif
  48057. +
  48058. +default:
  48059. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  48060. +
  48061. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  48062. + $(DOXYGEN) doc/doxygen.cfg
  48063. +
  48064. +tags: $(wildcard *.[hc])
  48065. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  48066. +
  48067. +endif
  48068. +
  48069. +clean:
  48070. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  48071. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_common_port/usb.h linux-3.12.11/drivers/usb/host/dwc_common_port/usb.h
  48072. --- linux-3.12.11.orig/drivers/usb/host/dwc_common_port/usb.h 1970-01-01 01:00:00.000000000 +0100
  48073. +++ linux-3.12.11/drivers/usb/host/dwc_common_port/usb.h 2014-02-18 11:52:14.000000000 +0100
  48074. @@ -0,0 +1,946 @@
  48075. +/*
  48076. + * Copyright (c) 1998 The NetBSD Foundation, Inc.
  48077. + * All rights reserved.
  48078. + *
  48079. + * This code is derived from software contributed to The NetBSD Foundation
  48080. + * by Lennart Augustsson (lennart@augustsson.net) at
  48081. + * Carlstedt Research & Technology.
  48082. + *
  48083. + * Redistribution and use in source and binary forms, with or without
  48084. + * modification, are permitted provided that the following conditions
  48085. + * are met:
  48086. + * 1. Redistributions of source code must retain the above copyright
  48087. + * notice, this list of conditions and the following disclaimer.
  48088. + * 2. Redistributions in binary form must reproduce the above copyright
  48089. + * notice, this list of conditions and the following disclaimer in the
  48090. + * documentation and/or other materials provided with the distribution.
  48091. + * 3. All advertising materials mentioning features or use of this software
  48092. + * must display the following acknowledgement:
  48093. + * This product includes software developed by the NetBSD
  48094. + * Foundation, Inc. and its contributors.
  48095. + * 4. Neither the name of The NetBSD Foundation nor the names of its
  48096. + * contributors may be used to endorse or promote products derived
  48097. + * from this software without specific prior written permission.
  48098. + *
  48099. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  48100. + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  48101. + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  48102. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  48103. + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  48104. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  48105. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48106. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  48107. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  48108. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  48109. + * POSSIBILITY OF SUCH DAMAGE.
  48110. + */
  48111. +
  48112. +/* Modified by Synopsys, Inc, 12/12/2007 */
  48113. +
  48114. +
  48115. +#ifndef _USB_H_
  48116. +#define _USB_H_
  48117. +
  48118. +#ifdef __cplusplus
  48119. +extern "C" {
  48120. +#endif
  48121. +
  48122. +/*
  48123. + * The USB records contain some unaligned little-endian word
  48124. + * components. The U[SG]ETW macros take care of both the alignment
  48125. + * and endian problem and should always be used to access non-byte
  48126. + * values.
  48127. + */
  48128. +typedef u_int8_t uByte;
  48129. +typedef u_int8_t uWord[2];
  48130. +typedef u_int8_t uDWord[4];
  48131. +
  48132. +#define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
  48133. +#define UCONSTW(x) { (x) & 0xff, ((x) >> 8) & 0xff }
  48134. +#define UCONSTDW(x) { (x) & 0xff, ((x) >> 8) & 0xff, \
  48135. + ((x) >> 16) & 0xff, ((x) >> 24) & 0xff }
  48136. +
  48137. +#if 1
  48138. +#define UGETW(w) ((w)[0] | ((w)[1] << 8))
  48139. +#define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
  48140. +#define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
  48141. +#define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
  48142. + (w)[1] = (u_int8_t)((v) >> 8), \
  48143. + (w)[2] = (u_int8_t)((v) >> 16), \
  48144. + (w)[3] = (u_int8_t)((v) >> 24))
  48145. +#else
  48146. +/*
  48147. + * On little-endian machines that can handle unanliged accesses
  48148. + * (e.g. i386) these macros can be replaced by the following.
  48149. + */
  48150. +#define UGETW(w) (*(u_int16_t *)(w))
  48151. +#define USETW(w,v) (*(u_int16_t *)(w) = (v))
  48152. +#define UGETDW(w) (*(u_int32_t *)(w))
  48153. +#define USETDW(w,v) (*(u_int32_t *)(w) = (v))
  48154. +#endif
  48155. +
  48156. +/*
  48157. + * Macros for accessing UAS IU fields, which are big-endian
  48158. + */
  48159. +#define IUSETW2(w,h,l) ((w)[0] = (u_int8_t)(h), (w)[1] = (u_int8_t)(l))
  48160. +#define IUCONSTW(x) { ((x) >> 8) & 0xff, (x) & 0xff }
  48161. +#define IUCONSTDW(x) { ((x) >> 24) & 0xff, ((x) >> 16) & 0xff, \
  48162. + ((x) >> 8) & 0xff, (x) & 0xff }
  48163. +#define IUGETW(w) (((w)[0] << 8) | (w)[1])
  48164. +#define IUSETW(w,v) ((w)[0] = (u_int8_t)((v) >> 8), (w)[1] = (u_int8_t)(v))
  48165. +#define IUGETDW(w) (((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3])
  48166. +#define IUSETDW(w,v) ((w)[0] = (u_int8_t)((v) >> 24), \
  48167. + (w)[1] = (u_int8_t)((v) >> 16), \
  48168. + (w)[2] = (u_int8_t)((v) >> 8), \
  48169. + (w)[3] = (u_int8_t)(v))
  48170. +
  48171. +#define UPACKED __attribute__((__packed__))
  48172. +
  48173. +typedef struct {
  48174. + uByte bmRequestType;
  48175. + uByte bRequest;
  48176. + uWord wValue;
  48177. + uWord wIndex;
  48178. + uWord wLength;
  48179. +} UPACKED usb_device_request_t;
  48180. +
  48181. +#define UT_GET_DIR(a) ((a) & 0x80)
  48182. +#define UT_WRITE 0x00
  48183. +#define UT_READ 0x80
  48184. +
  48185. +#define UT_GET_TYPE(a) ((a) & 0x60)
  48186. +#define UT_STANDARD 0x00
  48187. +#define UT_CLASS 0x20
  48188. +#define UT_VENDOR 0x40
  48189. +
  48190. +#define UT_GET_RECIPIENT(a) ((a) & 0x1f)
  48191. +#define UT_DEVICE 0x00
  48192. +#define UT_INTERFACE 0x01
  48193. +#define UT_ENDPOINT 0x02
  48194. +#define UT_OTHER 0x03
  48195. +
  48196. +#define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE)
  48197. +#define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE)
  48198. +#define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT)
  48199. +#define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE)
  48200. +#define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE)
  48201. +#define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT)
  48202. +#define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE)
  48203. +#define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE)
  48204. +#define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER)
  48205. +#define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT)
  48206. +#define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE)
  48207. +#define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
  48208. +#define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER)
  48209. +#define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT)
  48210. +#define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE)
  48211. +#define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE)
  48212. +#define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER)
  48213. +#define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT)
  48214. +#define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE)
  48215. +#define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
  48216. +#define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER)
  48217. +#define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
  48218. +
  48219. +/* Requests */
  48220. +#define UR_GET_STATUS 0x00
  48221. +#define USTAT_STANDARD_STATUS 0x00
  48222. +#define WUSTAT_WUSB_FEATURE 0x01
  48223. +#define WUSTAT_CHANNEL_INFO 0x02
  48224. +#define WUSTAT_RECEIVED_DATA 0x03
  48225. +#define WUSTAT_MAS_AVAILABILITY 0x04
  48226. +#define WUSTAT_CURRENT_TRANSMIT_POWER 0x05
  48227. +#define UR_CLEAR_FEATURE 0x01
  48228. +#define UR_SET_FEATURE 0x03
  48229. +#define UR_SET_AND_TEST_FEATURE 0x0c
  48230. +#define UR_SET_ADDRESS 0x05
  48231. +#define UR_GET_DESCRIPTOR 0x06
  48232. +#define UDESC_DEVICE 0x01
  48233. +#define UDESC_CONFIG 0x02
  48234. +#define UDESC_STRING 0x03
  48235. +#define UDESC_INTERFACE 0x04
  48236. +#define UDESC_ENDPOINT 0x05
  48237. +#define UDESC_SS_USB_COMPANION 0x30
  48238. +#define UDESC_DEVICE_QUALIFIER 0x06
  48239. +#define UDESC_OTHER_SPEED_CONFIGURATION 0x07
  48240. +#define UDESC_INTERFACE_POWER 0x08
  48241. +#define UDESC_OTG 0x09
  48242. +#define WUDESC_SECURITY 0x0c
  48243. +#define WUDESC_KEY 0x0d
  48244. +#define WUD_GET_KEY_INDEX(_wValue_) ((_wValue_) & 0xf)
  48245. +#define WUD_GET_KEY_TYPE(_wValue_) (((_wValue_) & 0x30) >> 4)
  48246. +#define WUD_KEY_TYPE_ASSOC 0x01
  48247. +#define WUD_KEY_TYPE_GTK 0x02
  48248. +#define WUD_GET_KEY_ORIGIN(_wValue_) (((_wValue_) & 0x40) >> 6)
  48249. +#define WUD_KEY_ORIGIN_HOST 0x00
  48250. +#define WUD_KEY_ORIGIN_DEVICE 0x01
  48251. +#define WUDESC_ENCRYPTION_TYPE 0x0e
  48252. +#define WUDESC_BOS 0x0f
  48253. +#define WUDESC_DEVICE_CAPABILITY 0x10
  48254. +#define WUDESC_WIRELESS_ENDPOINT_COMPANION 0x11
  48255. +#define UDESC_BOS 0x0f
  48256. +#define UDESC_DEVICE_CAPABILITY 0x10
  48257. +#define UDESC_CS_DEVICE 0x21 /* class specific */
  48258. +#define UDESC_CS_CONFIG 0x22
  48259. +#define UDESC_CS_STRING 0x23
  48260. +#define UDESC_CS_INTERFACE 0x24
  48261. +#define UDESC_CS_ENDPOINT 0x25
  48262. +#define UDESC_HUB 0x29
  48263. +#define UR_SET_DESCRIPTOR 0x07
  48264. +#define UR_GET_CONFIG 0x08
  48265. +#define UR_SET_CONFIG 0x09
  48266. +#define UR_GET_INTERFACE 0x0a
  48267. +#define UR_SET_INTERFACE 0x0b
  48268. +#define UR_SYNCH_FRAME 0x0c
  48269. +#define WUR_SET_ENCRYPTION 0x0d
  48270. +#define WUR_GET_ENCRYPTION 0x0e
  48271. +#define WUR_SET_HANDSHAKE 0x0f
  48272. +#define WUR_GET_HANDSHAKE 0x10
  48273. +#define WUR_SET_CONNECTION 0x11
  48274. +#define WUR_SET_SECURITY_DATA 0x12
  48275. +#define WUR_GET_SECURITY_DATA 0x13
  48276. +#define WUR_SET_WUSB_DATA 0x14
  48277. +#define WUDATA_DRPIE_INFO 0x01
  48278. +#define WUDATA_TRANSMIT_DATA 0x02
  48279. +#define WUDATA_TRANSMIT_PARAMS 0x03
  48280. +#define WUDATA_RECEIVE_PARAMS 0x04
  48281. +#define WUDATA_TRANSMIT_POWER 0x05
  48282. +#define WUR_LOOPBACK_DATA_WRITE 0x15
  48283. +#define WUR_LOOPBACK_DATA_READ 0x16
  48284. +#define WUR_SET_INTERFACE_DS 0x17
  48285. +
  48286. +/* Feature numbers */
  48287. +#define UF_ENDPOINT_HALT 0
  48288. +#define UF_DEVICE_REMOTE_WAKEUP 1
  48289. +#define UF_TEST_MODE 2
  48290. +#define UF_DEVICE_B_HNP_ENABLE 3
  48291. +#define UF_DEVICE_A_HNP_SUPPORT 4
  48292. +#define UF_DEVICE_A_ALT_HNP_SUPPORT 5
  48293. +#define WUF_WUSB 3
  48294. +#define WUF_TX_DRPIE 0x0
  48295. +#define WUF_DEV_XMIT_PACKET 0x1
  48296. +#define WUF_COUNT_PACKETS 0x2
  48297. +#define WUF_CAPTURE_PACKETS 0x3
  48298. +#define UF_FUNCTION_SUSPEND 0
  48299. +#define UF_U1_ENABLE 48
  48300. +#define UF_U2_ENABLE 49
  48301. +#define UF_LTM_ENABLE 50
  48302. +
  48303. +/* Class requests from the USB 2.0 hub spec, table 11-15 */
  48304. +#define UCR_CLEAR_HUB_FEATURE (0x2000 | UR_CLEAR_FEATURE)
  48305. +#define UCR_CLEAR_PORT_FEATURE (0x2300 | UR_CLEAR_FEATURE)
  48306. +#define UCR_GET_HUB_DESCRIPTOR (0xa000 | UR_GET_DESCRIPTOR)
  48307. +#define UCR_GET_HUB_STATUS (0xa000 | UR_GET_STATUS)
  48308. +#define UCR_GET_PORT_STATUS (0xa300 | UR_GET_STATUS)
  48309. +#define UCR_SET_HUB_FEATURE (0x2000 | UR_SET_FEATURE)
  48310. +#define UCR_SET_PORT_FEATURE (0x2300 | UR_SET_FEATURE)
  48311. +#define UCR_SET_AND_TEST_PORT_FEATURE (0xa300 | UR_SET_AND_TEST_FEATURE)
  48312. +
  48313. +#ifdef _MSC_VER
  48314. +#include <pshpack1.h>
  48315. +#endif
  48316. +
  48317. +typedef struct {
  48318. + uByte bLength;
  48319. + uByte bDescriptorType;
  48320. + uByte bDescriptorSubtype;
  48321. +} UPACKED usb_descriptor_t;
  48322. +
  48323. +typedef struct {
  48324. + uByte bLength;
  48325. + uByte bDescriptorType;
  48326. +} UPACKED usb_descriptor_header_t;
  48327. +
  48328. +typedef struct {
  48329. + uByte bLength;
  48330. + uByte bDescriptorType;
  48331. + uWord bcdUSB;
  48332. +#define UD_USB_2_0 0x0200
  48333. +#define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
  48334. + uByte bDeviceClass;
  48335. + uByte bDeviceSubClass;
  48336. + uByte bDeviceProtocol;
  48337. + uByte bMaxPacketSize;
  48338. + /* The fields below are not part of the initial descriptor. */
  48339. + uWord idVendor;
  48340. + uWord idProduct;
  48341. + uWord bcdDevice;
  48342. + uByte iManufacturer;
  48343. + uByte iProduct;
  48344. + uByte iSerialNumber;
  48345. + uByte bNumConfigurations;
  48346. +} UPACKED usb_device_descriptor_t;
  48347. +#define USB_DEVICE_DESCRIPTOR_SIZE 18
  48348. +
  48349. +typedef struct {
  48350. + uByte bLength;
  48351. + uByte bDescriptorType;
  48352. + uWord wTotalLength;
  48353. + uByte bNumInterface;
  48354. + uByte bConfigurationValue;
  48355. + uByte iConfiguration;
  48356. +#define UC_ATT_ONE (1 << 7) /* must be set */
  48357. +#define UC_ATT_SELFPOWER (1 << 6) /* self powered */
  48358. +#define UC_ATT_WAKEUP (1 << 5) /* can wakeup */
  48359. +#define UC_ATT_BATTERY (1 << 4) /* battery powered */
  48360. + uByte bmAttributes;
  48361. +#define UC_BUS_POWERED 0x80
  48362. +#define UC_SELF_POWERED 0x40
  48363. +#define UC_REMOTE_WAKEUP 0x20
  48364. + uByte bMaxPower; /* max current in 2 mA units */
  48365. +#define UC_POWER_FACTOR 2
  48366. +} UPACKED usb_config_descriptor_t;
  48367. +#define USB_CONFIG_DESCRIPTOR_SIZE 9
  48368. +
  48369. +typedef struct {
  48370. + uByte bLength;
  48371. + uByte bDescriptorType;
  48372. + uByte bInterfaceNumber;
  48373. + uByte bAlternateSetting;
  48374. + uByte bNumEndpoints;
  48375. + uByte bInterfaceClass;
  48376. + uByte bInterfaceSubClass;
  48377. + uByte bInterfaceProtocol;
  48378. + uByte iInterface;
  48379. +} UPACKED usb_interface_descriptor_t;
  48380. +#define USB_INTERFACE_DESCRIPTOR_SIZE 9
  48381. +
  48382. +typedef struct {
  48383. + uByte bLength;
  48384. + uByte bDescriptorType;
  48385. + uByte bEndpointAddress;
  48386. +#define UE_GET_DIR(a) ((a) & 0x80)
  48387. +#define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7))
  48388. +#define UE_DIR_IN 0x80
  48389. +#define UE_DIR_OUT 0x00
  48390. +#define UE_ADDR 0x0f
  48391. +#define UE_GET_ADDR(a) ((a) & UE_ADDR)
  48392. + uByte bmAttributes;
  48393. +#define UE_XFERTYPE 0x03
  48394. +#define UE_CONTROL 0x00
  48395. +#define UE_ISOCHRONOUS 0x01
  48396. +#define UE_BULK 0x02
  48397. +#define UE_INTERRUPT 0x03
  48398. +#define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
  48399. +#define UE_ISO_TYPE 0x0c
  48400. +#define UE_ISO_ASYNC 0x04
  48401. +#define UE_ISO_ADAPT 0x08
  48402. +#define UE_ISO_SYNC 0x0c
  48403. +#define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
  48404. + uWord wMaxPacketSize;
  48405. + uByte bInterval;
  48406. +} UPACKED usb_endpoint_descriptor_t;
  48407. +#define USB_ENDPOINT_DESCRIPTOR_SIZE 7
  48408. +
  48409. +typedef struct ss_endpoint_companion_descriptor {
  48410. + uByte bLength;
  48411. + uByte bDescriptorType;
  48412. + uByte bMaxBurst;
  48413. +#define USSE_GET_MAX_STREAMS(a) ((a) & 0x1f)
  48414. +#define USSE_SET_MAX_STREAMS(a, b) ((a) | ((b) & 0x1f))
  48415. +#define USSE_GET_MAX_PACKET_NUM(a) ((a) & 0x03)
  48416. +#define USSE_SET_MAX_PACKET_NUM(a, b) ((a) | ((b) & 0x03))
  48417. + uByte bmAttributes;
  48418. + uWord wBytesPerInterval;
  48419. +} UPACKED ss_endpoint_companion_descriptor_t;
  48420. +#define USB_SS_ENDPOINT_COMPANION_DESCRIPTOR_SIZE 6
  48421. +
  48422. +typedef struct {
  48423. + uByte bLength;
  48424. + uByte bDescriptorType;
  48425. + uWord bString[127];
  48426. +} UPACKED usb_string_descriptor_t;
  48427. +#define USB_MAX_STRING_LEN 128
  48428. +#define USB_LANGUAGE_TABLE 0 /* # of the string language id table */
  48429. +
  48430. +/* Hub specific request */
  48431. +#define UR_GET_BUS_STATE 0x02
  48432. +#define UR_CLEAR_TT_BUFFER 0x08
  48433. +#define UR_RESET_TT 0x09
  48434. +#define UR_GET_TT_STATE 0x0a
  48435. +#define UR_STOP_TT 0x0b
  48436. +
  48437. +/* Hub features */
  48438. +#define UHF_C_HUB_LOCAL_POWER 0
  48439. +#define UHF_C_HUB_OVER_CURRENT 1
  48440. +#define UHF_PORT_CONNECTION 0
  48441. +#define UHF_PORT_ENABLE 1
  48442. +#define UHF_PORT_SUSPEND 2
  48443. +#define UHF_PORT_OVER_CURRENT 3
  48444. +#define UHF_PORT_RESET 4
  48445. +#define UHF_PORT_L1 5
  48446. +#define UHF_PORT_POWER 8
  48447. +#define UHF_PORT_LOW_SPEED 9
  48448. +#define UHF_PORT_HIGH_SPEED 10
  48449. +#define UHF_C_PORT_CONNECTION 16
  48450. +#define UHF_C_PORT_ENABLE 17
  48451. +#define UHF_C_PORT_SUSPEND 18
  48452. +#define UHF_C_PORT_OVER_CURRENT 19
  48453. +#define UHF_C_PORT_RESET 20
  48454. +#define UHF_C_PORT_L1 23
  48455. +#define UHF_PORT_TEST 21
  48456. +#define UHF_PORT_INDICATOR 22
  48457. +
  48458. +typedef struct {
  48459. + uByte bDescLength;
  48460. + uByte bDescriptorType;
  48461. + uByte bNbrPorts;
  48462. + uWord wHubCharacteristics;
  48463. +#define UHD_PWR 0x0003
  48464. +#define UHD_PWR_GANGED 0x0000
  48465. +#define UHD_PWR_INDIVIDUAL 0x0001
  48466. +#define UHD_PWR_NO_SWITCH 0x0002
  48467. +#define UHD_COMPOUND 0x0004
  48468. +#define UHD_OC 0x0018
  48469. +#define UHD_OC_GLOBAL 0x0000
  48470. +#define UHD_OC_INDIVIDUAL 0x0008
  48471. +#define UHD_OC_NONE 0x0010
  48472. +#define UHD_TT_THINK 0x0060
  48473. +#define UHD_TT_THINK_8 0x0000
  48474. +#define UHD_TT_THINK_16 0x0020
  48475. +#define UHD_TT_THINK_24 0x0040
  48476. +#define UHD_TT_THINK_32 0x0060
  48477. +#define UHD_PORT_IND 0x0080
  48478. + uByte bPwrOn2PwrGood; /* delay in 2 ms units */
  48479. +#define UHD_PWRON_FACTOR 2
  48480. + uByte bHubContrCurrent;
  48481. + uByte DeviceRemovable[32]; /* max 255 ports */
  48482. +#define UHD_NOT_REMOV(desc, i) \
  48483. + (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
  48484. + /* deprecated */ uByte PortPowerCtrlMask[1];
  48485. +} UPACKED usb_hub_descriptor_t;
  48486. +#define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
  48487. +
  48488. +typedef struct {
  48489. + uByte bLength;
  48490. + uByte bDescriptorType;
  48491. + uWord bcdUSB;
  48492. + uByte bDeviceClass;
  48493. + uByte bDeviceSubClass;
  48494. + uByte bDeviceProtocol;
  48495. + uByte bMaxPacketSize0;
  48496. + uByte bNumConfigurations;
  48497. + uByte bReserved;
  48498. +} UPACKED usb_device_qualifier_t;
  48499. +#define USB_DEVICE_QUALIFIER_SIZE 10
  48500. +
  48501. +typedef struct {
  48502. + uByte bLength;
  48503. + uByte bDescriptorType;
  48504. + uByte bmAttributes;
  48505. +#define UOTG_SRP 0x01
  48506. +#define UOTG_HNP 0x02
  48507. +} UPACKED usb_otg_descriptor_t;
  48508. +
  48509. +/* OTG feature selectors */
  48510. +#define UOTG_B_HNP_ENABLE 3
  48511. +#define UOTG_A_HNP_SUPPORT 4
  48512. +#define UOTG_A_ALT_HNP_SUPPORT 5
  48513. +
  48514. +typedef struct {
  48515. + uWord wStatus;
  48516. +/* Device status flags */
  48517. +#define UDS_SELF_POWERED 0x0001
  48518. +#define UDS_REMOTE_WAKEUP 0x0002
  48519. +/* Endpoint status flags */
  48520. +#define UES_HALT 0x0001
  48521. +} UPACKED usb_status_t;
  48522. +
  48523. +typedef struct {
  48524. + uWord wHubStatus;
  48525. +#define UHS_LOCAL_POWER 0x0001
  48526. +#define UHS_OVER_CURRENT 0x0002
  48527. + uWord wHubChange;
  48528. +} UPACKED usb_hub_status_t;
  48529. +
  48530. +typedef struct {
  48531. + uWord wPortStatus;
  48532. +#define UPS_CURRENT_CONNECT_STATUS 0x0001
  48533. +#define UPS_PORT_ENABLED 0x0002
  48534. +#define UPS_SUSPEND 0x0004
  48535. +#define UPS_OVERCURRENT_INDICATOR 0x0008
  48536. +#define UPS_RESET 0x0010
  48537. +#define UPS_PORT_POWER 0x0100
  48538. +#define UPS_LOW_SPEED 0x0200
  48539. +#define UPS_HIGH_SPEED 0x0400
  48540. +#define UPS_PORT_TEST 0x0800
  48541. +#define UPS_PORT_INDICATOR 0x1000
  48542. + uWord wPortChange;
  48543. +#define UPS_C_CONNECT_STATUS 0x0001
  48544. +#define UPS_C_PORT_ENABLED 0x0002
  48545. +#define UPS_C_SUSPEND 0x0004
  48546. +#define UPS_C_OVERCURRENT_INDICATOR 0x0008
  48547. +#define UPS_C_PORT_RESET 0x0010
  48548. +} UPACKED usb_port_status_t;
  48549. +
  48550. +#ifdef _MSC_VER
  48551. +#include <poppack.h>
  48552. +#endif
  48553. +
  48554. +/* Device class codes */
  48555. +#define UDCLASS_IN_INTERFACE 0x00
  48556. +#define UDCLASS_COMM 0x02
  48557. +#define UDCLASS_HUB 0x09
  48558. +#define UDSUBCLASS_HUB 0x00
  48559. +#define UDPROTO_FSHUB 0x00
  48560. +#define UDPROTO_HSHUBSTT 0x01
  48561. +#define UDPROTO_HSHUBMTT 0x02
  48562. +#define UDCLASS_DIAGNOSTIC 0xdc
  48563. +#define UDCLASS_WIRELESS 0xe0
  48564. +#define UDSUBCLASS_RF 0x01
  48565. +#define UDPROTO_BLUETOOTH 0x01
  48566. +#define UDCLASS_VENDOR 0xff
  48567. +
  48568. +/* Interface class codes */
  48569. +#define UICLASS_UNSPEC 0x00
  48570. +
  48571. +#define UICLASS_AUDIO 0x01
  48572. +#define UISUBCLASS_AUDIOCONTROL 1
  48573. +#define UISUBCLASS_AUDIOSTREAM 2
  48574. +#define UISUBCLASS_MIDISTREAM 3
  48575. +
  48576. +#define UICLASS_CDC 0x02 /* communication */
  48577. +#define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1
  48578. +#define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2
  48579. +#define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3
  48580. +#define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4
  48581. +#define UISUBCLASS_CAPI_CONTROLMODEL 5
  48582. +#define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
  48583. +#define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
  48584. +#define UIPROTO_CDC_AT 1
  48585. +
  48586. +#define UICLASS_HID 0x03
  48587. +#define UISUBCLASS_BOOT 1
  48588. +#define UIPROTO_BOOT_KEYBOARD 1
  48589. +
  48590. +#define UICLASS_PHYSICAL 0x05
  48591. +
  48592. +#define UICLASS_IMAGE 0x06
  48593. +
  48594. +#define UICLASS_PRINTER 0x07
  48595. +#define UISUBCLASS_PRINTER 1
  48596. +#define UIPROTO_PRINTER_UNI 1
  48597. +#define UIPROTO_PRINTER_BI 2
  48598. +#define UIPROTO_PRINTER_1284 3
  48599. +
  48600. +#define UICLASS_MASS 0x08
  48601. +#define UISUBCLASS_RBC 1
  48602. +#define UISUBCLASS_SFF8020I 2
  48603. +#define UISUBCLASS_QIC157 3
  48604. +#define UISUBCLASS_UFI 4
  48605. +#define UISUBCLASS_SFF8070I 5
  48606. +#define UISUBCLASS_SCSI 6
  48607. +#define UIPROTO_MASS_CBI_I 0
  48608. +#define UIPROTO_MASS_CBI 1
  48609. +#define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
  48610. +#define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
  48611. +
  48612. +#define UICLASS_HUB 0x09
  48613. +#define UISUBCLASS_HUB 0
  48614. +#define UIPROTO_FSHUB 0
  48615. +#define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
  48616. +#define UIPROTO_HSHUBMTT 1
  48617. +
  48618. +#define UICLASS_CDC_DATA 0x0a
  48619. +#define UISUBCLASS_DATA 0
  48620. +#define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */
  48621. +#define UIPROTO_DATA_HDLC 0x31 /* HDLC */
  48622. +#define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */
  48623. +#define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */
  48624. +#define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */
  48625. +#define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */
  48626. +#define UIPROTO_DATA_V42BIS 0x90 /* Data compression */
  48627. +#define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */
  48628. +#define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */
  48629. +#define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */
  48630. +#define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */
  48631. +#define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc.*/
  48632. +#define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */
  48633. +
  48634. +#define UICLASS_SMARTCARD 0x0b
  48635. +
  48636. +/*#define UICLASS_FIRM_UPD 0x0c*/
  48637. +
  48638. +#define UICLASS_SECURITY 0x0d
  48639. +
  48640. +#define UICLASS_DIAGNOSTIC 0xdc
  48641. +
  48642. +#define UICLASS_WIRELESS 0xe0
  48643. +#define UISUBCLASS_RF 0x01
  48644. +#define UIPROTO_BLUETOOTH 0x01
  48645. +
  48646. +#define UICLASS_APPL_SPEC 0xfe
  48647. +#define UISUBCLASS_FIRMWARE_DOWNLOAD 1
  48648. +#define UISUBCLASS_IRDA 2
  48649. +#define UIPROTO_IRDA 0
  48650. +
  48651. +#define UICLASS_VENDOR 0xff
  48652. +
  48653. +#define USB_HUB_MAX_DEPTH 5
  48654. +
  48655. +/*
  48656. + * Minimum time a device needs to be powered down to go through
  48657. + * a power cycle. XXX Are these time in the spec?
  48658. + */
  48659. +#define USB_POWER_DOWN_TIME 200 /* ms */
  48660. +#define USB_PORT_POWER_DOWN_TIME 100 /* ms */
  48661. +
  48662. +#if 0
  48663. +/* These are the values from the spec. */
  48664. +#define USB_PORT_RESET_DELAY 10 /* ms */
  48665. +#define USB_PORT_ROOT_RESET_DELAY 50 /* ms */
  48666. +#define USB_PORT_RESET_RECOVERY 10 /* ms */
  48667. +#define USB_PORT_POWERUP_DELAY 100 /* ms */
  48668. +#define USB_SET_ADDRESS_SETTLE 2 /* ms */
  48669. +#define USB_RESUME_DELAY (20*5) /* ms */
  48670. +#define USB_RESUME_WAIT 10 /* ms */
  48671. +#define USB_RESUME_RECOVERY 10 /* ms */
  48672. +#define USB_EXTRA_POWER_UP_TIME 0 /* ms */
  48673. +#else
  48674. +/* Allow for marginal (i.e. non-conforming) devices. */
  48675. +#define USB_PORT_RESET_DELAY 50 /* ms */
  48676. +#define USB_PORT_ROOT_RESET_DELAY 250 /* ms */
  48677. +#define USB_PORT_RESET_RECOVERY 250 /* ms */
  48678. +#define USB_PORT_POWERUP_DELAY 300 /* ms */
  48679. +#define USB_SET_ADDRESS_SETTLE 10 /* ms */
  48680. +#define USB_RESUME_DELAY (50*5) /* ms */
  48681. +#define USB_RESUME_WAIT 50 /* ms */
  48682. +#define USB_RESUME_RECOVERY 50 /* ms */
  48683. +#define USB_EXTRA_POWER_UP_TIME 20 /* ms */
  48684. +#endif
  48685. +
  48686. +#define USB_MIN_POWER 100 /* mA */
  48687. +#define USB_MAX_POWER 500 /* mA */
  48688. +
  48689. +#define USB_BUS_RESET_DELAY 100 /* ms XXX?*/
  48690. +
  48691. +#define USB_UNCONFIG_NO 0
  48692. +#define USB_UNCONFIG_INDEX (-1)
  48693. +
  48694. +/*** ioctl() related stuff ***/
  48695. +
  48696. +struct usb_ctl_request {
  48697. + int ucr_addr;
  48698. + usb_device_request_t ucr_request;
  48699. + void *ucr_data;
  48700. + int ucr_flags;
  48701. +#define USBD_SHORT_XFER_OK 0x04 /* allow short reads */
  48702. + int ucr_actlen; /* actual length transferred */
  48703. +};
  48704. +
  48705. +struct usb_alt_interface {
  48706. + int uai_config_index;
  48707. + int uai_interface_index;
  48708. + int uai_alt_no;
  48709. +};
  48710. +
  48711. +#define USB_CURRENT_CONFIG_INDEX (-1)
  48712. +#define USB_CURRENT_ALT_INDEX (-1)
  48713. +
  48714. +struct usb_config_desc {
  48715. + int ucd_config_index;
  48716. + usb_config_descriptor_t ucd_desc;
  48717. +};
  48718. +
  48719. +struct usb_interface_desc {
  48720. + int uid_config_index;
  48721. + int uid_interface_index;
  48722. + int uid_alt_index;
  48723. + usb_interface_descriptor_t uid_desc;
  48724. +};
  48725. +
  48726. +struct usb_endpoint_desc {
  48727. + int ued_config_index;
  48728. + int ued_interface_index;
  48729. + int ued_alt_index;
  48730. + int ued_endpoint_index;
  48731. + usb_endpoint_descriptor_t ued_desc;
  48732. +};
  48733. +
  48734. +struct usb_full_desc {
  48735. + int ufd_config_index;
  48736. + u_int ufd_size;
  48737. + u_char *ufd_data;
  48738. +};
  48739. +
  48740. +struct usb_string_desc {
  48741. + int usd_string_index;
  48742. + int usd_language_id;
  48743. + usb_string_descriptor_t usd_desc;
  48744. +};
  48745. +
  48746. +struct usb_ctl_report_desc {
  48747. + int ucrd_size;
  48748. + u_char ucrd_data[1024]; /* filled data size will vary */
  48749. +};
  48750. +
  48751. +typedef struct { u_int32_t cookie; } usb_event_cookie_t;
  48752. +
  48753. +#define USB_MAX_DEVNAMES 4
  48754. +#define USB_MAX_DEVNAMELEN 16
  48755. +struct usb_device_info {
  48756. + u_int8_t udi_bus;
  48757. + u_int8_t udi_addr; /* device address */
  48758. + usb_event_cookie_t udi_cookie;
  48759. + char udi_product[USB_MAX_STRING_LEN];
  48760. + char udi_vendor[USB_MAX_STRING_LEN];
  48761. + char udi_release[8];
  48762. + u_int16_t udi_productNo;
  48763. + u_int16_t udi_vendorNo;
  48764. + u_int16_t udi_releaseNo;
  48765. + u_int8_t udi_class;
  48766. + u_int8_t udi_subclass;
  48767. + u_int8_t udi_protocol;
  48768. + u_int8_t udi_config;
  48769. + u_int8_t udi_speed;
  48770. +#define USB_SPEED_UNKNOWN 0
  48771. +#define USB_SPEED_LOW 1
  48772. +#define USB_SPEED_FULL 2
  48773. +#define USB_SPEED_HIGH 3
  48774. +#define USB_SPEED_VARIABLE 4
  48775. +#define USB_SPEED_SUPER 5
  48776. + int udi_power; /* power consumption in mA, 0 if selfpowered */
  48777. + int udi_nports;
  48778. + char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
  48779. + u_int8_t udi_ports[16];/* hub only: addresses of devices on ports */
  48780. +#define USB_PORT_ENABLED 0xff
  48781. +#define USB_PORT_SUSPENDED 0xfe
  48782. +#define USB_PORT_POWERED 0xfd
  48783. +#define USB_PORT_DISABLED 0xfc
  48784. +};
  48785. +
  48786. +struct usb_ctl_report {
  48787. + int ucr_report;
  48788. + u_char ucr_data[1024]; /* filled data size will vary */
  48789. +};
  48790. +
  48791. +struct usb_device_stats {
  48792. + u_long uds_requests[4]; /* indexed by transfer type UE_* */
  48793. +};
  48794. +
  48795. +#define WUSB_MIN_IE 0x80
  48796. +#define WUSB_WCTA_IE 0x80
  48797. +#define WUSB_WCONNECTACK_IE 0x81
  48798. +#define WUSB_WHOSTINFO_IE 0x82
  48799. +#define WUHI_GET_CA(_bmAttributes_) ((_bmAttributes_) & 0x3)
  48800. +#define WUHI_CA_RECONN 0x00
  48801. +#define WUHI_CA_LIMITED 0x01
  48802. +#define WUHI_CA_ALL 0x03
  48803. +#define WUHI_GET_MLSI(_bmAttributes_) (((_bmAttributes_) & 0x38) >> 3)
  48804. +#define WUSB_WCHCHANGEANNOUNCE_IE 0x83
  48805. +#define WUSB_WDEV_DISCONNECT_IE 0x84
  48806. +#define WUSB_WHOST_DISCONNECT_IE 0x85
  48807. +#define WUSB_WRELEASE_CHANNEL_IE 0x86
  48808. +#define WUSB_WWORK_IE 0x87
  48809. +#define WUSB_WCHANNEL_STOP_IE 0x88
  48810. +#define WUSB_WDEV_KEEPALIVE_IE 0x89
  48811. +#define WUSB_WISOCH_DISCARD_IE 0x8A
  48812. +#define WUSB_WRESETDEVICE_IE 0x8B
  48813. +#define WUSB_WXMIT_PACKET_ADJUST_IE 0x8C
  48814. +#define WUSB_MAX_IE 0x8C
  48815. +
  48816. +/* Device Notification Types */
  48817. +
  48818. +#define WUSB_DN_MIN 0x01
  48819. +#define WUSB_DN_CONNECT 0x01
  48820. +# define WUSB_DA_OLDCONN 0x00
  48821. +# define WUSB_DA_NEWCONN 0x01
  48822. +# define WUSB_DA_SELF_BEACON 0x02
  48823. +# define WUSB_DA_DIR_BEACON 0x04
  48824. +# define WUSB_DA_NO_BEACON 0x06
  48825. +#define WUSB_DN_DISCONNECT 0x02
  48826. +#define WUSB_DN_EPRDY 0x03
  48827. +#define WUSB_DN_MASAVAILCHANGED 0x04
  48828. +#define WUSB_DN_REMOTEWAKEUP 0x05
  48829. +#define WUSB_DN_SLEEP 0x06
  48830. +#define WUSB_DN_ALIVE 0x07
  48831. +#define WUSB_DN_MAX 0x07
  48832. +
  48833. +#ifdef _MSC_VER
  48834. +#include <pshpack1.h>
  48835. +#endif
  48836. +
  48837. +/* WUSB Handshake Data. Used during the SET/GET HANDSHAKE requests */
  48838. +typedef struct wusb_hndshk_data {
  48839. + uByte bMessageNumber;
  48840. + uByte bStatus;
  48841. + uByte tTKID[3];
  48842. + uByte bReserved;
  48843. + uByte CDID[16];
  48844. + uByte Nonce[16];
  48845. + uByte MIC[8];
  48846. +} UPACKED wusb_hndshk_data_t;
  48847. +#define WUSB_HANDSHAKE_LEN_FOR_MIC 38
  48848. +
  48849. +/* WUSB Connection Context */
  48850. +typedef struct wusb_conn_context {
  48851. + uByte CHID [16];
  48852. + uByte CDID [16];
  48853. + uByte CK [16];
  48854. +} UPACKED wusb_conn_context_t;
  48855. +
  48856. +/* WUSB Security Descriptor */
  48857. +typedef struct wusb_security_desc {
  48858. + uByte bLength;
  48859. + uByte bDescriptorType;
  48860. + uWord wTotalLength;
  48861. + uByte bNumEncryptionTypes;
  48862. +} UPACKED wusb_security_desc_t;
  48863. +
  48864. +/* WUSB Encryption Type Descriptor */
  48865. +typedef struct wusb_encrypt_type_desc {
  48866. + uByte bLength;
  48867. + uByte bDescriptorType;
  48868. +
  48869. + uByte bEncryptionType;
  48870. +#define WUETD_UNSECURE 0
  48871. +#define WUETD_WIRED 1
  48872. +#define WUETD_CCM_1 2
  48873. +#define WUETD_RSA_1 3
  48874. +
  48875. + uByte bEncryptionValue;
  48876. + uByte bAuthKeyIndex;
  48877. +} UPACKED wusb_encrypt_type_desc_t;
  48878. +
  48879. +/* WUSB Key Descriptor */
  48880. +typedef struct wusb_key_desc {
  48881. + uByte bLength;
  48882. + uByte bDescriptorType;
  48883. + uByte tTKID[3];
  48884. + uByte bReserved;
  48885. + uByte KeyData[1]; /* variable length */
  48886. +} UPACKED wusb_key_desc_t;
  48887. +
  48888. +/* WUSB BOS Descriptor (Binary device Object Store) */
  48889. +typedef struct wusb_bos_desc {
  48890. + uByte bLength;
  48891. + uByte bDescriptorType;
  48892. + uWord wTotalLength;
  48893. + uByte bNumDeviceCaps;
  48894. +} UPACKED wusb_bos_desc_t;
  48895. +
  48896. +#define USB_DEVICE_CAPABILITY_20_EXTENSION 0x02
  48897. +typedef struct usb_dev_cap_20_ext_desc {
  48898. + uByte bLength;
  48899. + uByte bDescriptorType;
  48900. + uByte bDevCapabilityType;
  48901. +#define USB_20_EXT_LPM 0x02
  48902. + uDWord bmAttributes;
  48903. +} UPACKED usb_dev_cap_20_ext_desc_t;
  48904. +
  48905. +#define USB_DEVICE_CAPABILITY_SS_USB 0x03
  48906. +typedef struct usb_dev_cap_ss_usb {
  48907. + uByte bLength;
  48908. + uByte bDescriptorType;
  48909. + uByte bDevCapabilityType;
  48910. +#define USB_DC_SS_USB_LTM_CAPABLE 0x02
  48911. + uByte bmAttributes;
  48912. +#define USB_DC_SS_USB_SPEED_SUPPORT_LOW 0x01
  48913. +#define USB_DC_SS_USB_SPEED_SUPPORT_FULL 0x02
  48914. +#define USB_DC_SS_USB_SPEED_SUPPORT_HIGH 0x04
  48915. +#define USB_DC_SS_USB_SPEED_SUPPORT_SS 0x08
  48916. + uWord wSpeedsSupported;
  48917. + uByte bFunctionalitySupport;
  48918. + uByte bU1DevExitLat;
  48919. + uWord wU2DevExitLat;
  48920. +} UPACKED usb_dev_cap_ss_usb_t;
  48921. +
  48922. +#define USB_DEVICE_CAPABILITY_CONTAINER_ID 0x04
  48923. +typedef struct usb_dev_cap_container_id {
  48924. + uByte bLength;
  48925. + uByte bDescriptorType;
  48926. + uByte bDevCapabilityType;
  48927. + uByte bReserved;
  48928. + uByte containerID[16];
  48929. +} UPACKED usb_dev_cap_container_id_t;
  48930. +
  48931. +/* Device Capability Type Codes */
  48932. +#define WUSB_DEVICE_CAPABILITY_WIRELESS_USB 0x01
  48933. +
  48934. +/* Device Capability Descriptor */
  48935. +typedef struct wusb_dev_cap_desc {
  48936. + uByte bLength;
  48937. + uByte bDescriptorType;
  48938. + uByte bDevCapabilityType;
  48939. + uByte caps[1]; /* Variable length */
  48940. +} UPACKED wusb_dev_cap_desc_t;
  48941. +
  48942. +/* Device Capability Descriptor */
  48943. +typedef struct wusb_dev_cap_uwb_desc {
  48944. + uByte bLength;
  48945. + uByte bDescriptorType;
  48946. + uByte bDevCapabilityType;
  48947. + uByte bmAttributes;
  48948. + uWord wPHYRates; /* Bitmap */
  48949. + uByte bmTFITXPowerInfo;
  48950. + uByte bmFFITXPowerInfo;
  48951. + uWord bmBandGroup;
  48952. + uByte bReserved;
  48953. +} UPACKED wusb_dev_cap_uwb_desc_t;
  48954. +
  48955. +/* Wireless USB Endpoint Companion Descriptor */
  48956. +typedef struct wusb_endpoint_companion_desc {
  48957. + uByte bLength;
  48958. + uByte bDescriptorType;
  48959. + uByte bMaxBurst;
  48960. + uByte bMaxSequence;
  48961. + uWord wMaxStreamDelay;
  48962. + uWord wOverTheAirPacketSize;
  48963. + uByte bOverTheAirInterval;
  48964. + uByte bmCompAttributes;
  48965. +} UPACKED wusb_endpoint_companion_desc_t;
  48966. +
  48967. +/* Wireless USB Numeric Association M1 Data Structure */
  48968. +typedef struct wusb_m1_data {
  48969. + uByte version;
  48970. + uWord langId;
  48971. + uByte deviceFriendlyNameLength;
  48972. + uByte sha_256_m3[32];
  48973. + uByte deviceFriendlyName[256];
  48974. +} UPACKED wusb_m1_data_t;
  48975. +
  48976. +typedef struct wusb_m2_data {
  48977. + uByte version;
  48978. + uWord langId;
  48979. + uByte hostFriendlyNameLength;
  48980. + uByte pkh[384];
  48981. + uByte hostFriendlyName[256];
  48982. +} UPACKED wusb_m2_data_t;
  48983. +
  48984. +typedef struct wusb_m3_data {
  48985. + uByte pkd[384];
  48986. + uByte nd;
  48987. +} UPACKED wusb_m3_data_t;
  48988. +
  48989. +typedef struct wusb_m4_data {
  48990. + uDWord _attributeTypeIdAndLength_1;
  48991. + uWord associationTypeId;
  48992. +
  48993. + uDWord _attributeTypeIdAndLength_2;
  48994. + uWord associationSubTypeId;
  48995. +
  48996. + uDWord _attributeTypeIdAndLength_3;
  48997. + uDWord length;
  48998. +
  48999. + uDWord _attributeTypeIdAndLength_4;
  49000. + uDWord associationStatus;
  49001. +
  49002. + uDWord _attributeTypeIdAndLength_5;
  49003. + uByte chid[16];
  49004. +
  49005. + uDWord _attributeTypeIdAndLength_6;
  49006. + uByte cdid[16];
  49007. +
  49008. + uDWord _attributeTypeIdAndLength_7;
  49009. + uByte bandGroups[2];
  49010. +} UPACKED wusb_m4_data_t;
  49011. +
  49012. +#ifdef _MSC_VER
  49013. +#include <poppack.h>
  49014. +#endif
  49015. +
  49016. +#ifdef __cplusplus
  49017. +}
  49018. +#endif
  49019. +
  49020. +#endif /* _USB_H_ */
  49021. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/doc/doxygen.cfg linux-3.12.11/drivers/usb/host/dwc_otg/doc/doxygen.cfg
  49022. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  49023. +++ linux-3.12.11/drivers/usb/host/dwc_otg/doc/doxygen.cfg 2014-02-18 11:52:14.000000000 +0100
  49024. @@ -0,0 +1,224 @@
  49025. +# Doxyfile 1.3.9.1
  49026. +
  49027. +#---------------------------------------------------------------------------
  49028. +# Project related configuration options
  49029. +#---------------------------------------------------------------------------
  49030. +PROJECT_NAME = "DesignWare USB 2.0 OTG Controller (DWC_otg) Device Driver"
  49031. +PROJECT_NUMBER = v3.00a
  49032. +OUTPUT_DIRECTORY = ./doc/
  49033. +CREATE_SUBDIRS = NO
  49034. +OUTPUT_LANGUAGE = English
  49035. +BRIEF_MEMBER_DESC = YES
  49036. +REPEAT_BRIEF = YES
  49037. +ABBREVIATE_BRIEF = "The $name class" \
  49038. + "The $name widget" \
  49039. + "The $name file" \
  49040. + is \
  49041. + provides \
  49042. + specifies \
  49043. + contains \
  49044. + represents \
  49045. + a \
  49046. + an \
  49047. + the
  49048. +ALWAYS_DETAILED_SEC = NO
  49049. +INLINE_INHERITED_MEMB = NO
  49050. +FULL_PATH_NAMES = NO
  49051. +STRIP_FROM_PATH =
  49052. +STRIP_FROM_INC_PATH =
  49053. +SHORT_NAMES = NO
  49054. +JAVADOC_AUTOBRIEF = YES
  49055. +MULTILINE_CPP_IS_BRIEF = NO
  49056. +INHERIT_DOCS = YES
  49057. +DISTRIBUTE_GROUP_DOC = NO
  49058. +TAB_SIZE = 8
  49059. +ALIASES =
  49060. +OPTIMIZE_OUTPUT_FOR_C = YES
  49061. +OPTIMIZE_OUTPUT_JAVA = NO
  49062. +SUBGROUPING = YES
  49063. +#---------------------------------------------------------------------------
  49064. +# Build related configuration options
  49065. +#---------------------------------------------------------------------------
  49066. +EXTRACT_ALL = NO
  49067. +EXTRACT_PRIVATE = YES
  49068. +EXTRACT_STATIC = YES
  49069. +EXTRACT_LOCAL_CLASSES = YES
  49070. +EXTRACT_LOCAL_METHODS = NO
  49071. +HIDE_UNDOC_MEMBERS = NO
  49072. +HIDE_UNDOC_CLASSES = NO
  49073. +HIDE_FRIEND_COMPOUNDS = NO
  49074. +HIDE_IN_BODY_DOCS = NO
  49075. +INTERNAL_DOCS = NO
  49076. +CASE_SENSE_NAMES = NO
  49077. +HIDE_SCOPE_NAMES = NO
  49078. +SHOW_INCLUDE_FILES = YES
  49079. +INLINE_INFO = YES
  49080. +SORT_MEMBER_DOCS = NO
  49081. +SORT_BRIEF_DOCS = NO
  49082. +SORT_BY_SCOPE_NAME = NO
  49083. +GENERATE_TODOLIST = YES
  49084. +GENERATE_TESTLIST = YES
  49085. +GENERATE_BUGLIST = YES
  49086. +GENERATE_DEPRECATEDLIST= YES
  49087. +ENABLED_SECTIONS =
  49088. +MAX_INITIALIZER_LINES = 30
  49089. +SHOW_USED_FILES = YES
  49090. +SHOW_DIRECTORIES = YES
  49091. +#---------------------------------------------------------------------------
  49092. +# configuration options related to warning and progress messages
  49093. +#---------------------------------------------------------------------------
  49094. +QUIET = YES
  49095. +WARNINGS = YES
  49096. +WARN_IF_UNDOCUMENTED = NO
  49097. +WARN_IF_DOC_ERROR = YES
  49098. +WARN_FORMAT = "$file:$line: $text"
  49099. +WARN_LOGFILE =
  49100. +#---------------------------------------------------------------------------
  49101. +# configuration options related to the input files
  49102. +#---------------------------------------------------------------------------
  49103. +INPUT = .
  49104. +FILE_PATTERNS = *.c \
  49105. + *.h \
  49106. + ./linux/*.c \
  49107. + ./linux/*.h
  49108. +RECURSIVE = NO
  49109. +EXCLUDE = ./test/ \
  49110. + ./dwc_otg/.AppleDouble/
  49111. +EXCLUDE_SYMLINKS = YES
  49112. +EXCLUDE_PATTERNS = *.mod.*
  49113. +EXAMPLE_PATH =
  49114. +EXAMPLE_PATTERNS = *
  49115. +EXAMPLE_RECURSIVE = NO
  49116. +IMAGE_PATH =
  49117. +INPUT_FILTER =
  49118. +FILTER_PATTERNS =
  49119. +FILTER_SOURCE_FILES = NO
  49120. +#---------------------------------------------------------------------------
  49121. +# configuration options related to source browsing
  49122. +#---------------------------------------------------------------------------
  49123. +SOURCE_BROWSER = YES
  49124. +INLINE_SOURCES = NO
  49125. +STRIP_CODE_COMMENTS = YES
  49126. +REFERENCED_BY_RELATION = NO
  49127. +REFERENCES_RELATION = NO
  49128. +VERBATIM_HEADERS = NO
  49129. +#---------------------------------------------------------------------------
  49130. +# configuration options related to the alphabetical class index
  49131. +#---------------------------------------------------------------------------
  49132. +ALPHABETICAL_INDEX = NO
  49133. +COLS_IN_ALPHA_INDEX = 5
  49134. +IGNORE_PREFIX =
  49135. +#---------------------------------------------------------------------------
  49136. +# configuration options related to the HTML output
  49137. +#---------------------------------------------------------------------------
  49138. +GENERATE_HTML = YES
  49139. +HTML_OUTPUT = html
  49140. +HTML_FILE_EXTENSION = .html
  49141. +HTML_HEADER =
  49142. +HTML_FOOTER =
  49143. +HTML_STYLESHEET =
  49144. +HTML_ALIGN_MEMBERS = YES
  49145. +GENERATE_HTMLHELP = NO
  49146. +CHM_FILE =
  49147. +HHC_LOCATION =
  49148. +GENERATE_CHI = NO
  49149. +BINARY_TOC = NO
  49150. +TOC_EXPAND = NO
  49151. +DISABLE_INDEX = NO
  49152. +ENUM_VALUES_PER_LINE = 4
  49153. +GENERATE_TREEVIEW = YES
  49154. +TREEVIEW_WIDTH = 250
  49155. +#---------------------------------------------------------------------------
  49156. +# configuration options related to the LaTeX output
  49157. +#---------------------------------------------------------------------------
  49158. +GENERATE_LATEX = NO
  49159. +LATEX_OUTPUT = latex
  49160. +LATEX_CMD_NAME = latex
  49161. +MAKEINDEX_CMD_NAME = makeindex
  49162. +COMPACT_LATEX = NO
  49163. +PAPER_TYPE = a4wide
  49164. +EXTRA_PACKAGES =
  49165. +LATEX_HEADER =
  49166. +PDF_HYPERLINKS = NO
  49167. +USE_PDFLATEX = NO
  49168. +LATEX_BATCHMODE = NO
  49169. +LATEX_HIDE_INDICES = NO
  49170. +#---------------------------------------------------------------------------
  49171. +# configuration options related to the RTF output
  49172. +#---------------------------------------------------------------------------
  49173. +GENERATE_RTF = NO
  49174. +RTF_OUTPUT = rtf
  49175. +COMPACT_RTF = NO
  49176. +RTF_HYPERLINKS = NO
  49177. +RTF_STYLESHEET_FILE =
  49178. +RTF_EXTENSIONS_FILE =
  49179. +#---------------------------------------------------------------------------
  49180. +# configuration options related to the man page output
  49181. +#---------------------------------------------------------------------------
  49182. +GENERATE_MAN = NO
  49183. +MAN_OUTPUT = man
  49184. +MAN_EXTENSION = .3
  49185. +MAN_LINKS = NO
  49186. +#---------------------------------------------------------------------------
  49187. +# configuration options related to the XML output
  49188. +#---------------------------------------------------------------------------
  49189. +GENERATE_XML = NO
  49190. +XML_OUTPUT = xml
  49191. +XML_SCHEMA =
  49192. +XML_DTD =
  49193. +XML_PROGRAMLISTING = YES
  49194. +#---------------------------------------------------------------------------
  49195. +# configuration options for the AutoGen Definitions output
  49196. +#---------------------------------------------------------------------------
  49197. +GENERATE_AUTOGEN_DEF = NO
  49198. +#---------------------------------------------------------------------------
  49199. +# configuration options related to the Perl module output
  49200. +#---------------------------------------------------------------------------
  49201. +GENERATE_PERLMOD = NO
  49202. +PERLMOD_LATEX = NO
  49203. +PERLMOD_PRETTY = YES
  49204. +PERLMOD_MAKEVAR_PREFIX =
  49205. +#---------------------------------------------------------------------------
  49206. +# Configuration options related to the preprocessor
  49207. +#---------------------------------------------------------------------------
  49208. +ENABLE_PREPROCESSING = YES
  49209. +MACRO_EXPANSION = YES
  49210. +EXPAND_ONLY_PREDEF = YES
  49211. +SEARCH_INCLUDES = YES
  49212. +INCLUDE_PATH =
  49213. +INCLUDE_FILE_PATTERNS =
  49214. +PREDEFINED = DEVICE_ATTR DWC_EN_ISOC
  49215. +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
  49216. +SKIP_FUNCTION_MACROS = NO
  49217. +#---------------------------------------------------------------------------
  49218. +# Configuration::additions related to external references
  49219. +#---------------------------------------------------------------------------
  49220. +TAGFILES =
  49221. +GENERATE_TAGFILE =
  49222. +ALLEXTERNALS = NO
  49223. +EXTERNAL_GROUPS = YES
  49224. +PERL_PATH = /usr/bin/perl
  49225. +#---------------------------------------------------------------------------
  49226. +# Configuration options related to the dot tool
  49227. +#---------------------------------------------------------------------------
  49228. +CLASS_DIAGRAMS = YES
  49229. +HIDE_UNDOC_RELATIONS = YES
  49230. +HAVE_DOT = NO
  49231. +CLASS_GRAPH = YES
  49232. +COLLABORATION_GRAPH = YES
  49233. +UML_LOOK = NO
  49234. +TEMPLATE_RELATIONS = NO
  49235. +INCLUDE_GRAPH = YES
  49236. +INCLUDED_BY_GRAPH = YES
  49237. +CALL_GRAPH = NO
  49238. +GRAPHICAL_HIERARCHY = YES
  49239. +DOT_IMAGE_FORMAT = png
  49240. +DOT_PATH =
  49241. +DOTFILE_DIRS =
  49242. +MAX_DOT_GRAPH_DEPTH = 1000
  49243. +GENERATE_LEGEND = YES
  49244. +DOT_CLEANUP = YES
  49245. +#---------------------------------------------------------------------------
  49246. +# Configuration::additions related to the search engine
  49247. +#---------------------------------------------------------------------------
  49248. +SEARCHENGINE = NO
  49249. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dummy_audio.c linux-3.12.11/drivers/usb/host/dwc_otg/dummy_audio.c
  49250. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dummy_audio.c 1970-01-01 01:00:00.000000000 +0100
  49251. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dummy_audio.c 2014-02-18 11:52:14.000000000 +0100
  49252. @@ -0,0 +1,1575 @@
  49253. +/*
  49254. + * zero.c -- Gadget Zero, for USB development
  49255. + *
  49256. + * Copyright (C) 2003-2004 David Brownell
  49257. + * All rights reserved.
  49258. + *
  49259. + * Redistribution and use in source and binary forms, with or without
  49260. + * modification, are permitted provided that the following conditions
  49261. + * are met:
  49262. + * 1. Redistributions of source code must retain the above copyright
  49263. + * notice, this list of conditions, and the following disclaimer,
  49264. + * without modification.
  49265. + * 2. Redistributions in binary form must reproduce the above copyright
  49266. + * notice, this list of conditions and the following disclaimer in the
  49267. + * documentation and/or other materials provided with the distribution.
  49268. + * 3. The names of the above-listed copyright holders may not be used
  49269. + * to endorse or promote products derived from this software without
  49270. + * specific prior written permission.
  49271. + *
  49272. + * ALTERNATIVELY, this software may be distributed under the terms of the
  49273. + * GNU General Public License ("GPL") as published by the Free Software
  49274. + * Foundation, either version 2 of that License or (at your option) any
  49275. + * later version.
  49276. + *
  49277. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  49278. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  49279. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  49280. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  49281. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  49282. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  49283. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  49284. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  49285. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  49286. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  49287. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49288. + */
  49289. +
  49290. +
  49291. +/*
  49292. + * Gadget Zero only needs two bulk endpoints, and is an example of how you
  49293. + * can write a hardware-agnostic gadget driver running inside a USB device.
  49294. + *
  49295. + * Hardware details are visible (see CONFIG_USB_ZERO_* below) but don't
  49296. + * affect most of the driver.
  49297. + *
  49298. + * Use it with the Linux host/master side "usbtest" driver to get a basic
  49299. + * functional test of your device-side usb stack, or with "usb-skeleton".
  49300. + *
  49301. + * It supports two similar configurations. One sinks whatever the usb host
  49302. + * writes, and in return sources zeroes. The other loops whatever the host
  49303. + * writes back, so the host can read it. Module options include:
  49304. + *
  49305. + * buflen=N default N=4096, buffer size used
  49306. + * qlen=N default N=32, how many buffers in the loopback queue
  49307. + * loopdefault default false, list loopback config first
  49308. + *
  49309. + * Many drivers will only have one configuration, letting them be much
  49310. + * simpler if they also don't support high speed operation (like this
  49311. + * driver does).
  49312. + */
  49313. +
  49314. +#include <linux/config.h>
  49315. +#include <linux/module.h>
  49316. +#include <linux/kernel.h>
  49317. +#include <linux/delay.h>
  49318. +#include <linux/ioport.h>
  49319. +#include <linux/sched.h>
  49320. +#include <linux/slab.h>
  49321. +#include <linux/smp_lock.h>
  49322. +#include <linux/errno.h>
  49323. +#include <linux/init.h>
  49324. +#include <linux/timer.h>
  49325. +#include <linux/list.h>
  49326. +#include <linux/interrupt.h>
  49327. +#include <linux/uts.h>
  49328. +#include <linux/version.h>
  49329. +#include <linux/device.h>
  49330. +#include <linux/moduleparam.h>
  49331. +#include <linux/proc_fs.h>
  49332. +
  49333. +#include <asm/byteorder.h>
  49334. +#include <asm/io.h>
  49335. +#include <asm/irq.h>
  49336. +#include <asm/system.h>
  49337. +#include <asm/unaligned.h>
  49338. +
  49339. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  49340. +# include <linux/usb/ch9.h>
  49341. +#else
  49342. +# include <linux/usb_ch9.h>
  49343. +#endif
  49344. +
  49345. +#include <linux/usb_gadget.h>
  49346. +
  49347. +
  49348. +/*-------------------------------------------------------------------------*/
  49349. +/*-------------------------------------------------------------------------*/
  49350. +
  49351. +
  49352. +static int utf8_to_utf16le(const char *s, u16 *cp, unsigned len)
  49353. +{
  49354. + int count = 0;
  49355. + u8 c;
  49356. + u16 uchar;
  49357. +
  49358. + /* this insists on correct encodings, though not minimal ones.
  49359. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  49360. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  49361. + */
  49362. + while (len != 0 && (c = (u8) *s++) != 0) {
  49363. + if (unlikely(c & 0x80)) {
  49364. + // 2-byte sequence:
  49365. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  49366. + if ((c & 0xe0) == 0xc0) {
  49367. + uchar = (c & 0x1f) << 6;
  49368. +
  49369. + c = (u8) *s++;
  49370. + if ((c & 0xc0) != 0xc0)
  49371. + goto fail;
  49372. + c &= 0x3f;
  49373. + uchar |= c;
  49374. +
  49375. + // 3-byte sequence (most CJKV characters):
  49376. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  49377. + } else if ((c & 0xf0) == 0xe0) {
  49378. + uchar = (c & 0x0f) << 12;
  49379. +
  49380. + c = (u8) *s++;
  49381. + if ((c & 0xc0) != 0xc0)
  49382. + goto fail;
  49383. + c &= 0x3f;
  49384. + uchar |= c << 6;
  49385. +
  49386. + c = (u8) *s++;
  49387. + if ((c & 0xc0) != 0xc0)
  49388. + goto fail;
  49389. + c &= 0x3f;
  49390. + uchar |= c;
  49391. +
  49392. + /* no bogus surrogates */
  49393. + if (0xd800 <= uchar && uchar <= 0xdfff)
  49394. + goto fail;
  49395. +
  49396. + // 4-byte sequence (surrogate pairs, currently rare):
  49397. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  49398. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  49399. + // (uuuuu = wwww + 1)
  49400. + // FIXME accept the surrogate code points (only)
  49401. +
  49402. + } else
  49403. + goto fail;
  49404. + } else
  49405. + uchar = c;
  49406. + put_unaligned (cpu_to_le16 (uchar), cp++);
  49407. + count++;
  49408. + len--;
  49409. + }
  49410. + return count;
  49411. +fail:
  49412. + return -1;
  49413. +}
  49414. +
  49415. +
  49416. +/**
  49417. + * usb_gadget_get_string - fill out a string descriptor
  49418. + * @table: of c strings encoded using UTF-8
  49419. + * @id: string id, from low byte of wValue in get string descriptor
  49420. + * @buf: at least 256 bytes
  49421. + *
  49422. + * Finds the UTF-8 string matching the ID, and converts it into a
  49423. + * string descriptor in utf16-le.
  49424. + * Returns length of descriptor (always even) or negative errno
  49425. + *
  49426. + * If your driver needs stings in multiple languages, you'll probably
  49427. + * "switch (wIndex) { ... }" in your ep0 string descriptor logic,
  49428. + * using this routine after choosing which set of UTF-8 strings to use.
  49429. + * Note that US-ASCII is a strict subset of UTF-8; any string bytes with
  49430. + * the eighth bit set will be multibyte UTF-8 characters, not ISO-8859/1
  49431. + * characters (which are also widely used in C strings).
  49432. + */
  49433. +int
  49434. +usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf)
  49435. +{
  49436. + struct usb_string *s;
  49437. + int len;
  49438. +
  49439. + /* descriptor 0 has the language id */
  49440. + if (id == 0) {
  49441. + buf [0] = 4;
  49442. + buf [1] = USB_DT_STRING;
  49443. + buf [2] = (u8) table->language;
  49444. + buf [3] = (u8) (table->language >> 8);
  49445. + return 4;
  49446. + }
  49447. + for (s = table->strings; s && s->s; s++)
  49448. + if (s->id == id)
  49449. + break;
  49450. +
  49451. + /* unrecognized: stall. */
  49452. + if (!s || !s->s)
  49453. + return -EINVAL;
  49454. +
  49455. + /* string descriptors have length, tag, then UTF16-LE text */
  49456. + len = min ((size_t) 126, strlen (s->s));
  49457. + memset (buf + 2, 0, 2 * len); /* zero all the bytes */
  49458. + len = utf8_to_utf16le(s->s, (u16 *)&buf[2], len);
  49459. + if (len < 0)
  49460. + return -EINVAL;
  49461. + buf [0] = (len + 1) * 2;
  49462. + buf [1] = USB_DT_STRING;
  49463. + return buf [0];
  49464. +}
  49465. +
  49466. +
  49467. +/*-------------------------------------------------------------------------*/
  49468. +/*-------------------------------------------------------------------------*/
  49469. +
  49470. +
  49471. +/**
  49472. + * usb_descriptor_fillbuf - fill buffer with descriptors
  49473. + * @buf: Buffer to be filled
  49474. + * @buflen: Size of buf
  49475. + * @src: Array of descriptor pointers, terminated by null pointer.
  49476. + *
  49477. + * Copies descriptors into the buffer, returning the length or a
  49478. + * negative error code if they can't all be copied. Useful when
  49479. + * assembling descriptors for an associated set of interfaces used
  49480. + * as part of configuring a composite device; or in other cases where
  49481. + * sets of descriptors need to be marshaled.
  49482. + */
  49483. +int
  49484. +usb_descriptor_fillbuf(void *buf, unsigned buflen,
  49485. + const struct usb_descriptor_header **src)
  49486. +{
  49487. + u8 *dest = buf;
  49488. +
  49489. + if (!src)
  49490. + return -EINVAL;
  49491. +
  49492. + /* fill buffer from src[] until null descriptor ptr */
  49493. + for (; 0 != *src; src++) {
  49494. + unsigned len = (*src)->bLength;
  49495. +
  49496. + if (len > buflen)
  49497. + return -EINVAL;
  49498. + memcpy(dest, *src, len);
  49499. + buflen -= len;
  49500. + dest += len;
  49501. + }
  49502. + return dest - (u8 *)buf;
  49503. +}
  49504. +
  49505. +
  49506. +/**
  49507. + * usb_gadget_config_buf - builts a complete configuration descriptor
  49508. + * @config: Header for the descriptor, including characteristics such
  49509. + * as power requirements and number of interfaces.
  49510. + * @desc: Null-terminated vector of pointers to the descriptors (interface,
  49511. + * endpoint, etc) defining all functions in this device configuration.
  49512. + * @buf: Buffer for the resulting configuration descriptor.
  49513. + * @length: Length of buffer. If this is not big enough to hold the
  49514. + * entire configuration descriptor, an error code will be returned.
  49515. + *
  49516. + * This copies descriptors into the response buffer, building a descriptor
  49517. + * for that configuration. It returns the buffer length or a negative
  49518. + * status code. The config.wTotalLength field is set to match the length
  49519. + * of the result, but other descriptor fields (including power usage and
  49520. + * interface count) must be set by the caller.
  49521. + *
  49522. + * Gadget drivers could use this when constructing a config descriptor
  49523. + * in response to USB_REQ_GET_DESCRIPTOR. They will need to patch the
  49524. + * resulting bDescriptorType value if USB_DT_OTHER_SPEED_CONFIG is needed.
  49525. + */
  49526. +int usb_gadget_config_buf(
  49527. + const struct usb_config_descriptor *config,
  49528. + void *buf,
  49529. + unsigned length,
  49530. + const struct usb_descriptor_header **desc
  49531. +)
  49532. +{
  49533. + struct usb_config_descriptor *cp = buf;
  49534. + int len;
  49535. +
  49536. + /* config descriptor first */
  49537. + if (length < USB_DT_CONFIG_SIZE || !desc)
  49538. + return -EINVAL;
  49539. + *cp = *config;
  49540. +
  49541. + /* then interface/endpoint/class/vendor/... */
  49542. + len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8*)buf,
  49543. + length - USB_DT_CONFIG_SIZE, desc);
  49544. + if (len < 0)
  49545. + return len;
  49546. + len += USB_DT_CONFIG_SIZE;
  49547. + if (len > 0xffff)
  49548. + return -EINVAL;
  49549. +
  49550. + /* patch up the config descriptor */
  49551. + cp->bLength = USB_DT_CONFIG_SIZE;
  49552. + cp->bDescriptorType = USB_DT_CONFIG;
  49553. + cp->wTotalLength = cpu_to_le16(len);
  49554. + cp->bmAttributes |= USB_CONFIG_ATT_ONE;
  49555. + return len;
  49556. +}
  49557. +
  49558. +/*-------------------------------------------------------------------------*/
  49559. +/*-------------------------------------------------------------------------*/
  49560. +
  49561. +
  49562. +#define RBUF_LEN (1024*1024)
  49563. +static int rbuf_start;
  49564. +static int rbuf_len;
  49565. +static __u8 rbuf[RBUF_LEN];
  49566. +
  49567. +/*-------------------------------------------------------------------------*/
  49568. +
  49569. +#define DRIVER_VERSION "St Patrick's Day 2004"
  49570. +
  49571. +static const char shortname [] = "zero";
  49572. +static const char longname [] = "YAMAHA YST-MS35D USB Speaker ";
  49573. +
  49574. +static const char source_sink [] = "source and sink data";
  49575. +static const char loopback [] = "loop input to output";
  49576. +
  49577. +/*-------------------------------------------------------------------------*/
  49578. +
  49579. +/*
  49580. + * driver assumes self-powered hardware, and
  49581. + * has no way for users to trigger remote wakeup.
  49582. + *
  49583. + * this version autoconfigures as much as possible,
  49584. + * which is reasonable for most "bulk-only" drivers.
  49585. + */
  49586. +static const char *EP_IN_NAME; /* source */
  49587. +static const char *EP_OUT_NAME; /* sink */
  49588. +
  49589. +/*-------------------------------------------------------------------------*/
  49590. +
  49591. +/* big enough to hold our biggest descriptor */
  49592. +#define USB_BUFSIZ 512
  49593. +
  49594. +struct zero_dev {
  49595. + spinlock_t lock;
  49596. + struct usb_gadget *gadget;
  49597. + struct usb_request *req; /* for control responses */
  49598. +
  49599. + /* when configured, we have one of two configs:
  49600. + * - source data (in to host) and sink it (out from host)
  49601. + * - or loop it back (out from host back in to host)
  49602. + */
  49603. + u8 config;
  49604. + struct usb_ep *in_ep, *out_ep;
  49605. +
  49606. + /* autoresume timer */
  49607. + struct timer_list resume;
  49608. +};
  49609. +
  49610. +#define xprintk(d,level,fmt,args...) \
  49611. + dev_printk(level , &(d)->gadget->dev , fmt , ## args)
  49612. +
  49613. +#ifdef DEBUG
  49614. +#define DBG(dev,fmt,args...) \
  49615. + xprintk(dev , KERN_DEBUG , fmt , ## args)
  49616. +#else
  49617. +#define DBG(dev,fmt,args...) \
  49618. + do { } while (0)
  49619. +#endif /* DEBUG */
  49620. +
  49621. +#ifdef VERBOSE
  49622. +#define VDBG DBG
  49623. +#else
  49624. +#define VDBG(dev,fmt,args...) \
  49625. + do { } while (0)
  49626. +#endif /* VERBOSE */
  49627. +
  49628. +#define ERROR(dev,fmt,args...) \
  49629. + xprintk(dev , KERN_ERR , fmt , ## args)
  49630. +#define WARN(dev,fmt,args...) \
  49631. + xprintk(dev , KERN_WARNING , fmt , ## args)
  49632. +#define INFO(dev,fmt,args...) \
  49633. + xprintk(dev , KERN_INFO , fmt , ## args)
  49634. +
  49635. +/*-------------------------------------------------------------------------*/
  49636. +
  49637. +static unsigned buflen = 4096;
  49638. +static unsigned qlen = 32;
  49639. +static unsigned pattern = 0;
  49640. +
  49641. +module_param (buflen, uint, S_IRUGO|S_IWUSR);
  49642. +module_param (qlen, uint, S_IRUGO|S_IWUSR);
  49643. +module_param (pattern, uint, S_IRUGO|S_IWUSR);
  49644. +
  49645. +/*
  49646. + * if it's nonzero, autoresume says how many seconds to wait
  49647. + * before trying to wake up the host after suspend.
  49648. + */
  49649. +static unsigned autoresume = 0;
  49650. +module_param (autoresume, uint, 0);
  49651. +
  49652. +/*
  49653. + * Normally the "loopback" configuration is second (index 1) so
  49654. + * it's not the default. Here's where to change that order, to
  49655. + * work better with hosts where config changes are problematic.
  49656. + * Or controllers (like superh) that only support one config.
  49657. + */
  49658. +static int loopdefault = 0;
  49659. +
  49660. +module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
  49661. +
  49662. +/*-------------------------------------------------------------------------*/
  49663. +
  49664. +/* Thanks to NetChip Technologies for donating this product ID.
  49665. + *
  49666. + * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
  49667. + * Instead: allocate your own, using normal USB-IF procedures.
  49668. + */
  49669. +#ifndef CONFIG_USB_ZERO_HNPTEST
  49670. +#define DRIVER_VENDOR_NUM 0x0525 /* NetChip */
  49671. +#define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */
  49672. +#else
  49673. +#define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */
  49674. +#define DRIVER_PRODUCT_NUM 0xbadd
  49675. +#endif
  49676. +
  49677. +/*-------------------------------------------------------------------------*/
  49678. +
  49679. +/*
  49680. + * DESCRIPTORS ... most are static, but strings and (full)
  49681. + * configuration descriptors are built on demand.
  49682. + */
  49683. +
  49684. +/*
  49685. +#define STRING_MANUFACTURER 25
  49686. +#define STRING_PRODUCT 42
  49687. +#define STRING_SERIAL 101
  49688. +*/
  49689. +#define STRING_MANUFACTURER 1
  49690. +#define STRING_PRODUCT 2
  49691. +#define STRING_SERIAL 3
  49692. +
  49693. +#define STRING_SOURCE_SINK 250
  49694. +#define STRING_LOOPBACK 251
  49695. +
  49696. +/*
  49697. + * This device advertises two configurations; these numbers work
  49698. + * on a pxa250 as well as more flexible hardware.
  49699. + */
  49700. +#define CONFIG_SOURCE_SINK 3
  49701. +#define CONFIG_LOOPBACK 2
  49702. +
  49703. +/*
  49704. +static struct usb_device_descriptor
  49705. +device_desc = {
  49706. + .bLength = sizeof device_desc,
  49707. + .bDescriptorType = USB_DT_DEVICE,
  49708. +
  49709. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  49710. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  49711. +
  49712. + .idVendor = __constant_cpu_to_le16 (DRIVER_VENDOR_NUM),
  49713. + .idProduct = __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM),
  49714. + .iManufacturer = STRING_MANUFACTURER,
  49715. + .iProduct = STRING_PRODUCT,
  49716. + .iSerialNumber = STRING_SERIAL,
  49717. + .bNumConfigurations = 2,
  49718. +};
  49719. +*/
  49720. +static struct usb_device_descriptor
  49721. +device_desc = {
  49722. + .bLength = sizeof device_desc,
  49723. + .bDescriptorType = USB_DT_DEVICE,
  49724. + .bcdUSB = __constant_cpu_to_le16 (0x0100),
  49725. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  49726. + .bDeviceSubClass = 0,
  49727. + .bDeviceProtocol = 0,
  49728. + .bMaxPacketSize0 = 64,
  49729. + .bcdDevice = __constant_cpu_to_le16 (0x0100),
  49730. + .idVendor = __constant_cpu_to_le16 (0x0499),
  49731. + .idProduct = __constant_cpu_to_le16 (0x3002),
  49732. + .iManufacturer = STRING_MANUFACTURER,
  49733. + .iProduct = STRING_PRODUCT,
  49734. + .iSerialNumber = STRING_SERIAL,
  49735. + .bNumConfigurations = 1,
  49736. +};
  49737. +
  49738. +static struct usb_config_descriptor
  49739. +z_config = {
  49740. + .bLength = sizeof z_config,
  49741. + .bDescriptorType = USB_DT_CONFIG,
  49742. +
  49743. + /* compute wTotalLength on the fly */
  49744. + .bNumInterfaces = 2,
  49745. + .bConfigurationValue = 1,
  49746. + .iConfiguration = 0,
  49747. + .bmAttributes = 0x40,
  49748. + .bMaxPower = 0, /* self-powered */
  49749. +};
  49750. +
  49751. +
  49752. +static struct usb_otg_descriptor
  49753. +otg_descriptor = {
  49754. + .bLength = sizeof otg_descriptor,
  49755. + .bDescriptorType = USB_DT_OTG,
  49756. +
  49757. + .bmAttributes = USB_OTG_SRP,
  49758. +};
  49759. +
  49760. +/* one interface in each configuration */
  49761. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  49762. +
  49763. +/*
  49764. + * usb 2.0 devices need to expose both high speed and full speed
  49765. + * descriptors, unless they only run at full speed.
  49766. + *
  49767. + * that means alternate endpoint descriptors (bigger packets)
  49768. + * and a "device qualifier" ... plus more construction options
  49769. + * for the config descriptor.
  49770. + */
  49771. +
  49772. +static struct usb_qualifier_descriptor
  49773. +dev_qualifier = {
  49774. + .bLength = sizeof dev_qualifier,
  49775. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  49776. +
  49777. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  49778. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  49779. +
  49780. + .bNumConfigurations = 2,
  49781. +};
  49782. +
  49783. +
  49784. +struct usb_cs_as_general_descriptor {
  49785. + __u8 bLength;
  49786. + __u8 bDescriptorType;
  49787. +
  49788. + __u8 bDescriptorSubType;
  49789. + __u8 bTerminalLink;
  49790. + __u8 bDelay;
  49791. + __u16 wFormatTag;
  49792. +} __attribute__ ((packed));
  49793. +
  49794. +struct usb_cs_as_format_descriptor {
  49795. + __u8 bLength;
  49796. + __u8 bDescriptorType;
  49797. +
  49798. + __u8 bDescriptorSubType;
  49799. + __u8 bFormatType;
  49800. + __u8 bNrChannels;
  49801. + __u8 bSubframeSize;
  49802. + __u8 bBitResolution;
  49803. + __u8 bSamfreqType;
  49804. + __u8 tLowerSamFreq[3];
  49805. + __u8 tUpperSamFreq[3];
  49806. +} __attribute__ ((packed));
  49807. +
  49808. +static const struct usb_interface_descriptor
  49809. +z_audio_control_if_desc = {
  49810. + .bLength = sizeof z_audio_control_if_desc,
  49811. + .bDescriptorType = USB_DT_INTERFACE,
  49812. + .bInterfaceNumber = 0,
  49813. + .bAlternateSetting = 0,
  49814. + .bNumEndpoints = 0,
  49815. + .bInterfaceClass = USB_CLASS_AUDIO,
  49816. + .bInterfaceSubClass = 0x1,
  49817. + .bInterfaceProtocol = 0,
  49818. + .iInterface = 0,
  49819. +};
  49820. +
  49821. +static const struct usb_interface_descriptor
  49822. +z_audio_if_desc = {
  49823. + .bLength = sizeof z_audio_if_desc,
  49824. + .bDescriptorType = USB_DT_INTERFACE,
  49825. + .bInterfaceNumber = 1,
  49826. + .bAlternateSetting = 0,
  49827. + .bNumEndpoints = 0,
  49828. + .bInterfaceClass = USB_CLASS_AUDIO,
  49829. + .bInterfaceSubClass = 0x2,
  49830. + .bInterfaceProtocol = 0,
  49831. + .iInterface = 0,
  49832. +};
  49833. +
  49834. +static const struct usb_interface_descriptor
  49835. +z_audio_if_desc2 = {
  49836. + .bLength = sizeof z_audio_if_desc,
  49837. + .bDescriptorType = USB_DT_INTERFACE,
  49838. + .bInterfaceNumber = 1,
  49839. + .bAlternateSetting = 1,
  49840. + .bNumEndpoints = 1,
  49841. + .bInterfaceClass = USB_CLASS_AUDIO,
  49842. + .bInterfaceSubClass = 0x2,
  49843. + .bInterfaceProtocol = 0,
  49844. + .iInterface = 0,
  49845. +};
  49846. +
  49847. +static const struct usb_cs_as_general_descriptor
  49848. +z_audio_cs_as_if_desc = {
  49849. + .bLength = 7,
  49850. + .bDescriptorType = 0x24,
  49851. +
  49852. + .bDescriptorSubType = 0x01,
  49853. + .bTerminalLink = 0x01,
  49854. + .bDelay = 0x0,
  49855. + .wFormatTag = __constant_cpu_to_le16 (0x0001)
  49856. +};
  49857. +
  49858. +
  49859. +static const struct usb_cs_as_format_descriptor
  49860. +z_audio_cs_as_format_desc = {
  49861. + .bLength = 0xe,
  49862. + .bDescriptorType = 0x24,
  49863. +
  49864. + .bDescriptorSubType = 2,
  49865. + .bFormatType = 1,
  49866. + .bNrChannels = 1,
  49867. + .bSubframeSize = 1,
  49868. + .bBitResolution = 8,
  49869. + .bSamfreqType = 0,
  49870. + .tLowerSamFreq = {0x7e, 0x13, 0x00},
  49871. + .tUpperSamFreq = {0xe2, 0xd6, 0x00},
  49872. +};
  49873. +
  49874. +static const struct usb_endpoint_descriptor
  49875. +z_iso_ep = {
  49876. + .bLength = 0x09,
  49877. + .bDescriptorType = 0x05,
  49878. + .bEndpointAddress = 0x04,
  49879. + .bmAttributes = 0x09,
  49880. + .wMaxPacketSize = 0x0038,
  49881. + .bInterval = 0x01,
  49882. + .bRefresh = 0x00,
  49883. + .bSynchAddress = 0x00,
  49884. +};
  49885. +
  49886. +static char z_iso_ep2[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49887. +
  49888. +// 9 bytes
  49889. +static char z_ac_interface_header_desc[] =
  49890. +{ 0x09, 0x24, 0x01, 0x00, 0x01, 0x2b, 0x00, 0x01, 0x01 };
  49891. +
  49892. +// 12 bytes
  49893. +static char z_0[] = {0x0c, 0x24, 0x02, 0x01, 0x01, 0x01, 0x00, 0x02,
  49894. + 0x03, 0x00, 0x00, 0x00};
  49895. +// 13 bytes
  49896. +static char z_1[] = {0x0d, 0x24, 0x06, 0x02, 0x01, 0x02, 0x15, 0x00,
  49897. + 0x02, 0x00, 0x02, 0x00, 0x00};
  49898. +// 9 bytes
  49899. +static char z_2[] = {0x09, 0x24, 0x03, 0x03, 0x01, 0x03, 0x00, 0x02,
  49900. + 0x00};
  49901. +
  49902. +static char za_0[] = {0x09, 0x04, 0x01, 0x02, 0x01, 0x01, 0x02, 0x00,
  49903. + 0x00};
  49904. +
  49905. +static char za_1[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49906. +
  49907. +static char za_2[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x01, 0x08, 0x00,
  49908. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49909. +
  49910. +static char za_3[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  49911. + 0x00};
  49912. +
  49913. +static char za_4[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49914. +
  49915. +static char za_5[] = {0x09, 0x04, 0x01, 0x03, 0x01, 0x01, 0x02, 0x00,
  49916. + 0x00};
  49917. +
  49918. +static char za_6[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49919. +
  49920. +static char za_7[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x02, 0x10, 0x00,
  49921. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49922. +
  49923. +static char za_8[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  49924. + 0x00};
  49925. +
  49926. +static char za_9[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49927. +
  49928. +static char za_10[] = {0x09, 0x04, 0x01, 0x04, 0x01, 0x01, 0x02, 0x00,
  49929. + 0x00};
  49930. +
  49931. +static char za_11[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49932. +
  49933. +static char za_12[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x02, 0x10, 0x00,
  49934. + 0x73, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49935. +
  49936. +static char za_13[] = {0x09, 0x05, 0x04, 0x09, 0xe0, 0x00, 0x01, 0x00,
  49937. + 0x00};
  49938. +
  49939. +static char za_14[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49940. +
  49941. +static char za_15[] = {0x09, 0x04, 0x01, 0x05, 0x01, 0x01, 0x02, 0x00,
  49942. + 0x00};
  49943. +
  49944. +static char za_16[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49945. +
  49946. +static char za_17[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x03, 0x14, 0x00,
  49947. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49948. +
  49949. +static char za_18[] = {0x09, 0x05, 0x04, 0x09, 0xa8, 0x00, 0x01, 0x00,
  49950. + 0x00};
  49951. +
  49952. +static char za_19[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49953. +
  49954. +static char za_20[] = {0x09, 0x04, 0x01, 0x06, 0x01, 0x01, 0x02, 0x00,
  49955. + 0x00};
  49956. +
  49957. +static char za_21[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49958. +
  49959. +static char za_22[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x03, 0x14, 0x00,
  49960. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49961. +
  49962. +static char za_23[] = {0x09, 0x05, 0x04, 0x09, 0x50, 0x01, 0x01, 0x00,
  49963. + 0x00};
  49964. +
  49965. +static char za_24[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49966. +
  49967. +
  49968. +
  49969. +static const struct usb_descriptor_header *z_function [] = {
  49970. + (struct usb_descriptor_header *) &z_audio_control_if_desc,
  49971. + (struct usb_descriptor_header *) &z_ac_interface_header_desc,
  49972. + (struct usb_descriptor_header *) &z_0,
  49973. + (struct usb_descriptor_header *) &z_1,
  49974. + (struct usb_descriptor_header *) &z_2,
  49975. + (struct usb_descriptor_header *) &z_audio_if_desc,
  49976. + (struct usb_descriptor_header *) &z_audio_if_desc2,
  49977. + (struct usb_descriptor_header *) &z_audio_cs_as_if_desc,
  49978. + (struct usb_descriptor_header *) &z_audio_cs_as_format_desc,
  49979. + (struct usb_descriptor_header *) &z_iso_ep,
  49980. + (struct usb_descriptor_header *) &z_iso_ep2,
  49981. + (struct usb_descriptor_header *) &za_0,
  49982. + (struct usb_descriptor_header *) &za_1,
  49983. + (struct usb_descriptor_header *) &za_2,
  49984. + (struct usb_descriptor_header *) &za_3,
  49985. + (struct usb_descriptor_header *) &za_4,
  49986. + (struct usb_descriptor_header *) &za_5,
  49987. + (struct usb_descriptor_header *) &za_6,
  49988. + (struct usb_descriptor_header *) &za_7,
  49989. + (struct usb_descriptor_header *) &za_8,
  49990. + (struct usb_descriptor_header *) &za_9,
  49991. + (struct usb_descriptor_header *) &za_10,
  49992. + (struct usb_descriptor_header *) &za_11,
  49993. + (struct usb_descriptor_header *) &za_12,
  49994. + (struct usb_descriptor_header *) &za_13,
  49995. + (struct usb_descriptor_header *) &za_14,
  49996. + (struct usb_descriptor_header *) &za_15,
  49997. + (struct usb_descriptor_header *) &za_16,
  49998. + (struct usb_descriptor_header *) &za_17,
  49999. + (struct usb_descriptor_header *) &za_18,
  50000. + (struct usb_descriptor_header *) &za_19,
  50001. + (struct usb_descriptor_header *) &za_20,
  50002. + (struct usb_descriptor_header *) &za_21,
  50003. + (struct usb_descriptor_header *) &za_22,
  50004. + (struct usb_descriptor_header *) &za_23,
  50005. + (struct usb_descriptor_header *) &za_24,
  50006. + NULL,
  50007. +};
  50008. +
  50009. +/* maxpacket and other transfer characteristics vary by speed. */
  50010. +#define ep_desc(g,hs,fs) (((g)->speed==USB_SPEED_HIGH)?(hs):(fs))
  50011. +
  50012. +#else
  50013. +
  50014. +/* if there's no high speed support, maxpacket doesn't change. */
  50015. +#define ep_desc(g,hs,fs) fs
  50016. +
  50017. +#endif /* !CONFIG_USB_GADGET_DUALSPEED */
  50018. +
  50019. +static char manufacturer [40];
  50020. +//static char serial [40];
  50021. +static char serial [] = "Ser 00 em";
  50022. +
  50023. +/* static strings, in UTF-8 */
  50024. +static struct usb_string strings [] = {
  50025. + { STRING_MANUFACTURER, manufacturer, },
  50026. + { STRING_PRODUCT, longname, },
  50027. + { STRING_SERIAL, serial, },
  50028. + { STRING_LOOPBACK, loopback, },
  50029. + { STRING_SOURCE_SINK, source_sink, },
  50030. + { } /* end of list */
  50031. +};
  50032. +
  50033. +static struct usb_gadget_strings stringtab = {
  50034. + .language = 0x0409, /* en-us */
  50035. + .strings = strings,
  50036. +};
  50037. +
  50038. +/*
  50039. + * config descriptors are also handcrafted. these must agree with code
  50040. + * that sets configurations, and with code managing interfaces and their
  50041. + * altsettings. other complexity may come from:
  50042. + *
  50043. + * - high speed support, including "other speed config" rules
  50044. + * - multiple configurations
  50045. + * - interfaces with alternate settings
  50046. + * - embedded class or vendor-specific descriptors
  50047. + *
  50048. + * this handles high speed, and has a second config that could as easily
  50049. + * have been an alternate interface setting (on most hardware).
  50050. + *
  50051. + * NOTE: to demonstrate (and test) more USB capabilities, this driver
  50052. + * should include an altsetting to test interrupt transfers, including
  50053. + * high bandwidth modes at high speed. (Maybe work like Intel's test
  50054. + * device?)
  50055. + */
  50056. +static int
  50057. +config_buf (struct usb_gadget *gadget, u8 *buf, u8 type, unsigned index)
  50058. +{
  50059. + int len;
  50060. + const struct usb_descriptor_header **function;
  50061. +
  50062. + function = z_function;
  50063. + len = usb_gadget_config_buf (&z_config, buf, USB_BUFSIZ, function);
  50064. + if (len < 0)
  50065. + return len;
  50066. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  50067. + return len;
  50068. +}
  50069. +
  50070. +/*-------------------------------------------------------------------------*/
  50071. +
  50072. +static struct usb_request *
  50073. +alloc_ep_req (struct usb_ep *ep, unsigned length)
  50074. +{
  50075. + struct usb_request *req;
  50076. +
  50077. + req = usb_ep_alloc_request (ep, GFP_ATOMIC);
  50078. + if (req) {
  50079. + req->length = length;
  50080. + req->buf = usb_ep_alloc_buffer (ep, length,
  50081. + &req->dma, GFP_ATOMIC);
  50082. + if (!req->buf) {
  50083. + usb_ep_free_request (ep, req);
  50084. + req = NULL;
  50085. + }
  50086. + }
  50087. + return req;
  50088. +}
  50089. +
  50090. +static void free_ep_req (struct usb_ep *ep, struct usb_request *req)
  50091. +{
  50092. + if (req->buf)
  50093. + usb_ep_free_buffer (ep, req->buf, req->dma, req->length);
  50094. + usb_ep_free_request (ep, req);
  50095. +}
  50096. +
  50097. +/*-------------------------------------------------------------------------*/
  50098. +
  50099. +/* optionally require specific source/sink data patterns */
  50100. +
  50101. +static int
  50102. +check_read_data (
  50103. + struct zero_dev *dev,
  50104. + struct usb_ep *ep,
  50105. + struct usb_request *req
  50106. +)
  50107. +{
  50108. + unsigned i;
  50109. + u8 *buf = req->buf;
  50110. +
  50111. + for (i = 0; i < req->actual; i++, buf++) {
  50112. + switch (pattern) {
  50113. + /* all-zeroes has no synchronization issues */
  50114. + case 0:
  50115. + if (*buf == 0)
  50116. + continue;
  50117. + break;
  50118. + /* mod63 stays in sync with short-terminated transfers,
  50119. + * or otherwise when host and gadget agree on how large
  50120. + * each usb transfer request should be. resync is done
  50121. + * with set_interface or set_config.
  50122. + */
  50123. + case 1:
  50124. + if (*buf == (u8)(i % 63))
  50125. + continue;
  50126. + break;
  50127. + }
  50128. + ERROR (dev, "bad OUT byte, buf [%d] = %d\n", i, *buf);
  50129. + usb_ep_set_halt (ep);
  50130. + return -EINVAL;
  50131. + }
  50132. + return 0;
  50133. +}
  50134. +
  50135. +/*-------------------------------------------------------------------------*/
  50136. +
  50137. +static void zero_reset_config (struct zero_dev *dev)
  50138. +{
  50139. + if (dev->config == 0)
  50140. + return;
  50141. +
  50142. + DBG (dev, "reset config\n");
  50143. +
  50144. + /* just disable endpoints, forcing completion of pending i/o.
  50145. + * all our completion handlers free their requests in this case.
  50146. + */
  50147. + if (dev->in_ep) {
  50148. + usb_ep_disable (dev->in_ep);
  50149. + dev->in_ep = NULL;
  50150. + }
  50151. + if (dev->out_ep) {
  50152. + usb_ep_disable (dev->out_ep);
  50153. + dev->out_ep = NULL;
  50154. + }
  50155. + dev->config = 0;
  50156. + del_timer (&dev->resume);
  50157. +}
  50158. +
  50159. +#define _write(f, buf, sz) (f->f_op->write(f, buf, sz, &f->f_pos))
  50160. +
  50161. +static void
  50162. +zero_isoc_complete (struct usb_ep *ep, struct usb_request *req)
  50163. +{
  50164. + struct zero_dev *dev = ep->driver_data;
  50165. + int status = req->status;
  50166. + int i, j;
  50167. +
  50168. + switch (status) {
  50169. +
  50170. + case 0: /* normal completion? */
  50171. + //printk ("\nzero ---------------> isoc normal completion %d bytes\n", req->actual);
  50172. + for (i=0, j=rbuf_start; i<req->actual; i++) {
  50173. + //printk ("%02x ", ((__u8*)req->buf)[i]);
  50174. + rbuf[j] = ((__u8*)req->buf)[i];
  50175. + j++;
  50176. + if (j >= RBUF_LEN) j=0;
  50177. + }
  50178. + rbuf_start = j;
  50179. + //printk ("\n\n");
  50180. +
  50181. + if (rbuf_len < RBUF_LEN) {
  50182. + rbuf_len += req->actual;
  50183. + if (rbuf_len > RBUF_LEN) {
  50184. + rbuf_len = RBUF_LEN;
  50185. + }
  50186. + }
  50187. +
  50188. + break;
  50189. +
  50190. + /* this endpoint is normally active while we're configured */
  50191. + case -ECONNABORTED: /* hardware forced ep reset */
  50192. + case -ECONNRESET: /* request dequeued */
  50193. + case -ESHUTDOWN: /* disconnect from host */
  50194. + VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status,
  50195. + req->actual, req->length);
  50196. + if (ep == dev->out_ep)
  50197. + check_read_data (dev, ep, req);
  50198. + free_ep_req (ep, req);
  50199. + return;
  50200. +
  50201. + case -EOVERFLOW: /* buffer overrun on read means that
  50202. + * we didn't provide a big enough
  50203. + * buffer.
  50204. + */
  50205. + default:
  50206. +#if 1
  50207. + DBG (dev, "%s complete --> %d, %d/%d\n", ep->name,
  50208. + status, req->actual, req->length);
  50209. +#endif
  50210. + case -EREMOTEIO: /* short read */
  50211. + break;
  50212. + }
  50213. +
  50214. + status = usb_ep_queue (ep, req, GFP_ATOMIC);
  50215. + if (status) {
  50216. + ERROR (dev, "kill %s: resubmit %d bytes --> %d\n",
  50217. + ep->name, req->length, status);
  50218. + usb_ep_set_halt (ep);
  50219. + /* FIXME recover later ... somehow */
  50220. + }
  50221. +}
  50222. +
  50223. +static struct usb_request *
  50224. +zero_start_isoc_ep (struct usb_ep *ep, int gfp_flags)
  50225. +{
  50226. + struct usb_request *req;
  50227. + int status;
  50228. +
  50229. + req = alloc_ep_req (ep, 512);
  50230. + if (!req)
  50231. + return NULL;
  50232. +
  50233. + req->complete = zero_isoc_complete;
  50234. +
  50235. + status = usb_ep_queue (ep, req, gfp_flags);
  50236. + if (status) {
  50237. + struct zero_dev *dev = ep->driver_data;
  50238. +
  50239. + ERROR (dev, "start %s --> %d\n", ep->name, status);
  50240. + free_ep_req (ep, req);
  50241. + req = NULL;
  50242. + }
  50243. +
  50244. + return req;
  50245. +}
  50246. +
  50247. +/* change our operational config. this code must agree with the code
  50248. + * that returns config descriptors, and altsetting code.
  50249. + *
  50250. + * it's also responsible for power management interactions. some
  50251. + * configurations might not work with our current power sources.
  50252. + *
  50253. + * note that some device controller hardware will constrain what this
  50254. + * code can do, perhaps by disallowing more than one configuration or
  50255. + * by limiting configuration choices (like the pxa2xx).
  50256. + */
  50257. +static int
  50258. +zero_set_config (struct zero_dev *dev, unsigned number, int gfp_flags)
  50259. +{
  50260. + int result = 0;
  50261. + struct usb_gadget *gadget = dev->gadget;
  50262. + const struct usb_endpoint_descriptor *d;
  50263. + struct usb_ep *ep;
  50264. +
  50265. + if (number == dev->config)
  50266. + return 0;
  50267. +
  50268. + zero_reset_config (dev);
  50269. +
  50270. + gadget_for_each_ep (ep, gadget) {
  50271. +
  50272. + if (strcmp (ep->name, "ep4") == 0) {
  50273. +
  50274. + d = (struct usb_endpoint_descripter *)&za_23; // isoc ep desc for audio i/f alt setting 6
  50275. + result = usb_ep_enable (ep, d);
  50276. +
  50277. + if (result == 0) {
  50278. + ep->driver_data = dev;
  50279. + dev->in_ep = ep;
  50280. +
  50281. + if (zero_start_isoc_ep (ep, gfp_flags) != 0) {
  50282. +
  50283. + dev->in_ep = ep;
  50284. + continue;
  50285. + }
  50286. +
  50287. + usb_ep_disable (ep);
  50288. + result = -EIO;
  50289. + }
  50290. + }
  50291. +
  50292. + }
  50293. +
  50294. + dev->config = number;
  50295. + return result;
  50296. +}
  50297. +
  50298. +/*-------------------------------------------------------------------------*/
  50299. +
  50300. +static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req)
  50301. +{
  50302. + if (req->status || req->actual != req->length)
  50303. + DBG ((struct zero_dev *) ep->driver_data,
  50304. + "setup complete --> %d, %d/%d\n",
  50305. + req->status, req->actual, req->length);
  50306. +}
  50307. +
  50308. +/*
  50309. + * The setup() callback implements all the ep0 functionality that's
  50310. + * not handled lower down, in hardware or the hardware driver (like
  50311. + * device and endpoint feature flags, and their status). It's all
  50312. + * housekeeping for the gadget function we're implementing. Most of
  50313. + * the work is in config-specific setup.
  50314. + */
  50315. +static int
  50316. +zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
  50317. +{
  50318. + struct zero_dev *dev = get_gadget_data (gadget);
  50319. + struct usb_request *req = dev->req;
  50320. + int value = -EOPNOTSUPP;
  50321. +
  50322. + /* usually this stores reply data in the pre-allocated ep0 buffer,
  50323. + * but config change events will reconfigure hardware.
  50324. + */
  50325. + req->zero = 0;
  50326. + switch (ctrl->bRequest) {
  50327. +
  50328. + case USB_REQ_GET_DESCRIPTOR:
  50329. +
  50330. + switch (ctrl->wValue >> 8) {
  50331. +
  50332. + case USB_DT_DEVICE:
  50333. + value = min (ctrl->wLength, (u16) sizeof device_desc);
  50334. + memcpy (req->buf, &device_desc, value);
  50335. + break;
  50336. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  50337. + case USB_DT_DEVICE_QUALIFIER:
  50338. + if (!gadget->is_dualspeed)
  50339. + break;
  50340. + value = min (ctrl->wLength, (u16) sizeof dev_qualifier);
  50341. + memcpy (req->buf, &dev_qualifier, value);
  50342. + break;
  50343. +
  50344. + case USB_DT_OTHER_SPEED_CONFIG:
  50345. + if (!gadget->is_dualspeed)
  50346. + break;
  50347. + // FALLTHROUGH
  50348. +#endif /* CONFIG_USB_GADGET_DUALSPEED */
  50349. + case USB_DT_CONFIG:
  50350. + value = config_buf (gadget, req->buf,
  50351. + ctrl->wValue >> 8,
  50352. + ctrl->wValue & 0xff);
  50353. + if (value >= 0)
  50354. + value = min (ctrl->wLength, (u16) value);
  50355. + break;
  50356. +
  50357. + case USB_DT_STRING:
  50358. + /* wIndex == language code.
  50359. + * this driver only handles one language, you can
  50360. + * add string tables for other languages, using
  50361. + * any UTF-8 characters
  50362. + */
  50363. + value = usb_gadget_get_string (&stringtab,
  50364. + ctrl->wValue & 0xff, req->buf);
  50365. + if (value >= 0) {
  50366. + value = min (ctrl->wLength, (u16) value);
  50367. + }
  50368. + break;
  50369. + }
  50370. + break;
  50371. +
  50372. + /* currently two configs, two speeds */
  50373. + case USB_REQ_SET_CONFIGURATION:
  50374. + if (ctrl->bRequestType != 0)
  50375. + goto unknown;
  50376. +
  50377. + spin_lock (&dev->lock);
  50378. + value = zero_set_config (dev, ctrl->wValue, GFP_ATOMIC);
  50379. + spin_unlock (&dev->lock);
  50380. + break;
  50381. + case USB_REQ_GET_CONFIGURATION:
  50382. + if (ctrl->bRequestType != USB_DIR_IN)
  50383. + goto unknown;
  50384. + *(u8 *)req->buf = dev->config;
  50385. + value = min (ctrl->wLength, (u16) 1);
  50386. + break;
  50387. +
  50388. + /* until we add altsetting support, or other interfaces,
  50389. + * only 0/0 are possible. pxa2xx only supports 0/0 (poorly)
  50390. + * and already killed pending endpoint I/O.
  50391. + */
  50392. + case USB_REQ_SET_INTERFACE:
  50393. +
  50394. + if (ctrl->bRequestType != USB_RECIP_INTERFACE)
  50395. + goto unknown;
  50396. + spin_lock (&dev->lock);
  50397. + if (dev->config) {
  50398. + u8 config = dev->config;
  50399. +
  50400. + /* resets interface configuration, forgets about
  50401. + * previous transaction state (queued bufs, etc)
  50402. + * and re-inits endpoint state (toggle etc)
  50403. + * no response queued, just zero status == success.
  50404. + * if we had more than one interface we couldn't
  50405. + * use this "reset the config" shortcut.
  50406. + */
  50407. + zero_reset_config (dev);
  50408. + zero_set_config (dev, config, GFP_ATOMIC);
  50409. + value = 0;
  50410. + }
  50411. + spin_unlock (&dev->lock);
  50412. + break;
  50413. + case USB_REQ_GET_INTERFACE:
  50414. + if ((ctrl->bRequestType == 0x21) && (ctrl->wIndex == 0x02)) {
  50415. + value = ctrl->wLength;
  50416. + break;
  50417. + }
  50418. + else {
  50419. + if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
  50420. + goto unknown;
  50421. + if (!dev->config)
  50422. + break;
  50423. + if (ctrl->wIndex != 0) {
  50424. + value = -EDOM;
  50425. + break;
  50426. + }
  50427. + *(u8 *)req->buf = 0;
  50428. + value = min (ctrl->wLength, (u16) 1);
  50429. + }
  50430. + break;
  50431. +
  50432. + /*
  50433. + * These are the same vendor-specific requests supported by
  50434. + * Intel's USB 2.0 compliance test devices. We exceed that
  50435. + * device spec by allowing multiple-packet requests.
  50436. + */
  50437. + case 0x5b: /* control WRITE test -- fill the buffer */
  50438. + if (ctrl->bRequestType != (USB_DIR_OUT|USB_TYPE_VENDOR))
  50439. + goto unknown;
  50440. + if (ctrl->wValue || ctrl->wIndex)
  50441. + break;
  50442. + /* just read that many bytes into the buffer */
  50443. + if (ctrl->wLength > USB_BUFSIZ)
  50444. + break;
  50445. + value = ctrl->wLength;
  50446. + break;
  50447. + case 0x5c: /* control READ test -- return the buffer */
  50448. + if (ctrl->bRequestType != (USB_DIR_IN|USB_TYPE_VENDOR))
  50449. + goto unknown;
  50450. + if (ctrl->wValue || ctrl->wIndex)
  50451. + break;
  50452. + /* expect those bytes are still in the buffer; send back */
  50453. + if (ctrl->wLength > USB_BUFSIZ
  50454. + || ctrl->wLength != req->length)
  50455. + break;
  50456. + value = ctrl->wLength;
  50457. + break;
  50458. +
  50459. + case 0x01: // SET_CUR
  50460. + case 0x02:
  50461. + case 0x03:
  50462. + case 0x04:
  50463. + case 0x05:
  50464. + value = ctrl->wLength;
  50465. + break;
  50466. + case 0x81:
  50467. + switch (ctrl->wValue) {
  50468. + case 0x0201:
  50469. + case 0x0202:
  50470. + ((u8*)req->buf)[0] = 0x00;
  50471. + ((u8*)req->buf)[1] = 0xe3;
  50472. + break;
  50473. + case 0x0300:
  50474. + case 0x0500:
  50475. + ((u8*)req->buf)[0] = 0x00;
  50476. + break;
  50477. + }
  50478. + //((u8*)req->buf)[0] = 0x81;
  50479. + //((u8*)req->buf)[1] = 0x81;
  50480. + value = ctrl->wLength;
  50481. + break;
  50482. + case 0x82:
  50483. + switch (ctrl->wValue) {
  50484. + case 0x0201:
  50485. + case 0x0202:
  50486. + ((u8*)req->buf)[0] = 0x00;
  50487. + ((u8*)req->buf)[1] = 0xc3;
  50488. + break;
  50489. + case 0x0300:
  50490. + case 0x0500:
  50491. + ((u8*)req->buf)[0] = 0x00;
  50492. + break;
  50493. + }
  50494. + //((u8*)req->buf)[0] = 0x82;
  50495. + //((u8*)req->buf)[1] = 0x82;
  50496. + value = ctrl->wLength;
  50497. + break;
  50498. + case 0x83:
  50499. + switch (ctrl->wValue) {
  50500. + case 0x0201:
  50501. + case 0x0202:
  50502. + ((u8*)req->buf)[0] = 0x00;
  50503. + ((u8*)req->buf)[1] = 0x00;
  50504. + break;
  50505. + case 0x0300:
  50506. + ((u8*)req->buf)[0] = 0x60;
  50507. + break;
  50508. + case 0x0500:
  50509. + ((u8*)req->buf)[0] = 0x18;
  50510. + break;
  50511. + }
  50512. + //((u8*)req->buf)[0] = 0x83;
  50513. + //((u8*)req->buf)[1] = 0x83;
  50514. + value = ctrl->wLength;
  50515. + break;
  50516. + case 0x84:
  50517. + switch (ctrl->wValue) {
  50518. + case 0x0201:
  50519. + case 0x0202:
  50520. + ((u8*)req->buf)[0] = 0x00;
  50521. + ((u8*)req->buf)[1] = 0x01;
  50522. + break;
  50523. + case 0x0300:
  50524. + case 0x0500:
  50525. + ((u8*)req->buf)[0] = 0x08;
  50526. + break;
  50527. + }
  50528. + //((u8*)req->buf)[0] = 0x84;
  50529. + //((u8*)req->buf)[1] = 0x84;
  50530. + value = ctrl->wLength;
  50531. + break;
  50532. + case 0x85:
  50533. + ((u8*)req->buf)[0] = 0x85;
  50534. + ((u8*)req->buf)[1] = 0x85;
  50535. + value = ctrl->wLength;
  50536. + break;
  50537. +
  50538. +
  50539. + default:
  50540. +unknown:
  50541. + printk("unknown control req%02x.%02x v%04x i%04x l%d\n",
  50542. + ctrl->bRequestType, ctrl->bRequest,
  50543. + ctrl->wValue, ctrl->wIndex, ctrl->wLength);
  50544. + }
  50545. +
  50546. + /* respond with data transfer before status phase? */
  50547. + if (value >= 0) {
  50548. + req->length = value;
  50549. + req->zero = value < ctrl->wLength
  50550. + && (value % gadget->ep0->maxpacket) == 0;
  50551. + value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);
  50552. + if (value < 0) {
  50553. + DBG (dev, "ep_queue < 0 --> %d\n", value);
  50554. + req->status = 0;
  50555. + zero_setup_complete (gadget->ep0, req);
  50556. + }
  50557. + }
  50558. +
  50559. + /* device either stalls (value < 0) or reports success */
  50560. + return value;
  50561. +}
  50562. +
  50563. +static void
  50564. +zero_disconnect (struct usb_gadget *gadget)
  50565. +{
  50566. + struct zero_dev *dev = get_gadget_data (gadget);
  50567. + unsigned long flags;
  50568. +
  50569. + spin_lock_irqsave (&dev->lock, flags);
  50570. + zero_reset_config (dev);
  50571. +
  50572. + /* a more significant application might have some non-usb
  50573. + * activities to quiesce here, saving resources like power
  50574. + * or pushing the notification up a network stack.
  50575. + */
  50576. + spin_unlock_irqrestore (&dev->lock, flags);
  50577. +
  50578. + /* next we may get setup() calls to enumerate new connections;
  50579. + * or an unbind() during shutdown (including removing module).
  50580. + */
  50581. +}
  50582. +
  50583. +static void
  50584. +zero_autoresume (unsigned long _dev)
  50585. +{
  50586. + struct zero_dev *dev = (struct zero_dev *) _dev;
  50587. + int status;
  50588. +
  50589. + /* normally the host would be woken up for something
  50590. + * more significant than just a timer firing...
  50591. + */
  50592. + if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
  50593. + status = usb_gadget_wakeup (dev->gadget);
  50594. + DBG (dev, "wakeup --> %d\n", status);
  50595. + }
  50596. +}
  50597. +
  50598. +/*-------------------------------------------------------------------------*/
  50599. +
  50600. +static void
  50601. +zero_unbind (struct usb_gadget *gadget)
  50602. +{
  50603. + struct zero_dev *dev = get_gadget_data (gadget);
  50604. +
  50605. + DBG (dev, "unbind\n");
  50606. +
  50607. + /* we've already been disconnected ... no i/o is active */
  50608. + if (dev->req)
  50609. + free_ep_req (gadget->ep0, dev->req);
  50610. + del_timer_sync (&dev->resume);
  50611. + kfree (dev);
  50612. + set_gadget_data (gadget, NULL);
  50613. +}
  50614. +
  50615. +static int
  50616. +zero_bind (struct usb_gadget *gadget)
  50617. +{
  50618. + struct zero_dev *dev;
  50619. + //struct usb_ep *ep;
  50620. +
  50621. + printk("binding\n");
  50622. + /*
  50623. + * DRIVER POLICY CHOICE: you may want to do this differently.
  50624. + * One thing to avoid is reusing a bcdDevice revision code
  50625. + * with different host-visible configurations or behavior
  50626. + * restrictions -- using ep1in/ep2out vs ep1out/ep3in, etc
  50627. + */
  50628. + //device_desc.bcdDevice = __constant_cpu_to_le16 (0x0201);
  50629. +
  50630. +
  50631. + /* ok, we made sense of the hardware ... */
  50632. + dev = kmalloc (sizeof *dev, SLAB_KERNEL);
  50633. + if (!dev)
  50634. + return -ENOMEM;
  50635. + memset (dev, 0, sizeof *dev);
  50636. + spin_lock_init (&dev->lock);
  50637. + dev->gadget = gadget;
  50638. + set_gadget_data (gadget, dev);
  50639. +
  50640. + /* preallocate control response and buffer */
  50641. + dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL);
  50642. + if (!dev->req)
  50643. + goto enomem;
  50644. + dev->req->buf = usb_ep_alloc_buffer (gadget->ep0, USB_BUFSIZ,
  50645. + &dev->req->dma, GFP_KERNEL);
  50646. + if (!dev->req->buf)
  50647. + goto enomem;
  50648. +
  50649. + dev->req->complete = zero_setup_complete;
  50650. +
  50651. + device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
  50652. +
  50653. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  50654. + /* assume ep0 uses the same value for both speeds ... */
  50655. + dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
  50656. +
  50657. + /* and that all endpoints are dual-speed */
  50658. + //hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
  50659. + //hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
  50660. +#endif
  50661. +
  50662. + usb_gadget_set_selfpowered (gadget);
  50663. +
  50664. + init_timer (&dev->resume);
  50665. + dev->resume.function = zero_autoresume;
  50666. + dev->resume.data = (unsigned long) dev;
  50667. +
  50668. + gadget->ep0->driver_data = dev;
  50669. +
  50670. + INFO (dev, "%s, version: " DRIVER_VERSION "\n", longname);
  50671. + INFO (dev, "using %s, OUT %s IN %s\n", gadget->name,
  50672. + EP_OUT_NAME, EP_IN_NAME);
  50673. +
  50674. + snprintf (manufacturer, sizeof manufacturer,
  50675. + UTS_SYSNAME " " UTS_RELEASE " with %s",
  50676. + gadget->name);
  50677. +
  50678. + return 0;
  50679. +
  50680. +enomem:
  50681. + zero_unbind (gadget);
  50682. + return -ENOMEM;
  50683. +}
  50684. +
  50685. +/*-------------------------------------------------------------------------*/
  50686. +
  50687. +static void
  50688. +zero_suspend (struct usb_gadget *gadget)
  50689. +{
  50690. + struct zero_dev *dev = get_gadget_data (gadget);
  50691. +
  50692. + if (gadget->speed == USB_SPEED_UNKNOWN)
  50693. + return;
  50694. +
  50695. + if (autoresume) {
  50696. + mod_timer (&dev->resume, jiffies + (HZ * autoresume));
  50697. + DBG (dev, "suspend, wakeup in %d seconds\n", autoresume);
  50698. + } else
  50699. + DBG (dev, "suspend\n");
  50700. +}
  50701. +
  50702. +static void
  50703. +zero_resume (struct usb_gadget *gadget)
  50704. +{
  50705. + struct zero_dev *dev = get_gadget_data (gadget);
  50706. +
  50707. + DBG (dev, "resume\n");
  50708. + del_timer (&dev->resume);
  50709. +}
  50710. +
  50711. +
  50712. +/*-------------------------------------------------------------------------*/
  50713. +
  50714. +static struct usb_gadget_driver zero_driver = {
  50715. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  50716. + .speed = USB_SPEED_HIGH,
  50717. +#else
  50718. + .speed = USB_SPEED_FULL,
  50719. +#endif
  50720. + .function = (char *) longname,
  50721. + .bind = zero_bind,
  50722. + .unbind = zero_unbind,
  50723. +
  50724. + .setup = zero_setup,
  50725. + .disconnect = zero_disconnect,
  50726. +
  50727. + .suspend = zero_suspend,
  50728. + .resume = zero_resume,
  50729. +
  50730. + .driver = {
  50731. + .name = (char *) shortname,
  50732. + // .shutdown = ...
  50733. + // .suspend = ...
  50734. + // .resume = ...
  50735. + },
  50736. +};
  50737. +
  50738. +MODULE_AUTHOR ("David Brownell");
  50739. +MODULE_LICENSE ("Dual BSD/GPL");
  50740. +
  50741. +static struct proc_dir_entry *pdir, *pfile;
  50742. +
  50743. +static int isoc_read_data (char *page, char **start,
  50744. + off_t off, int count,
  50745. + int *eof, void *data)
  50746. +{
  50747. + int i;
  50748. + static int c = 0;
  50749. + static int done = 0;
  50750. + static int s = 0;
  50751. +
  50752. +/*
  50753. + printk ("\ncount: %d\n", count);
  50754. + printk ("rbuf_start: %d\n", rbuf_start);
  50755. + printk ("rbuf_len: %d\n", rbuf_len);
  50756. + printk ("off: %d\n", off);
  50757. + printk ("start: %p\n\n", *start);
  50758. +*/
  50759. + if (done) {
  50760. + c = 0;
  50761. + done = 0;
  50762. + *eof = 1;
  50763. + return 0;
  50764. + }
  50765. +
  50766. + if (c == 0) {
  50767. + if (rbuf_len == RBUF_LEN)
  50768. + s = rbuf_start;
  50769. + else s = 0;
  50770. + }
  50771. +
  50772. + for (i=0; i<count && c<rbuf_len; i++, c++) {
  50773. + page[i] = rbuf[(c+s) % RBUF_LEN];
  50774. + }
  50775. + *start = page;
  50776. +
  50777. + if (c >= rbuf_len) {
  50778. + *eof = 1;
  50779. + done = 1;
  50780. + }
  50781. +
  50782. +
  50783. + return i;
  50784. +}
  50785. +
  50786. +static int __init init (void)
  50787. +{
  50788. +
  50789. + int retval = 0;
  50790. +
  50791. + pdir = proc_mkdir("isoc_test", NULL);
  50792. + if(pdir == NULL) {
  50793. + retval = -ENOMEM;
  50794. + printk("Error creating dir\n");
  50795. + goto done;
  50796. + }
  50797. + pdir->owner = THIS_MODULE;
  50798. +
  50799. + pfile = create_proc_read_entry("isoc_data",
  50800. + 0444, pdir,
  50801. + isoc_read_data,
  50802. + NULL);
  50803. + if (pfile == NULL) {
  50804. + retval = -ENOMEM;
  50805. + printk("Error creating file\n");
  50806. + goto no_file;
  50807. + }
  50808. + pfile->owner = THIS_MODULE;
  50809. +
  50810. + return usb_gadget_register_driver (&zero_driver);
  50811. +
  50812. + no_file:
  50813. + remove_proc_entry("isoc_data", NULL);
  50814. + done:
  50815. + return retval;
  50816. +}
  50817. +module_init (init);
  50818. +
  50819. +static void __exit cleanup (void)
  50820. +{
  50821. +
  50822. + usb_gadget_unregister_driver (&zero_driver);
  50823. +
  50824. + remove_proc_entry("isoc_data", pdir);
  50825. + remove_proc_entry("isoc_test", NULL);
  50826. +}
  50827. +module_exit (cleanup);
  50828. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_cfi_common.h linux-3.12.11/drivers/usb/host/dwc_otg/dwc_cfi_common.h
  50829. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_cfi_common.h 1970-01-01 01:00:00.000000000 +0100
  50830. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_cfi_common.h 2014-02-18 11:52:14.000000000 +0100
  50831. @@ -0,0 +1,142 @@
  50832. +/* ==========================================================================
  50833. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  50834. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  50835. + * otherwise expressly agreed to in writing between Synopsys and you.
  50836. + *
  50837. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  50838. + * any End User Software License Agreement or Agreement for Licensed Product
  50839. + * with Synopsys or any supplement thereto. You are permitted to use and
  50840. + * redistribute this Software in source and binary forms, with or without
  50841. + * modification, provided that redistributions of source code must retain this
  50842. + * notice. You may not view, use, disclose, copy or distribute this file or
  50843. + * any information contained herein except pursuant to this license grant from
  50844. + * Synopsys. If you do not agree with this notice, including the disclaimer
  50845. + * below, then you are not authorized to use the Software.
  50846. + *
  50847. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  50848. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50849. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  50850. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  50851. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  50852. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  50853. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  50854. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  50855. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50856. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  50857. + * DAMAGE.
  50858. + * ========================================================================== */
  50859. +
  50860. +#if !defined(__DWC_CFI_COMMON_H__)
  50861. +#define __DWC_CFI_COMMON_H__
  50862. +
  50863. +//#include <linux/types.h>
  50864. +
  50865. +/**
  50866. + * @file
  50867. + *
  50868. + * This file contains the CFI specific common constants, interfaces
  50869. + * (functions and macros) and structures for Linux. No PCD specific
  50870. + * data structure or definition is to be included in this file.
  50871. + *
  50872. + */
  50873. +
  50874. +/** This is a request for all Core Features */
  50875. +#define VEN_CORE_GET_FEATURES 0xB1
  50876. +
  50877. +/** This is a request to get the value of a specific Core Feature */
  50878. +#define VEN_CORE_GET_FEATURE 0xB2
  50879. +
  50880. +/** This command allows the host to set the value of a specific Core Feature */
  50881. +#define VEN_CORE_SET_FEATURE 0xB3
  50882. +
  50883. +/** This command allows the host to set the default values of
  50884. + * either all or any specific Core Feature
  50885. + */
  50886. +#define VEN_CORE_RESET_FEATURES 0xB4
  50887. +
  50888. +/** This command forces the PCD to write the deferred values of a Core Features */
  50889. +#define VEN_CORE_ACTIVATE_FEATURES 0xB5
  50890. +
  50891. +/** This request reads a DWORD value from a register at the specified offset */
  50892. +#define VEN_CORE_READ_REGISTER 0xB6
  50893. +
  50894. +/** This request writes a DWORD value into a register at the specified offset */
  50895. +#define VEN_CORE_WRITE_REGISTER 0xB7
  50896. +
  50897. +/** This structure is the header of the Core Features dataset returned to
  50898. + * the Host
  50899. + */
  50900. +struct cfi_all_features_header {
  50901. +/** The features header structure length is */
  50902. +#define CFI_ALL_FEATURES_HDR_LEN 8
  50903. + /**
  50904. + * The total length of the features dataset returned to the Host
  50905. + */
  50906. + uint16_t wTotalLen;
  50907. +
  50908. + /**
  50909. + * CFI version number inBinary-Coded Decimal (i.e., 1.00 is 100H).
  50910. + * This field identifies the version of the CFI Specification with which
  50911. + * the device is compliant.
  50912. + */
  50913. + uint16_t wVersion;
  50914. +
  50915. + /** The ID of the Core */
  50916. + uint16_t wCoreID;
  50917. +#define CFI_CORE_ID_UDC 1
  50918. +#define CFI_CORE_ID_OTG 2
  50919. +#define CFI_CORE_ID_WUDEV 3
  50920. +
  50921. + /** Number of features returned by VEN_CORE_GET_FEATURES request */
  50922. + uint16_t wNumFeatures;
  50923. +} UPACKED;
  50924. +
  50925. +typedef struct cfi_all_features_header cfi_all_features_header_t;
  50926. +
  50927. +/** This structure is a header of the Core Feature descriptor dataset returned to
  50928. + * the Host after the VEN_CORE_GET_FEATURES request
  50929. + */
  50930. +struct cfi_feature_desc_header {
  50931. +#define CFI_FEATURE_DESC_HDR_LEN 8
  50932. +
  50933. + /** The feature ID */
  50934. + uint16_t wFeatureID;
  50935. +
  50936. + /** Length of this feature descriptor in bytes - including the
  50937. + * length of the feature name string
  50938. + */
  50939. + uint16_t wLength;
  50940. +
  50941. + /** The data length of this feature in bytes */
  50942. + uint16_t wDataLength;
  50943. +
  50944. + /**
  50945. + * Attributes of this features
  50946. + * D0: Access rights
  50947. + * 0 - Read/Write
  50948. + * 1 - Read only
  50949. + */
  50950. + uint8_t bmAttributes;
  50951. +#define CFI_FEATURE_ATTR_RO 1
  50952. +#define CFI_FEATURE_ATTR_RW 0
  50953. +
  50954. + /** Length of the feature name in bytes */
  50955. + uint8_t bNameLen;
  50956. +
  50957. + /** The feature name buffer */
  50958. + //uint8_t *name;
  50959. +} UPACKED;
  50960. +
  50961. +typedef struct cfi_feature_desc_header cfi_feature_desc_header_t;
  50962. +
  50963. +/**
  50964. + * This structure describes a NULL terminated string referenced by its id field.
  50965. + * It is very similar to usb_string structure but has the id field type set to 16-bit.
  50966. + */
  50967. +struct cfi_string {
  50968. + uint16_t id;
  50969. + const uint8_t *s;
  50970. +};
  50971. +typedef struct cfi_string cfi_string_t;
  50972. +
  50973. +#endif
  50974. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_adp.c linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_adp.c
  50975. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_adp.c 1970-01-01 01:00:00.000000000 +0100
  50976. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_adp.c 2014-02-18 11:52:14.000000000 +0100
  50977. @@ -0,0 +1,854 @@
  50978. +/* ==========================================================================
  50979. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.c $
  50980. + * $Revision: #12 $
  50981. + * $Date: 2011/10/26 $
  50982. + * $Change: 1873028 $
  50983. + *
  50984. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  50985. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  50986. + * otherwise expressly agreed to in writing between Synopsys and you.
  50987. + *
  50988. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  50989. + * any End User Software License Agreement or Agreement for Licensed Product
  50990. + * with Synopsys or any supplement thereto. You are permitted to use and
  50991. + * redistribute this Software in source and binary forms, with or without
  50992. + * modification, provided that redistributions of source code must retain this
  50993. + * notice. You may not view, use, disclose, copy or distribute this file or
  50994. + * any information contained herein except pursuant to this license grant from
  50995. + * Synopsys. If you do not agree with this notice, including the disclaimer
  50996. + * below, then you are not authorized to use the Software.
  50997. + *
  50998. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  50999. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  51000. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51001. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  51002. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  51003. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  51004. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  51005. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  51006. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  51007. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  51008. + * DAMAGE.
  51009. + * ========================================================================== */
  51010. +
  51011. +#include "dwc_os.h"
  51012. +#include "dwc_otg_regs.h"
  51013. +#include "dwc_otg_cil.h"
  51014. +#include "dwc_otg_adp.h"
  51015. +
  51016. +/** @file
  51017. + *
  51018. + * This file contains the most of the Attach Detect Protocol implementation for
  51019. + * the driver to support OTG Rev2.0.
  51020. + *
  51021. + */
  51022. +
  51023. +void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value)
  51024. +{
  51025. + adpctl_data_t adpctl;
  51026. +
  51027. + adpctl.d32 = value;
  51028. + adpctl.b.ar = 0x2;
  51029. +
  51030. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  51031. +
  51032. + while (adpctl.b.ar) {
  51033. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  51034. + }
  51035. +
  51036. +}
  51037. +
  51038. +/**
  51039. + * Function is called to read ADP registers
  51040. + */
  51041. +uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if)
  51042. +{
  51043. + adpctl_data_t adpctl;
  51044. +
  51045. + adpctl.d32 = 0;
  51046. + adpctl.b.ar = 0x1;
  51047. +
  51048. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  51049. +
  51050. + while (adpctl.b.ar) {
  51051. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  51052. + }
  51053. +
  51054. + return adpctl.d32;
  51055. +}
  51056. +
  51057. +/**
  51058. + * Function is called to read ADPCTL register and filter Write-clear bits
  51059. + */
  51060. +uint32_t dwc_otg_adp_read_reg_filter(dwc_otg_core_if_t * core_if)
  51061. +{
  51062. + adpctl_data_t adpctl;
  51063. +
  51064. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51065. + adpctl.b.adp_tmout_int = 0;
  51066. + adpctl.b.adp_prb_int = 0;
  51067. + adpctl.b.adp_tmout_int = 0;
  51068. +
  51069. + return adpctl.d32;
  51070. +}
  51071. +
  51072. +/**
  51073. + * Function is called to write ADP registers
  51074. + */
  51075. +void dwc_otg_adp_modify_reg(dwc_otg_core_if_t * core_if, uint32_t clr,
  51076. + uint32_t set)
  51077. +{
  51078. + dwc_otg_adp_write_reg(core_if,
  51079. + (dwc_otg_adp_read_reg(core_if) & (~clr)) | set);
  51080. +}
  51081. +
  51082. +static void adp_sense_timeout(void *ptr)
  51083. +{
  51084. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  51085. + core_if->adp.sense_timer_started = 0;
  51086. + DWC_PRINTF("ADP SENSE TIMEOUT\n");
  51087. + if (core_if->adp_enable) {
  51088. + dwc_otg_adp_sense_stop(core_if);
  51089. + dwc_otg_adp_probe_start(core_if);
  51090. + }
  51091. +}
  51092. +
  51093. +/**
  51094. + * This function is called when the ADP vbus timer expires. Timeout is 1.1s.
  51095. + */
  51096. +static void adp_vbuson_timeout(void *ptr)
  51097. +{
  51098. + gpwrdn_data_t gpwrdn;
  51099. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  51100. + hprt0_data_t hprt0 = {.d32 = 0 };
  51101. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  51102. + DWC_PRINTF("%s: 1.1 seconds expire after turning on VBUS\n",__FUNCTION__);
  51103. + if (core_if) {
  51104. + core_if->adp.vbuson_timer_started = 0;
  51105. + /* Turn off vbus */
  51106. + hprt0.b.prtpwr = 1;
  51107. + DWC_MODIFY_REG32(core_if->host_if->hprt0, hprt0.d32, 0);
  51108. + gpwrdn.d32 = 0;
  51109. +
  51110. + /* Power off the core */
  51111. + if (core_if->power_down == 2) {
  51112. + /* Enable Wakeup Logic */
  51113. +// gpwrdn.b.wkupactiv = 1;
  51114. + gpwrdn.b.pmuactv = 0;
  51115. + gpwrdn.b.pwrdnrstn = 1;
  51116. + gpwrdn.b.pwrdnclmp = 1;
  51117. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  51118. + gpwrdn.d32);
  51119. +
  51120. + /* Suspend the Phy Clock */
  51121. + pcgcctl.b.stoppclk = 1;
  51122. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  51123. +
  51124. + /* Switch on VDD */
  51125. +// gpwrdn.b.wkupactiv = 1;
  51126. + gpwrdn.b.pmuactv = 1;
  51127. + gpwrdn.b.pwrdnrstn = 1;
  51128. + gpwrdn.b.pwrdnclmp = 1;
  51129. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  51130. + gpwrdn.d32);
  51131. + } else {
  51132. + /* Enable Power Down Logic */
  51133. + gpwrdn.b.pmuintsel = 1;
  51134. + gpwrdn.b.pmuactv = 1;
  51135. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51136. + }
  51137. +
  51138. + /* Power off the core */
  51139. + if (core_if->power_down == 2) {
  51140. + gpwrdn.d32 = 0;
  51141. + gpwrdn.b.pwrdnswtch = 1;
  51142. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn,
  51143. + gpwrdn.d32, 0);
  51144. + }
  51145. +
  51146. + /* Unmask SRP detected interrupt from Power Down Logic */
  51147. + gpwrdn.d32 = 0;
  51148. + gpwrdn.b.srp_det_msk = 1;
  51149. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51150. +
  51151. + dwc_otg_adp_probe_start(core_if);
  51152. + dwc_otg_dump_global_registers(core_if);
  51153. + dwc_otg_dump_host_registers(core_if);
  51154. + }
  51155. +
  51156. +}
  51157. +
  51158. +/**
  51159. + * Start the ADP Initial Probe timer to detect if Port Connected interrupt is
  51160. + * not asserted within 1.1 seconds.
  51161. + *
  51162. + * @param core_if the pointer to core_if strucure.
  51163. + */
  51164. +void dwc_otg_adp_vbuson_timer_start(dwc_otg_core_if_t * core_if)
  51165. +{
  51166. + core_if->adp.vbuson_timer_started = 1;
  51167. + if (core_if->adp.vbuson_timer)
  51168. + {
  51169. + DWC_PRINTF("SCHEDULING VBUSON TIMER\n");
  51170. + /* 1.1 secs + 60ms necessary for cil_hcd_start*/
  51171. + DWC_TIMER_SCHEDULE(core_if->adp.vbuson_timer, 1160);
  51172. + } else {
  51173. + DWC_WARN("VBUSON_TIMER = %p\n",core_if->adp.vbuson_timer);
  51174. + }
  51175. +}
  51176. +
  51177. +#if 0
  51178. +/**
  51179. + * Masks all DWC OTG core interrupts
  51180. + *
  51181. + */
  51182. +static void mask_all_interrupts(dwc_otg_core_if_t * core_if)
  51183. +{
  51184. + int i;
  51185. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  51186. +
  51187. + /* Mask Host Interrupts */
  51188. +
  51189. + /* Clear and disable HCINTs */
  51190. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  51191. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk, 0);
  51192. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcint, 0xFFFFFFFF);
  51193. +
  51194. + }
  51195. +
  51196. + /* Clear and disable HAINT */
  51197. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk, 0x0000);
  51198. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haint, 0xFFFFFFFF);
  51199. +
  51200. + /* Mask Device Interrupts */
  51201. + if (!core_if->multiproc_int_enable) {
  51202. + /* Clear and disable IN Endpoint interrupts */
  51203. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, 0);
  51204. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  51205. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  51206. + diepint, 0xFFFFFFFF);
  51207. + }
  51208. +
  51209. + /* Clear and disable OUT Endpoint interrupts */
  51210. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, 0);
  51211. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  51212. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  51213. + doepint, 0xFFFFFFFF);
  51214. + }
  51215. +
  51216. + /* Clear and disable DAINT */
  51217. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daint,
  51218. + 0xFFFFFFFF);
  51219. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, 0);
  51220. + } else {
  51221. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  51222. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  51223. + diepeachintmsk[i], 0);
  51224. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  51225. + diepint, 0xFFFFFFFF);
  51226. + }
  51227. +
  51228. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  51229. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  51230. + doepeachintmsk[i], 0);
  51231. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  51232. + doepint, 0xFFFFFFFF);
  51233. + }
  51234. +
  51235. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  51236. + 0);
  51237. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachint,
  51238. + 0xFFFFFFFF);
  51239. +
  51240. + }
  51241. +
  51242. + /* Disable interrupts */
  51243. + ahbcfg.b.glblintrmsk = 1;
  51244. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  51245. +
  51246. + /* Disable all interrupts. */
  51247. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  51248. +
  51249. + /* Clear any pending interrupts */
  51250. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  51251. +
  51252. + /* Clear any pending OTG Interrupts */
  51253. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, 0xFFFFFFFF);
  51254. +}
  51255. +
  51256. +/**
  51257. + * Unmask Port Connection Detected interrupt
  51258. + *
  51259. + */
  51260. +static void unmask_conn_det_intr(dwc_otg_core_if_t * core_if)
  51261. +{
  51262. + gintmsk_data_t gintmsk = {.d32 = 0,.b.portintr = 1 };
  51263. +
  51264. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  51265. +}
  51266. +#endif
  51267. +
  51268. +/**
  51269. + * Starts the ADP Probing
  51270. + *
  51271. + * @param core_if the pointer to core_if structure.
  51272. + */
  51273. +uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if)
  51274. +{
  51275. +
  51276. + adpctl_data_t adpctl = {.d32 = 0};
  51277. + gpwrdn_data_t gpwrdn;
  51278. +#if 0
  51279. + adpctl_data_t adpctl_int = {.d32 = 0, .b.adp_prb_int = 1,
  51280. + .b.adp_sns_int = 1, b.adp_tmout_int};
  51281. +#endif
  51282. + dwc_otg_disable_global_interrupts(core_if);
  51283. + DWC_PRINTF("ADP Probe Start\n");
  51284. + core_if->adp.probe_enabled = 1;
  51285. +
  51286. + adpctl.b.adpres = 1;
  51287. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51288. +
  51289. + while (adpctl.b.adpres) {
  51290. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51291. + }
  51292. +
  51293. + adpctl.d32 = 0;
  51294. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51295. +
  51296. + /* In Host mode unmask SRP detected interrupt */
  51297. + gpwrdn.d32 = 0;
  51298. + gpwrdn.b.sts_chngint_msk = 1;
  51299. + if (!gpwrdn.b.idsts) {
  51300. + gpwrdn.b.srp_det_msk = 1;
  51301. + }
  51302. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51303. +
  51304. + adpctl.b.adp_tmout_int_msk = 1;
  51305. + adpctl.b.adp_prb_int_msk = 1;
  51306. + adpctl.b.prb_dschg = 1;
  51307. + adpctl.b.prb_delta = 1;
  51308. + adpctl.b.prb_per = 1;
  51309. + adpctl.b.adpen = 1;
  51310. + adpctl.b.enaprb = 1;
  51311. +
  51312. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51313. + DWC_PRINTF("ADP Probe Finish\n");
  51314. + return 0;
  51315. +}
  51316. +
  51317. +/**
  51318. + * Starts the ADP Sense timer to detect if ADP Sense interrupt is not asserted
  51319. + * within 3 seconds.
  51320. + *
  51321. + * @param core_if the pointer to core_if strucure.
  51322. + */
  51323. +void dwc_otg_adp_sense_timer_start(dwc_otg_core_if_t * core_if)
  51324. +{
  51325. + core_if->adp.sense_timer_started = 1;
  51326. + DWC_TIMER_SCHEDULE(core_if->adp.sense_timer, 3000 /* 3 secs */ );
  51327. +}
  51328. +
  51329. +/**
  51330. + * Starts the ADP Sense
  51331. + *
  51332. + * @param core_if the pointer to core_if strucure.
  51333. + */
  51334. +uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if)
  51335. +{
  51336. + adpctl_data_t adpctl;
  51337. +
  51338. + DWC_PRINTF("ADP Sense Start\n");
  51339. +
  51340. + /* Unmask ADP sense interrupt and mask all other from the core */
  51341. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  51342. + adpctl.b.adp_sns_int_msk = 1;
  51343. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51344. + dwc_otg_disable_global_interrupts(core_if); // vahrama
  51345. +
  51346. + /* Set ADP reset bit*/
  51347. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  51348. + adpctl.b.adpres = 1;
  51349. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51350. +
  51351. + while (adpctl.b.adpres) {
  51352. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51353. + }
  51354. +
  51355. + adpctl.b.adpres = 0;
  51356. + adpctl.b.adpen = 1;
  51357. + adpctl.b.enasns = 1;
  51358. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51359. +
  51360. + dwc_otg_adp_sense_timer_start(core_if);
  51361. +
  51362. + return 0;
  51363. +}
  51364. +
  51365. +/**
  51366. + * Stops the ADP Probing
  51367. + *
  51368. + * @param core_if the pointer to core_if strucure.
  51369. + */
  51370. +uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if)
  51371. +{
  51372. +
  51373. + adpctl_data_t adpctl;
  51374. + DWC_PRINTF("Stop ADP probe\n");
  51375. + core_if->adp.probe_enabled = 0;
  51376. + core_if->adp.probe_counter = 0;
  51377. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51378. +
  51379. + adpctl.b.adpen = 0;
  51380. + adpctl.b.adp_prb_int = 1;
  51381. + adpctl.b.adp_tmout_int = 1;
  51382. + adpctl.b.adp_sns_int = 1;
  51383. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51384. +
  51385. + return 0;
  51386. +}
  51387. +
  51388. +/**
  51389. + * Stops the ADP Sensing
  51390. + *
  51391. + * @param core_if the pointer to core_if strucure.
  51392. + */
  51393. +uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if)
  51394. +{
  51395. + adpctl_data_t adpctl;
  51396. +
  51397. + core_if->adp.sense_enabled = 0;
  51398. +
  51399. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  51400. + adpctl.b.enasns = 0;
  51401. + adpctl.b.adp_sns_int = 1;
  51402. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51403. +
  51404. + return 0;
  51405. +}
  51406. +
  51407. +/**
  51408. + * Called to turn on the VBUS after initial ADP probe in host mode.
  51409. + * If port power was already enabled in cil_hcd_start function then
  51410. + * only schedule a timer.
  51411. + *
  51412. + * @param core_if the pointer to core_if structure.
  51413. + */
  51414. +void dwc_otg_adp_turnon_vbus(dwc_otg_core_if_t * core_if)
  51415. +{
  51416. + hprt0_data_t hprt0 = {.d32 = 0 };
  51417. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  51418. + DWC_PRINTF("Turn on VBUS for 1.1s, port power is %d\n", hprt0.b.prtpwr);
  51419. +
  51420. + if (hprt0.b.prtpwr == 0) {
  51421. + hprt0.b.prtpwr = 1;
  51422. + //DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  51423. + }
  51424. +
  51425. + dwc_otg_adp_vbuson_timer_start(core_if);
  51426. +}
  51427. +
  51428. +/**
  51429. + * Called right after driver is loaded
  51430. + * to perform initial actions for ADP
  51431. + *
  51432. + * @param core_if the pointer to core_if structure.
  51433. + * @param is_host - flag for current mode of operation either from GINTSTS or GPWRDN
  51434. + */
  51435. +void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host)
  51436. +{
  51437. + gpwrdn_data_t gpwrdn;
  51438. +
  51439. + DWC_PRINTF("ADP Initial Start\n");
  51440. + core_if->adp.adp_started = 1;
  51441. +
  51442. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  51443. + dwc_otg_disable_global_interrupts(core_if);
  51444. + if (is_host) {
  51445. + DWC_PRINTF("HOST MODE\n");
  51446. + /* Enable Power Down Logic Interrupt*/
  51447. + gpwrdn.d32 = 0;
  51448. + gpwrdn.b.pmuintsel = 1;
  51449. + gpwrdn.b.pmuactv = 1;
  51450. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51451. + /* Initialize first ADP probe to obtain Ramp Time value */
  51452. + core_if->adp.initial_probe = 1;
  51453. + dwc_otg_adp_probe_start(core_if);
  51454. + } else {
  51455. + gotgctl_data_t gotgctl;
  51456. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  51457. + DWC_PRINTF("DEVICE MODE\n");
  51458. + if (gotgctl.b.bsesvld == 0) {
  51459. + /* Enable Power Down Logic Interrupt*/
  51460. + gpwrdn.d32 = 0;
  51461. + DWC_PRINTF("VBUS is not valid - start ADP probe\n");
  51462. + gpwrdn.b.pmuintsel = 1;
  51463. + gpwrdn.b.pmuactv = 1;
  51464. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51465. + core_if->adp.initial_probe = 1;
  51466. + dwc_otg_adp_probe_start(core_if);
  51467. + } else {
  51468. + DWC_PRINTF("VBUS is valid - initialize core as a Device\n");
  51469. + core_if->op_state = B_PERIPHERAL;
  51470. + dwc_otg_core_init(core_if);
  51471. + dwc_otg_enable_global_interrupts(core_if);
  51472. + cil_pcd_start(core_if);
  51473. + dwc_otg_dump_global_registers(core_if);
  51474. + dwc_otg_dump_dev_registers(core_if);
  51475. + }
  51476. + }
  51477. +}
  51478. +
  51479. +void dwc_otg_adp_init(dwc_otg_core_if_t * core_if)
  51480. +{
  51481. + core_if->adp.adp_started = 0;
  51482. + core_if->adp.initial_probe = 0;
  51483. + core_if->adp.probe_timer_values[0] = -1;
  51484. + core_if->adp.probe_timer_values[1] = -1;
  51485. + core_if->adp.probe_enabled = 0;
  51486. + core_if->adp.sense_enabled = 0;
  51487. + core_if->adp.sense_timer_started = 0;
  51488. + core_if->adp.vbuson_timer_started = 0;
  51489. + core_if->adp.probe_counter = 0;
  51490. + core_if->adp.gpwrdn = 0;
  51491. + core_if->adp.attached = DWC_OTG_ADP_UNKOWN;
  51492. + /* Initialize timers */
  51493. + core_if->adp.sense_timer =
  51494. + DWC_TIMER_ALLOC("ADP SENSE TIMER", adp_sense_timeout, core_if);
  51495. + core_if->adp.vbuson_timer =
  51496. + DWC_TIMER_ALLOC("ADP VBUS ON TIMER", adp_vbuson_timeout, core_if);
  51497. + if (!core_if->adp.sense_timer || !core_if->adp.vbuson_timer)
  51498. + {
  51499. + DWC_ERROR("Could not allocate memory for ADP timers\n");
  51500. + }
  51501. +}
  51502. +
  51503. +void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if)
  51504. +{
  51505. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  51506. + gpwrdn.b.pmuintsel = 1;
  51507. + gpwrdn.b.pmuactv = 1;
  51508. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  51509. +
  51510. + if (core_if->adp.probe_enabled)
  51511. + dwc_otg_adp_probe_stop(core_if);
  51512. + if (core_if->adp.sense_enabled)
  51513. + dwc_otg_adp_sense_stop(core_if);
  51514. + if (core_if->adp.sense_timer_started)
  51515. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  51516. + if (core_if->adp.vbuson_timer_started)
  51517. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  51518. + DWC_TIMER_FREE(core_if->adp.sense_timer);
  51519. + DWC_TIMER_FREE(core_if->adp.vbuson_timer);
  51520. +}
  51521. +
  51522. +/////////////////////////////////////////////////////////////////////
  51523. +////////////// ADP Interrupt Handlers ///////////////////////////////
  51524. +/////////////////////////////////////////////////////////////////////
  51525. +/**
  51526. + * This function sets Ramp Timer values
  51527. + */
  51528. +static uint32_t set_timer_value(dwc_otg_core_if_t * core_if, uint32_t val)
  51529. +{
  51530. + if (core_if->adp.probe_timer_values[0] == -1) {
  51531. + core_if->adp.probe_timer_values[0] = val;
  51532. + core_if->adp.probe_timer_values[1] = -1;
  51533. + return 1;
  51534. + } else {
  51535. + core_if->adp.probe_timer_values[1] =
  51536. + core_if->adp.probe_timer_values[0];
  51537. + core_if->adp.probe_timer_values[0] = val;
  51538. + return 0;
  51539. + }
  51540. +}
  51541. +
  51542. +/**
  51543. + * This function compares Ramp Timer values
  51544. + */
  51545. +static uint32_t compare_timer_values(dwc_otg_core_if_t * core_if)
  51546. +{
  51547. + uint32_t diff;
  51548. + if (core_if->adp.probe_timer_values[0]>=core_if->adp.probe_timer_values[1])
  51549. + diff = core_if->adp.probe_timer_values[0]-core_if->adp.probe_timer_values[1];
  51550. + else
  51551. + diff = core_if->adp.probe_timer_values[1]-core_if->adp.probe_timer_values[0];
  51552. + if(diff < 2) {
  51553. + return 0;
  51554. + } else {
  51555. + return 1;
  51556. + }
  51557. +}
  51558. +
  51559. +/**
  51560. + * This function handles ADP Probe Interrupts
  51561. + */
  51562. +static int32_t dwc_otg_adp_handle_prb_intr(dwc_otg_core_if_t * core_if,
  51563. + uint32_t val)
  51564. +{
  51565. + adpctl_data_t adpctl = {.d32 = 0 };
  51566. + gpwrdn_data_t gpwrdn, temp;
  51567. + adpctl.d32 = val;
  51568. +
  51569. + temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51570. + core_if->adp.probe_counter++;
  51571. + core_if->adp.gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51572. + if (adpctl.b.rtim == 0 && !temp.b.idsts){
  51573. + DWC_PRINTF("RTIM value is 0\n");
  51574. + goto exit;
  51575. + }
  51576. + if (set_timer_value(core_if, adpctl.b.rtim) &&
  51577. + core_if->adp.initial_probe) {
  51578. + core_if->adp.initial_probe = 0;
  51579. + dwc_otg_adp_probe_stop(core_if);
  51580. + gpwrdn.d32 = 0;
  51581. + gpwrdn.b.pmuactv = 1;
  51582. + gpwrdn.b.pmuintsel = 1;
  51583. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  51584. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  51585. +
  51586. + /* check which value is for device mode and which for Host mode */
  51587. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  51588. + /*
  51589. + * Turn on VBUS after initial ADP probe.
  51590. + */
  51591. + core_if->op_state = A_HOST;
  51592. + dwc_otg_enable_global_interrupts(core_if);
  51593. + DWC_SPINUNLOCK(core_if->lock);
  51594. + cil_hcd_start(core_if);
  51595. + dwc_otg_adp_turnon_vbus(core_if);
  51596. + DWC_SPINLOCK(core_if->lock);
  51597. + } else {
  51598. + /*
  51599. + * Initiate SRP after initial ADP probe.
  51600. + */
  51601. + dwc_otg_enable_global_interrupts(core_if);
  51602. + dwc_otg_initiate_srp(core_if);
  51603. + }
  51604. + } else if (core_if->adp.probe_counter > 2){
  51605. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51606. + if (compare_timer_values(core_if)) {
  51607. + DWC_PRINTF("Difference in timer values !!! \n");
  51608. +// core_if->adp.attached = DWC_OTG_ADP_ATTACHED;
  51609. + dwc_otg_adp_probe_stop(core_if);
  51610. +
  51611. + /* Power on the core */
  51612. + if (core_if->power_down == 2) {
  51613. + gpwrdn.b.pwrdnswtch = 1;
  51614. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51615. + gpwrdn, 0, gpwrdn.d32);
  51616. + }
  51617. +
  51618. + /* check which value is for device mode and which for Host mode */
  51619. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  51620. + /* Disable Interrupt from Power Down Logic */
  51621. + gpwrdn.d32 = 0;
  51622. + gpwrdn.b.pmuintsel = 1;
  51623. + gpwrdn.b.pmuactv = 1;
  51624. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51625. + gpwrdn, gpwrdn.d32, 0);
  51626. +
  51627. + /*
  51628. + * Initialize the Core for Host mode.
  51629. + */
  51630. + core_if->op_state = A_HOST;
  51631. + dwc_otg_core_init(core_if);
  51632. + dwc_otg_enable_global_interrupts(core_if);
  51633. + cil_hcd_start(core_if);
  51634. + } else {
  51635. + gotgctl_data_t gotgctl;
  51636. + /* Mask SRP detected interrupt from Power Down Logic */
  51637. + gpwrdn.d32 = 0;
  51638. + gpwrdn.b.srp_det_msk = 1;
  51639. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51640. + gpwrdn, gpwrdn.d32, 0);
  51641. +
  51642. + /* Disable Power Down Logic */
  51643. + gpwrdn.d32 = 0;
  51644. + gpwrdn.b.pmuintsel = 1;
  51645. + gpwrdn.b.pmuactv = 1;
  51646. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51647. + gpwrdn, gpwrdn.d32, 0);
  51648. +
  51649. + /*
  51650. + * Initialize the Core for Device mode.
  51651. + */
  51652. + core_if->op_state = B_PERIPHERAL;
  51653. + dwc_otg_core_init(core_if);
  51654. + dwc_otg_enable_global_interrupts(core_if);
  51655. + cil_pcd_start(core_if);
  51656. +
  51657. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  51658. + if (!gotgctl.b.bsesvld) {
  51659. + dwc_otg_initiate_srp(core_if);
  51660. + }
  51661. + }
  51662. + }
  51663. + if (core_if->power_down == 2) {
  51664. + if (gpwrdn.b.bsessvld) {
  51665. + /* Mask SRP detected interrupt from Power Down Logic */
  51666. + gpwrdn.d32 = 0;
  51667. + gpwrdn.b.srp_det_msk = 1;
  51668. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  51669. +
  51670. + /* Disable Power Down Logic */
  51671. + gpwrdn.d32 = 0;
  51672. + gpwrdn.b.pmuactv = 1;
  51673. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  51674. +
  51675. + /*
  51676. + * Initialize the Core for Device mode.
  51677. + */
  51678. + core_if->op_state = B_PERIPHERAL;
  51679. + dwc_otg_core_init(core_if);
  51680. + dwc_otg_enable_global_interrupts(core_if);
  51681. + cil_pcd_start(core_if);
  51682. + }
  51683. + }
  51684. + }
  51685. +exit:
  51686. + /* Clear interrupt */
  51687. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51688. + adpctl.b.adp_prb_int = 1;
  51689. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51690. +
  51691. + return 0;
  51692. +}
  51693. +
  51694. +/**
  51695. + * This function hadles ADP Sense Interrupt
  51696. + */
  51697. +static int32_t dwc_otg_adp_handle_sns_intr(dwc_otg_core_if_t * core_if)
  51698. +{
  51699. + adpctl_data_t adpctl;
  51700. + /* Stop ADP Sense timer */
  51701. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  51702. +
  51703. + /* Restart ADP Sense timer */
  51704. + dwc_otg_adp_sense_timer_start(core_if);
  51705. +
  51706. + /* Clear interrupt */
  51707. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51708. + adpctl.b.adp_sns_int = 1;
  51709. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51710. +
  51711. + return 0;
  51712. +}
  51713. +
  51714. +/**
  51715. + * This function handles ADP Probe Interrupts
  51716. + */
  51717. +static int32_t dwc_otg_adp_handle_prb_tmout_intr(dwc_otg_core_if_t * core_if,
  51718. + uint32_t val)
  51719. +{
  51720. + adpctl_data_t adpctl = {.d32 = 0 };
  51721. + adpctl.d32 = val;
  51722. + set_timer_value(core_if, adpctl.b.rtim);
  51723. +
  51724. + /* Clear interrupt */
  51725. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51726. + adpctl.b.adp_tmout_int = 1;
  51727. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51728. +
  51729. + return 0;
  51730. +}
  51731. +
  51732. +/**
  51733. + * ADP Interrupt handler.
  51734. + *
  51735. + */
  51736. +int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if)
  51737. +{
  51738. + int retval = 0;
  51739. + adpctl_data_t adpctl = {.d32 = 0};
  51740. +
  51741. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51742. + DWC_PRINTF("ADPCTL = %08x\n",adpctl.d32);
  51743. +
  51744. + if (adpctl.b.adp_sns_int & adpctl.b.adp_sns_int_msk) {
  51745. + DWC_PRINTF("ADP Sense interrupt\n");
  51746. + retval |= dwc_otg_adp_handle_sns_intr(core_if);
  51747. + }
  51748. + if (adpctl.b.adp_tmout_int & adpctl.b.adp_tmout_int_msk) {
  51749. + DWC_PRINTF("ADP timeout interrupt\n");
  51750. + retval |= dwc_otg_adp_handle_prb_tmout_intr(core_if, adpctl.d32);
  51751. + }
  51752. + if (adpctl.b.adp_prb_int & adpctl.b.adp_prb_int_msk) {
  51753. + DWC_PRINTF("ADP Probe interrupt\n");
  51754. + adpctl.b.adp_prb_int = 1;
  51755. + retval |= dwc_otg_adp_handle_prb_intr(core_if, adpctl.d32);
  51756. + }
  51757. +
  51758. +// dwc_otg_adp_modify_reg(core_if, adpctl.d32, 0);
  51759. + //dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51760. + DWC_PRINTF("RETURN FROM ADP ISR\n");
  51761. +
  51762. + return retval;
  51763. +}
  51764. +
  51765. +/**
  51766. + *
  51767. + * @param core_if Programming view of DWC_otg controller.
  51768. + */
  51769. +int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if)
  51770. +{
  51771. +
  51772. +#ifndef DWC_HOST_ONLY
  51773. + hprt0_data_t hprt0;
  51774. + gpwrdn_data_t gpwrdn;
  51775. + DWC_DEBUGPL(DBG_ANY, "++ Power Down Logic Session Request Interrupt++\n");
  51776. +
  51777. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51778. + /* check which value is for device mode and which for Host mode */
  51779. + if (!gpwrdn.b.idsts) { /* considered host mode value is 0 */
  51780. + DWC_PRINTF("SRP: Host mode\n");
  51781. +
  51782. + if (core_if->adp_enable) {
  51783. + dwc_otg_adp_probe_stop(core_if);
  51784. +
  51785. + /* Power on the core */
  51786. + if (core_if->power_down == 2) {
  51787. + gpwrdn.b.pwrdnswtch = 1;
  51788. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51789. + gpwrdn, 0, gpwrdn.d32);
  51790. + }
  51791. +
  51792. + core_if->op_state = A_HOST;
  51793. + dwc_otg_core_init(core_if);
  51794. + dwc_otg_enable_global_interrupts(core_if);
  51795. + cil_hcd_start(core_if);
  51796. + }
  51797. +
  51798. + /* Turn on the port power bit. */
  51799. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  51800. + hprt0.b.prtpwr = 1;
  51801. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  51802. +
  51803. + /* Start the Connection timer. So a message can be displayed
  51804. + * if connect does not occur within 10 seconds. */
  51805. + cil_hcd_session_start(core_if);
  51806. + } else {
  51807. + DWC_PRINTF("SRP: Device mode %s\n", __FUNCTION__);
  51808. + if (core_if->adp_enable) {
  51809. + dwc_otg_adp_probe_stop(core_if);
  51810. +
  51811. + /* Power on the core */
  51812. + if (core_if->power_down == 2) {
  51813. + gpwrdn.b.pwrdnswtch = 1;
  51814. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51815. + gpwrdn, 0, gpwrdn.d32);
  51816. + }
  51817. +
  51818. + gpwrdn.d32 = 0;
  51819. + gpwrdn.b.pmuactv = 0;
  51820. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  51821. + gpwrdn.d32);
  51822. +
  51823. + core_if->op_state = B_PERIPHERAL;
  51824. + dwc_otg_core_init(core_if);
  51825. + dwc_otg_enable_global_interrupts(core_if);
  51826. + cil_pcd_start(core_if);
  51827. + }
  51828. + }
  51829. +#endif
  51830. + return 1;
  51831. +}
  51832. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_adp.h linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_adp.h
  51833. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_adp.h 1970-01-01 01:00:00.000000000 +0100
  51834. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_adp.h 2014-02-18 11:52:14.000000000 +0100
  51835. @@ -0,0 +1,80 @@
  51836. +/* ==========================================================================
  51837. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.h $
  51838. + * $Revision: #7 $
  51839. + * $Date: 2011/10/24 $
  51840. + * $Change: 1871159 $
  51841. + *
  51842. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  51843. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  51844. + * otherwise expressly agreed to in writing between Synopsys and you.
  51845. + *
  51846. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  51847. + * any End User Software License Agreement or Agreement for Licensed Product
  51848. + * with Synopsys or any supplement thereto. You are permitted to use and
  51849. + * redistribute this Software in source and binary forms, with or without
  51850. + * modification, provided that redistributions of source code must retain this
  51851. + * notice. You may not view, use, disclose, copy or distribute this file or
  51852. + * any information contained herein except pursuant to this license grant from
  51853. + * Synopsys. If you do not agree with this notice, including the disclaimer
  51854. + * below, then you are not authorized to use the Software.
  51855. + *
  51856. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  51857. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  51858. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51859. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  51860. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  51861. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  51862. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  51863. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  51864. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  51865. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  51866. + * DAMAGE.
  51867. + * ========================================================================== */
  51868. +
  51869. +#ifndef __DWC_OTG_ADP_H__
  51870. +#define __DWC_OTG_ADP_H__
  51871. +
  51872. +/**
  51873. + * @file
  51874. + *
  51875. + * This file contains the Attach Detect Protocol interfaces and defines
  51876. + * (functions) and structures for Linux.
  51877. + *
  51878. + */
  51879. +
  51880. +#define DWC_OTG_ADP_UNATTACHED 0
  51881. +#define DWC_OTG_ADP_ATTACHED 1
  51882. +#define DWC_OTG_ADP_UNKOWN 2
  51883. +
  51884. +typedef struct dwc_otg_adp {
  51885. + uint32_t adp_started;
  51886. + uint32_t initial_probe;
  51887. + int32_t probe_timer_values[2];
  51888. + uint32_t probe_enabled;
  51889. + uint32_t sense_enabled;
  51890. + dwc_timer_t *sense_timer;
  51891. + uint32_t sense_timer_started;
  51892. + dwc_timer_t *vbuson_timer;
  51893. + uint32_t vbuson_timer_started;
  51894. + uint32_t attached;
  51895. + uint32_t probe_counter;
  51896. + uint32_t gpwrdn;
  51897. +} dwc_otg_adp_t;
  51898. +
  51899. +/**
  51900. + * Attach Detect Protocol functions
  51901. + */
  51902. +
  51903. +extern void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value);
  51904. +extern uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if);
  51905. +extern uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if);
  51906. +extern uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if);
  51907. +extern uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if);
  51908. +extern uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if);
  51909. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  51910. +extern void dwc_otg_adp_init(dwc_otg_core_if_t * core_if);
  51911. +extern void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if);
  51912. +extern int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if);
  51913. +extern int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if);
  51914. +
  51915. +#endif //__DWC_OTG_ADP_H__
  51916. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_attr.c linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_attr.c
  51917. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_attr.c 1970-01-01 01:00:00.000000000 +0100
  51918. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_attr.c 2014-02-18 11:52:14.000000000 +0100
  51919. @@ -0,0 +1,1210 @@
  51920. +/* ==========================================================================
  51921. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.c $
  51922. + * $Revision: #44 $
  51923. + * $Date: 2010/11/29 $
  51924. + * $Change: 1636033 $
  51925. + *
  51926. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  51927. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  51928. + * otherwise expressly agreed to in writing between Synopsys and you.
  51929. + *
  51930. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  51931. + * any End User Software License Agreement or Agreement for Licensed Product
  51932. + * with Synopsys or any supplement thereto. You are permitted to use and
  51933. + * redistribute this Software in source and binary forms, with or without
  51934. + * modification, provided that redistributions of source code must retain this
  51935. + * notice. You may not view, use, disclose, copy or distribute this file or
  51936. + * any information contained herein except pursuant to this license grant from
  51937. + * Synopsys. If you do not agree with this notice, including the disclaimer
  51938. + * below, then you are not authorized to use the Software.
  51939. + *
  51940. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  51941. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  51942. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51943. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  51944. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  51945. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  51946. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  51947. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  51948. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  51949. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  51950. + * DAMAGE.
  51951. + * ========================================================================== */
  51952. +
  51953. +/** @file
  51954. + *
  51955. + * The diagnostic interface will provide access to the controller for
  51956. + * bringing up the hardware and testing. The Linux driver attributes
  51957. + * feature will be used to provide the Linux Diagnostic
  51958. + * Interface. These attributes are accessed through sysfs.
  51959. + */
  51960. +
  51961. +/** @page "Linux Module Attributes"
  51962. + *
  51963. + * The Linux module attributes feature is used to provide the Linux
  51964. + * Diagnostic Interface. These attributes are accessed through sysfs.
  51965. + * The diagnostic interface will provide access to the controller for
  51966. + * bringing up the hardware and testing.
  51967. +
  51968. + The following table shows the attributes.
  51969. + <table>
  51970. + <tr>
  51971. + <td><b> Name</b></td>
  51972. + <td><b> Description</b></td>
  51973. + <td><b> Access</b></td>
  51974. + </tr>
  51975. +
  51976. + <tr>
  51977. + <td> mode </td>
  51978. + <td> Returns the current mode: 0 for device mode, 1 for host mode</td>
  51979. + <td> Read</td>
  51980. + </tr>
  51981. +
  51982. + <tr>
  51983. + <td> hnpcapable </td>
  51984. + <td> Gets or sets the "HNP-capable" bit in the Core USB Configuraton Register.
  51985. + Read returns the current value.</td>
  51986. + <td> Read/Write</td>
  51987. + </tr>
  51988. +
  51989. + <tr>
  51990. + <td> srpcapable </td>
  51991. + <td> Gets or sets the "SRP-capable" bit in the Core USB Configuraton Register.
  51992. + Read returns the current value.</td>
  51993. + <td> Read/Write</td>
  51994. + </tr>
  51995. +
  51996. + <tr>
  51997. + <td> hsic_connect </td>
  51998. + <td> Gets or sets the "HSIC-Connect" bit in the GLPMCFG Register.
  51999. + Read returns the current value.</td>
  52000. + <td> Read/Write</td>
  52001. + </tr>
  52002. +
  52003. + <tr>
  52004. + <td> inv_sel_hsic </td>
  52005. + <td> Gets or sets the "Invert Select HSIC" bit in the GLPMFG Register.
  52006. + Read returns the current value.</td>
  52007. + <td> Read/Write</td>
  52008. + </tr>
  52009. +
  52010. + <tr>
  52011. + <td> hnp </td>
  52012. + <td> Initiates the Host Negotiation Protocol. Read returns the status.</td>
  52013. + <td> Read/Write</td>
  52014. + </tr>
  52015. +
  52016. + <tr>
  52017. + <td> srp </td>
  52018. + <td> Initiates the Session Request Protocol. Read returns the status.</td>
  52019. + <td> Read/Write</td>
  52020. + </tr>
  52021. +
  52022. + <tr>
  52023. + <td> buspower </td>
  52024. + <td> Gets or sets the Power State of the bus (0 - Off or 1 - On)</td>
  52025. + <td> Read/Write</td>
  52026. + </tr>
  52027. +
  52028. + <tr>
  52029. + <td> bussuspend </td>
  52030. + <td> Suspends the USB bus.</td>
  52031. + <td> Read/Write</td>
  52032. + </tr>
  52033. +
  52034. + <tr>
  52035. + <td> busconnected </td>
  52036. + <td> Gets the connection status of the bus</td>
  52037. + <td> Read</td>
  52038. + </tr>
  52039. +
  52040. + <tr>
  52041. + <td> gotgctl </td>
  52042. + <td> Gets or sets the Core Control Status Register.</td>
  52043. + <td> Read/Write</td>
  52044. + </tr>
  52045. +
  52046. + <tr>
  52047. + <td> gusbcfg </td>
  52048. + <td> Gets or sets the Core USB Configuration Register</td>
  52049. + <td> Read/Write</td>
  52050. + </tr>
  52051. +
  52052. + <tr>
  52053. + <td> grxfsiz </td>
  52054. + <td> Gets or sets the Receive FIFO Size Register</td>
  52055. + <td> Read/Write</td>
  52056. + </tr>
  52057. +
  52058. + <tr>
  52059. + <td> gnptxfsiz </td>
  52060. + <td> Gets or sets the non-periodic Transmit Size Register</td>
  52061. + <td> Read/Write</td>
  52062. + </tr>
  52063. +
  52064. + <tr>
  52065. + <td> gpvndctl </td>
  52066. + <td> Gets or sets the PHY Vendor Control Register</td>
  52067. + <td> Read/Write</td>
  52068. + </tr>
  52069. +
  52070. + <tr>
  52071. + <td> ggpio </td>
  52072. + <td> Gets the value in the lower 16-bits of the General Purpose IO Register
  52073. + or sets the upper 16 bits.</td>
  52074. + <td> Read/Write</td>
  52075. + </tr>
  52076. +
  52077. + <tr>
  52078. + <td> guid </td>
  52079. + <td> Gets or sets the value of the User ID Register</td>
  52080. + <td> Read/Write</td>
  52081. + </tr>
  52082. +
  52083. + <tr>
  52084. + <td> gsnpsid </td>
  52085. + <td> Gets the value of the Synopsys ID Regester</td>
  52086. + <td> Read</td>
  52087. + </tr>
  52088. +
  52089. + <tr>
  52090. + <td> devspeed </td>
  52091. + <td> Gets or sets the device speed setting in the DCFG register</td>
  52092. + <td> Read/Write</td>
  52093. + </tr>
  52094. +
  52095. + <tr>
  52096. + <td> enumspeed </td>
  52097. + <td> Gets the device enumeration Speed.</td>
  52098. + <td> Read</td>
  52099. + </tr>
  52100. +
  52101. + <tr>
  52102. + <td> hptxfsiz </td>
  52103. + <td> Gets the value of the Host Periodic Transmit FIFO</td>
  52104. + <td> Read</td>
  52105. + </tr>
  52106. +
  52107. + <tr>
  52108. + <td> hprt0 </td>
  52109. + <td> Gets or sets the value in the Host Port Control and Status Register</td>
  52110. + <td> Read/Write</td>
  52111. + </tr>
  52112. +
  52113. + <tr>
  52114. + <td> regoffset </td>
  52115. + <td> Sets the register offset for the next Register Access</td>
  52116. + <td> Read/Write</td>
  52117. + </tr>
  52118. +
  52119. + <tr>
  52120. + <td> regvalue </td>
  52121. + <td> Gets or sets the value of the register at the offset in the regoffset attribute.</td>
  52122. + <td> Read/Write</td>
  52123. + </tr>
  52124. +
  52125. + <tr>
  52126. + <td> remote_wakeup </td>
  52127. + <td> On read, shows the status of Remote Wakeup. On write, initiates a remote
  52128. + wakeup of the host. When bit 0 is 1 and Remote Wakeup is enabled, the Remote
  52129. + Wakeup signalling bit in the Device Control Register is set for 1
  52130. + milli-second.</td>
  52131. + <td> Read/Write</td>
  52132. + </tr>
  52133. +
  52134. + <tr>
  52135. + <td> rem_wakeup_pwrdn </td>
  52136. + <td> On read, shows the status core - hibernated or not. On write, initiates
  52137. + a remote wakeup of the device from Hibernation. </td>
  52138. + <td> Read/Write</td>
  52139. + </tr>
  52140. +
  52141. + <tr>
  52142. + <td> mode_ch_tim_en </td>
  52143. + <td> This bit is used to enable or disable the host core to wait for 200 PHY
  52144. + clock cycles at the end of Resume to change the opmode signal to the PHY to 00
  52145. + after Suspend or LPM. </td>
  52146. + <td> Read/Write</td>
  52147. + </tr>
  52148. +
  52149. + <tr>
  52150. + <td> fr_interval </td>
  52151. + <td> On read, shows the value of HFIR Frame Interval. On write, dynamically
  52152. + reload HFIR register during runtime. The application can write a value to this
  52153. + register only after the Port Enable bit of the Host Port Control and Status
  52154. + register (HPRT.PrtEnaPort) has been set </td>
  52155. + <td> Read/Write</td>
  52156. + </tr>
  52157. +
  52158. + <tr>
  52159. + <td> disconnect_us </td>
  52160. + <td> On read, shows the status of disconnect_device_us. On write, sets disconnect_us
  52161. + which causes soft disconnect for 100us. Applicable only for device mode of operation.</td>
  52162. + <td> Read/Write</td>
  52163. + </tr>
  52164. +
  52165. + <tr>
  52166. + <td> regdump </td>
  52167. + <td> Dumps the contents of core registers.</td>
  52168. + <td> Read</td>
  52169. + </tr>
  52170. +
  52171. + <tr>
  52172. + <td> spramdump </td>
  52173. + <td> Dumps the contents of core registers.</td>
  52174. + <td> Read</td>
  52175. + </tr>
  52176. +
  52177. + <tr>
  52178. + <td> hcddump </td>
  52179. + <td> Dumps the current HCD state.</td>
  52180. + <td> Read</td>
  52181. + </tr>
  52182. +
  52183. + <tr>
  52184. + <td> hcd_frrem </td>
  52185. + <td> Shows the average value of the Frame Remaining
  52186. + field in the Host Frame Number/Frame Remaining register when an SOF interrupt
  52187. + occurs. This can be used to determine the average interrupt latency. Also
  52188. + shows the average Frame Remaining value for start_transfer and the "a" and
  52189. + "b" sample points. The "a" and "b" sample points may be used during debugging
  52190. + bto determine how long it takes to execute a section of the HCD code.</td>
  52191. + <td> Read</td>
  52192. + </tr>
  52193. +
  52194. + <tr>
  52195. + <td> rd_reg_test </td>
  52196. + <td> Displays the time required to read the GNPTXFSIZ register many times
  52197. + (the output shows the number of times the register is read).
  52198. + <td> Read</td>
  52199. + </tr>
  52200. +
  52201. + <tr>
  52202. + <td> wr_reg_test </td>
  52203. + <td> Displays the time required to write the GNPTXFSIZ register many times
  52204. + (the output shows the number of times the register is written).
  52205. + <td> Read</td>
  52206. + </tr>
  52207. +
  52208. + <tr>
  52209. + <td> lpm_response </td>
  52210. + <td> Gets or sets lpm_response mode. Applicable only in device mode.
  52211. + <td> Write</td>
  52212. + </tr>
  52213. +
  52214. + <tr>
  52215. + <td> sleep_status </td>
  52216. + <td> Shows sleep status of device.
  52217. + <td> Read</td>
  52218. + </tr>
  52219. +
  52220. + </table>
  52221. +
  52222. + Example usage:
  52223. + To get the current mode:
  52224. + cat /sys/devices/lm0/mode
  52225. +
  52226. + To power down the USB:
  52227. + echo 0 > /sys/devices/lm0/buspower
  52228. + */
  52229. +
  52230. +#include "dwc_otg_os_dep.h"
  52231. +#include "dwc_os.h"
  52232. +#include "dwc_otg_driver.h"
  52233. +#include "dwc_otg_attr.h"
  52234. +#include "dwc_otg_core_if.h"
  52235. +#include "dwc_otg_pcd_if.h"
  52236. +#include "dwc_otg_hcd_if.h"
  52237. +
  52238. +/*
  52239. + * MACROs for defining sysfs attribute
  52240. + */
  52241. +#ifdef LM_INTERFACE
  52242. +
  52243. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52244. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52245. +{ \
  52246. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  52247. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  52248. + uint32_t val; \
  52249. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52250. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  52251. +}
  52252. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  52253. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52254. + const char *buf, size_t count) \
  52255. +{ \
  52256. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  52257. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  52258. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  52259. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  52260. + return count; \
  52261. +}
  52262. +
  52263. +#elif defined(PCI_INTERFACE)
  52264. +
  52265. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52266. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52267. +{ \
  52268. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  52269. + uint32_t val; \
  52270. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52271. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  52272. +}
  52273. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  52274. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52275. + const char *buf, size_t count) \
  52276. +{ \
  52277. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  52278. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  52279. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  52280. + return count; \
  52281. +}
  52282. +
  52283. +#elif defined(PLATFORM_INTERFACE)
  52284. +
  52285. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52286. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52287. +{ \
  52288. + struct platform_device *platform_dev = \
  52289. + container_of(_dev, struct platform_device, dev); \
  52290. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  52291. + uint32_t val; \
  52292. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  52293. + __func__, _dev, platform_dev, otg_dev); \
  52294. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52295. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  52296. +}
  52297. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  52298. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52299. + const char *buf, size_t count) \
  52300. +{ \
  52301. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  52302. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  52303. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  52304. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  52305. + return count; \
  52306. +}
  52307. +#endif
  52308. +
  52309. +/*
  52310. + * MACROs for defining sysfs attribute for 32-bit registers
  52311. + */
  52312. +#ifdef LM_INTERFACE
  52313. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52314. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52315. +{ \
  52316. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  52317. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  52318. + uint32_t val; \
  52319. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52320. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  52321. +}
  52322. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  52323. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52324. + const char *buf, size_t count) \
  52325. +{ \
  52326. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  52327. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  52328. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  52329. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  52330. + return count; \
  52331. +}
  52332. +#elif defined(PCI_INTERFACE)
  52333. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52334. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52335. +{ \
  52336. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  52337. + uint32_t val; \
  52338. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52339. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  52340. +}
  52341. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  52342. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52343. + const char *buf, size_t count) \
  52344. +{ \
  52345. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  52346. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  52347. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  52348. + return count; \
  52349. +}
  52350. +
  52351. +#elif defined(PLATFORM_INTERFACE)
  52352. +#include "dwc_otg_dbg.h"
  52353. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52354. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52355. +{ \
  52356. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  52357. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  52358. + uint32_t val; \
  52359. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  52360. + __func__, _dev, platform_dev, otg_dev); \
  52361. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52362. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  52363. +}
  52364. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  52365. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52366. + const char *buf, size_t count) \
  52367. +{ \
  52368. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  52369. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  52370. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  52371. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  52372. + return count; \
  52373. +}
  52374. +
  52375. +#endif
  52376. +
  52377. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_string_) \
  52378. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52379. +DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  52380. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  52381. +
  52382. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_string_) \
  52383. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52384. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  52385. +
  52386. +#define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
  52387. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52388. +DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  52389. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  52390. +
  52391. +#define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
  52392. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52393. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  52394. +
  52395. +/** @name Functions for Show/Store of Attributes */
  52396. +/**@{*/
  52397. +
  52398. +/**
  52399. + * Helper function returning the otg_device structure of the given device
  52400. + */
  52401. +static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  52402. +{
  52403. + dwc_otg_device_t *otg_dev;
  52404. + DWC_OTG_GETDRVDEV(otg_dev, _dev);
  52405. + return otg_dev;
  52406. +}
  52407. +
  52408. +/**
  52409. + * Show the register offset of the Register Access.
  52410. + */
  52411. +static ssize_t regoffset_show(struct device *_dev,
  52412. + struct device_attribute *attr, char *buf)
  52413. +{
  52414. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52415. + return snprintf(buf, sizeof("0xFFFFFFFF\n") + 1, "0x%08x\n",
  52416. + otg_dev->os_dep.reg_offset);
  52417. +}
  52418. +
  52419. +/**
  52420. + * Set the register offset for the next Register Access Read/Write
  52421. + */
  52422. +static ssize_t regoffset_store(struct device *_dev,
  52423. + struct device_attribute *attr,
  52424. + const char *buf, size_t count)
  52425. +{
  52426. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52427. + uint32_t offset = simple_strtoul(buf, NULL, 16);
  52428. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  52429. + if (offset < SZ_256K) {
  52430. +#elif defined(PCI_INTERFACE)
  52431. + if (offset < 0x00040000) {
  52432. +#endif
  52433. + otg_dev->os_dep.reg_offset = offset;
  52434. + } else {
  52435. + dev_err(_dev, "invalid offset\n");
  52436. + }
  52437. +
  52438. + return count;
  52439. +}
  52440. +
  52441. +DEVICE_ATTR(regoffset, S_IRUGO | S_IWUSR, regoffset_show, regoffset_store);
  52442. +
  52443. +/**
  52444. + * Show the value of the register at the offset in the reg_offset
  52445. + * attribute.
  52446. + */
  52447. +static ssize_t regvalue_show(struct device *_dev,
  52448. + struct device_attribute *attr, char *buf)
  52449. +{
  52450. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52451. + uint32_t val;
  52452. + volatile uint32_t *addr;
  52453. +
  52454. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  52455. + /* Calculate the address */
  52456. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  52457. + (uint8_t *) otg_dev->os_dep.base);
  52458. + val = DWC_READ_REG32(addr);
  52459. + return snprintf(buf,
  52460. + sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n") + 1,
  52461. + "Reg@0x%06x = 0x%08x\n", otg_dev->os_dep.reg_offset,
  52462. + val);
  52463. + } else {
  52464. + dev_err(_dev, "Invalid offset (0x%0x)\n", otg_dev->os_dep.reg_offset);
  52465. + return sprintf(buf, "invalid offset\n");
  52466. + }
  52467. +}
  52468. +
  52469. +/**
  52470. + * Store the value in the register at the offset in the reg_offset
  52471. + * attribute.
  52472. + *
  52473. + */
  52474. +static ssize_t regvalue_store(struct device *_dev,
  52475. + struct device_attribute *attr,
  52476. + const char *buf, size_t count)
  52477. +{
  52478. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52479. + volatile uint32_t *addr;
  52480. + uint32_t val = simple_strtoul(buf, NULL, 16);
  52481. + //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
  52482. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  52483. + /* Calculate the address */
  52484. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  52485. + (uint8_t *) otg_dev->os_dep.base);
  52486. + DWC_WRITE_REG32(addr, val);
  52487. + } else {
  52488. + dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
  52489. + otg_dev->os_dep.reg_offset);
  52490. + }
  52491. + return count;
  52492. +}
  52493. +
  52494. +DEVICE_ATTR(regvalue, S_IRUGO | S_IWUSR, regvalue_show, regvalue_store);
  52495. +
  52496. +/*
  52497. + * Attributes
  52498. + */
  52499. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode, "Mode");
  52500. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable, "HNPCapable");
  52501. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable, "SRPCapable");
  52502. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hsic_connect, "HSIC Connect");
  52503. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(inv_sel_hsic, "Invert Select HSIC");
  52504. +
  52505. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  52506. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  52507. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected, "Bus Connected");
  52508. +
  52509. +DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl, 0, "GOTGCTL");
  52510. +DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,
  52511. + &(otg_dev->core_if->core_global_regs->gusbcfg),
  52512. + "GUSBCFG");
  52513. +DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,
  52514. + &(otg_dev->core_if->core_global_regs->grxfsiz),
  52515. + "GRXFSIZ");
  52516. +DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,
  52517. + &(otg_dev->core_if->core_global_regs->gnptxfsiz),
  52518. + "GNPTXFSIZ");
  52519. +DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,
  52520. + &(otg_dev->core_if->core_global_regs->gpvndctl),
  52521. + "GPVNDCTL");
  52522. +DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,
  52523. + &(otg_dev->core_if->core_global_regs->ggpio),
  52524. + "GGPIO");
  52525. +DWC_OTG_DEVICE_ATTR_REG32_RW(guid, &(otg_dev->core_if->core_global_regs->guid),
  52526. + "GUID");
  52527. +DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,
  52528. + &(otg_dev->core_if->core_global_regs->gsnpsid),
  52529. + "GSNPSID");
  52530. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed, "Device Speed");
  52531. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed, "Device Enumeration Speed");
  52532. +
  52533. +DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,
  52534. + &(otg_dev->core_if->core_global_regs->hptxfsiz),
  52535. + "HPTXFSIZ");
  52536. +DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0, otg_dev->core_if->host_if->hprt0, "HPRT0");
  52537. +
  52538. +/**
  52539. + * @todo Add code to initiate the HNP.
  52540. + */
  52541. +/**
  52542. + * Show the HNP status bit
  52543. + */
  52544. +static ssize_t hnp_show(struct device *_dev,
  52545. + struct device_attribute *attr, char *buf)
  52546. +{
  52547. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52548. + return sprintf(buf, "HstNegScs = 0x%x\n",
  52549. + dwc_otg_get_hnpstatus(otg_dev->core_if));
  52550. +}
  52551. +
  52552. +/**
  52553. + * Set the HNP Request bit
  52554. + */
  52555. +static ssize_t hnp_store(struct device *_dev,
  52556. + struct device_attribute *attr,
  52557. + const char *buf, size_t count)
  52558. +{
  52559. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52560. + uint32_t in = simple_strtoul(buf, NULL, 16);
  52561. + dwc_otg_set_hnpreq(otg_dev->core_if, in);
  52562. + return count;
  52563. +}
  52564. +
  52565. +DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
  52566. +
  52567. +/**
  52568. + * @todo Add code to initiate the SRP.
  52569. + */
  52570. +/**
  52571. + * Show the SRP status bit
  52572. + */
  52573. +static ssize_t srp_show(struct device *_dev,
  52574. + struct device_attribute *attr, char *buf)
  52575. +{
  52576. +#ifndef DWC_HOST_ONLY
  52577. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52578. + return sprintf(buf, "SesReqScs = 0x%x\n",
  52579. + dwc_otg_get_srpstatus(otg_dev->core_if));
  52580. +#else
  52581. + return sprintf(buf, "Host Only Mode!\n");
  52582. +#endif
  52583. +}
  52584. +
  52585. +/**
  52586. + * Set the SRP Request bit
  52587. + */
  52588. +static ssize_t srp_store(struct device *_dev,
  52589. + struct device_attribute *attr,
  52590. + const char *buf, size_t count)
  52591. +{
  52592. +#ifndef DWC_HOST_ONLY
  52593. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52594. + dwc_otg_pcd_initiate_srp(otg_dev->pcd);
  52595. +#endif
  52596. + return count;
  52597. +}
  52598. +
  52599. +DEVICE_ATTR(srp, 0644, srp_show, srp_store);
  52600. +
  52601. +/**
  52602. + * @todo Need to do more for power on/off?
  52603. + */
  52604. +/**
  52605. + * Show the Bus Power status
  52606. + */
  52607. +static ssize_t buspower_show(struct device *_dev,
  52608. + struct device_attribute *attr, char *buf)
  52609. +{
  52610. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52611. + return sprintf(buf, "Bus Power = 0x%x\n",
  52612. + dwc_otg_get_prtpower(otg_dev->core_if));
  52613. +}
  52614. +
  52615. +/**
  52616. + * Set the Bus Power status
  52617. + */
  52618. +static ssize_t buspower_store(struct device *_dev,
  52619. + struct device_attribute *attr,
  52620. + const char *buf, size_t count)
  52621. +{
  52622. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52623. + uint32_t on = simple_strtoul(buf, NULL, 16);
  52624. + dwc_otg_set_prtpower(otg_dev->core_if, on);
  52625. + return count;
  52626. +}
  52627. +
  52628. +DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
  52629. +
  52630. +/**
  52631. + * @todo Need to do more for suspend?
  52632. + */
  52633. +/**
  52634. + * Show the Bus Suspend status
  52635. + */
  52636. +static ssize_t bussuspend_show(struct device *_dev,
  52637. + struct device_attribute *attr, char *buf)
  52638. +{
  52639. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52640. + return sprintf(buf, "Bus Suspend = 0x%x\n",
  52641. + dwc_otg_get_prtsuspend(otg_dev->core_if));
  52642. +}
  52643. +
  52644. +/**
  52645. + * Set the Bus Suspend status
  52646. + */
  52647. +static ssize_t bussuspend_store(struct device *_dev,
  52648. + struct device_attribute *attr,
  52649. + const char *buf, size_t count)
  52650. +{
  52651. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52652. + uint32_t in = simple_strtoul(buf, NULL, 16);
  52653. + dwc_otg_set_prtsuspend(otg_dev->core_if, in);
  52654. + return count;
  52655. +}
  52656. +
  52657. +DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
  52658. +
  52659. +/**
  52660. + * Show the Mode Change Ready Timer status
  52661. + */
  52662. +static ssize_t mode_ch_tim_en_show(struct device *_dev,
  52663. + struct device_attribute *attr, char *buf)
  52664. +{
  52665. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52666. + return sprintf(buf, "Mode Change Ready Timer Enable = 0x%x\n",
  52667. + dwc_otg_get_mode_ch_tim(otg_dev->core_if));
  52668. +}
  52669. +
  52670. +/**
  52671. + * Set the Mode Change Ready Timer status
  52672. + */
  52673. +static ssize_t mode_ch_tim_en_store(struct device *_dev,
  52674. + struct device_attribute *attr,
  52675. + const char *buf, size_t count)
  52676. +{
  52677. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52678. + uint32_t in = simple_strtoul(buf, NULL, 16);
  52679. + dwc_otg_set_mode_ch_tim(otg_dev->core_if, in);
  52680. + return count;
  52681. +}
  52682. +
  52683. +DEVICE_ATTR(mode_ch_tim_en, 0644, mode_ch_tim_en_show, mode_ch_tim_en_store);
  52684. +
  52685. +/**
  52686. + * Show the value of HFIR Frame Interval bitfield
  52687. + */
  52688. +static ssize_t fr_interval_show(struct device *_dev,
  52689. + struct device_attribute *attr, char *buf)
  52690. +{
  52691. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52692. + return sprintf(buf, "Frame Interval = 0x%x\n",
  52693. + dwc_otg_get_fr_interval(otg_dev->core_if));
  52694. +}
  52695. +
  52696. +/**
  52697. + * Set the HFIR Frame Interval value
  52698. + */
  52699. +static ssize_t fr_interval_store(struct device *_dev,
  52700. + struct device_attribute *attr,
  52701. + const char *buf, size_t count)
  52702. +{
  52703. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52704. + uint32_t in = simple_strtoul(buf, NULL, 10);
  52705. + dwc_otg_set_fr_interval(otg_dev->core_if, in);
  52706. + return count;
  52707. +}
  52708. +
  52709. +DEVICE_ATTR(fr_interval, 0644, fr_interval_show, fr_interval_store);
  52710. +
  52711. +/**
  52712. + * Show the status of Remote Wakeup.
  52713. + */
  52714. +static ssize_t remote_wakeup_show(struct device *_dev,
  52715. + struct device_attribute *attr, char *buf)
  52716. +{
  52717. +#ifndef DWC_HOST_ONLY
  52718. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52719. +
  52720. + return sprintf(buf,
  52721. + "Remote Wakeup Sig = %d Enabled = %d LPM Remote Wakeup = %d\n",
  52722. + dwc_otg_get_remotewakesig(otg_dev->core_if),
  52723. + dwc_otg_pcd_get_rmwkup_enable(otg_dev->pcd),
  52724. + dwc_otg_get_lpm_remotewakeenabled(otg_dev->core_if));
  52725. +#else
  52726. + return sprintf(buf, "Host Only Mode!\n");
  52727. +#endif /* DWC_HOST_ONLY */
  52728. +}
  52729. +
  52730. +/**
  52731. + * Initiate a remote wakeup of the host. The Device control register
  52732. + * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
  52733. + * flag is set.
  52734. + *
  52735. + */
  52736. +static ssize_t remote_wakeup_store(struct device *_dev,
  52737. + struct device_attribute *attr,
  52738. + const char *buf, size_t count)
  52739. +{
  52740. +#ifndef DWC_HOST_ONLY
  52741. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52742. + uint32_t val = simple_strtoul(buf, NULL, 16);
  52743. +
  52744. + if (val & 1) {
  52745. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
  52746. + } else {
  52747. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
  52748. + }
  52749. +#endif /* DWC_HOST_ONLY */
  52750. + return count;
  52751. +}
  52752. +
  52753. +DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR, remote_wakeup_show,
  52754. + remote_wakeup_store);
  52755. +
  52756. +/**
  52757. + * Show the whether core is hibernated or not.
  52758. + */
  52759. +static ssize_t rem_wakeup_pwrdn_show(struct device *_dev,
  52760. + struct device_attribute *attr, char *buf)
  52761. +{
  52762. +#ifndef DWC_HOST_ONLY
  52763. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52764. +
  52765. + if (dwc_otg_get_core_state(otg_dev->core_if)) {
  52766. + DWC_PRINTF("Core is in hibernation\n");
  52767. + } else {
  52768. + DWC_PRINTF("Core is not in hibernation\n");
  52769. + }
  52770. +#endif /* DWC_HOST_ONLY */
  52771. + return 0;
  52772. +}
  52773. +
  52774. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  52775. + int rem_wakeup, int reset);
  52776. +
  52777. +/**
  52778. + * Initiate a remote wakeup of the device to exit from hibernation.
  52779. + */
  52780. +static ssize_t rem_wakeup_pwrdn_store(struct device *_dev,
  52781. + struct device_attribute *attr,
  52782. + const char *buf, size_t count)
  52783. +{
  52784. +#ifndef DWC_HOST_ONLY
  52785. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52786. + dwc_otg_device_hibernation_restore(otg_dev->core_if, 1, 0);
  52787. +#endif
  52788. + return count;
  52789. +}
  52790. +
  52791. +DEVICE_ATTR(rem_wakeup_pwrdn, S_IRUGO | S_IWUSR, rem_wakeup_pwrdn_show,
  52792. + rem_wakeup_pwrdn_store);
  52793. +
  52794. +static ssize_t disconnect_us(struct device *_dev,
  52795. + struct device_attribute *attr,
  52796. + const char *buf, size_t count)
  52797. +{
  52798. +
  52799. +#ifndef DWC_HOST_ONLY
  52800. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52801. + uint32_t val = simple_strtoul(buf, NULL, 16);
  52802. + DWC_PRINTF("The Passed value is %04x\n", val);
  52803. +
  52804. + dwc_otg_pcd_disconnect_us(otg_dev->pcd, 50);
  52805. +
  52806. +#endif /* DWC_HOST_ONLY */
  52807. + return count;
  52808. +}
  52809. +
  52810. +DEVICE_ATTR(disconnect_us, S_IWUSR, 0, disconnect_us);
  52811. +
  52812. +/**
  52813. + * Dump global registers and either host or device registers (depending on the
  52814. + * current mode of the core).
  52815. + */
  52816. +static ssize_t regdump_show(struct device *_dev,
  52817. + struct device_attribute *attr, char *buf)
  52818. +{
  52819. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52820. +
  52821. + dwc_otg_dump_global_registers(otg_dev->core_if);
  52822. + if (dwc_otg_is_host_mode(otg_dev->core_if)) {
  52823. + dwc_otg_dump_host_registers(otg_dev->core_if);
  52824. + } else {
  52825. + dwc_otg_dump_dev_registers(otg_dev->core_if);
  52826. +
  52827. + }
  52828. + return sprintf(buf, "Register Dump\n");
  52829. +}
  52830. +
  52831. +DEVICE_ATTR(regdump, S_IRUGO, regdump_show, 0);
  52832. +
  52833. +/**
  52834. + * Dump global registers and either host or device registers (depending on the
  52835. + * current mode of the core).
  52836. + */
  52837. +static ssize_t spramdump_show(struct device *_dev,
  52838. + struct device_attribute *attr, char *buf)
  52839. +{
  52840. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52841. +
  52842. + //dwc_otg_dump_spram(otg_dev->core_if);
  52843. +
  52844. + return sprintf(buf, "SPRAM Dump\n");
  52845. +}
  52846. +
  52847. +DEVICE_ATTR(spramdump, S_IRUGO, spramdump_show, 0);
  52848. +
  52849. +/**
  52850. + * Dump the current hcd state.
  52851. + */
  52852. +static ssize_t hcddump_show(struct device *_dev,
  52853. + struct device_attribute *attr, char *buf)
  52854. +{
  52855. +#ifndef DWC_DEVICE_ONLY
  52856. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52857. + dwc_otg_hcd_dump_state(otg_dev->hcd);
  52858. +#endif /* DWC_DEVICE_ONLY */
  52859. + return sprintf(buf, "HCD Dump\n");
  52860. +}
  52861. +
  52862. +DEVICE_ATTR(hcddump, S_IRUGO, hcddump_show, 0);
  52863. +
  52864. +/**
  52865. + * Dump the average frame remaining at SOF. This can be used to
  52866. + * determine average interrupt latency. Frame remaining is also shown for
  52867. + * start transfer and two additional sample points.
  52868. + */
  52869. +static ssize_t hcd_frrem_show(struct device *_dev,
  52870. + struct device_attribute *attr, char *buf)
  52871. +{
  52872. +#ifndef DWC_DEVICE_ONLY
  52873. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52874. +
  52875. + dwc_otg_hcd_dump_frrem(otg_dev->hcd);
  52876. +#endif /* DWC_DEVICE_ONLY */
  52877. + return sprintf(buf, "HCD Dump Frame Remaining\n");
  52878. +}
  52879. +
  52880. +DEVICE_ATTR(hcd_frrem, S_IRUGO, hcd_frrem_show, 0);
  52881. +
  52882. +/**
  52883. + * Displays the time required to read the GNPTXFSIZ register many times (the
  52884. + * output shows the number of times the register is read).
  52885. + */
  52886. +#define RW_REG_COUNT 10000000
  52887. +#define MSEC_PER_JIFFIE 1000/HZ
  52888. +static ssize_t rd_reg_test_show(struct device *_dev,
  52889. + struct device_attribute *attr, char *buf)
  52890. +{
  52891. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52892. + int i;
  52893. + int time;
  52894. + int start_jiffies;
  52895. +
  52896. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  52897. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  52898. + start_jiffies = jiffies;
  52899. + for (i = 0; i < RW_REG_COUNT; i++) {
  52900. + dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  52901. + }
  52902. + time = jiffies - start_jiffies;
  52903. + return sprintf(buf,
  52904. + "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  52905. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  52906. +}
  52907. +
  52908. +DEVICE_ATTR(rd_reg_test, S_IRUGO, rd_reg_test_show, 0);
  52909. +
  52910. +/**
  52911. + * Displays the time required to write the GNPTXFSIZ register many times (the
  52912. + * output shows the number of times the register is written).
  52913. + */
  52914. +static ssize_t wr_reg_test_show(struct device *_dev,
  52915. + struct device_attribute *attr, char *buf)
  52916. +{
  52917. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52918. + uint32_t reg_val;
  52919. + int i;
  52920. + int time;
  52921. + int start_jiffies;
  52922. +
  52923. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  52924. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  52925. + reg_val = dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  52926. + start_jiffies = jiffies;
  52927. + for (i = 0; i < RW_REG_COUNT; i++) {
  52928. + dwc_otg_set_gnptxfsiz(otg_dev->core_if, reg_val);
  52929. + }
  52930. + time = jiffies - start_jiffies;
  52931. + return sprintf(buf,
  52932. + "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  52933. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  52934. +}
  52935. +
  52936. +DEVICE_ATTR(wr_reg_test, S_IRUGO, wr_reg_test_show, 0);
  52937. +
  52938. +#ifdef CONFIG_USB_DWC_OTG_LPM
  52939. +
  52940. +/**
  52941. +* Show the lpm_response attribute.
  52942. +*/
  52943. +static ssize_t lpmresp_show(struct device *_dev,
  52944. + struct device_attribute *attr, char *buf)
  52945. +{
  52946. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52947. +
  52948. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
  52949. + return sprintf(buf, "** LPM is DISABLED **\n");
  52950. +
  52951. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  52952. + return sprintf(buf, "** Current mode is not device mode\n");
  52953. + }
  52954. + return sprintf(buf, "lpm_response = %d\n",
  52955. + dwc_otg_get_lpmresponse(otg_dev->core_if));
  52956. +}
  52957. +
  52958. +/**
  52959. +* Store the lpm_response attribute.
  52960. +*/
  52961. +static ssize_t lpmresp_store(struct device *_dev,
  52962. + struct device_attribute *attr,
  52963. + const char *buf, size_t count)
  52964. +{
  52965. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52966. + uint32_t val = simple_strtoul(buf, NULL, 16);
  52967. +
  52968. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if)) {
  52969. + return 0;
  52970. + }
  52971. +
  52972. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  52973. + return 0;
  52974. + }
  52975. +
  52976. + dwc_otg_set_lpmresponse(otg_dev->core_if, val);
  52977. + return count;
  52978. +}
  52979. +
  52980. +DEVICE_ATTR(lpm_response, S_IRUGO | S_IWUSR, lpmresp_show, lpmresp_store);
  52981. +
  52982. +/**
  52983. +* Show the sleep_status attribute.
  52984. +*/
  52985. +static ssize_t sleepstatus_show(struct device *_dev,
  52986. + struct device_attribute *attr, char *buf)
  52987. +{
  52988. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52989. + return sprintf(buf, "Sleep Status = %d\n",
  52990. + dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if));
  52991. +}
  52992. +
  52993. +/**
  52994. + * Store the sleep_status attribure.
  52995. + */
  52996. +static ssize_t sleepstatus_store(struct device *_dev,
  52997. + struct device_attribute *attr,
  52998. + const char *buf, size_t count)
  52999. +{
  53000. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  53001. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  53002. +
  53003. + if (dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if)) {
  53004. + if (dwc_otg_is_host_mode(core_if)) {
  53005. +
  53006. + DWC_PRINTF("Host initiated resume\n");
  53007. + dwc_otg_set_prtresume(otg_dev->core_if, 1);
  53008. + }
  53009. + }
  53010. +
  53011. + return count;
  53012. +}
  53013. +
  53014. +DEVICE_ATTR(sleep_status, S_IRUGO | S_IWUSR, sleepstatus_show,
  53015. + sleepstatus_store);
  53016. +
  53017. +#endif /* CONFIG_USB_DWC_OTG_LPM_ENABLE */
  53018. +
  53019. +/**@}*/
  53020. +
  53021. +/**
  53022. + * Create the device files
  53023. + */
  53024. +void dwc_otg_attr_create(
  53025. +#ifdef LM_INTERFACE
  53026. + struct lm_device *dev
  53027. +#elif defined(PCI_INTERFACE)
  53028. + struct pci_dev *dev
  53029. +#elif defined(PLATFORM_INTERFACE)
  53030. + struct platform_device *dev
  53031. +#endif
  53032. + )
  53033. +{
  53034. + int error;
  53035. +
  53036. + error = device_create_file(&dev->dev, &dev_attr_regoffset);
  53037. + error = device_create_file(&dev->dev, &dev_attr_regvalue);
  53038. + error = device_create_file(&dev->dev, &dev_attr_mode);
  53039. + error = device_create_file(&dev->dev, &dev_attr_hnpcapable);
  53040. + error = device_create_file(&dev->dev, &dev_attr_srpcapable);
  53041. + error = device_create_file(&dev->dev, &dev_attr_hsic_connect);
  53042. + error = device_create_file(&dev->dev, &dev_attr_inv_sel_hsic);
  53043. + error = device_create_file(&dev->dev, &dev_attr_hnp);
  53044. + error = device_create_file(&dev->dev, &dev_attr_srp);
  53045. + error = device_create_file(&dev->dev, &dev_attr_buspower);
  53046. + error = device_create_file(&dev->dev, &dev_attr_bussuspend);
  53047. + error = device_create_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  53048. + error = device_create_file(&dev->dev, &dev_attr_fr_interval);
  53049. + error = device_create_file(&dev->dev, &dev_attr_busconnected);
  53050. + error = device_create_file(&dev->dev, &dev_attr_gotgctl);
  53051. + error = device_create_file(&dev->dev, &dev_attr_gusbcfg);
  53052. + error = device_create_file(&dev->dev, &dev_attr_grxfsiz);
  53053. + error = device_create_file(&dev->dev, &dev_attr_gnptxfsiz);
  53054. + error = device_create_file(&dev->dev, &dev_attr_gpvndctl);
  53055. + error = device_create_file(&dev->dev, &dev_attr_ggpio);
  53056. + error = device_create_file(&dev->dev, &dev_attr_guid);
  53057. + error = device_create_file(&dev->dev, &dev_attr_gsnpsid);
  53058. + error = device_create_file(&dev->dev, &dev_attr_devspeed);
  53059. + error = device_create_file(&dev->dev, &dev_attr_enumspeed);
  53060. + error = device_create_file(&dev->dev, &dev_attr_hptxfsiz);
  53061. + error = device_create_file(&dev->dev, &dev_attr_hprt0);
  53062. + error = device_create_file(&dev->dev, &dev_attr_remote_wakeup);
  53063. + error = device_create_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  53064. + error = device_create_file(&dev->dev, &dev_attr_disconnect_us);
  53065. + error = device_create_file(&dev->dev, &dev_attr_regdump);
  53066. + error = device_create_file(&dev->dev, &dev_attr_spramdump);
  53067. + error = device_create_file(&dev->dev, &dev_attr_hcddump);
  53068. + error = device_create_file(&dev->dev, &dev_attr_hcd_frrem);
  53069. + error = device_create_file(&dev->dev, &dev_attr_rd_reg_test);
  53070. + error = device_create_file(&dev->dev, &dev_attr_wr_reg_test);
  53071. +#ifdef CONFIG_USB_DWC_OTG_LPM
  53072. + error = device_create_file(&dev->dev, &dev_attr_lpm_response);
  53073. + error = device_create_file(&dev->dev, &dev_attr_sleep_status);
  53074. +#endif
  53075. +}
  53076. +
  53077. +/**
  53078. + * Remove the device files
  53079. + */
  53080. +void dwc_otg_attr_remove(
  53081. +#ifdef LM_INTERFACE
  53082. + struct lm_device *dev
  53083. +#elif defined(PCI_INTERFACE)
  53084. + struct pci_dev *dev
  53085. +#elif defined(PLATFORM_INTERFACE)
  53086. + struct platform_device *dev
  53087. +#endif
  53088. + )
  53089. +{
  53090. + device_remove_file(&dev->dev, &dev_attr_regoffset);
  53091. + device_remove_file(&dev->dev, &dev_attr_regvalue);
  53092. + device_remove_file(&dev->dev, &dev_attr_mode);
  53093. + device_remove_file(&dev->dev, &dev_attr_hnpcapable);
  53094. + device_remove_file(&dev->dev, &dev_attr_srpcapable);
  53095. + device_remove_file(&dev->dev, &dev_attr_hsic_connect);
  53096. + device_remove_file(&dev->dev, &dev_attr_inv_sel_hsic);
  53097. + device_remove_file(&dev->dev, &dev_attr_hnp);
  53098. + device_remove_file(&dev->dev, &dev_attr_srp);
  53099. + device_remove_file(&dev->dev, &dev_attr_buspower);
  53100. + device_remove_file(&dev->dev, &dev_attr_bussuspend);
  53101. + device_remove_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  53102. + device_remove_file(&dev->dev, &dev_attr_fr_interval);
  53103. + device_remove_file(&dev->dev, &dev_attr_busconnected);
  53104. + device_remove_file(&dev->dev, &dev_attr_gotgctl);
  53105. + device_remove_file(&dev->dev, &dev_attr_gusbcfg);
  53106. + device_remove_file(&dev->dev, &dev_attr_grxfsiz);
  53107. + device_remove_file(&dev->dev, &dev_attr_gnptxfsiz);
  53108. + device_remove_file(&dev->dev, &dev_attr_gpvndctl);
  53109. + device_remove_file(&dev->dev, &dev_attr_ggpio);
  53110. + device_remove_file(&dev->dev, &dev_attr_guid);
  53111. + device_remove_file(&dev->dev, &dev_attr_gsnpsid);
  53112. + device_remove_file(&dev->dev, &dev_attr_devspeed);
  53113. + device_remove_file(&dev->dev, &dev_attr_enumspeed);
  53114. + device_remove_file(&dev->dev, &dev_attr_hptxfsiz);
  53115. + device_remove_file(&dev->dev, &dev_attr_hprt0);
  53116. + device_remove_file(&dev->dev, &dev_attr_remote_wakeup);
  53117. + device_remove_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  53118. + device_remove_file(&dev->dev, &dev_attr_disconnect_us);
  53119. + device_remove_file(&dev->dev, &dev_attr_regdump);
  53120. + device_remove_file(&dev->dev, &dev_attr_spramdump);
  53121. + device_remove_file(&dev->dev, &dev_attr_hcddump);
  53122. + device_remove_file(&dev->dev, &dev_attr_hcd_frrem);
  53123. + device_remove_file(&dev->dev, &dev_attr_rd_reg_test);
  53124. + device_remove_file(&dev->dev, &dev_attr_wr_reg_test);
  53125. +#ifdef CONFIG_USB_DWC_OTG_LPM
  53126. + device_remove_file(&dev->dev, &dev_attr_lpm_response);
  53127. + device_remove_file(&dev->dev, &dev_attr_sleep_status);
  53128. +#endif
  53129. +}
  53130. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_attr.h linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_attr.h
  53131. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_attr.h 1970-01-01 01:00:00.000000000 +0100
  53132. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_attr.h 2014-02-18 11:52:14.000000000 +0100
  53133. @@ -0,0 +1,89 @@
  53134. +/* ==========================================================================
  53135. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.h $
  53136. + * $Revision: #13 $
  53137. + * $Date: 2010/06/21 $
  53138. + * $Change: 1532021 $
  53139. + *
  53140. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  53141. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  53142. + * otherwise expressly agreed to in writing between Synopsys and you.
  53143. + *
  53144. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  53145. + * any End User Software License Agreement or Agreement for Licensed Product
  53146. + * with Synopsys or any supplement thereto. You are permitted to use and
  53147. + * redistribute this Software in source and binary forms, with or without
  53148. + * modification, provided that redistributions of source code must retain this
  53149. + * notice. You may not view, use, disclose, copy or distribute this file or
  53150. + * any information contained herein except pursuant to this license grant from
  53151. + * Synopsys. If you do not agree with this notice, including the disclaimer
  53152. + * below, then you are not authorized to use the Software.
  53153. + *
  53154. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  53155. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  53156. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  53157. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  53158. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  53159. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  53160. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  53161. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  53162. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  53163. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  53164. + * DAMAGE.
  53165. + * ========================================================================== */
  53166. +
  53167. +#if !defined(__DWC_OTG_ATTR_H__)
  53168. +#define __DWC_OTG_ATTR_H__
  53169. +
  53170. +/** @file
  53171. + * This file contains the interface to the Linux device attributes.
  53172. + */
  53173. +extern struct device_attribute dev_attr_regoffset;
  53174. +extern struct device_attribute dev_attr_regvalue;
  53175. +
  53176. +extern struct device_attribute dev_attr_mode;
  53177. +extern struct device_attribute dev_attr_hnpcapable;
  53178. +extern struct device_attribute dev_attr_srpcapable;
  53179. +extern struct device_attribute dev_attr_hnp;
  53180. +extern struct device_attribute dev_attr_srp;
  53181. +extern struct device_attribute dev_attr_buspower;
  53182. +extern struct device_attribute dev_attr_bussuspend;
  53183. +extern struct device_attribute dev_attr_mode_ch_tim_en;
  53184. +extern struct device_attribute dev_attr_fr_interval;
  53185. +extern struct device_attribute dev_attr_busconnected;
  53186. +extern struct device_attribute dev_attr_gotgctl;
  53187. +extern struct device_attribute dev_attr_gusbcfg;
  53188. +extern struct device_attribute dev_attr_grxfsiz;
  53189. +extern struct device_attribute dev_attr_gnptxfsiz;
  53190. +extern struct device_attribute dev_attr_gpvndctl;
  53191. +extern struct device_attribute dev_attr_ggpio;
  53192. +extern struct device_attribute dev_attr_guid;
  53193. +extern struct device_attribute dev_attr_gsnpsid;
  53194. +extern struct device_attribute dev_attr_devspeed;
  53195. +extern struct device_attribute dev_attr_enumspeed;
  53196. +extern struct device_attribute dev_attr_hptxfsiz;
  53197. +extern struct device_attribute dev_attr_hprt0;
  53198. +#ifdef CONFIG_USB_DWC_OTG_LPM
  53199. +extern struct device_attribute dev_attr_lpm_response;
  53200. +extern struct device_attribute devi_attr_sleep_status;
  53201. +#endif
  53202. +
  53203. +void dwc_otg_attr_create(
  53204. +#ifdef LM_INTERFACE
  53205. + struct lm_device *dev
  53206. +#elif defined(PCI_INTERFACE)
  53207. + struct pci_dev *dev
  53208. +#elif defined(PLATFORM_INTERFACE)
  53209. + struct platform_device *dev
  53210. +#endif
  53211. + );
  53212. +
  53213. +void dwc_otg_attr_remove(
  53214. +#ifdef LM_INTERFACE
  53215. + struct lm_device *dev
  53216. +#elif defined(PCI_INTERFACE)
  53217. + struct pci_dev *dev
  53218. +#elif defined(PLATFORM_INTERFACE)
  53219. + struct platform_device *dev
  53220. +#endif
  53221. + );
  53222. +#endif
  53223. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_cfi.c linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_cfi.c
  53224. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 1970-01-01 01:00:00.000000000 +0100
  53225. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 2014-02-18 11:52:14.000000000 +0100
  53226. @@ -0,0 +1,1876 @@
  53227. +/* ==========================================================================
  53228. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  53229. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  53230. + * otherwise expressly agreed to in writing between Synopsys and you.
  53231. + *
  53232. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  53233. + * any End User Software License Agreement or Agreement for Licensed Product
  53234. + * with Synopsys or any supplement thereto. You are permitted to use and
  53235. + * redistribute this Software in source and binary forms, with or without
  53236. + * modification, provided that redistributions of source code must retain this
  53237. + * notice. You may not view, use, disclose, copy or distribute this file or
  53238. + * any information contained herein except pursuant to this license grant from
  53239. + * Synopsys. If you do not agree with this notice, including the disclaimer
  53240. + * below, then you are not authorized to use the Software.
  53241. + *
  53242. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  53243. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  53244. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  53245. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  53246. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  53247. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  53248. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  53249. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  53250. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  53251. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  53252. + * DAMAGE.
  53253. + * ========================================================================== */
  53254. +
  53255. +/** @file
  53256. + *
  53257. + * This file contains the most of the CFI(Core Feature Interface)
  53258. + * implementation for the OTG.
  53259. + */
  53260. +
  53261. +#ifdef DWC_UTE_CFI
  53262. +
  53263. +#include "dwc_otg_pcd.h"
  53264. +#include "dwc_otg_cfi.h"
  53265. +
  53266. +/** This definition should actually migrate to the Portability Library */
  53267. +#define DWC_CONSTANT_CPU_TO_LE16(x) (x)
  53268. +
  53269. +extern dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex);
  53270. +
  53271. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen);
  53272. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  53273. + struct dwc_otg_pcd *pcd,
  53274. + struct cfi_usb_ctrlrequest *ctrl_req);
  53275. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd);
  53276. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  53277. + struct cfi_usb_ctrlrequest *req);
  53278. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  53279. + struct cfi_usb_ctrlrequest *req);
  53280. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  53281. + struct cfi_usb_ctrlrequest *req);
  53282. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  53283. + struct cfi_usb_ctrlrequest *req);
  53284. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep);
  53285. +
  53286. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if);
  53287. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue);
  53288. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue);
  53289. +
  53290. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if);
  53291. +
  53292. +/** This is the header of the all features descriptor */
  53293. +static cfi_all_features_header_t all_props_desc_header = {
  53294. + .wVersion = DWC_CONSTANT_CPU_TO_LE16(0x100),
  53295. + .wCoreID = DWC_CONSTANT_CPU_TO_LE16(CFI_CORE_ID_OTG),
  53296. + .wNumFeatures = DWC_CONSTANT_CPU_TO_LE16(9),
  53297. +};
  53298. +
  53299. +/** This is an array of statically allocated feature descriptors */
  53300. +static cfi_feature_desc_header_t prop_descs[] = {
  53301. +
  53302. + /* FT_ID_DMA_MODE */
  53303. + {
  53304. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_MODE),
  53305. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53306. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(1),
  53307. + },
  53308. +
  53309. + /* FT_ID_DMA_BUFFER_SETUP */
  53310. + {
  53311. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFFER_SETUP),
  53312. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53313. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  53314. + },
  53315. +
  53316. + /* FT_ID_DMA_BUFF_ALIGN */
  53317. + {
  53318. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFF_ALIGN),
  53319. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53320. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  53321. + },
  53322. +
  53323. + /* FT_ID_DMA_CONCAT_SETUP */
  53324. + {
  53325. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CONCAT_SETUP),
  53326. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53327. + //.wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  53328. + },
  53329. +
  53330. + /* FT_ID_DMA_CIRCULAR */
  53331. + {
  53332. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CIRCULAR),
  53333. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53334. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  53335. + },
  53336. +
  53337. + /* FT_ID_THRESHOLD_SETUP */
  53338. + {
  53339. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_THRESHOLD_SETUP),
  53340. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53341. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  53342. + },
  53343. +
  53344. + /* FT_ID_DFIFO_DEPTH */
  53345. + {
  53346. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DFIFO_DEPTH),
  53347. + .bmAttributes = CFI_FEATURE_ATTR_RO,
  53348. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  53349. + },
  53350. +
  53351. + /* FT_ID_TX_FIFO_DEPTH */
  53352. + {
  53353. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_TX_FIFO_DEPTH),
  53354. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53355. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  53356. + },
  53357. +
  53358. + /* FT_ID_RX_FIFO_DEPTH */
  53359. + {
  53360. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_RX_FIFO_DEPTH),
  53361. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53362. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  53363. + }
  53364. +};
  53365. +
  53366. +/** The table of feature names */
  53367. +cfi_string_t prop_name_table[] = {
  53368. + {FT_ID_DMA_MODE, "dma_mode"},
  53369. + {FT_ID_DMA_BUFFER_SETUP, "buffer_setup"},
  53370. + {FT_ID_DMA_BUFF_ALIGN, "buffer_align"},
  53371. + {FT_ID_DMA_CONCAT_SETUP, "concat_setup"},
  53372. + {FT_ID_DMA_CIRCULAR, "buffer_circular"},
  53373. + {FT_ID_THRESHOLD_SETUP, "threshold_setup"},
  53374. + {FT_ID_DFIFO_DEPTH, "dfifo_depth"},
  53375. + {FT_ID_TX_FIFO_DEPTH, "txfifo_depth"},
  53376. + {FT_ID_RX_FIFO_DEPTH, "rxfifo_depth"},
  53377. + {}
  53378. +};
  53379. +
  53380. +/************************************************************************/
  53381. +
  53382. +/**
  53383. + * Returns the name of the feature by its ID
  53384. + * or NULL if no featute ID matches.
  53385. + *
  53386. + */
  53387. +const uint8_t *get_prop_name(uint16_t prop_id, int *len)
  53388. +{
  53389. + cfi_string_t *pstr;
  53390. + *len = 0;
  53391. +
  53392. + for (pstr = prop_name_table; pstr && pstr->s; pstr++) {
  53393. + if (pstr->id == prop_id) {
  53394. + *len = DWC_STRLEN(pstr->s);
  53395. + return pstr->s;
  53396. + }
  53397. + }
  53398. + return NULL;
  53399. +}
  53400. +
  53401. +/**
  53402. + * This function handles all CFI specific control requests.
  53403. + *
  53404. + * Return a negative value to stall the DCE.
  53405. + */
  53406. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl)
  53407. +{
  53408. + int retval = 0;
  53409. + dwc_otg_pcd_ep_t *ep = NULL;
  53410. + cfiobject_t *cfi = pcd->cfi;
  53411. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  53412. + uint16_t wLen = DWC_LE16_TO_CPU(&ctrl->wLength);
  53413. + uint16_t wValue = DWC_LE16_TO_CPU(&ctrl->wValue);
  53414. + uint16_t wIndex = DWC_LE16_TO_CPU(&ctrl->wIndex);
  53415. + uint32_t regaddr = 0;
  53416. + uint32_t regval = 0;
  53417. +
  53418. + /* Save this Control Request in the CFI object.
  53419. + * The data field will be assigned in the data stage completion CB function.
  53420. + */
  53421. + cfi->ctrl_req = *ctrl;
  53422. + cfi->ctrl_req.data = NULL;
  53423. +
  53424. + cfi->need_gadget_att = 0;
  53425. + cfi->need_status_in_complete = 0;
  53426. +
  53427. + switch (ctrl->bRequest) {
  53428. + case VEN_CORE_GET_FEATURES:
  53429. + retval = cfi_core_features_buf(cfi->buf_in.buf, CFI_IN_BUF_LEN);
  53430. + if (retval >= 0) {
  53431. + //dump_msg(cfi->buf_in.buf, retval);
  53432. + ep = &pcd->ep0;
  53433. +
  53434. + retval = min((uint16_t) retval, wLen);
  53435. + /* Transfer this buffer to the host through the EP0-IN EP */
  53436. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  53437. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  53438. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  53439. + ep->dwc_ep.xfer_len = retval;
  53440. + ep->dwc_ep.xfer_count = 0;
  53441. + ep->dwc_ep.sent_zlp = 0;
  53442. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53443. +
  53444. + pcd->ep0_pending = 1;
  53445. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53446. + }
  53447. + retval = 0;
  53448. + break;
  53449. +
  53450. + case VEN_CORE_GET_FEATURE:
  53451. + CFI_INFO("VEN_CORE_GET_FEATURE\n");
  53452. + retval = cfi_get_feature_value(cfi->buf_in.buf, CFI_IN_BUF_LEN,
  53453. + pcd, ctrl);
  53454. + if (retval >= 0) {
  53455. + ep = &pcd->ep0;
  53456. +
  53457. + retval = min((uint16_t) retval, wLen);
  53458. + /* Transfer this buffer to the host through the EP0-IN EP */
  53459. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  53460. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  53461. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  53462. + ep->dwc_ep.xfer_len = retval;
  53463. + ep->dwc_ep.xfer_count = 0;
  53464. + ep->dwc_ep.sent_zlp = 0;
  53465. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53466. +
  53467. + pcd->ep0_pending = 1;
  53468. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53469. + }
  53470. + CFI_INFO("VEN_CORE_GET_FEATURE=%d\n", retval);
  53471. + dump_msg(cfi->buf_in.buf, retval);
  53472. + break;
  53473. +
  53474. + case VEN_CORE_SET_FEATURE:
  53475. + CFI_INFO("VEN_CORE_SET_FEATURE\n");
  53476. + /* Set up an XFER to get the data stage of the control request,
  53477. + * which is the new value of the feature to be modified.
  53478. + */
  53479. + ep = &pcd->ep0;
  53480. + ep->dwc_ep.is_in = 0;
  53481. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  53482. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  53483. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  53484. + ep->dwc_ep.xfer_len = wLen;
  53485. + ep->dwc_ep.xfer_count = 0;
  53486. + ep->dwc_ep.sent_zlp = 0;
  53487. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53488. +
  53489. + pcd->ep0_pending = 1;
  53490. + /* Read the control write's data stage */
  53491. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53492. + retval = 0;
  53493. + break;
  53494. +
  53495. + case VEN_CORE_RESET_FEATURES:
  53496. + CFI_INFO("VEN_CORE_RESET_FEATURES\n");
  53497. + cfi->need_gadget_att = 1;
  53498. + cfi->need_status_in_complete = 1;
  53499. + retval = cfi_preproc_reset(pcd, ctrl);
  53500. + CFI_INFO("VEN_CORE_RESET_FEATURES = (%d)\n", retval);
  53501. + break;
  53502. +
  53503. + case VEN_CORE_ACTIVATE_FEATURES:
  53504. + CFI_INFO("VEN_CORE_ACTIVATE_FEATURES\n");
  53505. + break;
  53506. +
  53507. + case VEN_CORE_READ_REGISTER:
  53508. + CFI_INFO("VEN_CORE_READ_REGISTER\n");
  53509. + /* wValue optionally contains the HI WORD of the register offset and
  53510. + * wIndex contains the LOW WORD of the register offset
  53511. + */
  53512. + if (wValue == 0) {
  53513. + /* @TODO - MAS - fix the access to the base field */
  53514. + regaddr = 0;
  53515. + //regaddr = (uint32_t) pcd->otg_dev->os_dep.base;
  53516. + //GET_CORE_IF(pcd)->co
  53517. + regaddr |= wIndex;
  53518. + } else {
  53519. + regaddr = (wValue << 16) | wIndex;
  53520. + }
  53521. +
  53522. + /* Read a 32-bit value of the memory at the regaddr */
  53523. + regval = DWC_READ_REG32((uint32_t *) regaddr);
  53524. +
  53525. + ep = &pcd->ep0;
  53526. + dwc_memcpy(cfi->buf_in.buf, &regval, sizeof(uint32_t));
  53527. + ep->dwc_ep.is_in = 1;
  53528. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  53529. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  53530. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  53531. + ep->dwc_ep.xfer_len = wLen;
  53532. + ep->dwc_ep.xfer_count = 0;
  53533. + ep->dwc_ep.sent_zlp = 0;
  53534. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53535. +
  53536. + pcd->ep0_pending = 1;
  53537. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53538. + cfi->need_gadget_att = 0;
  53539. + retval = 0;
  53540. + break;
  53541. +
  53542. + case VEN_CORE_WRITE_REGISTER:
  53543. + CFI_INFO("VEN_CORE_WRITE_REGISTER\n");
  53544. + /* Set up an XFER to get the data stage of the control request,
  53545. + * which is the new value of the register to be modified.
  53546. + */
  53547. + ep = &pcd->ep0;
  53548. + ep->dwc_ep.is_in = 0;
  53549. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  53550. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  53551. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  53552. + ep->dwc_ep.xfer_len = wLen;
  53553. + ep->dwc_ep.xfer_count = 0;
  53554. + ep->dwc_ep.sent_zlp = 0;
  53555. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53556. +
  53557. + pcd->ep0_pending = 1;
  53558. + /* Read the control write's data stage */
  53559. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53560. + retval = 0;
  53561. + break;
  53562. +
  53563. + default:
  53564. + retval = -DWC_E_NOT_SUPPORTED;
  53565. + break;
  53566. + }
  53567. +
  53568. + return retval;
  53569. +}
  53570. +
  53571. +/**
  53572. + * This function prepares the core features descriptors and copies its
  53573. + * raw representation into the buffer <buf>.
  53574. + *
  53575. + * The buffer structure is as follows:
  53576. + * all_features_header (8 bytes)
  53577. + * features_#1 (8 bytes + feature name string length)
  53578. + * features_#2 (8 bytes + feature name string length)
  53579. + * .....
  53580. + * features_#n - where n=the total count of feature descriptors
  53581. + */
  53582. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen)
  53583. +{
  53584. + cfi_feature_desc_header_t *prop_hdr = prop_descs;
  53585. + cfi_feature_desc_header_t *prop;
  53586. + cfi_all_features_header_t *all_props_hdr = &all_props_desc_header;
  53587. + cfi_all_features_header_t *tmp;
  53588. + uint8_t *tmpbuf = buf;
  53589. + const uint8_t *pname = NULL;
  53590. + int i, j, namelen = 0, totlen;
  53591. +
  53592. + /* Prepare and copy the core features into the buffer */
  53593. + CFI_INFO("%s:\n", __func__);
  53594. +
  53595. + tmp = (cfi_all_features_header_t *) tmpbuf;
  53596. + *tmp = *all_props_hdr;
  53597. + tmpbuf += CFI_ALL_FEATURES_HDR_LEN;
  53598. +
  53599. + j = sizeof(prop_descs) / sizeof(cfi_all_features_header_t);
  53600. + for (i = 0; i < j; i++, prop_hdr++) {
  53601. + pname = get_prop_name(prop_hdr->wFeatureID, &namelen);
  53602. + prop = (cfi_feature_desc_header_t *) tmpbuf;
  53603. + *prop = *prop_hdr;
  53604. +
  53605. + prop->bNameLen = namelen;
  53606. + prop->wLength =
  53607. + DWC_CONSTANT_CPU_TO_LE16(CFI_FEATURE_DESC_HDR_LEN +
  53608. + namelen);
  53609. +
  53610. + tmpbuf += CFI_FEATURE_DESC_HDR_LEN;
  53611. + dwc_memcpy(tmpbuf, pname, namelen);
  53612. + tmpbuf += namelen;
  53613. + }
  53614. +
  53615. + totlen = tmpbuf - buf;
  53616. +
  53617. + if (totlen > 0) {
  53618. + tmp = (cfi_all_features_header_t *) buf;
  53619. + tmp->wTotalLen = DWC_CONSTANT_CPU_TO_LE16(totlen);
  53620. + }
  53621. +
  53622. + return totlen;
  53623. +}
  53624. +
  53625. +/**
  53626. + * This function releases all the dynamic memory in the CFI object.
  53627. + */
  53628. +static void cfi_release(cfiobject_t * cfiobj)
  53629. +{
  53630. + cfi_ep_t *cfiep;
  53631. + dwc_list_link_t *tmp;
  53632. +
  53633. + CFI_INFO("%s\n", __func__);
  53634. +
  53635. + if (cfiobj->buf_in.buf) {
  53636. + DWC_DMA_FREE(CFI_IN_BUF_LEN, cfiobj->buf_in.buf,
  53637. + cfiobj->buf_in.addr);
  53638. + cfiobj->buf_in.buf = NULL;
  53639. + }
  53640. +
  53641. + if (cfiobj->buf_out.buf) {
  53642. + DWC_DMA_FREE(CFI_OUT_BUF_LEN, cfiobj->buf_out.buf,
  53643. + cfiobj->buf_out.addr);
  53644. + cfiobj->buf_out.buf = NULL;
  53645. + }
  53646. +
  53647. + /* Free the Buffer Setup values for each EP */
  53648. + //list_for_each_entry(cfiep, &cfiobj->active_eps, lh) {
  53649. + DWC_LIST_FOREACH(tmp, &cfiobj->active_eps) {
  53650. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  53651. + cfi_free_ep_bs_dyn_data(cfiep);
  53652. + }
  53653. +}
  53654. +
  53655. +/**
  53656. + * This function frees the dynamically allocated EP buffer setup data.
  53657. + */
  53658. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep)
  53659. +{
  53660. + if (cfiep->bm_sg) {
  53661. + DWC_FREE(cfiep->bm_sg);
  53662. + cfiep->bm_sg = NULL;
  53663. + }
  53664. +
  53665. + if (cfiep->bm_align) {
  53666. + DWC_FREE(cfiep->bm_align);
  53667. + cfiep->bm_align = NULL;
  53668. + }
  53669. +
  53670. + if (cfiep->bm_concat) {
  53671. + if (NULL != cfiep->bm_concat->wTxBytes) {
  53672. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  53673. + cfiep->bm_concat->wTxBytes = NULL;
  53674. + }
  53675. + DWC_FREE(cfiep->bm_concat);
  53676. + cfiep->bm_concat = NULL;
  53677. + }
  53678. +}
  53679. +
  53680. +/**
  53681. + * This function initializes the default values of the features
  53682. + * for a specific endpoint and should be called only once when
  53683. + * the EP is enabled first time.
  53684. + */
  53685. +static int cfi_ep_init_defaults(struct dwc_otg_pcd *pcd, cfi_ep_t * cfiep)
  53686. +{
  53687. + int retval = 0;
  53688. +
  53689. + cfiep->bm_sg = DWC_ALLOC(sizeof(ddma_sg_buffer_setup_t));
  53690. + if (NULL == cfiep->bm_sg) {
  53691. + CFI_INFO("Failed to allocate memory for SG feature value\n");
  53692. + return -DWC_E_NO_MEMORY;
  53693. + }
  53694. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  53695. +
  53696. + /* For the Concatenation feature's default value we do not allocate
  53697. + * memory for the wTxBytes field - it will be done in the set_feature_value
  53698. + * request handler.
  53699. + */
  53700. + cfiep->bm_concat = DWC_ALLOC(sizeof(ddma_concat_buffer_setup_t));
  53701. + if (NULL == cfiep->bm_concat) {
  53702. + CFI_INFO
  53703. + ("Failed to allocate memory for CONCATENATION feature value\n");
  53704. + DWC_FREE(cfiep->bm_sg);
  53705. + return -DWC_E_NO_MEMORY;
  53706. + }
  53707. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  53708. +
  53709. + cfiep->bm_align = DWC_ALLOC(sizeof(ddma_align_buffer_setup_t));
  53710. + if (NULL == cfiep->bm_align) {
  53711. + CFI_INFO
  53712. + ("Failed to allocate memory for Alignment feature value\n");
  53713. + DWC_FREE(cfiep->bm_sg);
  53714. + DWC_FREE(cfiep->bm_concat);
  53715. + return -DWC_E_NO_MEMORY;
  53716. + }
  53717. + dwc_memset(cfiep->bm_align, 0, sizeof(ddma_align_buffer_setup_t));
  53718. +
  53719. + return retval;
  53720. +}
  53721. +
  53722. +/**
  53723. + * The callback function that notifies the CFI on the activation of
  53724. + * an endpoint in the PCD. The following steps are done in this function:
  53725. + *
  53726. + * Create a dynamically allocated cfi_ep_t object (a CFI wrapper to the PCD's
  53727. + * active endpoint)
  53728. + * Create MAX_DMA_DESCS_PER_EP count DMA Descriptors for the EP
  53729. + * Set the Buffer Mode to standard
  53730. + * Initialize the default values for all EP modes (SG, Circular, Concat, Align)
  53731. + * Add the cfi_ep_t object to the list of active endpoints in the CFI object
  53732. + */
  53733. +static int cfi_ep_enable(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  53734. + struct dwc_otg_pcd_ep *ep)
  53735. +{
  53736. + cfi_ep_t *cfiep;
  53737. + int retval = -DWC_E_NOT_SUPPORTED;
  53738. +
  53739. + CFI_INFO("%s: epname=%s; epnum=0x%02x\n", __func__,
  53740. + "EP_" /*ep->ep.name */ , ep->desc->bEndpointAddress);
  53741. + /* MAS - Check whether this endpoint already is in the list */
  53742. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  53743. +
  53744. + if (NULL == cfiep) {
  53745. + /* Allocate a cfi_ep_t object */
  53746. + cfiep = DWC_ALLOC(sizeof(cfi_ep_t));
  53747. + if (NULL == cfiep) {
  53748. + CFI_INFO
  53749. + ("Unable to allocate memory for <cfiep> in function %s\n",
  53750. + __func__);
  53751. + return -DWC_E_NO_MEMORY;
  53752. + }
  53753. + dwc_memset(cfiep, 0, sizeof(cfi_ep_t));
  53754. +
  53755. + /* Save the dwc_otg_pcd_ep pointer in the cfiep object */
  53756. + cfiep->ep = ep;
  53757. +
  53758. + /* Allocate the DMA Descriptors chain of MAX_DMA_DESCS_PER_EP count */
  53759. + ep->dwc_ep.descs =
  53760. + DWC_DMA_ALLOC(MAX_DMA_DESCS_PER_EP *
  53761. + sizeof(dwc_otg_dma_desc_t),
  53762. + &ep->dwc_ep.descs_dma_addr);
  53763. +
  53764. + if (NULL == ep->dwc_ep.descs) {
  53765. + DWC_FREE(cfiep);
  53766. + return -DWC_E_NO_MEMORY;
  53767. + }
  53768. +
  53769. + DWC_LIST_INIT(&cfiep->lh);
  53770. +
  53771. + /* Set the buffer mode to BM_STANDARD. It will be modified
  53772. + * when building descriptors for a specific buffer mode */
  53773. + ep->dwc_ep.buff_mode = BM_STANDARD;
  53774. +
  53775. + /* Create and initialize the default values for this EP's Buffer modes */
  53776. + if ((retval = cfi_ep_init_defaults(pcd, cfiep)) < 0)
  53777. + return retval;
  53778. +
  53779. + /* Add the cfi_ep_t object to the CFI object's list of active endpoints */
  53780. + DWC_LIST_INSERT_TAIL(&cfi->active_eps, &cfiep->lh);
  53781. + retval = 0;
  53782. + } else { /* The sought EP already is in the list */
  53783. + CFI_INFO("%s: The sought EP already is in the list\n",
  53784. + __func__);
  53785. + }
  53786. +
  53787. + return retval;
  53788. +}
  53789. +
  53790. +/**
  53791. + * This function is called when the data stage of a 3-stage Control Write request
  53792. + * is complete.
  53793. + *
  53794. + */
  53795. +static int cfi_ctrl_write_complete(struct cfiobject *cfi,
  53796. + struct dwc_otg_pcd *pcd)
  53797. +{
  53798. + uint32_t addr, reg_value;
  53799. + uint16_t wIndex, wValue;
  53800. + uint8_t bRequest;
  53801. + uint8_t *buf = cfi->buf_out.buf;
  53802. + //struct usb_ctrlrequest *ctrl_req = &cfi->ctrl_req_saved;
  53803. + struct cfi_usb_ctrlrequest *ctrl_req = &cfi->ctrl_req;
  53804. + int retval = -DWC_E_NOT_SUPPORTED;
  53805. +
  53806. + CFI_INFO("%s\n", __func__);
  53807. +
  53808. + bRequest = ctrl_req->bRequest;
  53809. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  53810. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  53811. +
  53812. + /*
  53813. + * Save the pointer to the data stage in the ctrl_req's <data> field.
  53814. + * The request should be already saved in the command stage by now.
  53815. + */
  53816. + ctrl_req->data = cfi->buf_out.buf;
  53817. + cfi->need_status_in_complete = 0;
  53818. + cfi->need_gadget_att = 0;
  53819. +
  53820. + switch (bRequest) {
  53821. + case VEN_CORE_WRITE_REGISTER:
  53822. + /* The buffer contains raw data of the new value for the register */
  53823. + reg_value = *((uint32_t *) buf);
  53824. + if (wValue == 0) {
  53825. + addr = 0;
  53826. + //addr = (uint32_t) pcd->otg_dev->os_dep.base;
  53827. + addr += wIndex;
  53828. + } else {
  53829. + addr = (wValue << 16) | wIndex;
  53830. + }
  53831. +
  53832. + //writel(reg_value, addr);
  53833. +
  53834. + retval = 0;
  53835. + cfi->need_status_in_complete = 1;
  53836. + break;
  53837. +
  53838. + case VEN_CORE_SET_FEATURE:
  53839. + /* The buffer contains raw data of the new value of the feature */
  53840. + retval = cfi_set_feature_value(pcd);
  53841. + if (retval < 0)
  53842. + return retval;
  53843. +
  53844. + cfi->need_status_in_complete = 1;
  53845. + break;
  53846. +
  53847. + default:
  53848. + break;
  53849. + }
  53850. +
  53851. + return retval;
  53852. +}
  53853. +
  53854. +/**
  53855. + * This function builds the DMA descriptors for the SG buffer mode.
  53856. + */
  53857. +static void cfi_build_sg_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  53858. + dwc_otg_pcd_request_t * req)
  53859. +{
  53860. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  53861. + ddma_sg_buffer_setup_t *sgval = cfiep->bm_sg;
  53862. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  53863. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  53864. + dma_addr_t buff_addr = req->dma;
  53865. + int i;
  53866. + uint32_t txsize, off;
  53867. +
  53868. + txsize = sgval->wSize;
  53869. + off = sgval->bOffset;
  53870. +
  53871. +// CFI_INFO("%s: %s TXSIZE=0x%08x; OFFSET=0x%08x\n",
  53872. +// __func__, cfiep->ep->ep.name, txsize, off);
  53873. +
  53874. + for (i = 0; i < sgval->bCount; i++) {
  53875. + desc->status.b.bs = BS_HOST_BUSY;
  53876. + desc->buf = buff_addr;
  53877. + desc->status.b.l = 0;
  53878. + desc->status.b.ioc = 0;
  53879. + desc->status.b.sp = 0;
  53880. + desc->status.b.bytes = txsize;
  53881. + desc->status.b.bs = BS_HOST_READY;
  53882. +
  53883. + /* Set the next address of the buffer */
  53884. + buff_addr += txsize + off;
  53885. + desc_last = desc;
  53886. + desc++;
  53887. + }
  53888. +
  53889. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  53890. + desc_last->status.b.l = 1;
  53891. + desc_last->status.b.ioc = 1;
  53892. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  53893. + /* Save the last DMA descriptor pointer */
  53894. + cfiep->dma_desc_last = desc_last;
  53895. + cfiep->desc_count = sgval->bCount;
  53896. +}
  53897. +
  53898. +/**
  53899. + * This function builds the DMA descriptors for the Concatenation buffer mode.
  53900. + */
  53901. +static void cfi_build_concat_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  53902. + dwc_otg_pcd_request_t * req)
  53903. +{
  53904. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  53905. + ddma_concat_buffer_setup_t *concatval = cfiep->bm_concat;
  53906. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  53907. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  53908. + dma_addr_t buff_addr = req->dma;
  53909. + int i;
  53910. + uint16_t *txsize;
  53911. +
  53912. + txsize = concatval->wTxBytes;
  53913. +
  53914. + for (i = 0; i < concatval->hdr.bDescCount; i++) {
  53915. + desc->buf = buff_addr;
  53916. + desc->status.b.bs = BS_HOST_BUSY;
  53917. + desc->status.b.l = 0;
  53918. + desc->status.b.ioc = 0;
  53919. + desc->status.b.sp = 0;
  53920. + desc->status.b.bytes = *txsize;
  53921. + desc->status.b.bs = BS_HOST_READY;
  53922. +
  53923. + txsize++;
  53924. + /* Set the next address of the buffer */
  53925. + buff_addr += UGETW(ep->desc->wMaxPacketSize);
  53926. + desc_last = desc;
  53927. + desc++;
  53928. + }
  53929. +
  53930. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  53931. + desc_last->status.b.l = 1;
  53932. + desc_last->status.b.ioc = 1;
  53933. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  53934. + cfiep->dma_desc_last = desc_last;
  53935. + cfiep->desc_count = concatval->hdr.bDescCount;
  53936. +}
  53937. +
  53938. +/**
  53939. + * This function builds the DMA descriptors for the Circular buffer mode
  53940. + */
  53941. +static void cfi_build_circ_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  53942. + dwc_otg_pcd_request_t * req)
  53943. +{
  53944. + /* @todo: MAS - add implementation when this feature needs to be tested */
  53945. +}
  53946. +
  53947. +/**
  53948. + * This function builds the DMA descriptors for the Alignment buffer mode
  53949. + */
  53950. +static void cfi_build_align_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  53951. + dwc_otg_pcd_request_t * req)
  53952. +{
  53953. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  53954. + ddma_align_buffer_setup_t *alignval = cfiep->bm_align;
  53955. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  53956. + dma_addr_t buff_addr = req->dma;
  53957. +
  53958. + desc->status.b.bs = BS_HOST_BUSY;
  53959. + desc->status.b.l = 1;
  53960. + desc->status.b.ioc = 1;
  53961. + desc->status.b.sp = ep->dwc_ep.sent_zlp;
  53962. + desc->status.b.bytes = req->length;
  53963. + /* Adjust the buffer alignment */
  53964. + desc->buf = (buff_addr + alignval->bAlign);
  53965. + desc->status.b.bs = BS_HOST_READY;
  53966. + cfiep->dma_desc_last = desc;
  53967. + cfiep->desc_count = 1;
  53968. +}
  53969. +
  53970. +/**
  53971. + * This function builds the DMA descriptors chain for different modes of the
  53972. + * buffer setup of an endpoint.
  53973. + */
  53974. +static void cfi_build_descriptors(struct cfiobject *cfi,
  53975. + struct dwc_otg_pcd *pcd,
  53976. + struct dwc_otg_pcd_ep *ep,
  53977. + dwc_otg_pcd_request_t * req)
  53978. +{
  53979. + cfi_ep_t *cfiep;
  53980. +
  53981. + /* Get the cfiep by the dwc_otg_pcd_ep */
  53982. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  53983. + if (NULL == cfiep) {
  53984. + CFI_INFO("%s: Unable to find a matching active endpoint\n",
  53985. + __func__);
  53986. + return;
  53987. + }
  53988. +
  53989. + cfiep->xfer_len = req->length;
  53990. +
  53991. + /* Iterate through all the DMA descriptors */
  53992. + switch (cfiep->ep->dwc_ep.buff_mode) {
  53993. + case BM_SG:
  53994. + cfi_build_sg_descs(cfi, cfiep, req);
  53995. + break;
  53996. +
  53997. + case BM_CONCAT:
  53998. + cfi_build_concat_descs(cfi, cfiep, req);
  53999. + break;
  54000. +
  54001. + case BM_CIRCULAR:
  54002. + cfi_build_circ_descs(cfi, cfiep, req);
  54003. + break;
  54004. +
  54005. + case BM_ALIGN:
  54006. + cfi_build_align_descs(cfi, cfiep, req);
  54007. + break;
  54008. +
  54009. + default:
  54010. + break;
  54011. + }
  54012. +}
  54013. +
  54014. +/**
  54015. + * Allocate DMA buffer for different Buffer modes.
  54016. + */
  54017. +static void *cfi_ep_alloc_buf(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  54018. + struct dwc_otg_pcd_ep *ep, dma_addr_t * dma,
  54019. + unsigned size, gfp_t flags)
  54020. +{
  54021. + return DWC_DMA_ALLOC(size, dma);
  54022. +}
  54023. +
  54024. +/**
  54025. + * This function initializes the CFI object.
  54026. + */
  54027. +int init_cfi(cfiobject_t * cfiobj)
  54028. +{
  54029. + CFI_INFO("%s\n", __func__);
  54030. +
  54031. + /* Allocate a buffer for IN XFERs */
  54032. + cfiobj->buf_in.buf =
  54033. + DWC_DMA_ALLOC(CFI_IN_BUF_LEN, &cfiobj->buf_in.addr);
  54034. + if (NULL == cfiobj->buf_in.buf) {
  54035. + CFI_INFO("Unable to allocate buffer for INs\n");
  54036. + return -DWC_E_NO_MEMORY;
  54037. + }
  54038. +
  54039. + /* Allocate a buffer for OUT XFERs */
  54040. + cfiobj->buf_out.buf =
  54041. + DWC_DMA_ALLOC(CFI_OUT_BUF_LEN, &cfiobj->buf_out.addr);
  54042. + if (NULL == cfiobj->buf_out.buf) {
  54043. + CFI_INFO("Unable to allocate buffer for OUT\n");
  54044. + return -DWC_E_NO_MEMORY;
  54045. + }
  54046. +
  54047. + /* Initialize the callback function pointers */
  54048. + cfiobj->ops.release = cfi_release;
  54049. + cfiobj->ops.ep_enable = cfi_ep_enable;
  54050. + cfiobj->ops.ctrl_write_complete = cfi_ctrl_write_complete;
  54051. + cfiobj->ops.build_descriptors = cfi_build_descriptors;
  54052. + cfiobj->ops.ep_alloc_buf = cfi_ep_alloc_buf;
  54053. +
  54054. + /* Initialize the list of active endpoints in the CFI object */
  54055. + DWC_LIST_INIT(&cfiobj->active_eps);
  54056. +
  54057. + return 0;
  54058. +}
  54059. +
  54060. +/**
  54061. + * This function reads the required feature's current value into the buffer
  54062. + *
  54063. + * @retval: Returns negative as error, or the data length of the feature
  54064. + */
  54065. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  54066. + struct dwc_otg_pcd *pcd,
  54067. + struct cfi_usb_ctrlrequest *ctrl_req)
  54068. +{
  54069. + int retval = -DWC_E_NOT_SUPPORTED;
  54070. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  54071. + uint16_t dfifo, rxfifo, txfifo;
  54072. +
  54073. + switch (ctrl_req->wIndex) {
  54074. + /* Whether the DDMA is enabled or not */
  54075. + case FT_ID_DMA_MODE:
  54076. + *buf = (coreif->dma_enable && coreif->dma_desc_enable) ? 1 : 0;
  54077. + retval = 1;
  54078. + break;
  54079. +
  54080. + case FT_ID_DMA_BUFFER_SETUP:
  54081. + retval = cfi_ep_get_sg_val(buf, pcd, ctrl_req);
  54082. + break;
  54083. +
  54084. + case FT_ID_DMA_BUFF_ALIGN:
  54085. + retval = cfi_ep_get_align_val(buf, pcd, ctrl_req);
  54086. + break;
  54087. +
  54088. + case FT_ID_DMA_CONCAT_SETUP:
  54089. + retval = cfi_ep_get_concat_val(buf, pcd, ctrl_req);
  54090. + break;
  54091. +
  54092. + case FT_ID_DMA_CIRCULAR:
  54093. + CFI_INFO("GetFeature value (FT_ID_DMA_CIRCULAR)\n");
  54094. + break;
  54095. +
  54096. + case FT_ID_THRESHOLD_SETUP:
  54097. + CFI_INFO("GetFeature value (FT_ID_THRESHOLD_SETUP)\n");
  54098. + break;
  54099. +
  54100. + case FT_ID_DFIFO_DEPTH:
  54101. + dfifo = get_dfifo_size(coreif);
  54102. + *((uint16_t *) buf) = dfifo;
  54103. + retval = sizeof(uint16_t);
  54104. + break;
  54105. +
  54106. + case FT_ID_TX_FIFO_DEPTH:
  54107. + retval = get_txfifo_size(pcd, ctrl_req->wValue);
  54108. + if (retval >= 0) {
  54109. + txfifo = retval;
  54110. + *((uint16_t *) buf) = txfifo;
  54111. + retval = sizeof(uint16_t);
  54112. + }
  54113. + break;
  54114. +
  54115. + case FT_ID_RX_FIFO_DEPTH:
  54116. + retval = get_rxfifo_size(coreif, ctrl_req->wValue);
  54117. + if (retval >= 0) {
  54118. + rxfifo = retval;
  54119. + *((uint16_t *) buf) = rxfifo;
  54120. + retval = sizeof(uint16_t);
  54121. + }
  54122. + break;
  54123. + }
  54124. +
  54125. + return retval;
  54126. +}
  54127. +
  54128. +/**
  54129. + * This function resets the SG for the specified EP to its default value
  54130. + */
  54131. +static int cfi_reset_sg_val(cfi_ep_t * cfiep)
  54132. +{
  54133. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  54134. + return 0;
  54135. +}
  54136. +
  54137. +/**
  54138. + * This function resets the Alignment for the specified EP to its default value
  54139. + */
  54140. +static int cfi_reset_align_val(cfi_ep_t * cfiep)
  54141. +{
  54142. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  54143. + return 0;
  54144. +}
  54145. +
  54146. +/**
  54147. + * This function resets the Concatenation for the specified EP to its default value
  54148. + * This function will also set the value of the wTxBytes field to NULL after
  54149. + * freeing the memory previously allocated for this field.
  54150. + */
  54151. +static int cfi_reset_concat_val(cfi_ep_t * cfiep)
  54152. +{
  54153. + /* First we need to free the wTxBytes field */
  54154. + if (cfiep->bm_concat->wTxBytes) {
  54155. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  54156. + cfiep->bm_concat->wTxBytes = NULL;
  54157. + }
  54158. +
  54159. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  54160. + return 0;
  54161. +}
  54162. +
  54163. +/**
  54164. + * This function resets all the buffer setups of the specified endpoint
  54165. + */
  54166. +static int cfi_ep_reset_all_setup_vals(cfi_ep_t * cfiep)
  54167. +{
  54168. + cfi_reset_sg_val(cfiep);
  54169. + cfi_reset_align_val(cfiep);
  54170. + cfi_reset_concat_val(cfiep);
  54171. + return 0;
  54172. +}
  54173. +
  54174. +static int cfi_handle_reset_fifo_val(struct dwc_otg_pcd *pcd, uint8_t ep_addr,
  54175. + uint8_t rx_rst, uint8_t tx_rst)
  54176. +{
  54177. + int retval = -DWC_E_INVALID;
  54178. + uint16_t tx_siz[15];
  54179. + uint16_t rx_siz = 0;
  54180. + dwc_otg_pcd_ep_t *ep = NULL;
  54181. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  54182. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  54183. +
  54184. + if (rx_rst) {
  54185. + rx_siz = params->dev_rx_fifo_size;
  54186. + params->dev_rx_fifo_size = GET_CORE_IF(pcd)->init_rxfsiz;
  54187. + }
  54188. +
  54189. + if (tx_rst) {
  54190. + if (ep_addr == 0) {
  54191. + int i;
  54192. +
  54193. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54194. + tx_siz[i] =
  54195. + core_if->core_params->dev_tx_fifo_size[i];
  54196. + core_if->core_params->dev_tx_fifo_size[i] =
  54197. + core_if->init_txfsiz[i];
  54198. + }
  54199. + } else {
  54200. +
  54201. + ep = get_ep_by_addr(pcd, ep_addr);
  54202. +
  54203. + if (NULL == ep) {
  54204. + CFI_INFO
  54205. + ("%s: Unable to get the endpoint addr=0x%02x\n",
  54206. + __func__, ep_addr);
  54207. + return -DWC_E_INVALID;
  54208. + }
  54209. +
  54210. + tx_siz[0] =
  54211. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num -
  54212. + 1];
  54213. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] =
  54214. + GET_CORE_IF(pcd)->init_txfsiz[ep->
  54215. + dwc_ep.tx_fifo_num -
  54216. + 1];
  54217. + }
  54218. + }
  54219. +
  54220. + if (resize_fifos(GET_CORE_IF(pcd))) {
  54221. + retval = 0;
  54222. + } else {
  54223. + CFI_INFO
  54224. + ("%s: Error resetting the feature Reset All(FIFO size)\n",
  54225. + __func__);
  54226. + if (rx_rst) {
  54227. + params->dev_rx_fifo_size = rx_siz;
  54228. + }
  54229. +
  54230. + if (tx_rst) {
  54231. + if (ep_addr == 0) {
  54232. + int i;
  54233. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps;
  54234. + i++) {
  54235. + core_if->
  54236. + core_params->dev_tx_fifo_size[i] =
  54237. + tx_siz[i];
  54238. + }
  54239. + } else {
  54240. + params->dev_tx_fifo_size[ep->
  54241. + dwc_ep.tx_fifo_num -
  54242. + 1] = tx_siz[0];
  54243. + }
  54244. + }
  54245. + retval = -DWC_E_INVALID;
  54246. + }
  54247. + return retval;
  54248. +}
  54249. +
  54250. +static int cfi_handle_reset_all(struct dwc_otg_pcd *pcd, uint8_t addr)
  54251. +{
  54252. + int retval = 0;
  54253. + cfi_ep_t *cfiep;
  54254. + cfiobject_t *cfi = pcd->cfi;
  54255. + dwc_list_link_t *tmp;
  54256. +
  54257. + retval = cfi_handle_reset_fifo_val(pcd, addr, 1, 1);
  54258. + if (retval < 0) {
  54259. + return retval;
  54260. + }
  54261. +
  54262. + /* If the EP address is known then reset the features for only that EP */
  54263. + if (addr) {
  54264. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54265. + if (NULL == cfiep) {
  54266. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  54267. + __func__, addr);
  54268. + return -DWC_E_INVALID;
  54269. + }
  54270. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  54271. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  54272. + }
  54273. + /* Otherwise (wValue == 0), reset all features of all EP's */
  54274. + else {
  54275. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  54276. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  54277. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54278. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54279. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  54280. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  54281. + if (retval < 0) {
  54282. + CFI_INFO
  54283. + ("%s: Error resetting the feature Reset All\n",
  54284. + __func__);
  54285. + return retval;
  54286. + }
  54287. + }
  54288. + }
  54289. + return retval;
  54290. +}
  54291. +
  54292. +static int cfi_handle_reset_dma_buff_setup(struct dwc_otg_pcd *pcd,
  54293. + uint8_t addr)
  54294. +{
  54295. + int retval = 0;
  54296. + cfi_ep_t *cfiep;
  54297. + cfiobject_t *cfi = pcd->cfi;
  54298. + dwc_list_link_t *tmp;
  54299. +
  54300. + /* If the EP address is known then reset the features for only that EP */
  54301. + if (addr) {
  54302. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54303. + if (NULL == cfiep) {
  54304. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  54305. + __func__, addr);
  54306. + return -DWC_E_INVALID;
  54307. + }
  54308. + retval = cfi_reset_sg_val(cfiep);
  54309. + }
  54310. + /* Otherwise (wValue == 0), reset all features of all EP's */
  54311. + else {
  54312. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  54313. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  54314. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54315. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54316. + retval = cfi_reset_sg_val(cfiep);
  54317. + if (retval < 0) {
  54318. + CFI_INFO
  54319. + ("%s: Error resetting the feature Buffer Setup\n",
  54320. + __func__);
  54321. + return retval;
  54322. + }
  54323. + }
  54324. + }
  54325. + return retval;
  54326. +}
  54327. +
  54328. +static int cfi_handle_reset_concat_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  54329. +{
  54330. + int retval = 0;
  54331. + cfi_ep_t *cfiep;
  54332. + cfiobject_t *cfi = pcd->cfi;
  54333. + dwc_list_link_t *tmp;
  54334. +
  54335. + /* If the EP address is known then reset the features for only that EP */
  54336. + if (addr) {
  54337. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54338. + if (NULL == cfiep) {
  54339. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  54340. + __func__, addr);
  54341. + return -DWC_E_INVALID;
  54342. + }
  54343. + retval = cfi_reset_concat_val(cfiep);
  54344. + }
  54345. + /* Otherwise (wValue == 0), reset all features of all EP's */
  54346. + else {
  54347. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  54348. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  54349. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54350. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54351. + retval = cfi_reset_concat_val(cfiep);
  54352. + if (retval < 0) {
  54353. + CFI_INFO
  54354. + ("%s: Error resetting the feature Concatenation Value\n",
  54355. + __func__);
  54356. + return retval;
  54357. + }
  54358. + }
  54359. + }
  54360. + return retval;
  54361. +}
  54362. +
  54363. +static int cfi_handle_reset_align_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  54364. +{
  54365. + int retval = 0;
  54366. + cfi_ep_t *cfiep;
  54367. + cfiobject_t *cfi = pcd->cfi;
  54368. + dwc_list_link_t *tmp;
  54369. +
  54370. + /* If the EP address is known then reset the features for only that EP */
  54371. + if (addr) {
  54372. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54373. + if (NULL == cfiep) {
  54374. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  54375. + __func__, addr);
  54376. + return -DWC_E_INVALID;
  54377. + }
  54378. + retval = cfi_reset_align_val(cfiep);
  54379. + }
  54380. + /* Otherwise (wValue == 0), reset all features of all EP's */
  54381. + else {
  54382. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  54383. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  54384. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54385. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54386. + retval = cfi_reset_align_val(cfiep);
  54387. + if (retval < 0) {
  54388. + CFI_INFO
  54389. + ("%s: Error resetting the feature Aliignment Value\n",
  54390. + __func__);
  54391. + return retval;
  54392. + }
  54393. + }
  54394. + }
  54395. + return retval;
  54396. +
  54397. +}
  54398. +
  54399. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  54400. + struct cfi_usb_ctrlrequest *req)
  54401. +{
  54402. + int retval = 0;
  54403. +
  54404. + switch (req->wIndex) {
  54405. + case 0:
  54406. + /* Reset all features */
  54407. + retval = cfi_handle_reset_all(pcd, req->wValue & 0xff);
  54408. + break;
  54409. +
  54410. + case FT_ID_DMA_BUFFER_SETUP:
  54411. + /* Reset the SG buffer setup */
  54412. + retval =
  54413. + cfi_handle_reset_dma_buff_setup(pcd, req->wValue & 0xff);
  54414. + break;
  54415. +
  54416. + case FT_ID_DMA_CONCAT_SETUP:
  54417. + /* Reset the Concatenation buffer setup */
  54418. + retval = cfi_handle_reset_concat_val(pcd, req->wValue & 0xff);
  54419. + break;
  54420. +
  54421. + case FT_ID_DMA_BUFF_ALIGN:
  54422. + /* Reset the Alignment buffer setup */
  54423. + retval = cfi_handle_reset_align_val(pcd, req->wValue & 0xff);
  54424. + break;
  54425. +
  54426. + case FT_ID_TX_FIFO_DEPTH:
  54427. + retval =
  54428. + cfi_handle_reset_fifo_val(pcd, req->wValue & 0xff, 0, 1);
  54429. + pcd->cfi->need_gadget_att = 0;
  54430. + break;
  54431. +
  54432. + case FT_ID_RX_FIFO_DEPTH:
  54433. + retval = cfi_handle_reset_fifo_val(pcd, 0, 1, 0);
  54434. + pcd->cfi->need_gadget_att = 0;
  54435. + break;
  54436. + default:
  54437. + break;
  54438. + }
  54439. + return retval;
  54440. +}
  54441. +
  54442. +/**
  54443. + * This function sets a new value for the SG buffer setup.
  54444. + */
  54445. +static int cfi_ep_set_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  54446. +{
  54447. + uint8_t inaddr, outaddr;
  54448. + cfi_ep_t *epin, *epout;
  54449. + ddma_sg_buffer_setup_t *psgval;
  54450. + uint32_t desccount, size;
  54451. +
  54452. + CFI_INFO("%s\n", __func__);
  54453. +
  54454. + psgval = (ddma_sg_buffer_setup_t *) buf;
  54455. + desccount = (uint32_t) psgval->bCount;
  54456. + size = (uint32_t) psgval->wSize;
  54457. +
  54458. + /* Check the DMA descriptor count */
  54459. + if ((desccount > MAX_DMA_DESCS_PER_EP) || (desccount == 0)) {
  54460. + CFI_INFO
  54461. + ("%s: The count of DMA Descriptors should be between 1 and %d\n",
  54462. + __func__, MAX_DMA_DESCS_PER_EP);
  54463. + return -DWC_E_INVALID;
  54464. + }
  54465. +
  54466. + /* Check the DMA descriptor count */
  54467. +
  54468. + if (size == 0) {
  54469. +
  54470. + CFI_INFO("%s: The transfer size should be at least 1 byte\n",
  54471. + __func__);
  54472. +
  54473. + return -DWC_E_INVALID;
  54474. +
  54475. + }
  54476. +
  54477. + inaddr = psgval->bInEndpointAddress;
  54478. + outaddr = psgval->bOutEndpointAddress;
  54479. +
  54480. + epin = get_cfi_ep_by_addr(pcd->cfi, inaddr);
  54481. + epout = get_cfi_ep_by_addr(pcd->cfi, outaddr);
  54482. +
  54483. + if (NULL == epin || NULL == epout) {
  54484. + CFI_INFO
  54485. + ("%s: Unable to get the endpoints inaddr=0x%02x outaddr=0x%02x\n",
  54486. + __func__, inaddr, outaddr);
  54487. + return -DWC_E_INVALID;
  54488. + }
  54489. +
  54490. + epin->ep->dwc_ep.buff_mode = BM_SG;
  54491. + dwc_memcpy(epin->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  54492. +
  54493. + epout->ep->dwc_ep.buff_mode = BM_SG;
  54494. + dwc_memcpy(epout->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  54495. +
  54496. + return 0;
  54497. +}
  54498. +
  54499. +/**
  54500. + * This function sets a new value for the buffer Alignment setup.
  54501. + */
  54502. +static int cfi_ep_set_alignment_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  54503. +{
  54504. + cfi_ep_t *ep;
  54505. + uint8_t addr;
  54506. + ddma_align_buffer_setup_t *palignval;
  54507. +
  54508. + palignval = (ddma_align_buffer_setup_t *) buf;
  54509. + addr = palignval->bEndpointAddress;
  54510. +
  54511. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54512. +
  54513. + if (NULL == ep) {
  54514. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  54515. + __func__, addr);
  54516. + return -DWC_E_INVALID;
  54517. + }
  54518. +
  54519. + ep->ep->dwc_ep.buff_mode = BM_ALIGN;
  54520. + dwc_memcpy(ep->bm_align, palignval, sizeof(ddma_align_buffer_setup_t));
  54521. +
  54522. + return 0;
  54523. +}
  54524. +
  54525. +/**
  54526. + * This function sets a new value for the Concatenation buffer setup.
  54527. + */
  54528. +static int cfi_ep_set_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  54529. +{
  54530. + uint8_t addr;
  54531. + cfi_ep_t *ep;
  54532. + struct _ddma_concat_buffer_setup_hdr *pConcatValHdr;
  54533. + uint16_t *pVals;
  54534. + uint32_t desccount;
  54535. + int i;
  54536. + uint16_t mps;
  54537. +
  54538. + pConcatValHdr = (struct _ddma_concat_buffer_setup_hdr *)buf;
  54539. + desccount = (uint32_t) pConcatValHdr->bDescCount;
  54540. + pVals = (uint16_t *) (buf + BS_CONCAT_VAL_HDR_LEN);
  54541. +
  54542. + /* Check the DMA descriptor count */
  54543. + if (desccount > MAX_DMA_DESCS_PER_EP) {
  54544. + CFI_INFO("%s: Maximum DMA Descriptor count should be %d\n",
  54545. + __func__, MAX_DMA_DESCS_PER_EP);
  54546. + return -DWC_E_INVALID;
  54547. + }
  54548. +
  54549. + addr = pConcatValHdr->bEndpointAddress;
  54550. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54551. + if (NULL == ep) {
  54552. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  54553. + __func__, addr);
  54554. + return -DWC_E_INVALID;
  54555. + }
  54556. +
  54557. + mps = UGETW(ep->ep->desc->wMaxPacketSize);
  54558. +
  54559. +#if 0
  54560. + for (i = 0; i < desccount; i++) {
  54561. + CFI_INFO("%s: wTxSize[%d]=0x%04x\n", __func__, i, pVals[i]);
  54562. + }
  54563. + CFI_INFO("%s: epname=%s; mps=%d\n", __func__, ep->ep->ep.name, mps);
  54564. +#endif
  54565. +
  54566. + /* Check the wTxSizes to be less than or equal to the mps */
  54567. + for (i = 0; i < desccount; i++) {
  54568. + if (pVals[i] > mps) {
  54569. + CFI_INFO
  54570. + ("%s: ERROR - the wTxSize[%d] should be <= MPS (wTxSize=%d)\n",
  54571. + __func__, i, pVals[i]);
  54572. + return -DWC_E_INVALID;
  54573. + }
  54574. + }
  54575. +
  54576. + ep->ep->dwc_ep.buff_mode = BM_CONCAT;
  54577. + dwc_memcpy(ep->bm_concat, pConcatValHdr, BS_CONCAT_VAL_HDR_LEN);
  54578. +
  54579. + /* Free the previously allocated storage for the wTxBytes */
  54580. + if (ep->bm_concat->wTxBytes) {
  54581. + DWC_FREE(ep->bm_concat->wTxBytes);
  54582. + }
  54583. +
  54584. + /* Allocate a new storage for the wTxBytes field */
  54585. + ep->bm_concat->wTxBytes =
  54586. + DWC_ALLOC(sizeof(uint16_t) * pConcatValHdr->bDescCount);
  54587. + if (NULL == ep->bm_concat->wTxBytes) {
  54588. + CFI_INFO("%s: Unable to allocate memory\n", __func__);
  54589. + return -DWC_E_NO_MEMORY;
  54590. + }
  54591. +
  54592. + /* Copy the new values into the wTxBytes filed */
  54593. + dwc_memcpy(ep->bm_concat->wTxBytes, buf + BS_CONCAT_VAL_HDR_LEN,
  54594. + sizeof(uint16_t) * pConcatValHdr->bDescCount);
  54595. +
  54596. + return 0;
  54597. +}
  54598. +
  54599. +/**
  54600. + * This function calculates the total of all FIFO sizes
  54601. + *
  54602. + * @param core_if Programming view of DWC_otg controller
  54603. + *
  54604. + * @return The total of data FIFO sizes.
  54605. + *
  54606. + */
  54607. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if)
  54608. +{
  54609. + dwc_otg_core_params_t *params = core_if->core_params;
  54610. + uint16_t dfifo_total = 0;
  54611. + int i;
  54612. +
  54613. + /* The shared RxFIFO size */
  54614. + dfifo_total =
  54615. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  54616. +
  54617. + /* Add up each TxFIFO size to the total */
  54618. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54619. + dfifo_total += params->dev_tx_fifo_size[i];
  54620. + }
  54621. +
  54622. + return dfifo_total;
  54623. +}
  54624. +
  54625. +/**
  54626. + * This function returns Rx FIFO size
  54627. + *
  54628. + * @param core_if Programming view of DWC_otg controller
  54629. + *
  54630. + * @return The total of data FIFO sizes.
  54631. + *
  54632. + */
  54633. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue)
  54634. +{
  54635. + switch (wValue >> 8) {
  54636. + case 0:
  54637. + return (core_if->pwron_rxfsiz <
  54638. + 32768) ? core_if->pwron_rxfsiz : 32768;
  54639. + break;
  54640. + case 1:
  54641. + return core_if->core_params->dev_rx_fifo_size;
  54642. + break;
  54643. + default:
  54644. + return -DWC_E_INVALID;
  54645. + break;
  54646. + }
  54647. +}
  54648. +
  54649. +/**
  54650. + * This function returns Tx FIFO size for IN EP
  54651. + *
  54652. + * @param core_if Programming view of DWC_otg controller
  54653. + *
  54654. + * @return The total of data FIFO sizes.
  54655. + *
  54656. + */
  54657. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue)
  54658. +{
  54659. + dwc_otg_pcd_ep_t *ep;
  54660. +
  54661. + ep = get_ep_by_addr(pcd, wValue & 0xff);
  54662. +
  54663. + if (NULL == ep) {
  54664. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  54665. + __func__, wValue & 0xff);
  54666. + return -DWC_E_INVALID;
  54667. + }
  54668. +
  54669. + if (!ep->dwc_ep.is_in) {
  54670. + CFI_INFO
  54671. + ("%s: No Tx FIFO assingned to the Out endpoint addr=0x%02x\n",
  54672. + __func__, wValue & 0xff);
  54673. + return -DWC_E_INVALID;
  54674. + }
  54675. +
  54676. + switch (wValue >> 8) {
  54677. + case 0:
  54678. + return (GET_CORE_IF(pcd)->pwron_txfsiz
  54679. + [ep->dwc_ep.tx_fifo_num - 1] <
  54680. + 768) ? GET_CORE_IF(pcd)->pwron_txfsiz[ep->
  54681. + dwc_ep.tx_fifo_num
  54682. + - 1] : 32768;
  54683. + break;
  54684. + case 1:
  54685. + return GET_CORE_IF(pcd)->core_params->
  54686. + dev_tx_fifo_size[ep->dwc_ep.num - 1];
  54687. + break;
  54688. + default:
  54689. + return -DWC_E_INVALID;
  54690. + break;
  54691. + }
  54692. +}
  54693. +
  54694. +/**
  54695. + * This function checks if the submitted combination of
  54696. + * device mode FIFO sizes is possible or not.
  54697. + *
  54698. + * @param core_if Programming view of DWC_otg controller
  54699. + *
  54700. + * @return 1 if possible, 0 otherwise.
  54701. + *
  54702. + */
  54703. +static uint8_t check_fifo_sizes(dwc_otg_core_if_t * core_if)
  54704. +{
  54705. + uint16_t dfifo_actual = 0;
  54706. + dwc_otg_core_params_t *params = core_if->core_params;
  54707. + uint16_t start_addr = 0;
  54708. + int i;
  54709. +
  54710. + dfifo_actual =
  54711. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  54712. +
  54713. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54714. + dfifo_actual += params->dev_tx_fifo_size[i];
  54715. + }
  54716. +
  54717. + if (dfifo_actual > core_if->total_fifo_size) {
  54718. + return 0;
  54719. + }
  54720. +
  54721. + if (params->dev_rx_fifo_size > 32768 || params->dev_rx_fifo_size < 16)
  54722. + return 0;
  54723. +
  54724. + if (params->dev_nperio_tx_fifo_size > 32768
  54725. + || params->dev_nperio_tx_fifo_size < 16)
  54726. + return 0;
  54727. +
  54728. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54729. +
  54730. + if (params->dev_tx_fifo_size[i] > 768
  54731. + || params->dev_tx_fifo_size[i] < 4)
  54732. + return 0;
  54733. + }
  54734. +
  54735. + if (params->dev_rx_fifo_size > core_if->pwron_rxfsiz)
  54736. + return 0;
  54737. + start_addr = params->dev_rx_fifo_size;
  54738. +
  54739. + if (params->dev_nperio_tx_fifo_size > core_if->pwron_gnptxfsiz)
  54740. + return 0;
  54741. + start_addr += params->dev_nperio_tx_fifo_size;
  54742. +
  54743. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54744. +
  54745. + if (params->dev_tx_fifo_size[i] > core_if->pwron_txfsiz[i])
  54746. + return 0;
  54747. + start_addr += params->dev_tx_fifo_size[i];
  54748. + }
  54749. +
  54750. + return 1;
  54751. +}
  54752. +
  54753. +/**
  54754. + * This function resizes Device mode FIFOs
  54755. + *
  54756. + * @param core_if Programming view of DWC_otg controller
  54757. + *
  54758. + * @return 1 if successful, 0 otherwise
  54759. + *
  54760. + */
  54761. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if)
  54762. +{
  54763. + int i = 0;
  54764. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  54765. + dwc_otg_core_params_t *params = core_if->core_params;
  54766. + uint32_t rx_fifo_size;
  54767. + fifosize_data_t nptxfifosize;
  54768. + fifosize_data_t txfifosize[15];
  54769. +
  54770. + uint32_t rx_fsz_bak;
  54771. + uint32_t nptxfsz_bak;
  54772. + uint32_t txfsz_bak[15];
  54773. +
  54774. + uint16_t start_address;
  54775. + uint8_t retval = 1;
  54776. +
  54777. + if (!check_fifo_sizes(core_if)) {
  54778. + return 0;
  54779. + }
  54780. +
  54781. + /* Configure data FIFO sizes */
  54782. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  54783. + rx_fsz_bak = DWC_READ_REG32(&global_regs->grxfsiz);
  54784. + rx_fifo_size = params->dev_rx_fifo_size;
  54785. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  54786. +
  54787. + /*
  54788. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  54789. + * Indexes of the FIFO size module parameters in the
  54790. + * dev_tx_fifo_size array and the FIFO size registers in
  54791. + * the dtxfsiz array run from 0 to 14.
  54792. + */
  54793. +
  54794. + /* Non-periodic Tx FIFO */
  54795. + nptxfsz_bak = DWC_READ_REG32(&global_regs->gnptxfsiz);
  54796. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  54797. + start_address = params->dev_rx_fifo_size;
  54798. + nptxfifosize.b.startaddr = start_address;
  54799. +
  54800. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  54801. +
  54802. + start_address += nptxfifosize.b.depth;
  54803. +
  54804. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54805. + txfsz_bak[i] = DWC_READ_REG32(&global_regs->dtxfsiz[i]);
  54806. +
  54807. + txfifosize[i].b.depth = params->dev_tx_fifo_size[i];
  54808. + txfifosize[i].b.startaddr = start_address;
  54809. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  54810. + txfifosize[i].d32);
  54811. +
  54812. + start_address += txfifosize[i].b.depth;
  54813. + }
  54814. +
  54815. + /** Check if register values are set correctly */
  54816. + if (rx_fifo_size != DWC_READ_REG32(&global_regs->grxfsiz)) {
  54817. + retval = 0;
  54818. + }
  54819. +
  54820. + if (nptxfifosize.d32 != DWC_READ_REG32(&global_regs->gnptxfsiz)) {
  54821. + retval = 0;
  54822. + }
  54823. +
  54824. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54825. + if (txfifosize[i].d32 !=
  54826. + DWC_READ_REG32(&global_regs->dtxfsiz[i])) {
  54827. + retval = 0;
  54828. + }
  54829. + }
  54830. +
  54831. + /** If register values are not set correctly, reset old values */
  54832. + if (retval == 0) {
  54833. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fsz_bak);
  54834. +
  54835. + /* Non-periodic Tx FIFO */
  54836. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfsz_bak);
  54837. +
  54838. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54839. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  54840. + txfsz_bak[i]);
  54841. + }
  54842. + }
  54843. + } else {
  54844. + return 0;
  54845. + }
  54846. +
  54847. + /* Flush the FIFOs */
  54848. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  54849. + dwc_otg_flush_rx_fifo(core_if);
  54850. +
  54851. + return retval;
  54852. +}
  54853. +
  54854. +/**
  54855. + * This function sets a new value for the buffer Alignment setup.
  54856. + */
  54857. +static int cfi_ep_set_tx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  54858. +{
  54859. + int retval;
  54860. + uint32_t fsiz;
  54861. + uint16_t size;
  54862. + uint16_t ep_addr;
  54863. + dwc_otg_pcd_ep_t *ep;
  54864. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  54865. + tx_fifo_size_setup_t *ptxfifoval;
  54866. +
  54867. + ptxfifoval = (tx_fifo_size_setup_t *) buf;
  54868. + ep_addr = ptxfifoval->bEndpointAddress;
  54869. + size = ptxfifoval->wDepth;
  54870. +
  54871. + ep = get_ep_by_addr(pcd, ep_addr);
  54872. +
  54873. + CFI_INFO
  54874. + ("%s: Set Tx FIFO size: endpoint addr=0x%02x, depth=%d, FIFO Num=%d\n",
  54875. + __func__, ep_addr, size, ep->dwc_ep.tx_fifo_num);
  54876. +
  54877. + if (NULL == ep) {
  54878. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  54879. + __func__, ep_addr);
  54880. + return -DWC_E_INVALID;
  54881. + }
  54882. +
  54883. + fsiz = params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1];
  54884. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = size;
  54885. +
  54886. + if (resize_fifos(GET_CORE_IF(pcd))) {
  54887. + retval = 0;
  54888. + } else {
  54889. + CFI_INFO
  54890. + ("%s: Error setting the feature Tx FIFO Size for EP%d\n",
  54891. + __func__, ep_addr);
  54892. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = fsiz;
  54893. + retval = -DWC_E_INVALID;
  54894. + }
  54895. +
  54896. + return retval;
  54897. +}
  54898. +
  54899. +/**
  54900. + * This function sets a new value for the buffer Alignment setup.
  54901. + */
  54902. +static int cfi_set_rx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  54903. +{
  54904. + int retval;
  54905. + uint32_t fsiz;
  54906. + uint16_t size;
  54907. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  54908. + rx_fifo_size_setup_t *prxfifoval;
  54909. +
  54910. + prxfifoval = (rx_fifo_size_setup_t *) buf;
  54911. + size = prxfifoval->wDepth;
  54912. +
  54913. + fsiz = params->dev_rx_fifo_size;
  54914. + params->dev_rx_fifo_size = size;
  54915. +
  54916. + if (resize_fifos(GET_CORE_IF(pcd))) {
  54917. + retval = 0;
  54918. + } else {
  54919. + CFI_INFO("%s: Error setting the feature Rx FIFO Size\n",
  54920. + __func__);
  54921. + params->dev_rx_fifo_size = fsiz;
  54922. + retval = -DWC_E_INVALID;
  54923. + }
  54924. +
  54925. + return retval;
  54926. +}
  54927. +
  54928. +/**
  54929. + * This function reads the SG of an EP's buffer setup into the buffer buf
  54930. + */
  54931. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  54932. + struct cfi_usb_ctrlrequest *req)
  54933. +{
  54934. + int retval = -DWC_E_INVALID;
  54935. + uint8_t addr;
  54936. + cfi_ep_t *ep;
  54937. +
  54938. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  54939. + addr = req->wValue & 0xFF;
  54940. + if (addr == 0) /* The address should be non-zero */
  54941. + return retval;
  54942. +
  54943. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54944. + if (NULL == ep) {
  54945. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  54946. + __func__, addr);
  54947. + return retval;
  54948. + }
  54949. +
  54950. + dwc_memcpy(buf, ep->bm_sg, BS_SG_VAL_DESC_LEN);
  54951. + retval = BS_SG_VAL_DESC_LEN;
  54952. + return retval;
  54953. +}
  54954. +
  54955. +/**
  54956. + * This function reads the Concatenation value of an EP's buffer mode into
  54957. + * the buffer buf
  54958. + */
  54959. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  54960. + struct cfi_usb_ctrlrequest *req)
  54961. +{
  54962. + int retval = -DWC_E_INVALID;
  54963. + uint8_t addr;
  54964. + cfi_ep_t *ep;
  54965. + uint8_t desc_count;
  54966. +
  54967. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  54968. + addr = req->wValue & 0xFF;
  54969. + if (addr == 0) /* The address should be non-zero */
  54970. + return retval;
  54971. +
  54972. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54973. + if (NULL == ep) {
  54974. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  54975. + __func__, addr);
  54976. + return retval;
  54977. + }
  54978. +
  54979. + /* Copy the header to the buffer */
  54980. + dwc_memcpy(buf, ep->bm_concat, BS_CONCAT_VAL_HDR_LEN);
  54981. + /* Advance the buffer pointer by the header size */
  54982. + buf += BS_CONCAT_VAL_HDR_LEN;
  54983. +
  54984. + desc_count = ep->bm_concat->hdr.bDescCount;
  54985. + /* Copy alll the wTxBytes to the buffer */
  54986. + dwc_memcpy(buf, ep->bm_concat->wTxBytes, sizeof(uid16_t) * desc_count);
  54987. +
  54988. + retval = BS_CONCAT_VAL_HDR_LEN + sizeof(uid16_t) * desc_count;
  54989. + return retval;
  54990. +}
  54991. +
  54992. +/**
  54993. + * This function reads the buffer Alignment value of an EP's buffer mode into
  54994. + * the buffer buf
  54995. + *
  54996. + * @return The total number of bytes copied to the buffer or negative error code.
  54997. + */
  54998. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  54999. + struct cfi_usb_ctrlrequest *req)
  55000. +{
  55001. + int retval = -DWC_E_INVALID;
  55002. + uint8_t addr;
  55003. + cfi_ep_t *ep;
  55004. +
  55005. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  55006. + addr = req->wValue & 0xFF;
  55007. + if (addr == 0) /* The address should be non-zero */
  55008. + return retval;
  55009. +
  55010. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  55011. + if (NULL == ep) {
  55012. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  55013. + __func__, addr);
  55014. + return retval;
  55015. + }
  55016. +
  55017. + dwc_memcpy(buf, ep->bm_align, BS_ALIGN_VAL_HDR_LEN);
  55018. + retval = BS_ALIGN_VAL_HDR_LEN;
  55019. +
  55020. + return retval;
  55021. +}
  55022. +
  55023. +/**
  55024. + * This function sets a new value for the specified feature
  55025. + *
  55026. + * @param pcd A pointer to the PCD object
  55027. + *
  55028. + * @return 0 if successful, negative error code otherwise to stall the DCE.
  55029. + */
  55030. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd)
  55031. +{
  55032. + int retval = -DWC_E_NOT_SUPPORTED;
  55033. + uint16_t wIndex, wValue;
  55034. + uint8_t bRequest;
  55035. + struct dwc_otg_core_if *coreif;
  55036. + cfiobject_t *cfi = pcd->cfi;
  55037. + struct cfi_usb_ctrlrequest *ctrl_req;
  55038. + uint8_t *buf;
  55039. + ctrl_req = &cfi->ctrl_req;
  55040. +
  55041. + buf = pcd->cfi->ctrl_req.data;
  55042. +
  55043. + coreif = GET_CORE_IF(pcd);
  55044. + bRequest = ctrl_req->bRequest;
  55045. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  55046. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  55047. +
  55048. + /* See which feature is to be modified */
  55049. + switch (wIndex) {
  55050. + case FT_ID_DMA_BUFFER_SETUP:
  55051. + /* Modify the feature */
  55052. + if ((retval = cfi_ep_set_sg_val(buf, pcd)) < 0)
  55053. + return retval;
  55054. +
  55055. + /* And send this request to the gadget */
  55056. + cfi->need_gadget_att = 1;
  55057. + break;
  55058. +
  55059. + case FT_ID_DMA_BUFF_ALIGN:
  55060. + if ((retval = cfi_ep_set_alignment_val(buf, pcd)) < 0)
  55061. + return retval;
  55062. + cfi->need_gadget_att = 1;
  55063. + break;
  55064. +
  55065. + case FT_ID_DMA_CONCAT_SETUP:
  55066. + /* Modify the feature */
  55067. + if ((retval = cfi_ep_set_concat_val(buf, pcd)) < 0)
  55068. + return retval;
  55069. + cfi->need_gadget_att = 1;
  55070. + break;
  55071. +
  55072. + case FT_ID_DMA_CIRCULAR:
  55073. + CFI_INFO("FT_ID_DMA_CIRCULAR\n");
  55074. + break;
  55075. +
  55076. + case FT_ID_THRESHOLD_SETUP:
  55077. + CFI_INFO("FT_ID_THRESHOLD_SETUP\n");
  55078. + break;
  55079. +
  55080. + case FT_ID_DFIFO_DEPTH:
  55081. + CFI_INFO("FT_ID_DFIFO_DEPTH\n");
  55082. + break;
  55083. +
  55084. + case FT_ID_TX_FIFO_DEPTH:
  55085. + CFI_INFO("FT_ID_TX_FIFO_DEPTH\n");
  55086. + if ((retval = cfi_ep_set_tx_fifo_val(buf, pcd)) < 0)
  55087. + return retval;
  55088. + cfi->need_gadget_att = 0;
  55089. + break;
  55090. +
  55091. + case FT_ID_RX_FIFO_DEPTH:
  55092. + CFI_INFO("FT_ID_RX_FIFO_DEPTH\n");
  55093. + if ((retval = cfi_set_rx_fifo_val(buf, pcd)) < 0)
  55094. + return retval;
  55095. + cfi->need_gadget_att = 0;
  55096. + break;
  55097. + }
  55098. +
  55099. + return retval;
  55100. +}
  55101. +
  55102. +#endif //DWC_UTE_CFI
  55103. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_cfi.h linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_cfi.h
  55104. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 1970-01-01 01:00:00.000000000 +0100
  55105. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 2014-02-18 11:52:14.000000000 +0100
  55106. @@ -0,0 +1,320 @@
  55107. +/* ==========================================================================
  55108. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  55109. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  55110. + * otherwise expressly agreed to in writing between Synopsys and you.
  55111. + *
  55112. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  55113. + * any End User Software License Agreement or Agreement for Licensed Product
  55114. + * with Synopsys or any supplement thereto. You are permitted to use and
  55115. + * redistribute this Software in source and binary forms, with or without
  55116. + * modification, provided that redistributions of source code must retain this
  55117. + * notice. You may not view, use, disclose, copy or distribute this file or
  55118. + * any information contained herein except pursuant to this license grant from
  55119. + * Synopsys. If you do not agree with this notice, including the disclaimer
  55120. + * below, then you are not authorized to use the Software.
  55121. + *
  55122. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  55123. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  55124. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  55125. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  55126. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  55127. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  55128. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  55129. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  55130. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  55131. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  55132. + * DAMAGE.
  55133. + * ========================================================================== */
  55134. +
  55135. +#if !defined(__DWC_OTG_CFI_H__)
  55136. +#define __DWC_OTG_CFI_H__
  55137. +
  55138. +#include "dwc_otg_pcd.h"
  55139. +#include "dwc_cfi_common.h"
  55140. +
  55141. +/**
  55142. + * @file
  55143. + * This file contains the CFI related OTG PCD specific common constants,
  55144. + * interfaces(functions and macros) and data structures.The CFI Protocol is an
  55145. + * optional interface for internal testing purposes that a DUT may implement to
  55146. + * support testing of configurable features.
  55147. + *
  55148. + */
  55149. +
  55150. +struct dwc_otg_pcd;
  55151. +struct dwc_otg_pcd_ep;
  55152. +
  55153. +/** OTG CFI Features (properties) ID constants */
  55154. +/** This is a request for all Core Features */
  55155. +#define FT_ID_DMA_MODE 0x0001
  55156. +#define FT_ID_DMA_BUFFER_SETUP 0x0002
  55157. +#define FT_ID_DMA_BUFF_ALIGN 0x0003
  55158. +#define FT_ID_DMA_CONCAT_SETUP 0x0004
  55159. +#define FT_ID_DMA_CIRCULAR 0x0005
  55160. +#define FT_ID_THRESHOLD_SETUP 0x0006
  55161. +#define FT_ID_DFIFO_DEPTH 0x0007
  55162. +#define FT_ID_TX_FIFO_DEPTH 0x0008
  55163. +#define FT_ID_RX_FIFO_DEPTH 0x0009
  55164. +
  55165. +/**********************************************************/
  55166. +#define CFI_INFO_DEF
  55167. +
  55168. +#ifdef CFI_INFO_DEF
  55169. +#define CFI_INFO(fmt...) DWC_PRINTF("CFI: " fmt);
  55170. +#else
  55171. +#define CFI_INFO(fmt...)
  55172. +#endif
  55173. +
  55174. +#define min(x,y) ({ \
  55175. + x < y ? x : y; })
  55176. +
  55177. +#define max(x,y) ({ \
  55178. + x > y ? x : y; })
  55179. +
  55180. +/**
  55181. + * Descriptor DMA SG Buffer setup structure (SG buffer). This structure is
  55182. + * also used for setting up a buffer for Circular DDMA.
  55183. + */
  55184. +struct _ddma_sg_buffer_setup {
  55185. +#define BS_SG_VAL_DESC_LEN 6
  55186. + /* The OUT EP address */
  55187. + uint8_t bOutEndpointAddress;
  55188. + /* The IN EP address */
  55189. + uint8_t bInEndpointAddress;
  55190. + /* Number of bytes to put between transfer segments (must be DWORD boundaries) */
  55191. + uint8_t bOffset;
  55192. + /* The number of transfer segments (a DMA descriptors per each segment) */
  55193. + uint8_t bCount;
  55194. + /* Size (in byte) of each transfer segment */
  55195. + uint16_t wSize;
  55196. +} __attribute__ ((packed));
  55197. +typedef struct _ddma_sg_buffer_setup ddma_sg_buffer_setup_t;
  55198. +
  55199. +/** Descriptor DMA Concatenation Buffer setup structure */
  55200. +struct _ddma_concat_buffer_setup_hdr {
  55201. +#define BS_CONCAT_VAL_HDR_LEN 4
  55202. + /* The endpoint for which the buffer is to be set up */
  55203. + uint8_t bEndpointAddress;
  55204. + /* The count of descriptors to be used */
  55205. + uint8_t bDescCount;
  55206. + /* The total size of the transfer */
  55207. + uint16_t wSize;
  55208. +} __attribute__ ((packed));
  55209. +typedef struct _ddma_concat_buffer_setup_hdr ddma_concat_buffer_setup_hdr_t;
  55210. +
  55211. +/** Descriptor DMA Concatenation Buffer setup structure */
  55212. +struct _ddma_concat_buffer_setup {
  55213. + /* The SG header */
  55214. + ddma_concat_buffer_setup_hdr_t hdr;
  55215. +
  55216. + /* The XFER sizes pointer (allocated dynamically) */
  55217. + uint16_t *wTxBytes;
  55218. +} __attribute__ ((packed));
  55219. +typedef struct _ddma_concat_buffer_setup ddma_concat_buffer_setup_t;
  55220. +
  55221. +/** Descriptor DMA Alignment Buffer setup structure */
  55222. +struct _ddma_align_buffer_setup {
  55223. +#define BS_ALIGN_VAL_HDR_LEN 2
  55224. + uint8_t bEndpointAddress;
  55225. + uint8_t bAlign;
  55226. +} __attribute__ ((packed));
  55227. +typedef struct _ddma_align_buffer_setup ddma_align_buffer_setup_t;
  55228. +
  55229. +/** Transmit FIFO Size setup structure */
  55230. +struct _tx_fifo_size_setup {
  55231. + uint8_t bEndpointAddress;
  55232. + uint16_t wDepth;
  55233. +} __attribute__ ((packed));
  55234. +typedef struct _tx_fifo_size_setup tx_fifo_size_setup_t;
  55235. +
  55236. +/** Transmit FIFO Size setup structure */
  55237. +struct _rx_fifo_size_setup {
  55238. + uint16_t wDepth;
  55239. +} __attribute__ ((packed));
  55240. +typedef struct _rx_fifo_size_setup rx_fifo_size_setup_t;
  55241. +
  55242. +/**
  55243. + * struct cfi_usb_ctrlrequest - the CFI implementation of the struct usb_ctrlrequest
  55244. + * This structure encapsulates the standard usb_ctrlrequest and adds a pointer
  55245. + * to the data returned in the data stage of a 3-stage Control Write requests.
  55246. + */
  55247. +struct cfi_usb_ctrlrequest {
  55248. + uint8_t bRequestType;
  55249. + uint8_t bRequest;
  55250. + uint16_t wValue;
  55251. + uint16_t wIndex;
  55252. + uint16_t wLength;
  55253. + uint8_t *data;
  55254. +} UPACKED;
  55255. +
  55256. +/*---------------------------------------------------------------------------*/
  55257. +
  55258. +/**
  55259. + * The CFI wrapper of the enabled and activated dwc_otg_pcd_ep structures.
  55260. + * This structure is used to store the buffer setup data for any
  55261. + * enabled endpoint in the PCD.
  55262. + */
  55263. +struct cfi_ep {
  55264. + /* Entry for the list container */
  55265. + dwc_list_link_t lh;
  55266. + /* Pointer to the active PCD endpoint structure */
  55267. + struct dwc_otg_pcd_ep *ep;
  55268. + /* The last descriptor in the chain of DMA descriptors of the endpoint */
  55269. + struct dwc_otg_dma_desc *dma_desc_last;
  55270. + /* The SG feature value */
  55271. + ddma_sg_buffer_setup_t *bm_sg;
  55272. + /* The Circular feature value */
  55273. + ddma_sg_buffer_setup_t *bm_circ;
  55274. + /* The Concatenation feature value */
  55275. + ddma_concat_buffer_setup_t *bm_concat;
  55276. + /* The Alignment feature value */
  55277. + ddma_align_buffer_setup_t *bm_align;
  55278. + /* XFER length */
  55279. + uint32_t xfer_len;
  55280. + /*
  55281. + * Count of DMA descriptors currently used.
  55282. + * The total should not exceed the MAX_DMA_DESCS_PER_EP value
  55283. + * defined in the dwc_otg_cil.h
  55284. + */
  55285. + uint32_t desc_count;
  55286. +};
  55287. +typedef struct cfi_ep cfi_ep_t;
  55288. +
  55289. +typedef struct cfi_dma_buff {
  55290. +#define CFI_IN_BUF_LEN 1024
  55291. +#define CFI_OUT_BUF_LEN 1024
  55292. + dma_addr_t addr;
  55293. + uint8_t *buf;
  55294. +} cfi_dma_buff_t;
  55295. +
  55296. +struct cfiobject;
  55297. +
  55298. +/**
  55299. + * This is the interface for the CFI operations.
  55300. + *
  55301. + * @param ep_enable Called when any endpoint is enabled and activated.
  55302. + * @param release Called when the CFI object is released and it needs to correctly
  55303. + * deallocate the dynamic memory
  55304. + * @param ctrl_write_complete Called when the data stage of the request is complete
  55305. + */
  55306. +typedef struct cfi_ops {
  55307. + int (*ep_enable) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  55308. + struct dwc_otg_pcd_ep * ep);
  55309. + void *(*ep_alloc_buf) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  55310. + struct dwc_otg_pcd_ep * ep, dma_addr_t * dma,
  55311. + unsigned size, gfp_t flags);
  55312. + void (*release) (struct cfiobject * cfi);
  55313. + int (*ctrl_write_complete) (struct cfiobject * cfi,
  55314. + struct dwc_otg_pcd * pcd);
  55315. + void (*build_descriptors) (struct cfiobject * cfi,
  55316. + struct dwc_otg_pcd * pcd,
  55317. + struct dwc_otg_pcd_ep * ep,
  55318. + dwc_otg_pcd_request_t * req);
  55319. +} cfi_ops_t;
  55320. +
  55321. +struct cfiobject {
  55322. + cfi_ops_t ops;
  55323. + struct dwc_otg_pcd *pcd;
  55324. + struct usb_gadget *gadget;
  55325. +
  55326. + /* Buffers used to send/receive CFI-related request data */
  55327. + cfi_dma_buff_t buf_in;
  55328. + cfi_dma_buff_t buf_out;
  55329. +
  55330. + /* CFI specific Control request wrapper */
  55331. + struct cfi_usb_ctrlrequest ctrl_req;
  55332. +
  55333. + /* The list of active EP's in the PCD of type cfi_ep_t */
  55334. + dwc_list_link_t active_eps;
  55335. +
  55336. + /* This flag shall control the propagation of a specific request
  55337. + * to the gadget's processing routines.
  55338. + * 0 - no gadget handling
  55339. + * 1 - the gadget needs to know about this request (w/o completing a status
  55340. + * phase - just return a 0 to the _setup callback)
  55341. + */
  55342. + uint8_t need_gadget_att;
  55343. +
  55344. + /* Flag indicating whether the status IN phase needs to be
  55345. + * completed by the PCD
  55346. + */
  55347. + uint8_t need_status_in_complete;
  55348. +};
  55349. +typedef struct cfiobject cfiobject_t;
  55350. +
  55351. +#define DUMP_MSG
  55352. +
  55353. +#if defined(DUMP_MSG)
  55354. +static inline void dump_msg(const u8 * buf, unsigned int length)
  55355. +{
  55356. + unsigned int start, num, i;
  55357. + char line[52], *p;
  55358. +
  55359. + if (length >= 512)
  55360. + return;
  55361. +
  55362. + start = 0;
  55363. + while (length > 0) {
  55364. + num = min(length, 16u);
  55365. + p = line;
  55366. + for (i = 0; i < num; ++i) {
  55367. + if (i == 8)
  55368. + *p++ = ' ';
  55369. + DWC_SPRINTF(p, " %02x", buf[i]);
  55370. + p += 3;
  55371. + }
  55372. + *p = 0;
  55373. + DWC_DEBUG("%6x: %s\n", start, line);
  55374. + buf += num;
  55375. + start += num;
  55376. + length -= num;
  55377. + }
  55378. +}
  55379. +#else
  55380. +static inline void dump_msg(const u8 * buf, unsigned int length)
  55381. +{
  55382. +}
  55383. +#endif
  55384. +
  55385. +/**
  55386. + * This function returns a pointer to cfi_ep_t object with the addr address.
  55387. + */
  55388. +static inline struct cfi_ep *get_cfi_ep_by_addr(struct cfiobject *cfi,
  55389. + uint8_t addr)
  55390. +{
  55391. + struct cfi_ep *pcfiep;
  55392. + dwc_list_link_t *tmp;
  55393. +
  55394. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  55395. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  55396. +
  55397. + if (pcfiep->ep->desc->bEndpointAddress == addr) {
  55398. + return pcfiep;
  55399. + }
  55400. + }
  55401. +
  55402. + return NULL;
  55403. +}
  55404. +
  55405. +/**
  55406. + * This function returns a pointer to cfi_ep_t object that matches
  55407. + * the dwc_otg_pcd_ep object.
  55408. + */
  55409. +static inline struct cfi_ep *get_cfi_ep_by_pcd_ep(struct cfiobject *cfi,
  55410. + struct dwc_otg_pcd_ep *ep)
  55411. +{
  55412. + struct cfi_ep *pcfiep = NULL;
  55413. + dwc_list_link_t *tmp;
  55414. +
  55415. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  55416. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  55417. + if (pcfiep->ep == ep) {
  55418. + return pcfiep;
  55419. + }
  55420. + }
  55421. + return NULL;
  55422. +}
  55423. +
  55424. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl);
  55425. +
  55426. +#endif /* (__DWC_OTG_CFI_H__) */
  55427. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_cil.c linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_cil.c
  55428. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_cil.c 1970-01-01 01:00:00.000000000 +0100
  55429. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_cil.c 2014-02-18 11:52:14.000000000 +0100
  55430. @@ -0,0 +1,7151 @@
  55431. +/* ==========================================================================
  55432. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.c $
  55433. + * $Revision: #191 $
  55434. + * $Date: 2012/08/10 $
  55435. + * $Change: 2047372 $
  55436. + *
  55437. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  55438. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  55439. + * otherwise expressly agreed to in writing between Synopsys and you.
  55440. + *
  55441. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  55442. + * any End User Software License Agreement or Agreement for Licensed Product
  55443. + * with Synopsys or any supplement thereto. You are permitted to use and
  55444. + * redistribute this Software in source and binary forms, with or without
  55445. + * modification, provided that redistributions of source code must retain this
  55446. + * notice. You may not view, use, disclose, copy or distribute this file or
  55447. + * any information contained herein except pursuant to this license grant from
  55448. + * Synopsys. If you do not agree with this notice, including the disclaimer
  55449. + * below, then you are not authorized to use the Software.
  55450. + *
  55451. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  55452. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  55453. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  55454. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  55455. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  55456. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  55457. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  55458. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  55459. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  55460. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  55461. + * DAMAGE.
  55462. + * ========================================================================== */
  55463. +
  55464. +/** @file
  55465. + *
  55466. + * The Core Interface Layer provides basic services for accessing and
  55467. + * managing the DWC_otg hardware. These services are used by both the
  55468. + * Host Controller Driver and the Peripheral Controller Driver.
  55469. + *
  55470. + * The CIL manages the memory map for the core so that the HCD and PCD
  55471. + * don't have to do this separately. It also handles basic tasks like
  55472. + * reading/writing the registers and data FIFOs in the controller.
  55473. + * Some of the data access functions provide encapsulation of several
  55474. + * operations required to perform a task, such as writing multiple
  55475. + * registers to start a transfer. Finally, the CIL performs basic
  55476. + * services that are not specific to either the host or device modes
  55477. + * of operation. These services include management of the OTG Host
  55478. + * Negotiation Protocol (HNP) and Session Request Protocol (SRP). A
  55479. + * Diagnostic API is also provided to allow testing of the controller
  55480. + * hardware.
  55481. + *
  55482. + * The Core Interface Layer has the following requirements:
  55483. + * - Provides basic controller operations.
  55484. + * - Minimal use of OS services.
  55485. + * - The OS services used will be abstracted by using inline functions
  55486. + * or macros.
  55487. + *
  55488. + */
  55489. +
  55490. +#include "dwc_os.h"
  55491. +#include "dwc_otg_regs.h"
  55492. +#include "dwc_otg_cil.h"
  55493. +
  55494. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if);
  55495. +
  55496. +/**
  55497. + * This function is called to initialize the DWC_otg CSR data
  55498. + * structures. The register addresses in the device and host
  55499. + * structures are initialized from the base address supplied by the
  55500. + * caller. The calling function must make the OS calls to get the
  55501. + * base address of the DWC_otg controller registers. The core_params
  55502. + * argument holds the parameters that specify how the core should be
  55503. + * configured.
  55504. + *
  55505. + * @param reg_base_addr Base address of DWC_otg core registers
  55506. + *
  55507. + */
  55508. +dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * reg_base_addr)
  55509. +{
  55510. + dwc_otg_core_if_t *core_if = 0;
  55511. + dwc_otg_dev_if_t *dev_if = 0;
  55512. + dwc_otg_host_if_t *host_if = 0;
  55513. + uint8_t *reg_base = (uint8_t *) reg_base_addr;
  55514. + int i = 0;
  55515. +
  55516. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, reg_base_addr);
  55517. +
  55518. + core_if = DWC_ALLOC(sizeof(dwc_otg_core_if_t));
  55519. +
  55520. + if (core_if == NULL) {
  55521. + DWC_DEBUGPL(DBG_CIL,
  55522. + "Allocation of dwc_otg_core_if_t failed\n");
  55523. + return 0;
  55524. + }
  55525. + core_if->core_global_regs = (dwc_otg_core_global_regs_t *) reg_base;
  55526. +
  55527. + /*
  55528. + * Allocate the Device Mode structures.
  55529. + */
  55530. + dev_if = DWC_ALLOC(sizeof(dwc_otg_dev_if_t));
  55531. +
  55532. + if (dev_if == NULL) {
  55533. + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_dev_if_t failed\n");
  55534. + DWC_FREE(core_if);
  55535. + return 0;
  55536. + }
  55537. +
  55538. + dev_if->dev_global_regs =
  55539. + (dwc_otg_device_global_regs_t *) (reg_base +
  55540. + DWC_DEV_GLOBAL_REG_OFFSET);
  55541. +
  55542. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  55543. + dev_if->in_ep_regs[i] = (dwc_otg_dev_in_ep_regs_t *)
  55544. + (reg_base + DWC_DEV_IN_EP_REG_OFFSET +
  55545. + (i * DWC_EP_REG_OFFSET));
  55546. +
  55547. + dev_if->out_ep_regs[i] = (dwc_otg_dev_out_ep_regs_t *)
  55548. + (reg_base + DWC_DEV_OUT_EP_REG_OFFSET +
  55549. + (i * DWC_EP_REG_OFFSET));
  55550. + DWC_DEBUGPL(DBG_CILV, "in_ep_regs[%d]->diepctl=%p\n",
  55551. + i, &dev_if->in_ep_regs[i]->diepctl);
  55552. + DWC_DEBUGPL(DBG_CILV, "out_ep_regs[%d]->doepctl=%p\n",
  55553. + i, &dev_if->out_ep_regs[i]->doepctl);
  55554. + }
  55555. +
  55556. + dev_if->speed = 0; // unknown
  55557. +
  55558. + core_if->dev_if = dev_if;
  55559. +
  55560. + /*
  55561. + * Allocate the Host Mode structures.
  55562. + */
  55563. + host_if = DWC_ALLOC(sizeof(dwc_otg_host_if_t));
  55564. +
  55565. + if (host_if == NULL) {
  55566. + DWC_DEBUGPL(DBG_CIL,
  55567. + "Allocation of dwc_otg_host_if_t failed\n");
  55568. + DWC_FREE(dev_if);
  55569. + DWC_FREE(core_if);
  55570. + return 0;
  55571. + }
  55572. +
  55573. + host_if->host_global_regs = (dwc_otg_host_global_regs_t *)
  55574. + (reg_base + DWC_OTG_HOST_GLOBAL_REG_OFFSET);
  55575. +
  55576. + host_if->hprt0 =
  55577. + (uint32_t *) (reg_base + DWC_OTG_HOST_PORT_REGS_OFFSET);
  55578. +
  55579. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  55580. + host_if->hc_regs[i] = (dwc_otg_hc_regs_t *)
  55581. + (reg_base + DWC_OTG_HOST_CHAN_REGS_OFFSET +
  55582. + (i * DWC_OTG_CHAN_REGS_OFFSET));
  55583. + DWC_DEBUGPL(DBG_CILV, "hc_reg[%d]->hcchar=%p\n",
  55584. + i, &host_if->hc_regs[i]->hcchar);
  55585. + }
  55586. +
  55587. + host_if->num_host_channels = MAX_EPS_CHANNELS;
  55588. + core_if->host_if = host_if;
  55589. +
  55590. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  55591. + core_if->data_fifo[i] =
  55592. + (uint32_t *) (reg_base + DWC_OTG_DATA_FIFO_OFFSET +
  55593. + (i * DWC_OTG_DATA_FIFO_SIZE));
  55594. + DWC_DEBUGPL(DBG_CILV, "data_fifo[%d]=0x%08lx\n",
  55595. + i, (unsigned long)core_if->data_fifo[i]);
  55596. + }
  55597. +
  55598. + core_if->pcgcctl = (uint32_t *) (reg_base + DWC_OTG_PCGCCTL_OFFSET);
  55599. +
  55600. + /* Initiate lx_state to L3 disconnected state */
  55601. + core_if->lx_state = DWC_OTG_L3;
  55602. + /*
  55603. + * Store the contents of the hardware configuration registers here for
  55604. + * easy access later.
  55605. + */
  55606. + core_if->hwcfg1.d32 =
  55607. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg1);
  55608. + core_if->hwcfg2.d32 =
  55609. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  55610. + core_if->hwcfg3.d32 =
  55611. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg3);
  55612. + core_if->hwcfg4.d32 =
  55613. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  55614. +
  55615. + /* Force host mode to get HPTXFSIZ exact power on value */
  55616. + {
  55617. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  55618. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  55619. + gusbcfg.b.force_host_mode = 1;
  55620. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  55621. + dwc_mdelay(100);
  55622. + core_if->hptxfsiz.d32 =
  55623. + DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  55624. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  55625. + gusbcfg.b.force_host_mode = 0;
  55626. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  55627. + dwc_mdelay(100);
  55628. + }
  55629. +
  55630. + DWC_DEBUGPL(DBG_CILV, "hwcfg1=%08x\n", core_if->hwcfg1.d32);
  55631. + DWC_DEBUGPL(DBG_CILV, "hwcfg2=%08x\n", core_if->hwcfg2.d32);
  55632. + DWC_DEBUGPL(DBG_CILV, "hwcfg3=%08x\n", core_if->hwcfg3.d32);
  55633. + DWC_DEBUGPL(DBG_CILV, "hwcfg4=%08x\n", core_if->hwcfg4.d32);
  55634. +
  55635. + core_if->hcfg.d32 =
  55636. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  55637. + core_if->dcfg.d32 =
  55638. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  55639. +
  55640. + DWC_DEBUGPL(DBG_CILV, "hcfg=%08x\n", core_if->hcfg.d32);
  55641. + DWC_DEBUGPL(DBG_CILV, "dcfg=%08x\n", core_if->dcfg.d32);
  55642. +
  55643. + DWC_DEBUGPL(DBG_CILV, "op_mode=%0x\n", core_if->hwcfg2.b.op_mode);
  55644. + DWC_DEBUGPL(DBG_CILV, "arch=%0x\n", core_if->hwcfg2.b.architecture);
  55645. + DWC_DEBUGPL(DBG_CILV, "num_dev_ep=%d\n", core_if->hwcfg2.b.num_dev_ep);
  55646. + DWC_DEBUGPL(DBG_CILV, "num_host_chan=%d\n",
  55647. + core_if->hwcfg2.b.num_host_chan);
  55648. + DWC_DEBUGPL(DBG_CILV, "nonperio_tx_q_depth=0x%0x\n",
  55649. + core_if->hwcfg2.b.nonperio_tx_q_depth);
  55650. + DWC_DEBUGPL(DBG_CILV, "host_perio_tx_q_depth=0x%0x\n",
  55651. + core_if->hwcfg2.b.host_perio_tx_q_depth);
  55652. + DWC_DEBUGPL(DBG_CILV, "dev_token_q_depth=0x%0x\n",
  55653. + core_if->hwcfg2.b.dev_token_q_depth);
  55654. +
  55655. + DWC_DEBUGPL(DBG_CILV, "Total FIFO SZ=%d\n",
  55656. + core_if->hwcfg3.b.dfifo_depth);
  55657. + DWC_DEBUGPL(DBG_CILV, "xfer_size_cntr_width=%0x\n",
  55658. + core_if->hwcfg3.b.xfer_size_cntr_width);
  55659. +
  55660. + /*
  55661. + * Set the SRP sucess bit for FS-I2c
  55662. + */
  55663. + core_if->srp_success = 0;
  55664. + core_if->srp_timer_started = 0;
  55665. +
  55666. + /*
  55667. + * Create new workqueue and init works
  55668. + */
  55669. + core_if->wq_otg = DWC_WORKQ_ALLOC("dwc_otg");
  55670. + if (core_if->wq_otg == 0) {
  55671. + DWC_WARN("DWC_WORKQ_ALLOC failed\n");
  55672. + DWC_FREE(host_if);
  55673. + DWC_FREE(dev_if);
  55674. + DWC_FREE(core_if);
  55675. + return 0;
  55676. + }
  55677. +
  55678. + core_if->snpsid = DWC_READ_REG32(&core_if->core_global_regs->gsnpsid);
  55679. +
  55680. + DWC_PRINTF("Core Release: %x.%x%x%x\n",
  55681. + (core_if->snpsid >> 12 & 0xF),
  55682. + (core_if->snpsid >> 8 & 0xF),
  55683. + (core_if->snpsid >> 4 & 0xF), (core_if->snpsid & 0xF));
  55684. +
  55685. + core_if->wkp_timer = DWC_TIMER_ALLOC("Wake Up Timer",
  55686. + w_wakeup_detected, core_if);
  55687. + if (core_if->wkp_timer == 0) {
  55688. + DWC_WARN("DWC_TIMER_ALLOC failed\n");
  55689. + DWC_FREE(host_if);
  55690. + DWC_FREE(dev_if);
  55691. + DWC_WORKQ_FREE(core_if->wq_otg);
  55692. + DWC_FREE(core_if);
  55693. + return 0;
  55694. + }
  55695. +
  55696. + if (dwc_otg_setup_params(core_if)) {
  55697. + DWC_WARN("Error while setting core params\n");
  55698. + }
  55699. +
  55700. + core_if->hibernation_suspend = 0;
  55701. +
  55702. + /** ADP initialization */
  55703. + dwc_otg_adp_init(core_if);
  55704. +
  55705. + return core_if;
  55706. +}
  55707. +
  55708. +/**
  55709. + * This function frees the structures allocated by dwc_otg_cil_init().
  55710. + *
  55711. + * @param core_if The core interface pointer returned from
  55712. + * dwc_otg_cil_init().
  55713. + *
  55714. + */
  55715. +void dwc_otg_cil_remove(dwc_otg_core_if_t * core_if)
  55716. +{
  55717. + dctl_data_t dctl = {.d32 = 0 };
  55718. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  55719. +
  55720. + /* Disable all interrupts */
  55721. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 1, 0);
  55722. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  55723. +
  55724. + dctl.b.sftdiscon = 1;
  55725. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  55726. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0,
  55727. + dctl.d32);
  55728. + }
  55729. +
  55730. + if (core_if->wq_otg) {
  55731. + DWC_WORKQ_WAIT_WORK_DONE(core_if->wq_otg, 500);
  55732. + DWC_WORKQ_FREE(core_if->wq_otg);
  55733. + }
  55734. + if (core_if->dev_if) {
  55735. + DWC_FREE(core_if->dev_if);
  55736. + }
  55737. + if (core_if->host_if) {
  55738. + DWC_FREE(core_if->host_if);
  55739. + }
  55740. +
  55741. + /** Remove ADP Stuff */
  55742. + dwc_otg_adp_remove(core_if);
  55743. + if (core_if->core_params) {
  55744. + DWC_FREE(core_if->core_params);
  55745. + }
  55746. + if (core_if->wkp_timer) {
  55747. + DWC_TIMER_FREE(core_if->wkp_timer);
  55748. + }
  55749. + if (core_if->srp_timer) {
  55750. + DWC_TIMER_FREE(core_if->srp_timer);
  55751. + }
  55752. + DWC_FREE(core_if);
  55753. +}
  55754. +
  55755. +/**
  55756. + * This function enables the controller's Global Interrupt in the AHB Config
  55757. + * register.
  55758. + *
  55759. + * @param core_if Programming view of DWC_otg controller.
  55760. + */
  55761. +void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * core_if)
  55762. +{
  55763. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  55764. + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
  55765. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 0, ahbcfg.d32);
  55766. +}
  55767. +
  55768. +/**
  55769. + * This function disables the controller's Global Interrupt in the AHB Config
  55770. + * register.
  55771. + *
  55772. + * @param core_if Programming view of DWC_otg controller.
  55773. + */
  55774. +void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * core_if)
  55775. +{
  55776. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  55777. + ahbcfg.b.glblintrmsk = 1; /* Disable interrupts */
  55778. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  55779. +}
  55780. +
  55781. +/**
  55782. + * This function initializes the commmon interrupts, used in both
  55783. + * device and host modes.
  55784. + *
  55785. + * @param core_if Programming view of the DWC_otg controller
  55786. + *
  55787. + */
  55788. +static void dwc_otg_enable_common_interrupts(dwc_otg_core_if_t * core_if)
  55789. +{
  55790. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  55791. + gintmsk_data_t intr_mask = {.d32 = 0 };
  55792. +
  55793. + /* Clear any pending OTG Interrupts */
  55794. + DWC_WRITE_REG32(&global_regs->gotgint, 0xFFFFFFFF);
  55795. +
  55796. + /* Clear any pending interrupts */
  55797. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  55798. +
  55799. + /*
  55800. + * Enable the interrupts in the GINTMSK.
  55801. + */
  55802. + intr_mask.b.modemismatch = 1;
  55803. + intr_mask.b.otgintr = 1;
  55804. +
  55805. + if (!core_if->dma_enable) {
  55806. + intr_mask.b.rxstsqlvl = 1;
  55807. + }
  55808. +
  55809. + intr_mask.b.conidstschng = 1;
  55810. + intr_mask.b.wkupintr = 1;
  55811. + intr_mask.b.disconnect = 0;
  55812. + intr_mask.b.usbsuspend = 1;
  55813. + intr_mask.b.sessreqintr = 1;
  55814. +#ifdef CONFIG_USB_DWC_OTG_LPM
  55815. + if (core_if->core_params->lpm_enable) {
  55816. + intr_mask.b.lpmtranrcvd = 1;
  55817. + }
  55818. +#endif
  55819. + DWC_WRITE_REG32(&global_regs->gintmsk, intr_mask.d32);
  55820. +}
  55821. +
  55822. +/*
  55823. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  55824. + * Hibernation. This function is for exiting from Device mode hibernation by
  55825. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  55826. + * @param core_if Programming view of DWC_otg controller.
  55827. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  55828. + * @param reset - indicates whether resume is initiated by Reset.
  55829. + */
  55830. +int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  55831. + int rem_wakeup, int reset)
  55832. +{
  55833. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  55834. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  55835. + dctl_data_t dctl = {.d32 = 0 };
  55836. +
  55837. + int timeout = 2000;
  55838. +
  55839. + if (!core_if->hibernation_suspend) {
  55840. + DWC_PRINTF("Already exited from Hibernation\n");
  55841. + return 1;
  55842. + }
  55843. +
  55844. + DWC_DEBUGPL(DBG_PCD, "%s called\n", __FUNCTION__);
  55845. + /* Switch-on voltage to the core */
  55846. + gpwrdn.b.pwrdnswtch = 1;
  55847. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55848. + dwc_udelay(10);
  55849. +
  55850. + /* Reset core */
  55851. + gpwrdn.d32 = 0;
  55852. + gpwrdn.b.pwrdnrstn = 1;
  55853. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55854. + dwc_udelay(10);
  55855. +
  55856. + /* Assert Restore signal */
  55857. + gpwrdn.d32 = 0;
  55858. + gpwrdn.b.restore = 1;
  55859. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  55860. + dwc_udelay(10);
  55861. +
  55862. + /* Disable power clamps */
  55863. + gpwrdn.d32 = 0;
  55864. + gpwrdn.b.pwrdnclmp = 1;
  55865. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55866. +
  55867. + if (rem_wakeup) {
  55868. + dwc_udelay(70);
  55869. + }
  55870. +
  55871. + /* Deassert Reset core */
  55872. + gpwrdn.d32 = 0;
  55873. + gpwrdn.b.pwrdnrstn = 1;
  55874. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  55875. + dwc_udelay(10);
  55876. +
  55877. + /* Disable PMU interrupt */
  55878. + gpwrdn.d32 = 0;
  55879. + gpwrdn.b.pmuintsel = 1;
  55880. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55881. +
  55882. + /* Mask interrupts from gpwrdn */
  55883. + gpwrdn.d32 = 0;
  55884. + gpwrdn.b.connect_det_msk = 1;
  55885. + gpwrdn.b.srp_det_msk = 1;
  55886. + gpwrdn.b.disconn_det_msk = 1;
  55887. + gpwrdn.b.rst_det_msk = 1;
  55888. + gpwrdn.b.lnstchng_msk = 1;
  55889. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55890. +
  55891. + /* Indicates that we are going out from hibernation */
  55892. + core_if->hibernation_suspend = 0;
  55893. +
  55894. + /*
  55895. + * Set Restore Essential Regs bit in PCGCCTL register, restore_mode = 1
  55896. + * indicates restore from remote_wakeup
  55897. + */
  55898. + restore_essential_regs(core_if, rem_wakeup, 0);
  55899. +
  55900. + /*
  55901. + * Wait a little for seeing new value of variable hibernation_suspend if
  55902. + * Restore done interrupt received before polling
  55903. + */
  55904. + dwc_udelay(10);
  55905. +
  55906. + if (core_if->hibernation_suspend == 0) {
  55907. + /*
  55908. + * Wait For Restore_done Interrupt. This mechanism of polling the
  55909. + * interrupt is introduced to avoid any possible race conditions
  55910. + */
  55911. + do {
  55912. + gintsts_data_t gintsts;
  55913. + gintsts.d32 =
  55914. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  55915. + if (gintsts.b.restoredone) {
  55916. + gintsts.d32 = 0;
  55917. + gintsts.b.restoredone = 1;
  55918. + DWC_WRITE_REG32(&core_if->core_global_regs->
  55919. + gintsts, gintsts.d32);
  55920. + DWC_PRINTF("Restore Done Interrupt seen\n");
  55921. + break;
  55922. + }
  55923. + dwc_udelay(10);
  55924. + } while (--timeout);
  55925. + if (!timeout) {
  55926. + DWC_PRINTF("Restore Done interrupt wasn't generated here\n");
  55927. + }
  55928. + }
  55929. + /* Clear all pending interupts */
  55930. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  55931. +
  55932. + /* De-assert Restore */
  55933. + gpwrdn.d32 = 0;
  55934. + gpwrdn.b.restore = 1;
  55935. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55936. + dwc_udelay(10);
  55937. +
  55938. + if (!rem_wakeup) {
  55939. + pcgcctl.d32 = 0;
  55940. + pcgcctl.b.rstpdwnmodule = 1;
  55941. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  55942. + }
  55943. +
  55944. + /* Restore GUSBCFG and DCFG */
  55945. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  55946. + core_if->gr_backup->gusbcfg_local);
  55947. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  55948. + core_if->dr_backup->dcfg);
  55949. +
  55950. + /* De-assert Wakeup Logic */
  55951. + gpwrdn.d32 = 0;
  55952. + gpwrdn.b.pmuactv = 1;
  55953. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55954. + dwc_udelay(10);
  55955. +
  55956. + if (!rem_wakeup) {
  55957. + /* Set Device programming done bit */
  55958. + dctl.b.pwronprgdone = 1;
  55959. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  55960. + } else {
  55961. + /* Start Remote Wakeup Signaling */
  55962. + dctl.d32 = core_if->dr_backup->dctl;
  55963. + dctl.b.rmtwkupsig = 1;
  55964. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  55965. + }
  55966. +
  55967. + dwc_mdelay(2);
  55968. + /* Clear all pending interupts */
  55969. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  55970. +
  55971. + /* Restore global registers */
  55972. + dwc_otg_restore_global_regs(core_if);
  55973. + /* Restore device global registers */
  55974. + dwc_otg_restore_dev_regs(core_if, rem_wakeup);
  55975. +
  55976. + if (rem_wakeup) {
  55977. + dwc_mdelay(7);
  55978. + dctl.d32 = 0;
  55979. + dctl.b.rmtwkupsig = 1;
  55980. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  55981. + }
  55982. +
  55983. + core_if->hibernation_suspend = 0;
  55984. + /* The core will be in ON STATE */
  55985. + core_if->lx_state = DWC_OTG_L0;
  55986. + DWC_PRINTF("Hibernation recovery completes here\n");
  55987. +
  55988. + return 1;
  55989. +}
  55990. +
  55991. +/*
  55992. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  55993. + * Hibernation. This function is for exiting from Host mode hibernation by
  55994. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  55995. + * @param core_if Programming view of DWC_otg controller.
  55996. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  55997. + * @param reset - indicates whether resume is initiated by Reset.
  55998. + */
  55999. +int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  56000. + int rem_wakeup, int reset)
  56001. +{
  56002. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  56003. + hprt0_data_t hprt0 = {.d32 = 0 };
  56004. +
  56005. + int timeout = 2000;
  56006. +
  56007. + DWC_DEBUGPL(DBG_HCD, "%s called\n", __FUNCTION__);
  56008. + /* Switch-on voltage to the core */
  56009. + gpwrdn.b.pwrdnswtch = 1;
  56010. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56011. + dwc_udelay(10);
  56012. +
  56013. + /* Reset core */
  56014. + gpwrdn.d32 = 0;
  56015. + gpwrdn.b.pwrdnrstn = 1;
  56016. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56017. + dwc_udelay(10);
  56018. +
  56019. + /* Assert Restore signal */
  56020. + gpwrdn.d32 = 0;
  56021. + gpwrdn.b.restore = 1;
  56022. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  56023. + dwc_udelay(10);
  56024. +
  56025. + /* Disable power clamps */
  56026. + gpwrdn.d32 = 0;
  56027. + gpwrdn.b.pwrdnclmp = 1;
  56028. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56029. +
  56030. + if (!rem_wakeup) {
  56031. + dwc_udelay(50);
  56032. + }
  56033. +
  56034. + /* Deassert Reset core */
  56035. + gpwrdn.d32 = 0;
  56036. + gpwrdn.b.pwrdnrstn = 1;
  56037. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  56038. + dwc_udelay(10);
  56039. +
  56040. + /* Disable PMU interrupt */
  56041. + gpwrdn.d32 = 0;
  56042. + gpwrdn.b.pmuintsel = 1;
  56043. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56044. +
  56045. + gpwrdn.d32 = 0;
  56046. + gpwrdn.b.connect_det_msk = 1;
  56047. + gpwrdn.b.srp_det_msk = 1;
  56048. + gpwrdn.b.disconn_det_msk = 1;
  56049. + gpwrdn.b.rst_det_msk = 1;
  56050. + gpwrdn.b.lnstchng_msk = 1;
  56051. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56052. +
  56053. + /* Indicates that we are going out from hibernation */
  56054. + core_if->hibernation_suspend = 0;
  56055. +
  56056. + /* Set Restore Essential Regs bit in PCGCCTL register */
  56057. + restore_essential_regs(core_if, rem_wakeup, 1);
  56058. +
  56059. + /* Wait a little for seeing new value of variable hibernation_suspend if
  56060. + * Restore done interrupt received before polling */
  56061. + dwc_udelay(10);
  56062. +
  56063. + if (core_if->hibernation_suspend == 0) {
  56064. + /* Wait For Restore_done Interrupt. This mechanism of polling the
  56065. + * interrupt is introduced to avoid any possible race conditions
  56066. + */
  56067. + do {
  56068. + gintsts_data_t gintsts;
  56069. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  56070. + if (gintsts.b.restoredone) {
  56071. + gintsts.d32 = 0;
  56072. + gintsts.b.restoredone = 1;
  56073. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  56074. + DWC_DEBUGPL(DBG_HCD,"Restore Done Interrupt seen\n");
  56075. + break;
  56076. + }
  56077. + dwc_udelay(10);
  56078. + } while (--timeout);
  56079. + if (!timeout) {
  56080. + DWC_WARN("Restore Done interrupt wasn't generated\n");
  56081. + }
  56082. + }
  56083. +
  56084. + /* Set the flag's value to 0 again after receiving restore done interrupt */
  56085. + core_if->hibernation_suspend = 0;
  56086. +
  56087. + /* This step is not described in functional spec but if not wait for this
  56088. + * delay, mismatch interrupts occurred because just after restore core is
  56089. + * in Device mode(gintsts.curmode == 0) */
  56090. + dwc_mdelay(100);
  56091. +
  56092. + /* Clear all pending interrupts */
  56093. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56094. +
  56095. + /* De-assert Restore */
  56096. + gpwrdn.d32 = 0;
  56097. + gpwrdn.b.restore = 1;
  56098. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56099. + dwc_udelay(10);
  56100. +
  56101. + /* Restore GUSBCFG and HCFG */
  56102. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  56103. + core_if->gr_backup->gusbcfg_local);
  56104. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  56105. + core_if->hr_backup->hcfg_local);
  56106. +
  56107. + /* De-assert Wakeup Logic */
  56108. + gpwrdn.d32 = 0;
  56109. + gpwrdn.b.pmuactv = 1;
  56110. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  56111. + dwc_udelay(10);
  56112. +
  56113. + /* Start the Resume operation by programming HPRT0 */
  56114. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  56115. + hprt0.b.prtpwr = 1;
  56116. + hprt0.b.prtena = 0;
  56117. + hprt0.b.prtsusp = 0;
  56118. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56119. +
  56120. + DWC_PRINTF("Resume Starts Now\n");
  56121. + if (!reset) { // Indicates it is Resume Operation
  56122. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  56123. + hprt0.b.prtres = 1;
  56124. + hprt0.b.prtpwr = 1;
  56125. + hprt0.b.prtena = 0;
  56126. + hprt0.b.prtsusp = 0;
  56127. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56128. +
  56129. + if (!rem_wakeup)
  56130. + hprt0.b.prtres = 0;
  56131. + /* Wait for Resume time and then program HPRT again */
  56132. + dwc_mdelay(100);
  56133. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56134. +
  56135. + } else { // Indicates it is Reset Operation
  56136. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  56137. + hprt0.b.prtrst = 1;
  56138. + hprt0.b.prtpwr = 1;
  56139. + hprt0.b.prtena = 0;
  56140. + hprt0.b.prtsusp = 0;
  56141. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56142. + /* Wait for Reset time and then program HPRT again */
  56143. + dwc_mdelay(60);
  56144. + hprt0.b.prtrst = 0;
  56145. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56146. + }
  56147. + /* Clear all interrupt status */
  56148. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  56149. + hprt0.b.prtconndet = 1;
  56150. + hprt0.b.prtenchng = 1;
  56151. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  56152. +
  56153. + /* Clear all pending interupts */
  56154. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56155. +
  56156. + /* Restore global registers */
  56157. + dwc_otg_restore_global_regs(core_if);
  56158. + /* Restore host global registers */
  56159. + dwc_otg_restore_host_regs(core_if, reset);
  56160. +
  56161. + /* The core will be in ON STATE */
  56162. + core_if->lx_state = DWC_OTG_L0;
  56163. + DWC_PRINTF("Hibernation recovery is complete here\n");
  56164. + return 0;
  56165. +}
  56166. +
  56167. +/** Saves some register values into system memory. */
  56168. +int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if)
  56169. +{
  56170. + struct dwc_otg_global_regs_backup *gr;
  56171. + int i;
  56172. +
  56173. + gr = core_if->gr_backup;
  56174. + if (!gr) {
  56175. + gr = DWC_ALLOC(sizeof(*gr));
  56176. + if (!gr) {
  56177. + return -DWC_E_NO_MEMORY;
  56178. + }
  56179. + core_if->gr_backup = gr;
  56180. + }
  56181. +
  56182. + gr->gotgctl_local = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  56183. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  56184. + gr->gahbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  56185. + gr->gusbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  56186. + gr->grxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  56187. + gr->gnptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  56188. + gr->hptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  56189. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56190. + gr->glpmcfg_local = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  56191. +#endif
  56192. + gr->gi2cctl_local = DWC_READ_REG32(&core_if->core_global_regs->gi2cctl);
  56193. + gr->pcgcctl_local = DWC_READ_REG32(core_if->pcgcctl);
  56194. + gr->gdfifocfg_local =
  56195. + DWC_READ_REG32(&core_if->core_global_regs->gdfifocfg);
  56196. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56197. + gr->dtxfsiz_local[i] =
  56198. + DWC_READ_REG32(&(core_if->core_global_regs->dtxfsiz[i]));
  56199. + }
  56200. +
  56201. + DWC_DEBUGPL(DBG_ANY, "===========Backing Global registers==========\n");
  56202. + DWC_DEBUGPL(DBG_ANY, "Backed up gotgctl = %08x\n", gr->gotgctl_local);
  56203. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  56204. + DWC_DEBUGPL(DBG_ANY, "Backed up gahbcfg = %08x\n", gr->gahbcfg_local);
  56205. + DWC_DEBUGPL(DBG_ANY, "Backed up gusbcfg = %08x\n", gr->gusbcfg_local);
  56206. + DWC_DEBUGPL(DBG_ANY, "Backed up grxfsiz = %08x\n", gr->grxfsiz_local);
  56207. + DWC_DEBUGPL(DBG_ANY, "Backed up gnptxfsiz = %08x\n",
  56208. + gr->gnptxfsiz_local);
  56209. + DWC_DEBUGPL(DBG_ANY, "Backed up hptxfsiz = %08x\n",
  56210. + gr->hptxfsiz_local);
  56211. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56212. + DWC_DEBUGPL(DBG_ANY, "Backed up glpmcfg = %08x\n", gr->glpmcfg_local);
  56213. +#endif
  56214. + DWC_DEBUGPL(DBG_ANY, "Backed up gi2cctl = %08x\n", gr->gi2cctl_local);
  56215. + DWC_DEBUGPL(DBG_ANY, "Backed up pcgcctl = %08x\n", gr->pcgcctl_local);
  56216. + DWC_DEBUGPL(DBG_ANY,"Backed up gdfifocfg = %08x\n",gr->gdfifocfg_local);
  56217. +
  56218. + return 0;
  56219. +}
  56220. +
  56221. +/** Saves GINTMSK register before setting the msk bits. */
  56222. +int dwc_otg_save_gintmsk_reg(dwc_otg_core_if_t * core_if)
  56223. +{
  56224. + struct dwc_otg_global_regs_backup *gr;
  56225. +
  56226. + gr = core_if->gr_backup;
  56227. + if (!gr) {
  56228. + gr = DWC_ALLOC(sizeof(*gr));
  56229. + if (!gr) {
  56230. + return -DWC_E_NO_MEMORY;
  56231. + }
  56232. + core_if->gr_backup = gr;
  56233. + }
  56234. +
  56235. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  56236. +
  56237. + DWC_DEBUGPL(DBG_ANY,"=============Backing GINTMSK registers============\n");
  56238. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  56239. +
  56240. + return 0;
  56241. +}
  56242. +
  56243. +int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if)
  56244. +{
  56245. + struct dwc_otg_dev_regs_backup *dr;
  56246. + int i;
  56247. +
  56248. + dr = core_if->dr_backup;
  56249. + if (!dr) {
  56250. + dr = DWC_ALLOC(sizeof(*dr));
  56251. + if (!dr) {
  56252. + return -DWC_E_NO_MEMORY;
  56253. + }
  56254. + core_if->dr_backup = dr;
  56255. + }
  56256. +
  56257. + dr->dcfg = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  56258. + dr->dctl = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  56259. + dr->daintmsk =
  56260. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  56261. + dr->diepmsk =
  56262. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->diepmsk);
  56263. + dr->doepmsk =
  56264. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->doepmsk);
  56265. +
  56266. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  56267. + dr->diepctl[i] =
  56268. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  56269. + dr->dieptsiz[i] =
  56270. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz);
  56271. + dr->diepdma[i] =
  56272. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma);
  56273. + }
  56274. +
  56275. + DWC_DEBUGPL(DBG_ANY,
  56276. + "=============Backing Host registers==============\n");
  56277. + DWC_DEBUGPL(DBG_ANY, "Backed up dcfg = %08x\n", dr->dcfg);
  56278. + DWC_DEBUGPL(DBG_ANY, "Backed up dctl = %08x\n", dr->dctl);
  56279. + DWC_DEBUGPL(DBG_ANY, "Backed up daintmsk = %08x\n",
  56280. + dr->daintmsk);
  56281. + DWC_DEBUGPL(DBG_ANY, "Backed up diepmsk = %08x\n", dr->diepmsk);
  56282. + DWC_DEBUGPL(DBG_ANY, "Backed up doepmsk = %08x\n", dr->doepmsk);
  56283. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  56284. + DWC_DEBUGPL(DBG_ANY, "Backed up diepctl[%d] = %08x\n", i,
  56285. + dr->diepctl[i]);
  56286. + DWC_DEBUGPL(DBG_ANY, "Backed up dieptsiz[%d] = %08x\n",
  56287. + i, dr->dieptsiz[i]);
  56288. + DWC_DEBUGPL(DBG_ANY, "Backed up diepdma[%d] = %08x\n", i,
  56289. + dr->diepdma[i]);
  56290. + }
  56291. +
  56292. + return 0;
  56293. +}
  56294. +
  56295. +int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if)
  56296. +{
  56297. + struct dwc_otg_host_regs_backup *hr;
  56298. + int i;
  56299. +
  56300. + hr = core_if->hr_backup;
  56301. + if (!hr) {
  56302. + hr = DWC_ALLOC(sizeof(*hr));
  56303. + if (!hr) {
  56304. + return -DWC_E_NO_MEMORY;
  56305. + }
  56306. + core_if->hr_backup = hr;
  56307. + }
  56308. +
  56309. + hr->hcfg_local =
  56310. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  56311. + hr->haintmsk_local =
  56312. + DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  56313. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  56314. + hr->hcintmsk_local[i] =
  56315. + DWC_READ_REG32(&core_if->host_if->hc_regs[i]->hcintmsk);
  56316. + }
  56317. + hr->hprt0_local = DWC_READ_REG32(core_if->host_if->hprt0);
  56318. + hr->hfir_local =
  56319. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  56320. +
  56321. + DWC_DEBUGPL(DBG_ANY,
  56322. + "=============Backing Host registers===============\n");
  56323. + DWC_DEBUGPL(DBG_ANY, "Backed up hcfg = %08x\n",
  56324. + hr->hcfg_local);
  56325. + DWC_DEBUGPL(DBG_ANY, "Backed up haintmsk = %08x\n", hr->haintmsk_local);
  56326. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  56327. + DWC_DEBUGPL(DBG_ANY, "Backed up hcintmsk[%02d]=%08x\n", i,
  56328. + hr->hcintmsk_local[i]);
  56329. + }
  56330. + DWC_DEBUGPL(DBG_ANY, "Backed up hprt0 = %08x\n",
  56331. + hr->hprt0_local);
  56332. + DWC_DEBUGPL(DBG_ANY, "Backed up hfir = %08x\n",
  56333. + hr->hfir_local);
  56334. +
  56335. + return 0;
  56336. +}
  56337. +
  56338. +int dwc_otg_restore_global_regs(dwc_otg_core_if_t *core_if)
  56339. +{
  56340. + struct dwc_otg_global_regs_backup *gr;
  56341. + int i;
  56342. +
  56343. + gr = core_if->gr_backup;
  56344. + if (!gr) {
  56345. + return -DWC_E_INVALID;
  56346. + }
  56347. +
  56348. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, gr->gotgctl_local);
  56349. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gr->gintmsk_local);
  56350. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gr->gusbcfg_local);
  56351. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gr->gahbcfg_local);
  56352. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, gr->grxfsiz_local);
  56353. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz,
  56354. + gr->gnptxfsiz_local);
  56355. + DWC_WRITE_REG32(&core_if->core_global_regs->hptxfsiz,
  56356. + gr->hptxfsiz_local);
  56357. + DWC_WRITE_REG32(&core_if->core_global_regs->gdfifocfg,
  56358. + gr->gdfifocfg_local);
  56359. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56360. + DWC_WRITE_REG32(&core_if->core_global_regs->dtxfsiz[i],
  56361. + gr->dtxfsiz_local[i]);
  56362. + }
  56363. +
  56364. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56365. + DWC_WRITE_REG32(core_if->host_if->hprt0, 0x0000100A);
  56366. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg,
  56367. + (gr->gahbcfg_local));
  56368. + return 0;
  56369. +}
  56370. +
  56371. +int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if, int rem_wakeup)
  56372. +{
  56373. + struct dwc_otg_dev_regs_backup *dr;
  56374. + int i;
  56375. +
  56376. + dr = core_if->dr_backup;
  56377. +
  56378. + if (!dr) {
  56379. + return -DWC_E_INVALID;
  56380. + }
  56381. +
  56382. + if (!rem_wakeup) {
  56383. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  56384. + dr->dctl);
  56385. + }
  56386. +
  56387. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, dr->daintmsk);
  56388. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, dr->diepmsk);
  56389. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, dr->doepmsk);
  56390. +
  56391. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  56392. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz, dr->dieptsiz[i]);
  56393. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma, dr->diepdma[i]);
  56394. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl, dr->diepctl[i]);
  56395. + }
  56396. +
  56397. + return 0;
  56398. +}
  56399. +
  56400. +int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset)
  56401. +{
  56402. + struct dwc_otg_host_regs_backup *hr;
  56403. + int i;
  56404. + hr = core_if->hr_backup;
  56405. +
  56406. + if (!hr) {
  56407. + return -DWC_E_INVALID;
  56408. + }
  56409. +
  56410. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hr->hcfg_local);
  56411. + //if (!reset)
  56412. + //{
  56413. + // DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hr->hfir_local);
  56414. + //}
  56415. +
  56416. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk,
  56417. + hr->haintmsk_local);
  56418. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  56419. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk,
  56420. + hr->hcintmsk_local[i]);
  56421. + }
  56422. +
  56423. + return 0;
  56424. +}
  56425. +
  56426. +int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if)
  56427. +{
  56428. + struct dwc_otg_global_regs_backup *gr;
  56429. +
  56430. + gr = core_if->gr_backup;
  56431. +
  56432. + /* Restore values for LPM and I2C */
  56433. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56434. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, gr->glpmcfg_local);
  56435. +#endif
  56436. + DWC_WRITE_REG32(&core_if->core_global_regs->gi2cctl, gr->gi2cctl_local);
  56437. +
  56438. + return 0;
  56439. +}
  56440. +
  56441. +int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode, int is_host)
  56442. +{
  56443. + struct dwc_otg_global_regs_backup *gr;
  56444. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  56445. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  56446. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  56447. + gintmsk_data_t gintmsk = {.d32 = 0 };
  56448. +
  56449. + /* Restore LPM and I2C registers */
  56450. + restore_lpm_i2c_regs(core_if);
  56451. +
  56452. + /* Set PCGCCTL to 0 */
  56453. + DWC_WRITE_REG32(core_if->pcgcctl, 0x00000000);
  56454. +
  56455. + gr = core_if->gr_backup;
  56456. + /* Load restore values for [31:14] bits */
  56457. + DWC_WRITE_REG32(core_if->pcgcctl,
  56458. + ((gr->pcgcctl_local & 0xffffc000) | 0x00020000));
  56459. +
  56460. + /* Umnask global Interrupt in GAHBCFG and restore it */
  56461. + gahbcfg.d32 = gr->gahbcfg_local;
  56462. + gahbcfg.b.glblintrmsk = 1;
  56463. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  56464. +
  56465. + /* Clear all pending interupts */
  56466. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56467. +
  56468. + /* Unmask restore done interrupt */
  56469. + gintmsk.b.restoredone = 1;
  56470. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  56471. +
  56472. + /* Restore GUSBCFG and HCFG/DCFG */
  56473. + gusbcfg.d32 = core_if->gr_backup->gusbcfg_local;
  56474. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  56475. +
  56476. + if (is_host) {
  56477. + hcfg_data_t hcfg = {.d32 = 0 };
  56478. + hcfg.d32 = core_if->hr_backup->hcfg_local;
  56479. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  56480. + hcfg.d32);
  56481. +
  56482. + /* Load restore values for [31:14] bits */
  56483. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  56484. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  56485. +
  56486. + if (rmode)
  56487. + pcgcctl.b.restoremode = 1;
  56488. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  56489. + dwc_udelay(10);
  56490. +
  56491. + /* Load restore values for [31:14] bits and set EssRegRestored bit */
  56492. + pcgcctl.d32 = gr->pcgcctl_local | 0xffffc000;
  56493. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  56494. + pcgcctl.b.ess_reg_restored = 1;
  56495. + if (rmode)
  56496. + pcgcctl.b.restoremode = 1;
  56497. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  56498. + } else {
  56499. + dcfg_data_t dcfg = {.d32 = 0 };
  56500. + dcfg.d32 = core_if->dr_backup->dcfg;
  56501. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  56502. +
  56503. + /* Load restore values for [31:14] bits */
  56504. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  56505. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  56506. + if (!rmode) {
  56507. + pcgcctl.d32 |= 0x208;
  56508. + }
  56509. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  56510. + dwc_udelay(10);
  56511. +
  56512. + /* Load restore values for [31:14] bits */
  56513. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  56514. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  56515. + pcgcctl.b.ess_reg_restored = 1;
  56516. + if (!rmode)
  56517. + pcgcctl.d32 |= 0x208;
  56518. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  56519. + }
  56520. +
  56521. + return 0;
  56522. +}
  56523. +
  56524. +/**
  56525. + * Initializes the FSLSPClkSel field of the HCFG register depending on the PHY
  56526. + * type.
  56527. + */
  56528. +static void init_fslspclksel(dwc_otg_core_if_t * core_if)
  56529. +{
  56530. + uint32_t val;
  56531. + hcfg_data_t hcfg;
  56532. +
  56533. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  56534. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  56535. + (core_if->core_params->ulpi_fs_ls)) ||
  56536. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  56537. + /* Full speed PHY */
  56538. + val = DWC_HCFG_48_MHZ;
  56539. + } else {
  56540. + /* High speed PHY running at full speed or high speed */
  56541. + val = DWC_HCFG_30_60_MHZ;
  56542. + }
  56543. +
  56544. + DWC_DEBUGPL(DBG_CIL, "Initializing HCFG.FSLSPClkSel to 0x%1x\n", val);
  56545. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  56546. + hcfg.b.fslspclksel = val;
  56547. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  56548. +}
  56549. +
  56550. +/**
  56551. + * Initializes the DevSpd field of the DCFG register depending on the PHY type
  56552. + * and the enumeration speed of the device.
  56553. + */
  56554. +static void init_devspd(dwc_otg_core_if_t * core_if)
  56555. +{
  56556. + uint32_t val;
  56557. + dcfg_data_t dcfg;
  56558. +
  56559. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  56560. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  56561. + (core_if->core_params->ulpi_fs_ls)) ||
  56562. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  56563. + /* Full speed PHY */
  56564. + val = 0x3;
  56565. + } else if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  56566. + /* High speed PHY running at full speed */
  56567. + val = 0x1;
  56568. + } else {
  56569. + /* High speed PHY running at high speed */
  56570. + val = 0x0;
  56571. + }
  56572. +
  56573. + DWC_DEBUGPL(DBG_CIL, "Initializing DCFG.DevSpd to 0x%1x\n", val);
  56574. +
  56575. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  56576. + dcfg.b.devspd = val;
  56577. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  56578. +}
  56579. +
  56580. +/**
  56581. + * This function calculates the number of IN EPS
  56582. + * using GHWCFG1 and GHWCFG2 registers values
  56583. + *
  56584. + * @param core_if Programming view of the DWC_otg controller
  56585. + */
  56586. +static uint32_t calc_num_in_eps(dwc_otg_core_if_t * core_if)
  56587. +{
  56588. + uint32_t num_in_eps = 0;
  56589. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  56590. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 3;
  56591. + uint32_t num_tx_fifos = core_if->hwcfg4.b.num_in_eps;
  56592. + int i;
  56593. +
  56594. + for (i = 0; i < num_eps; ++i) {
  56595. + if (!(hwcfg1 & 0x1))
  56596. + num_in_eps++;
  56597. +
  56598. + hwcfg1 >>= 2;
  56599. + }
  56600. +
  56601. + if (core_if->hwcfg4.b.ded_fifo_en) {
  56602. + num_in_eps =
  56603. + (num_in_eps > num_tx_fifos) ? num_tx_fifos : num_in_eps;
  56604. + }
  56605. +
  56606. + return num_in_eps;
  56607. +}
  56608. +
  56609. +/**
  56610. + * This function calculates the number of OUT EPS
  56611. + * using GHWCFG1 and GHWCFG2 registers values
  56612. + *
  56613. + * @param core_if Programming view of the DWC_otg controller
  56614. + */
  56615. +static uint32_t calc_num_out_eps(dwc_otg_core_if_t * core_if)
  56616. +{
  56617. + uint32_t num_out_eps = 0;
  56618. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  56619. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 2;
  56620. + int i;
  56621. +
  56622. + for (i = 0; i < num_eps; ++i) {
  56623. + if (!(hwcfg1 & 0x1))
  56624. + num_out_eps++;
  56625. +
  56626. + hwcfg1 >>= 2;
  56627. + }
  56628. + return num_out_eps;
  56629. +}
  56630. +
  56631. +/**
  56632. + * This function initializes the DWC_otg controller registers and
  56633. + * prepares the core for device mode or host mode operation.
  56634. + *
  56635. + * @param core_if Programming view of the DWC_otg controller
  56636. + *
  56637. + */
  56638. +void dwc_otg_core_init(dwc_otg_core_if_t * core_if)
  56639. +{
  56640. + int i = 0;
  56641. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56642. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  56643. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  56644. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  56645. + gi2cctl_data_t i2cctl = {.d32 = 0 };
  56646. +
  56647. + DWC_DEBUGPL(DBG_CILV, "dwc_otg_core_init(%p) regs at %p\n",
  56648. + core_if, global_regs);
  56649. +
  56650. + /* Common Initialization */
  56651. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56652. +
  56653. + /* Program the ULPI External VBUS bit if needed */
  56654. + usbcfg.b.ulpi_ext_vbus_drv =
  56655. + (core_if->core_params->phy_ulpi_ext_vbus ==
  56656. + DWC_PHY_ULPI_EXTERNAL_VBUS) ? 1 : 0;
  56657. +
  56658. + /* Set external TS Dline pulsing */
  56659. + usbcfg.b.term_sel_dl_pulse =
  56660. + (core_if->core_params->ts_dline == 1) ? 1 : 0;
  56661. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56662. +
  56663. + /* Reset the Controller */
  56664. + dwc_otg_core_reset(core_if);
  56665. +
  56666. + core_if->adp_enable = core_if->core_params->adp_supp_enable;
  56667. + core_if->power_down = core_if->core_params->power_down;
  56668. + core_if->otg_sts = 0;
  56669. +
  56670. + /* Initialize parameters from Hardware configuration registers. */
  56671. + dev_if->num_in_eps = calc_num_in_eps(core_if);
  56672. + dev_if->num_out_eps = calc_num_out_eps(core_if);
  56673. +
  56674. + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n",
  56675. + core_if->hwcfg4.b.num_dev_perio_in_ep);
  56676. +
  56677. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  56678. + dev_if->perio_tx_fifo_size[i] =
  56679. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  56680. + DWC_DEBUGPL(DBG_CIL, "Periodic Tx FIFO SZ #%d=0x%0x\n",
  56681. + i, dev_if->perio_tx_fifo_size[i]);
  56682. + }
  56683. +
  56684. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  56685. + dev_if->tx_fifo_size[i] =
  56686. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  56687. + DWC_DEBUGPL(DBG_CIL, "Tx FIFO SZ #%d=0x%0x\n",
  56688. + i, dev_if->tx_fifo_size[i]);
  56689. + }
  56690. +
  56691. + core_if->total_fifo_size = core_if->hwcfg3.b.dfifo_depth;
  56692. + core_if->rx_fifo_size = DWC_READ_REG32(&global_regs->grxfsiz);
  56693. + core_if->nperio_tx_fifo_size =
  56694. + DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16;
  56695. +
  56696. + DWC_DEBUGPL(DBG_CIL, "Total FIFO SZ=%d\n", core_if->total_fifo_size);
  56697. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO SZ=%d\n", core_if->rx_fifo_size);
  56698. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO SZ=%d\n",
  56699. + core_if->nperio_tx_fifo_size);
  56700. +
  56701. + /* This programming sequence needs to happen in FS mode before any other
  56702. + * programming occurs */
  56703. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) &&
  56704. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  56705. + /* If FS mode with FS PHY */
  56706. +
  56707. + /* core_init() is now called on every switch so only call the
  56708. + * following for the first time through. */
  56709. + if (!core_if->phy_init_done) {
  56710. + core_if->phy_init_done = 1;
  56711. + DWC_DEBUGPL(DBG_CIL, "FS_PHY detected\n");
  56712. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56713. + usbcfg.b.physel = 1;
  56714. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56715. +
  56716. + /* Reset after a PHY select */
  56717. + dwc_otg_core_reset(core_if);
  56718. + }
  56719. +
  56720. + /* Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
  56721. + * do this on HNP Dev/Host mode switches (done in dev_init and
  56722. + * host_init). */
  56723. + if (dwc_otg_is_host_mode(core_if)) {
  56724. + init_fslspclksel(core_if);
  56725. + } else {
  56726. + init_devspd(core_if);
  56727. + }
  56728. +
  56729. + if (core_if->core_params->i2c_enable) {
  56730. + DWC_DEBUGPL(DBG_CIL, "FS_PHY Enabling I2c\n");
  56731. + /* Program GUSBCFG.OtgUtmifsSel to I2C */
  56732. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56733. + usbcfg.b.otgutmifssel = 1;
  56734. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56735. +
  56736. + /* Program GI2CCTL.I2CEn */
  56737. + i2cctl.d32 = DWC_READ_REG32(&global_regs->gi2cctl);
  56738. + i2cctl.b.i2cdevaddr = 1;
  56739. + i2cctl.b.i2cen = 0;
  56740. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  56741. + i2cctl.b.i2cen = 1;
  56742. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  56743. + }
  56744. +
  56745. + } /* endif speed == DWC_SPEED_PARAM_FULL */
  56746. + else {
  56747. + /* High speed PHY. */
  56748. + if (!core_if->phy_init_done) {
  56749. + core_if->phy_init_done = 1;
  56750. + /* HS PHY parameters. These parameters are preserved
  56751. + * during soft reset so only program the first time. Do
  56752. + * a soft reset immediately after setting phyif. */
  56753. +
  56754. + if (core_if->core_params->phy_type == 2) {
  56755. + /* ULPI interface */
  56756. + usbcfg.b.ulpi_utmi_sel = 1;
  56757. + usbcfg.b.phyif = 0;
  56758. + usbcfg.b.ddrsel =
  56759. + core_if->core_params->phy_ulpi_ddr;
  56760. + } else if (core_if->core_params->phy_type == 1) {
  56761. + /* UTMI+ interface */
  56762. + usbcfg.b.ulpi_utmi_sel = 0;
  56763. + if (core_if->core_params->phy_utmi_width == 16) {
  56764. + usbcfg.b.phyif = 1;
  56765. +
  56766. + } else {
  56767. + usbcfg.b.phyif = 0;
  56768. + }
  56769. + } else {
  56770. + DWC_ERROR("FS PHY TYPE\n");
  56771. + }
  56772. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56773. + /* Reset after setting the PHY parameters */
  56774. + dwc_otg_core_reset(core_if);
  56775. + }
  56776. + }
  56777. +
  56778. + if ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  56779. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  56780. + (core_if->core_params->ulpi_fs_ls)) {
  56781. + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS\n");
  56782. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56783. + usbcfg.b.ulpi_fsls = 1;
  56784. + usbcfg.b.ulpi_clk_sus_m = 1;
  56785. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56786. + } else {
  56787. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56788. + usbcfg.b.ulpi_fsls = 0;
  56789. + usbcfg.b.ulpi_clk_sus_m = 0;
  56790. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56791. + }
  56792. +
  56793. + /* Program the GAHBCFG Register. */
  56794. + switch (core_if->hwcfg2.b.architecture) {
  56795. +
  56796. + case DWC_SLAVE_ONLY_ARCH:
  56797. + DWC_DEBUGPL(DBG_CIL, "Slave Only Mode\n");
  56798. + ahbcfg.b.nptxfemplvl_txfemplvl =
  56799. + DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  56800. + ahbcfg.b.ptxfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  56801. + core_if->dma_enable = 0;
  56802. + core_if->dma_desc_enable = 0;
  56803. + break;
  56804. +
  56805. + case DWC_EXT_DMA_ARCH:
  56806. + DWC_DEBUGPL(DBG_CIL, "External DMA Mode\n");
  56807. + {
  56808. + uint8_t brst_sz = core_if->core_params->dma_burst_size;
  56809. + ahbcfg.b.hburstlen = 0;
  56810. + while (brst_sz > 1) {
  56811. + ahbcfg.b.hburstlen++;
  56812. + brst_sz >>= 1;
  56813. + }
  56814. + }
  56815. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  56816. + core_if->dma_desc_enable =
  56817. + (core_if->core_params->dma_desc_enable != 0);
  56818. + break;
  56819. +
  56820. + case DWC_INT_DMA_ARCH:
  56821. + DWC_DEBUGPL(DBG_CIL, "Internal DMA Mode\n");
  56822. + /* Old value was DWC_GAHBCFG_INT_DMA_BURST_INCR - done for
  56823. + Host mode ISOC in issue fix - vahrama */
  56824. + /* Broadcom had altered to (1<<3)|(0<<0) - WRESP=1, max 4 beats */
  56825. + ahbcfg.b.hburstlen = (1<<3)|(0<<0);//DWC_GAHBCFG_INT_DMA_BURST_INCR4;
  56826. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  56827. + core_if->dma_desc_enable =
  56828. + (core_if->core_params->dma_desc_enable != 0);
  56829. + break;
  56830. +
  56831. + }
  56832. + if (core_if->dma_enable) {
  56833. + if (core_if->dma_desc_enable) {
  56834. + DWC_PRINTF("Using Descriptor DMA mode\n");
  56835. + } else {
  56836. + DWC_PRINTF("Using Buffer DMA mode\n");
  56837. +
  56838. + }
  56839. + } else {
  56840. + DWC_PRINTF("Using Slave mode\n");
  56841. + core_if->dma_desc_enable = 0;
  56842. + }
  56843. +
  56844. + if (core_if->core_params->ahb_single) {
  56845. + ahbcfg.b.ahbsingle = 1;
  56846. + }
  56847. +
  56848. + ahbcfg.b.dmaenable = core_if->dma_enable;
  56849. + DWC_WRITE_REG32(&global_regs->gahbcfg, ahbcfg.d32);
  56850. +
  56851. + core_if->en_multiple_tx_fifo = core_if->hwcfg4.b.ded_fifo_en;
  56852. +
  56853. + core_if->pti_enh_enable = core_if->core_params->pti_enable != 0;
  56854. + core_if->multiproc_int_enable = core_if->core_params->mpi_enable;
  56855. + DWC_PRINTF("Periodic Transfer Interrupt Enhancement - %s\n",
  56856. + ((core_if->pti_enh_enable) ? "enabled" : "disabled"));
  56857. + DWC_PRINTF("Multiprocessor Interrupt Enhancement - %s\n",
  56858. + ((core_if->multiproc_int_enable) ? "enabled" : "disabled"));
  56859. +
  56860. + /*
  56861. + * Program the GUSBCFG register.
  56862. + */
  56863. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56864. +
  56865. + switch (core_if->hwcfg2.b.op_mode) {
  56866. + case DWC_MODE_HNP_SRP_CAPABLE:
  56867. + usbcfg.b.hnpcap = (core_if->core_params->otg_cap ==
  56868. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  56869. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  56870. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  56871. + break;
  56872. +
  56873. + case DWC_MODE_SRP_ONLY_CAPABLE:
  56874. + usbcfg.b.hnpcap = 0;
  56875. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  56876. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  56877. + break;
  56878. +
  56879. + case DWC_MODE_NO_HNP_SRP_CAPABLE:
  56880. + usbcfg.b.hnpcap = 0;
  56881. + usbcfg.b.srpcap = 0;
  56882. + break;
  56883. +
  56884. + case DWC_MODE_SRP_CAPABLE_DEVICE:
  56885. + usbcfg.b.hnpcap = 0;
  56886. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  56887. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  56888. + break;
  56889. +
  56890. + case DWC_MODE_NO_SRP_CAPABLE_DEVICE:
  56891. + usbcfg.b.hnpcap = 0;
  56892. + usbcfg.b.srpcap = 0;
  56893. + break;
  56894. +
  56895. + case DWC_MODE_SRP_CAPABLE_HOST:
  56896. + usbcfg.b.hnpcap = 0;
  56897. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  56898. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  56899. + break;
  56900. +
  56901. + case DWC_MODE_NO_SRP_CAPABLE_HOST:
  56902. + usbcfg.b.hnpcap = 0;
  56903. + usbcfg.b.srpcap = 0;
  56904. + break;
  56905. + }
  56906. +
  56907. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56908. +
  56909. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56910. + if (core_if->core_params->lpm_enable) {
  56911. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  56912. +
  56913. + /* To enable LPM support set lpm_cap_en bit */
  56914. + lpmcfg.b.lpm_cap_en = 1;
  56915. +
  56916. + /* Make AppL1Res ACK */
  56917. + lpmcfg.b.appl_resp = 1;
  56918. +
  56919. + /* Retry 3 times */
  56920. + lpmcfg.b.retry_count = 3;
  56921. +
  56922. + DWC_MODIFY_REG32(&core_if->core_global_regs->glpmcfg,
  56923. + 0, lpmcfg.d32);
  56924. +
  56925. + }
  56926. +#endif
  56927. + if (core_if->core_params->ic_usb_cap) {
  56928. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  56929. + gusbcfg.b.ic_usb_cap = 1;
  56930. + DWC_MODIFY_REG32(&core_if->core_global_regs->gusbcfg,
  56931. + 0, gusbcfg.d32);
  56932. + }
  56933. + {
  56934. + gotgctl_data_t gotgctl = {.d32 = 0 };
  56935. + gotgctl.b.otgver = core_if->core_params->otg_ver;
  56936. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl, 0,
  56937. + gotgctl.d32);
  56938. + /* Set OTG version supported */
  56939. + core_if->otg_ver = core_if->core_params->otg_ver;
  56940. + DWC_PRINTF("OTG VER PARAM: %d, OTG VER FLAG: %d\n",
  56941. + core_if->core_params->otg_ver, core_if->otg_ver);
  56942. + }
  56943. +
  56944. +
  56945. + /* Enable common interrupts */
  56946. + dwc_otg_enable_common_interrupts(core_if);
  56947. +
  56948. + /* Do device or host intialization based on mode during PCD
  56949. + * and HCD initialization */
  56950. + if (dwc_otg_is_host_mode(core_if)) {
  56951. + DWC_DEBUGPL(DBG_ANY, "Host Mode\n");
  56952. + core_if->op_state = A_HOST;
  56953. + } else {
  56954. + DWC_DEBUGPL(DBG_ANY, "Device Mode\n");
  56955. + core_if->op_state = B_PERIPHERAL;
  56956. +#ifdef DWC_DEVICE_ONLY
  56957. + dwc_otg_core_dev_init(core_if);
  56958. +#endif
  56959. + }
  56960. +}
  56961. +
  56962. +/**
  56963. + * This function enables the Device mode interrupts.
  56964. + *
  56965. + * @param core_if Programming view of DWC_otg controller
  56966. + */
  56967. +void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * core_if)
  56968. +{
  56969. + gintmsk_data_t intr_mask = {.d32 = 0 };
  56970. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56971. +
  56972. + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
  56973. +
  56974. + /* Disable all interrupts. */
  56975. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  56976. +
  56977. + /* Clear any pending interrupts */
  56978. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  56979. +
  56980. + /* Enable the common interrupts */
  56981. + dwc_otg_enable_common_interrupts(core_if);
  56982. +
  56983. + /* Enable interrupts */
  56984. + intr_mask.b.usbreset = 1;
  56985. + intr_mask.b.enumdone = 1;
  56986. + /* Disable Disconnect interrupt in Device mode */
  56987. + intr_mask.b.disconnect = 0;
  56988. +
  56989. + if (!core_if->multiproc_int_enable) {
  56990. + intr_mask.b.inepintr = 1;
  56991. + intr_mask.b.outepintr = 1;
  56992. + }
  56993. +
  56994. + intr_mask.b.erlysuspend = 1;
  56995. +
  56996. + if (core_if->en_multiple_tx_fifo == 0) {
  56997. + intr_mask.b.epmismatch = 1;
  56998. + }
  56999. +
  57000. + //intr_mask.b.incomplisoout = 1;
  57001. + intr_mask.b.incomplisoin = 1;
  57002. +
  57003. +/* Enable the ignore frame number for ISOC xfers - MAS */
  57004. +/* Disable to support high bandwith ISOC transfers - manukz */
  57005. +#if 0
  57006. +#ifdef DWC_UTE_PER_IO
  57007. + if (core_if->dma_enable) {
  57008. + if (core_if->dma_desc_enable) {
  57009. + dctl_data_t dctl1 = {.d32 = 0 };
  57010. + dctl1.b.ifrmnum = 1;
  57011. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  57012. + dctl, 0, dctl1.d32);
  57013. + DWC_DEBUG("----Enabled Ignore frame number (0x%08x)",
  57014. + DWC_READ_REG32(&core_if->dev_if->
  57015. + dev_global_regs->dctl));
  57016. + }
  57017. + }
  57018. +#endif
  57019. +#endif
  57020. +#ifdef DWC_EN_ISOC
  57021. + if (core_if->dma_enable) {
  57022. + if (core_if->dma_desc_enable == 0) {
  57023. + if (core_if->pti_enh_enable) {
  57024. + dctl_data_t dctl = {.d32 = 0 };
  57025. + dctl.b.ifrmnum = 1;
  57026. + DWC_MODIFY_REG32(&core_if->
  57027. + dev_if->dev_global_regs->dctl,
  57028. + 0, dctl.d32);
  57029. + } else {
  57030. + intr_mask.b.incomplisoin = 1;
  57031. + intr_mask.b.incomplisoout = 1;
  57032. + }
  57033. + }
  57034. + } else {
  57035. + intr_mask.b.incomplisoin = 1;
  57036. + intr_mask.b.incomplisoout = 1;
  57037. + }
  57038. +#endif /* DWC_EN_ISOC */
  57039. +
  57040. + /** @todo NGS: Should this be a module parameter? */
  57041. +#ifdef USE_PERIODIC_EP
  57042. + intr_mask.b.isooutdrop = 1;
  57043. + intr_mask.b.eopframe = 1;
  57044. + intr_mask.b.incomplisoin = 1;
  57045. + intr_mask.b.incomplisoout = 1;
  57046. +#endif
  57047. +
  57048. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  57049. +
  57050. + DWC_DEBUGPL(DBG_CIL, "%s() gintmsk=%0x\n", __func__,
  57051. + DWC_READ_REG32(&global_regs->gintmsk));
  57052. +}
  57053. +
  57054. +/**
  57055. + * This function initializes the DWC_otg controller registers for
  57056. + * device mode.
  57057. + *
  57058. + * @param core_if Programming view of DWC_otg controller
  57059. + *
  57060. + */
  57061. +void dwc_otg_core_dev_init(dwc_otg_core_if_t * core_if)
  57062. +{
  57063. + int i;
  57064. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57065. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  57066. + dwc_otg_core_params_t *params = core_if->core_params;
  57067. + dcfg_data_t dcfg = {.d32 = 0 };
  57068. + depctl_data_t diepctl = {.d32 = 0 };
  57069. + grstctl_t resetctl = {.d32 = 0 };
  57070. + uint32_t rx_fifo_size;
  57071. + fifosize_data_t nptxfifosize;
  57072. + fifosize_data_t txfifosize;
  57073. + dthrctl_data_t dthrctl;
  57074. + fifosize_data_t ptxfifosize;
  57075. + uint16_t rxfsiz, nptxfsiz;
  57076. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  57077. + hwcfg3_data_t hwcfg3 = {.d32 = 0 };
  57078. +
  57079. + /* Restart the Phy Clock */
  57080. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  57081. +
  57082. + /* Device configuration register */
  57083. + init_devspd(core_if);
  57084. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  57085. + dcfg.b.descdma = (core_if->dma_desc_enable) ? 1 : 0;
  57086. + dcfg.b.perfrint = DWC_DCFG_FRAME_INTERVAL_80;
  57087. + /* Enable Device OUT NAK in case of DDMA mode*/
  57088. + if (core_if->core_params->dev_out_nak) {
  57089. + dcfg.b.endevoutnak = 1;
  57090. + }
  57091. +
  57092. + if (core_if->core_params->cont_on_bna) {
  57093. + dctl_data_t dctl = {.d32 = 0 };
  57094. + dctl.b.encontonbna = 1;
  57095. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  57096. + }
  57097. +
  57098. +
  57099. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  57100. +
  57101. + /* Configure data FIFO sizes */
  57102. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  57103. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  57104. + core_if->total_fifo_size);
  57105. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  57106. + params->dev_rx_fifo_size);
  57107. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  57108. + params->dev_nperio_tx_fifo_size);
  57109. +
  57110. + /* Rx FIFO */
  57111. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  57112. + DWC_READ_REG32(&global_regs->grxfsiz));
  57113. +
  57114. +#ifdef DWC_UTE_CFI
  57115. + core_if->pwron_rxfsiz = DWC_READ_REG32(&global_regs->grxfsiz);
  57116. + core_if->init_rxfsiz = params->dev_rx_fifo_size;
  57117. +#endif
  57118. + rx_fifo_size = params->dev_rx_fifo_size;
  57119. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  57120. +
  57121. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  57122. + DWC_READ_REG32(&global_regs->grxfsiz));
  57123. +
  57124. + /** Set Periodic Tx FIFO Mask all bits 0 */
  57125. + core_if->p_tx_msk = 0;
  57126. +
  57127. + /** Set Tx FIFO Mask all bits 0 */
  57128. + core_if->tx_msk = 0;
  57129. +
  57130. + if (core_if->en_multiple_tx_fifo == 0) {
  57131. + /* Non-periodic Tx FIFO */
  57132. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  57133. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57134. +
  57135. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  57136. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  57137. +
  57138. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  57139. + nptxfifosize.d32);
  57140. +
  57141. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  57142. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57143. +
  57144. + /**@todo NGS: Fix Periodic FIFO Sizing! */
  57145. + /*
  57146. + * Periodic Tx FIFOs These FIFOs are numbered from 1 to 15.
  57147. + * Indexes of the FIFO size module parameters in the
  57148. + * dev_perio_tx_fifo_size array and the FIFO size registers in
  57149. + * the dptxfsiz array run from 0 to 14.
  57150. + */
  57151. + /** @todo Finish debug of this */
  57152. + ptxfifosize.b.startaddr =
  57153. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  57154. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  57155. + ptxfifosize.b.depth =
  57156. + params->dev_perio_tx_fifo_size[i];
  57157. + DWC_DEBUGPL(DBG_CIL,
  57158. + "initial dtxfsiz[%d]=%08x\n", i,
  57159. + DWC_READ_REG32(&global_regs->dtxfsiz
  57160. + [i]));
  57161. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  57162. + ptxfifosize.d32);
  57163. + DWC_DEBUGPL(DBG_CIL, "new dtxfsiz[%d]=%08x\n",
  57164. + i,
  57165. + DWC_READ_REG32(&global_regs->dtxfsiz
  57166. + [i]));
  57167. + ptxfifosize.b.startaddr += ptxfifosize.b.depth;
  57168. + }
  57169. + } else {
  57170. + /*
  57171. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  57172. + * Indexes of the FIFO size module parameters in the
  57173. + * dev_tx_fifo_size array and the FIFO size registers in
  57174. + * the dtxfsiz array run from 0 to 14.
  57175. + */
  57176. +
  57177. + /* Non-periodic Tx FIFO */
  57178. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  57179. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57180. +
  57181. +#ifdef DWC_UTE_CFI
  57182. + core_if->pwron_gnptxfsiz =
  57183. + (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  57184. + core_if->init_gnptxfsiz =
  57185. + params->dev_nperio_tx_fifo_size;
  57186. +#endif
  57187. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  57188. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  57189. +
  57190. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  57191. + nptxfifosize.d32);
  57192. +
  57193. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  57194. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57195. +
  57196. + txfifosize.b.startaddr =
  57197. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  57198. +
  57199. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  57200. +
  57201. + txfifosize.b.depth =
  57202. + params->dev_tx_fifo_size[i];
  57203. +
  57204. + DWC_DEBUGPL(DBG_CIL,
  57205. + "initial dtxfsiz[%d]=%08x\n",
  57206. + i,
  57207. + DWC_READ_REG32(&global_regs->dtxfsiz
  57208. + [i]));
  57209. +
  57210. +#ifdef DWC_UTE_CFI
  57211. + core_if->pwron_txfsiz[i] =
  57212. + (DWC_READ_REG32
  57213. + (&global_regs->dtxfsiz[i]) >> 16);
  57214. + core_if->init_txfsiz[i] =
  57215. + params->dev_tx_fifo_size[i];
  57216. +#endif
  57217. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  57218. + txfifosize.d32);
  57219. +
  57220. + DWC_DEBUGPL(DBG_CIL,
  57221. + "new dtxfsiz[%d]=%08x\n",
  57222. + i,
  57223. + DWC_READ_REG32(&global_regs->dtxfsiz
  57224. + [i]));
  57225. +
  57226. + txfifosize.b.startaddr += txfifosize.b.depth;
  57227. + }
  57228. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  57229. + /* Calculating DFIFOCFG for Device mode to include RxFIFO and NPTXFIFO */
  57230. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  57231. + hwcfg3.d32 = DWC_READ_REG32(&global_regs->ghwcfg3);
  57232. + gdfifocfg.b.gdfifocfg = (DWC_READ_REG32(&global_regs->ghwcfg3) >> 16);
  57233. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  57234. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  57235. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  57236. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz;
  57237. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  57238. + }
  57239. + }
  57240. +
  57241. + /* Flush the FIFOs */
  57242. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  57243. + dwc_otg_flush_rx_fifo(core_if);
  57244. +
  57245. + /* Flush the Learning Queue. */
  57246. + resetctl.b.intknqflsh = 1;
  57247. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  57248. +
  57249. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  57250. + core_if->start_predict = 0;
  57251. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  57252. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  57253. + }
  57254. + core_if->nextep_seq[0] = 0;
  57255. + core_if->first_in_nextep_seq = 0;
  57256. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  57257. + diepctl.b.nextep = 0;
  57258. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  57259. +
  57260. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  57261. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  57262. + dcfg.b.epmscnt = 2;
  57263. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  57264. +
  57265. + DWC_DEBUGPL(DBG_CILV,"%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  57266. + __func__, core_if->first_in_nextep_seq);
  57267. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  57268. + DWC_DEBUGPL(DBG_CILV, "%2d ", core_if->nextep_seq[i]);
  57269. + }
  57270. + DWC_DEBUGPL(DBG_CILV,"\n");
  57271. + }
  57272. +
  57273. + /* Clear all pending Device Interrupts */
  57274. + /** @todo - if the condition needed to be checked
  57275. + * or in any case all pending interrutps should be cleared?
  57276. + */
  57277. + if (core_if->multiproc_int_enable) {
  57278. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  57279. + DWC_WRITE_REG32(&dev_if->
  57280. + dev_global_regs->diepeachintmsk[i], 0);
  57281. + }
  57282. + }
  57283. +
  57284. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  57285. + DWC_WRITE_REG32(&dev_if->
  57286. + dev_global_regs->doepeachintmsk[i], 0);
  57287. + }
  57288. +
  57289. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachint, 0xFFFFFFFF);
  57290. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk, 0);
  57291. + } else {
  57292. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, 0);
  57293. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, 0);
  57294. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daint, 0xFFFFFFFF);
  57295. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk, 0);
  57296. + }
  57297. +
  57298. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  57299. + depctl_data_t depctl;
  57300. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  57301. + if (depctl.b.epena) {
  57302. + depctl.d32 = 0;
  57303. + depctl.b.epdis = 1;
  57304. + depctl.b.snak = 1;
  57305. + } else {
  57306. + depctl.d32 = 0;
  57307. + }
  57308. +
  57309. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  57310. +
  57311. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, 0);
  57312. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, 0);
  57313. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepint, 0xFF);
  57314. + }
  57315. +
  57316. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  57317. + depctl_data_t depctl;
  57318. + depctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  57319. + if (depctl.b.epena) {
  57320. + dctl_data_t dctl = {.d32 = 0 };
  57321. + gintmsk_data_t gintsts = {.d32 = 0 };
  57322. + doepint_data_t doepint = {.d32 = 0 };
  57323. + dctl.b.sgoutnak = 1;
  57324. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  57325. + do {
  57326. + dwc_udelay(10);
  57327. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  57328. + } while (!gintsts.b.goutnakeff);
  57329. + gintsts.d32 = 0;
  57330. + gintsts.b.goutnakeff = 1;
  57331. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  57332. +
  57333. + depctl.d32 = 0;
  57334. + depctl.b.epdis = 1;
  57335. + depctl.b.snak = 1;
  57336. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  57337. + do {
  57338. + dwc_udelay(10);
  57339. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  57340. + out_ep_regs[i]->doepint);
  57341. + } while (!doepint.b.epdisabled);
  57342. +
  57343. + doepint.b.epdisabled = 1;
  57344. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepint, doepint.d32);
  57345. +
  57346. + dctl.d32 = 0;
  57347. + dctl.b.cgoutnak = 1;
  57348. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  57349. + } else {
  57350. + depctl.d32 = 0;
  57351. + }
  57352. +
  57353. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  57354. +
  57355. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doeptsiz, 0);
  57356. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepdma, 0);
  57357. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepint, 0xFF);
  57358. + }
  57359. +
  57360. + if (core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  57361. + dev_if->non_iso_tx_thr_en = params->thr_ctl & 0x1;
  57362. + dev_if->iso_tx_thr_en = (params->thr_ctl >> 1) & 0x1;
  57363. + dev_if->rx_thr_en = (params->thr_ctl >> 2) & 0x1;
  57364. +
  57365. + dev_if->rx_thr_length = params->rx_thr_length;
  57366. + dev_if->tx_thr_length = params->tx_thr_length;
  57367. +
  57368. + dev_if->setup_desc_index = 0;
  57369. +
  57370. + dthrctl.d32 = 0;
  57371. + dthrctl.b.non_iso_thr_en = dev_if->non_iso_tx_thr_en;
  57372. + dthrctl.b.iso_thr_en = dev_if->iso_tx_thr_en;
  57373. + dthrctl.b.tx_thr_len = dev_if->tx_thr_length;
  57374. + dthrctl.b.rx_thr_en = dev_if->rx_thr_en;
  57375. + dthrctl.b.rx_thr_len = dev_if->rx_thr_length;
  57376. + dthrctl.b.ahb_thr_ratio = params->ahb_thr_ratio;
  57377. +
  57378. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dtknqr3_dthrctl,
  57379. + dthrctl.d32);
  57380. +
  57381. + DWC_DEBUGPL(DBG_CIL,
  57382. + "Non ISO Tx Thr - %d\nISO Tx Thr - %d\nRx Thr - %d\nTx Thr Len - %d\nRx Thr Len - %d\n",
  57383. + dthrctl.b.non_iso_thr_en, dthrctl.b.iso_thr_en,
  57384. + dthrctl.b.rx_thr_en, dthrctl.b.tx_thr_len,
  57385. + dthrctl.b.rx_thr_len);
  57386. +
  57387. + }
  57388. +
  57389. + dwc_otg_enable_device_interrupts(core_if);
  57390. +
  57391. + {
  57392. + diepmsk_data_t msk = {.d32 = 0 };
  57393. + msk.b.txfifoundrn = 1;
  57394. + if (core_if->multiproc_int_enable) {
  57395. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->
  57396. + diepeachintmsk[0], msk.d32, msk.d32);
  57397. + } else {
  57398. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk,
  57399. + msk.d32, msk.d32);
  57400. + }
  57401. + }
  57402. +
  57403. + if (core_if->multiproc_int_enable) {
  57404. + /* Set NAK on Babble */
  57405. + dctl_data_t dctl = {.d32 = 0 };
  57406. + dctl.b.nakonbble = 1;
  57407. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  57408. + }
  57409. +
  57410. + if (core_if->snpsid >= OTG_CORE_REV_2_94a) {
  57411. + dctl_data_t dctl = {.d32 = 0 };
  57412. + dctl.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  57413. + dctl.b.sftdiscon = 0;
  57414. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl, dctl.d32);
  57415. + }
  57416. +}
  57417. +
  57418. +/**
  57419. + * This function enables the Host mode interrupts.
  57420. + *
  57421. + * @param core_if Programming view of DWC_otg controller
  57422. + */
  57423. +void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * core_if)
  57424. +{
  57425. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57426. + gintmsk_data_t intr_mask = {.d32 = 0 };
  57427. +
  57428. + DWC_DEBUGPL(DBG_CIL, "%s(%p)\n", __func__, core_if);
  57429. +
  57430. + /* Disable all interrupts. */
  57431. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  57432. +
  57433. + /* Clear any pending interrupts. */
  57434. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  57435. +
  57436. + /* Enable the common interrupts */
  57437. + dwc_otg_enable_common_interrupts(core_if);
  57438. +
  57439. + /*
  57440. + * Enable host mode interrupts without disturbing common
  57441. + * interrupts.
  57442. + */
  57443. +
  57444. + intr_mask.b.disconnect = 1;
  57445. + intr_mask.b.portintr = 1;
  57446. + intr_mask.b.hcintr = 1;
  57447. +
  57448. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  57449. +}
  57450. +
  57451. +/**
  57452. + * This function disables the Host Mode interrupts.
  57453. + *
  57454. + * @param core_if Programming view of DWC_otg controller
  57455. + */
  57456. +void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * core_if)
  57457. +{
  57458. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57459. + gintmsk_data_t intr_mask = {.d32 = 0 };
  57460. +
  57461. + DWC_DEBUGPL(DBG_CILV, "%s()\n", __func__);
  57462. +
  57463. + /*
  57464. + * Disable host mode interrupts without disturbing common
  57465. + * interrupts.
  57466. + */
  57467. + intr_mask.b.sofintr = 1;
  57468. + intr_mask.b.portintr = 1;
  57469. + intr_mask.b.hcintr = 1;
  57470. + intr_mask.b.ptxfempty = 1;
  57471. + intr_mask.b.nptxfempty = 1;
  57472. +
  57473. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, 0);
  57474. +}
  57475. +
  57476. +/**
  57477. + * This function initializes the DWC_otg controller registers for
  57478. + * host mode.
  57479. + *
  57480. + * This function flushes the Tx and Rx FIFOs and it flushes any entries in the
  57481. + * request queues. Host channels are reset to ensure that they are ready for
  57482. + * performing transfers.
  57483. + *
  57484. + * @param core_if Programming view of DWC_otg controller
  57485. + *
  57486. + */
  57487. +void dwc_otg_core_host_init(dwc_otg_core_if_t * core_if)
  57488. +{
  57489. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57490. + dwc_otg_host_if_t *host_if = core_if->host_if;
  57491. + dwc_otg_core_params_t *params = core_if->core_params;
  57492. + hprt0_data_t hprt0 = {.d32 = 0 };
  57493. + fifosize_data_t nptxfifosize;
  57494. + fifosize_data_t ptxfifosize;
  57495. + uint16_t rxfsiz, nptxfsiz, hptxfsiz;
  57496. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  57497. + int i;
  57498. + hcchar_data_t hcchar;
  57499. + hcfg_data_t hcfg;
  57500. + hfir_data_t hfir;
  57501. + dwc_otg_hc_regs_t *hc_regs;
  57502. + int num_channels;
  57503. + gotgctl_data_t gotgctl = {.d32 = 0 };
  57504. +
  57505. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  57506. +
  57507. + /* Restart the Phy Clock */
  57508. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  57509. +
  57510. + /* Initialize Host Configuration Register */
  57511. + init_fslspclksel(core_if);
  57512. + if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  57513. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  57514. + hcfg.b.fslssupp = 1;
  57515. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  57516. +
  57517. + }
  57518. +
  57519. + /* This bit allows dynamic reloading of the HFIR register
  57520. + * during runtime. This bit needs to be programmed during
  57521. + * initial configuration and its value must not be changed
  57522. + * during runtime.*/
  57523. + if (core_if->core_params->reload_ctl == 1) {
  57524. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  57525. + hfir.b.hfirrldctrl = 1;
  57526. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  57527. + }
  57528. +
  57529. + if (core_if->core_params->dma_desc_enable) {
  57530. + uint8_t op_mode = core_if->hwcfg2.b.op_mode;
  57531. + if (!
  57532. + (core_if->hwcfg4.b.desc_dma
  57533. + && (core_if->snpsid >= OTG_CORE_REV_2_90a)
  57534. + && ((op_mode == DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  57535. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  57536. + || (op_mode ==
  57537. + DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG)
  57538. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)
  57539. + || (op_mode ==
  57540. + DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST)))) {
  57541. +
  57542. + DWC_ERROR("Host can't operate in Descriptor DMA mode.\n"
  57543. + "Either core version is below 2.90a or "
  57544. + "GHWCFG2, GHWCFG4 registers' values do not allow Descriptor DMA in host mode.\n"
  57545. + "To run the driver in Buffer DMA host mode set dma_desc_enable "
  57546. + "module parameter to 0.\n");
  57547. + return;
  57548. + }
  57549. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  57550. + hcfg.b.descdma = 1;
  57551. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  57552. + }
  57553. +
  57554. + /* Configure data FIFO sizes */
  57555. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  57556. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  57557. + core_if->total_fifo_size);
  57558. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  57559. + params->host_rx_fifo_size);
  57560. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  57561. + params->host_nperio_tx_fifo_size);
  57562. + DWC_DEBUGPL(DBG_CIL, "P Tx FIFO Size=%d\n",
  57563. + params->host_perio_tx_fifo_size);
  57564. +
  57565. + /* Rx FIFO */
  57566. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  57567. + DWC_READ_REG32(&global_regs->grxfsiz));
  57568. + DWC_WRITE_REG32(&global_regs->grxfsiz,
  57569. + params->host_rx_fifo_size);
  57570. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  57571. + DWC_READ_REG32(&global_regs->grxfsiz));
  57572. +
  57573. + /* Non-periodic Tx FIFO */
  57574. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  57575. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57576. + nptxfifosize.b.depth = params->host_nperio_tx_fifo_size;
  57577. + nptxfifosize.b.startaddr = params->host_rx_fifo_size;
  57578. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  57579. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  57580. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57581. +
  57582. + /* Periodic Tx FIFO */
  57583. + DWC_DEBUGPL(DBG_CIL, "initial hptxfsiz=%08x\n",
  57584. + DWC_READ_REG32(&global_regs->hptxfsiz));
  57585. + ptxfifosize.b.depth = params->host_perio_tx_fifo_size;
  57586. + ptxfifosize.b.startaddr =
  57587. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  57588. + DWC_WRITE_REG32(&global_regs->hptxfsiz, ptxfifosize.d32);
  57589. + DWC_DEBUGPL(DBG_CIL, "new hptxfsiz=%08x\n",
  57590. + DWC_READ_REG32(&global_regs->hptxfsiz));
  57591. +
  57592. + if (core_if->en_multiple_tx_fifo
  57593. + && core_if->snpsid <= OTG_CORE_REV_2_94a) {
  57594. + /* Global DFIFOCFG calculation for Host mode - include RxFIFO, NPTXFIFO and HPTXFIFO */
  57595. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  57596. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  57597. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  57598. + hptxfsiz = (DWC_READ_REG32(&global_regs->hptxfsiz) >> 16);
  57599. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz + hptxfsiz;
  57600. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  57601. + }
  57602. + }
  57603. +
  57604. + /* TODO - check this */
  57605. + /* Clear Host Set HNP Enable in the OTG Control Register */
  57606. + gotgctl.b.hstsethnpen = 1;
  57607. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  57608. + /* Make sure the FIFOs are flushed. */
  57609. + dwc_otg_flush_tx_fifo(core_if, 0x10 /* all TX FIFOs */ );
  57610. + dwc_otg_flush_rx_fifo(core_if);
  57611. +
  57612. + /* Clear Host Set HNP Enable in the OTG Control Register */
  57613. + gotgctl.b.hstsethnpen = 1;
  57614. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  57615. +
  57616. + if (!core_if->core_params->dma_desc_enable) {
  57617. + /* Flush out any leftover queued requests. */
  57618. + num_channels = core_if->core_params->host_channels;
  57619. +
  57620. + for (i = 0; i < num_channels; i++) {
  57621. + hc_regs = core_if->host_if->hc_regs[i];
  57622. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57623. + hcchar.b.chen = 0;
  57624. + hcchar.b.chdis = 1;
  57625. + hcchar.b.epdir = 0;
  57626. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57627. + }
  57628. +
  57629. + /* Halt all channels to put them into a known state. */
  57630. + for (i = 0; i < num_channels; i++) {
  57631. + int count = 0;
  57632. + hc_regs = core_if->host_if->hc_regs[i];
  57633. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57634. + hcchar.b.chen = 1;
  57635. + hcchar.b.chdis = 1;
  57636. + hcchar.b.epdir = 0;
  57637. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57638. + DWC_DEBUGPL(DBG_HCDV, "%s: Halt channel %d regs %p\n", __func__, i, hc_regs);
  57639. + do {
  57640. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57641. + if (++count > 1000) {
  57642. + DWC_ERROR
  57643. + ("%s: Unable to clear halt on channel %d (timeout HCCHAR 0x%X @%p)\n",
  57644. + __func__, i, hcchar.d32, &hc_regs->hcchar);
  57645. + break;
  57646. + }
  57647. + dwc_udelay(1);
  57648. + } while (hcchar.b.chen);
  57649. + }
  57650. + }
  57651. +
  57652. + /* Turn on the vbus power. */
  57653. + DWC_PRINTF("Init: Port Power? op_state=%d\n", core_if->op_state);
  57654. + if (core_if->op_state == A_HOST) {
  57655. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  57656. + DWC_PRINTF("Init: Power Port (%d)\n", hprt0.b.prtpwr);
  57657. + if (hprt0.b.prtpwr == 0) {
  57658. + hprt0.b.prtpwr = 1;
  57659. + DWC_WRITE_REG32(host_if->hprt0, hprt0.d32);
  57660. + }
  57661. + }
  57662. +
  57663. + dwc_otg_enable_host_interrupts(core_if);
  57664. +}
  57665. +
  57666. +/**
  57667. + * Prepares a host channel for transferring packets to/from a specific
  57668. + * endpoint. The HCCHARn register is set up with the characteristics specified
  57669. + * in _hc. Host channel interrupts that may need to be serviced while this
  57670. + * transfer is in progress are enabled.
  57671. + *
  57672. + * @param core_if Programming view of DWC_otg controller
  57673. + * @param hc Information needed to initialize the host channel
  57674. + */
  57675. +void dwc_otg_hc_init(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57676. +{
  57677. + uint32_t intr_enable;
  57678. + hcintmsk_data_t hc_intr_mask;
  57679. + gintmsk_data_t gintmsk = {.d32 = 0 };
  57680. + hcchar_data_t hcchar;
  57681. + hcsplt_data_t hcsplt;
  57682. +
  57683. + uint8_t hc_num = hc->hc_num;
  57684. + dwc_otg_host_if_t *host_if = core_if->host_if;
  57685. + dwc_otg_hc_regs_t *hc_regs = host_if->hc_regs[hc_num];
  57686. +
  57687. + /* Clear old interrupt conditions for this host channel. */
  57688. + hc_intr_mask.d32 = 0xFFFFFFFF;
  57689. + hc_intr_mask.b.reserved14_31 = 0;
  57690. + DWC_WRITE_REG32(&hc_regs->hcint, hc_intr_mask.d32);
  57691. +
  57692. + /* Enable channel interrupts required for this transfer. */
  57693. + hc_intr_mask.d32 = 0;
  57694. + hc_intr_mask.b.chhltd = 1;
  57695. + if (core_if->dma_enable) {
  57696. + /* For Descriptor DMA mode core halts the channel on AHB error. Interrupt is not required */
  57697. + if (!core_if->dma_desc_enable)
  57698. + hc_intr_mask.b.ahberr = 1;
  57699. + else {
  57700. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  57701. + hc_intr_mask.b.xfercompl = 1;
  57702. + }
  57703. +
  57704. + if (hc->error_state && !hc->do_split &&
  57705. + hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  57706. + hc_intr_mask.b.ack = 1;
  57707. + if (hc->ep_is_in) {
  57708. + hc_intr_mask.b.datatglerr = 1;
  57709. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  57710. + hc_intr_mask.b.nak = 1;
  57711. + }
  57712. + }
  57713. + }
  57714. + } else {
  57715. + switch (hc->ep_type) {
  57716. + case DWC_OTG_EP_TYPE_CONTROL:
  57717. + case DWC_OTG_EP_TYPE_BULK:
  57718. + hc_intr_mask.b.xfercompl = 1;
  57719. + hc_intr_mask.b.stall = 1;
  57720. + hc_intr_mask.b.xacterr = 1;
  57721. + hc_intr_mask.b.datatglerr = 1;
  57722. + if (hc->ep_is_in) {
  57723. + hc_intr_mask.b.bblerr = 1;
  57724. + } else {
  57725. + hc_intr_mask.b.nak = 1;
  57726. + hc_intr_mask.b.nyet = 1;
  57727. + if (hc->do_ping) {
  57728. + hc_intr_mask.b.ack = 1;
  57729. + }
  57730. + }
  57731. +
  57732. + if (hc->do_split) {
  57733. + hc_intr_mask.b.nak = 1;
  57734. + if (hc->complete_split) {
  57735. + hc_intr_mask.b.nyet = 1;
  57736. + } else {
  57737. + hc_intr_mask.b.ack = 1;
  57738. + }
  57739. + }
  57740. +
  57741. + if (hc->error_state) {
  57742. + hc_intr_mask.b.ack = 1;
  57743. + }
  57744. + break;
  57745. + case DWC_OTG_EP_TYPE_INTR:
  57746. + hc_intr_mask.b.xfercompl = 1;
  57747. + hc_intr_mask.b.nak = 1;
  57748. + hc_intr_mask.b.stall = 1;
  57749. + hc_intr_mask.b.xacterr = 1;
  57750. + hc_intr_mask.b.datatglerr = 1;
  57751. + hc_intr_mask.b.frmovrun = 1;
  57752. +
  57753. + if (hc->ep_is_in) {
  57754. + hc_intr_mask.b.bblerr = 1;
  57755. + }
  57756. + if (hc->error_state) {
  57757. + hc_intr_mask.b.ack = 1;
  57758. + }
  57759. + if (hc->do_split) {
  57760. + if (hc->complete_split) {
  57761. + hc_intr_mask.b.nyet = 1;
  57762. + } else {
  57763. + hc_intr_mask.b.ack = 1;
  57764. + }
  57765. + }
  57766. + break;
  57767. + case DWC_OTG_EP_TYPE_ISOC:
  57768. + hc_intr_mask.b.xfercompl = 1;
  57769. + hc_intr_mask.b.frmovrun = 1;
  57770. + hc_intr_mask.b.ack = 1;
  57771. +
  57772. + if (hc->ep_is_in) {
  57773. + hc_intr_mask.b.xacterr = 1;
  57774. + hc_intr_mask.b.bblerr = 1;
  57775. + }
  57776. + break;
  57777. + }
  57778. + }
  57779. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hc_intr_mask.d32);
  57780. +
  57781. + /* Enable the top level host channel interrupt. */
  57782. + intr_enable = (1 << hc_num);
  57783. + DWC_MODIFY_REG32(&host_if->host_global_regs->haintmsk, 0, intr_enable);
  57784. +
  57785. + /* Make sure host channel interrupts are enabled. */
  57786. + gintmsk.b.hcintr = 1;
  57787. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  57788. +
  57789. + /*
  57790. + * Program the HCCHARn register with the endpoint characteristics for
  57791. + * the current transfer.
  57792. + */
  57793. + hcchar.d32 = 0;
  57794. + hcchar.b.devaddr = hc->dev_addr;
  57795. + hcchar.b.epnum = hc->ep_num;
  57796. + hcchar.b.epdir = hc->ep_is_in;
  57797. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  57798. + hcchar.b.eptype = hc->ep_type;
  57799. + hcchar.b.mps = hc->max_packet;
  57800. +
  57801. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcchar, hcchar.d32);
  57802. +
  57803. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d, Dev Addr %d, EP #%d\n",
  57804. + __func__, hc->hc_num, hcchar.b.devaddr, hcchar.b.epnum);
  57805. + DWC_DEBUGPL(DBG_HCDV, " Is In %d, Is Low Speed %d, EP Type %d, "
  57806. + "Max Pkt %d, Multi Cnt %d\n",
  57807. + hcchar.b.epdir, hcchar.b.lspddev, hcchar.b.eptype,
  57808. + hcchar.b.mps, hcchar.b.multicnt);
  57809. +
  57810. + /*
  57811. + * Program the HCSPLIT register for SPLITs
  57812. + */
  57813. + hcsplt.d32 = 0;
  57814. + if (hc->do_split) {
  57815. + DWC_DEBUGPL(DBG_HCDV, "Programming HC %d with split --> %s\n",
  57816. + hc->hc_num,
  57817. + hc->complete_split ? "CSPLIT" : "SSPLIT");
  57818. + hcsplt.b.compsplt = hc->complete_split;
  57819. + hcsplt.b.xactpos = hc->xact_pos;
  57820. + hcsplt.b.hubaddr = hc->hub_addr;
  57821. + hcsplt.b.prtaddr = hc->port_addr;
  57822. + DWC_DEBUGPL(DBG_HCDV, "\t comp split %d\n", hc->complete_split);
  57823. + DWC_DEBUGPL(DBG_HCDV, "\t xact pos %d\n", hc->xact_pos);
  57824. + DWC_DEBUGPL(DBG_HCDV, "\t hub addr %d\n", hc->hub_addr);
  57825. + DWC_DEBUGPL(DBG_HCDV, "\t port addr %d\n", hc->port_addr);
  57826. + DWC_DEBUGPL(DBG_HCDV, "\t is_in %d\n", hc->ep_is_in);
  57827. + DWC_DEBUGPL(DBG_HCDV, "\t Max Pkt: %d\n", hcchar.b.mps);
  57828. + DWC_DEBUGPL(DBG_HCDV, "\t xferlen: %d\n", hc->xfer_len);
  57829. + }
  57830. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcsplt, hcsplt.d32);
  57831. +
  57832. +}
  57833. +
  57834. +/**
  57835. + * Attempts to halt a host channel. This function should only be called in
  57836. + * Slave mode or to abort a transfer in either Slave mode or DMA mode. Under
  57837. + * normal circumstances in DMA mode, the controller halts the channel when the
  57838. + * transfer is complete or a condition occurs that requires application
  57839. + * intervention.
  57840. + *
  57841. + * In slave mode, checks for a free request queue entry, then sets the Channel
  57842. + * Enable and Channel Disable bits of the Host Channel Characteristics
  57843. + * register of the specified channel to intiate the halt. If there is no free
  57844. + * request queue entry, sets only the Channel Disable bit of the HCCHARn
  57845. + * register to flush requests for this channel. In the latter case, sets a
  57846. + * flag to indicate that the host channel needs to be halted when a request
  57847. + * queue slot is open.
  57848. + *
  57849. + * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
  57850. + * HCCHARn register. The controller ensures there is space in the request
  57851. + * queue before submitting the halt request.
  57852. + *
  57853. + * Some time may elapse before the core flushes any posted requests for this
  57854. + * host channel and halts. The Channel Halted interrupt handler completes the
  57855. + * deactivation of the host channel.
  57856. + *
  57857. + * @param core_if Controller register interface.
  57858. + * @param hc Host channel to halt.
  57859. + * @param halt_status Reason for halting the channel.
  57860. + */
  57861. +void dwc_otg_hc_halt(dwc_otg_core_if_t * core_if,
  57862. + dwc_hc_t * hc, dwc_otg_halt_status_e halt_status)
  57863. +{
  57864. + gnptxsts_data_t nptxsts;
  57865. + hptxsts_data_t hptxsts;
  57866. + hcchar_data_t hcchar;
  57867. + dwc_otg_hc_regs_t *hc_regs;
  57868. + dwc_otg_core_global_regs_t *global_regs;
  57869. + dwc_otg_host_global_regs_t *host_global_regs;
  57870. +
  57871. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  57872. + global_regs = core_if->core_global_regs;
  57873. + host_global_regs = core_if->host_if->host_global_regs;
  57874. +
  57875. + DWC_ASSERT(!(halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS),
  57876. + "halt_status = %d\n", halt_status);
  57877. +
  57878. + if (halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  57879. + halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  57880. + /*
  57881. + * Disable all channel interrupts except Ch Halted. The QTD
  57882. + * and QH state associated with this transfer has been cleared
  57883. + * (in the case of URB_DEQUEUE), so the channel needs to be
  57884. + * shut down carefully to prevent crashes.
  57885. + */
  57886. + hcintmsk_data_t hcintmsk;
  57887. + hcintmsk.d32 = 0;
  57888. + hcintmsk.b.chhltd = 1;
  57889. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hcintmsk.d32);
  57890. +
  57891. + /*
  57892. + * Make sure no other interrupts besides halt are currently
  57893. + * pending. Handling another interrupt could cause a crash due
  57894. + * to the QTD and QH state.
  57895. + */
  57896. + DWC_WRITE_REG32(&hc_regs->hcint, ~hcintmsk.d32);
  57897. +
  57898. + /*
  57899. + * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
  57900. + * even if the channel was already halted for some other
  57901. + * reason.
  57902. + */
  57903. + hc->halt_status = halt_status;
  57904. +
  57905. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57906. + if (hcchar.b.chen == 0) {
  57907. + /*
  57908. + * The channel is either already halted or it hasn't
  57909. + * started yet. In DMA mode, the transfer may halt if
  57910. + * it finishes normally or a condition occurs that
  57911. + * requires driver intervention. Don't want to halt
  57912. + * the channel again. In either Slave or DMA mode,
  57913. + * it's possible that the transfer has been assigned
  57914. + * to a channel, but not started yet when an URB is
  57915. + * dequeued. Don't want to halt a channel that hasn't
  57916. + * started yet.
  57917. + */
  57918. + return;
  57919. + }
  57920. + }
  57921. + if (hc->halt_pending) {
  57922. + /*
  57923. + * A halt has already been issued for this channel. This might
  57924. + * happen when a transfer is aborted by a higher level in
  57925. + * the stack.
  57926. + */
  57927. +#ifdef DEBUG
  57928. + DWC_PRINTF
  57929. + ("*** %s: Channel %d, _hc->halt_pending already set ***\n",
  57930. + __func__, hc->hc_num);
  57931. +
  57932. +#endif
  57933. + return;
  57934. + }
  57935. +
  57936. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57937. +
  57938. + /* No need to set the bit in DDMA for disabling the channel */
  57939. + //TODO check it everywhere channel is disabled
  57940. + if (!core_if->core_params->dma_desc_enable)
  57941. + hcchar.b.chen = 1;
  57942. + hcchar.b.chdis = 1;
  57943. +
  57944. + if (!core_if->dma_enable) {
  57945. + /* Check for space in the request queue to issue the halt. */
  57946. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  57947. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  57948. + nptxsts.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  57949. + if (nptxsts.b.nptxqspcavail == 0) {
  57950. + hcchar.b.chen = 0;
  57951. + }
  57952. + } else {
  57953. + hptxsts.d32 =
  57954. + DWC_READ_REG32(&host_global_regs->hptxsts);
  57955. + if ((hptxsts.b.ptxqspcavail == 0)
  57956. + || (core_if->queuing_high_bandwidth)) {
  57957. + hcchar.b.chen = 0;
  57958. + }
  57959. + }
  57960. + }
  57961. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57962. +
  57963. + hc->halt_status = halt_status;
  57964. +
  57965. + if (hcchar.b.chen) {
  57966. + hc->halt_pending = 1;
  57967. + hc->halt_on_queue = 0;
  57968. + } else {
  57969. + hc->halt_on_queue = 1;
  57970. + }
  57971. +
  57972. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  57973. + DWC_DEBUGPL(DBG_HCDV, " hcchar: 0x%08x\n", hcchar.d32);
  57974. + DWC_DEBUGPL(DBG_HCDV, " halt_pending: %d\n", hc->halt_pending);
  57975. + DWC_DEBUGPL(DBG_HCDV, " halt_on_queue: %d\n", hc->halt_on_queue);
  57976. + DWC_DEBUGPL(DBG_HCDV, " halt_status: %d\n", hc->halt_status);
  57977. +
  57978. + return;
  57979. +}
  57980. +
  57981. +/**
  57982. + * Clears the transfer state for a host channel. This function is normally
  57983. + * called after a transfer is done and the host channel is being released.
  57984. + *
  57985. + * @param core_if Programming view of DWC_otg controller.
  57986. + * @param hc Identifies the host channel to clean up.
  57987. + */
  57988. +void dwc_otg_hc_cleanup(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57989. +{
  57990. + dwc_otg_hc_regs_t *hc_regs;
  57991. +
  57992. + hc->xfer_started = 0;
  57993. +
  57994. + /*
  57995. + * Clear channel interrupt enables and any unhandled channel interrupt
  57996. + * conditions.
  57997. + */
  57998. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  57999. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0);
  58000. + DWC_WRITE_REG32(&hc_regs->hcint, 0xFFFFFFFF);
  58001. +#ifdef DEBUG
  58002. + DWC_TIMER_CANCEL(core_if->hc_xfer_timer[hc->hc_num]);
  58003. +#endif
  58004. +}
  58005. +
  58006. +/**
  58007. + * Sets the channel property that indicates in which frame a periodic transfer
  58008. + * should occur. This is always set to the _next_ frame. This function has no
  58009. + * effect on non-periodic transfers.
  58010. + *
  58011. + * @param core_if Programming view of DWC_otg controller.
  58012. + * @param hc Identifies the host channel to set up and its properties.
  58013. + * @param hcchar Current value of the HCCHAR register for the specified host
  58014. + * channel.
  58015. + */
  58016. +static inline void hc_set_even_odd_frame(dwc_otg_core_if_t * core_if,
  58017. + dwc_hc_t * hc, hcchar_data_t * hcchar)
  58018. +{
  58019. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  58020. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  58021. + hfnum_data_t hfnum;
  58022. + hfnum.d32 =
  58023. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfnum);
  58024. +
  58025. + /* 1 if _next_ frame is odd, 0 if it's even */
  58026. + hcchar->b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  58027. +#ifdef DEBUG
  58028. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR && hc->do_split
  58029. + && !hc->complete_split) {
  58030. + switch (hfnum.b.frnum & 0x7) {
  58031. + case 7:
  58032. + core_if->hfnum_7_samples++;
  58033. + core_if->hfnum_7_frrem_accum += hfnum.b.frrem;
  58034. + break;
  58035. + case 0:
  58036. + core_if->hfnum_0_samples++;
  58037. + core_if->hfnum_0_frrem_accum += hfnum.b.frrem;
  58038. + break;
  58039. + default:
  58040. + core_if->hfnum_other_samples++;
  58041. + core_if->hfnum_other_frrem_accum +=
  58042. + hfnum.b.frrem;
  58043. + break;
  58044. + }
  58045. + }
  58046. +#endif
  58047. + }
  58048. +}
  58049. +
  58050. +#ifdef DEBUG
  58051. +void hc_xfer_timeout(void *ptr)
  58052. +{
  58053. + hc_xfer_info_t *xfer_info = NULL;
  58054. + int hc_num = 0;
  58055. +
  58056. + if (ptr)
  58057. + xfer_info = (hc_xfer_info_t *) ptr;
  58058. +
  58059. + if (!xfer_info->hc) {
  58060. + DWC_ERROR("xfer_info->hc = %p\n", xfer_info->hc);
  58061. + return;
  58062. + }
  58063. +
  58064. + hc_num = xfer_info->hc->hc_num;
  58065. + DWC_WARN("%s: timeout on channel %d\n", __func__, hc_num);
  58066. + DWC_WARN(" start_hcchar_val 0x%08x\n",
  58067. + xfer_info->core_if->start_hcchar_val[hc_num]);
  58068. +}
  58069. +#endif
  58070. +
  58071. +void ep_xfer_timeout(void *ptr)
  58072. +{
  58073. + ep_xfer_info_t *xfer_info = NULL;
  58074. + int ep_num = 0;
  58075. + dctl_data_t dctl = {.d32 = 0 };
  58076. + gintsts_data_t gintsts = {.d32 = 0 };
  58077. + gintmsk_data_t gintmsk = {.d32 = 0 };
  58078. +
  58079. + if (ptr)
  58080. + xfer_info = (ep_xfer_info_t *) ptr;
  58081. +
  58082. + if (!xfer_info->ep) {
  58083. + DWC_ERROR("xfer_info->ep = %p\n", xfer_info->ep);
  58084. + return;
  58085. + }
  58086. +
  58087. + ep_num = xfer_info->ep->num;
  58088. + DWC_WARN("%s: timeout on endpoit %d\n", __func__, ep_num);
  58089. + /* Put the sate to 2 as it was time outed */
  58090. + xfer_info->state = 2;
  58091. +
  58092. + dctl.d32 =
  58093. + DWC_READ_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl);
  58094. + gintsts.d32 =
  58095. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintsts);
  58096. + gintmsk.d32 =
  58097. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintmsk);
  58098. +
  58099. + if (!gintmsk.b.goutnakeff) {
  58100. + /* Unmask it */
  58101. + gintmsk.b.goutnakeff = 1;
  58102. + DWC_WRITE_REG32(&xfer_info->core_if->core_global_regs->gintmsk,
  58103. + gintmsk.d32);
  58104. +
  58105. + }
  58106. +
  58107. + if (!gintsts.b.goutnakeff) {
  58108. + dctl.b.sgoutnak = 1;
  58109. + }
  58110. + DWC_WRITE_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl,
  58111. + dctl.d32);
  58112. +
  58113. +}
  58114. +
  58115. +void set_pid_isoc(dwc_hc_t * hc)
  58116. +{
  58117. + /* Set up the initial PID for the transfer. */
  58118. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  58119. + if (hc->ep_is_in) {
  58120. + if (hc->multi_count == 1) {
  58121. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  58122. + } else if (hc->multi_count == 2) {
  58123. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  58124. + } else {
  58125. + hc->data_pid_start = DWC_OTG_HC_PID_DATA2;
  58126. + }
  58127. + } else {
  58128. + if (hc->multi_count == 1) {
  58129. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  58130. + } else {
  58131. + hc->data_pid_start = DWC_OTG_HC_PID_MDATA;
  58132. + }
  58133. + }
  58134. + } else {
  58135. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  58136. + }
  58137. +}
  58138. +
  58139. +/**
  58140. + * This function does the setup for a data transfer for a host channel and
  58141. + * starts the transfer. May be called in either Slave mode or DMA mode. In
  58142. + * Slave mode, the caller must ensure that there is sufficient space in the
  58143. + * request queue and Tx Data FIFO.
  58144. + *
  58145. + * For an OUT transfer in Slave mode, it loads a data packet into the
  58146. + * appropriate FIFO. If necessary, additional data packets will be loaded in
  58147. + * the Host ISR.
  58148. + *
  58149. + * For an IN transfer in Slave mode, a data packet is requested. The data
  58150. + * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
  58151. + * additional data packets are requested in the Host ISR.
  58152. + *
  58153. + * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
  58154. + * register along with a packet count of 1 and the channel is enabled. This
  58155. + * causes a single PING transaction to occur. Other fields in HCTSIZ are
  58156. + * simply set to 0 since no data transfer occurs in this case.
  58157. + *
  58158. + * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
  58159. + * all the information required to perform the subsequent data transfer. In
  58160. + * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
  58161. + * controller performs the entire PING protocol, then starts the data
  58162. + * transfer.
  58163. + *
  58164. + * @param core_if Programming view of DWC_otg controller.
  58165. + * @param hc Information needed to initialize the host channel. The xfer_len
  58166. + * value may be reduced to accommodate the max widths of the XferSize and
  58167. + * PktCnt fields in the HCTSIZn register. The multi_count value may be changed
  58168. + * to reflect the final xfer_len value.
  58169. + */
  58170. +void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58171. +{
  58172. + hcchar_data_t hcchar;
  58173. + hctsiz_data_t hctsiz;
  58174. + uint16_t num_packets;
  58175. + uint32_t max_hc_xfer_size = core_if->core_params->max_transfer_size;
  58176. + uint16_t max_hc_pkt_count = core_if->core_params->max_packet_count;
  58177. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58178. +
  58179. + hctsiz.d32 = 0;
  58180. +
  58181. + if (hc->do_ping) {
  58182. + if (!core_if->dma_enable) {
  58183. + dwc_otg_hc_do_ping(core_if, hc);
  58184. + hc->xfer_started = 1;
  58185. + return;
  58186. + } else {
  58187. + hctsiz.b.dopng = 1;
  58188. + }
  58189. + }
  58190. +
  58191. + if (hc->do_split) {
  58192. + num_packets = 1;
  58193. +
  58194. + if (hc->complete_split && !hc->ep_is_in) {
  58195. + /* For CSPLIT OUT Transfer, set the size to 0 so the
  58196. + * core doesn't expect any data written to the FIFO */
  58197. + hc->xfer_len = 0;
  58198. + } else if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  58199. + hc->xfer_len = hc->max_packet;
  58200. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  58201. + hc->xfer_len = 188;
  58202. + }
  58203. +
  58204. + hctsiz.b.xfersize = hc->xfer_len;
  58205. + } else {
  58206. + /*
  58207. + * Ensure that the transfer length and packet count will fit
  58208. + * in the widths allocated for them in the HCTSIZn register.
  58209. + */
  58210. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  58211. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  58212. + /*
  58213. + * Make sure the transfer size is no larger than one
  58214. + * (micro)frame's worth of data. (A check was done
  58215. + * when the periodic transfer was accepted to ensure
  58216. + * that a (micro)frame's worth of data can be
  58217. + * programmed into a channel.)
  58218. + */
  58219. + uint32_t max_periodic_len =
  58220. + hc->multi_count * hc->max_packet;
  58221. + if (hc->xfer_len > max_periodic_len) {
  58222. + hc->xfer_len = max_periodic_len;
  58223. + } else {
  58224. + }
  58225. + } else if (hc->xfer_len > max_hc_xfer_size) {
  58226. + /* Make sure that xfer_len is a multiple of max packet size. */
  58227. + hc->xfer_len = max_hc_xfer_size - hc->max_packet + 1;
  58228. + }
  58229. +
  58230. + if (hc->xfer_len > 0) {
  58231. + num_packets =
  58232. + (hc->xfer_len + hc->max_packet -
  58233. + 1) / hc->max_packet;
  58234. + if (num_packets > max_hc_pkt_count) {
  58235. + num_packets = max_hc_pkt_count;
  58236. + hc->xfer_len = num_packets * hc->max_packet;
  58237. + }
  58238. + } else {
  58239. + /* Need 1 packet for transfer length of 0. */
  58240. + num_packets = 1;
  58241. + }
  58242. +
  58243. + if (hc->ep_is_in) {
  58244. + /* Always program an integral # of max packets for IN transfers. */
  58245. + hc->xfer_len = num_packets * hc->max_packet;
  58246. + }
  58247. +
  58248. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  58249. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  58250. + /*
  58251. + * Make sure that the multi_count field matches the
  58252. + * actual transfer length.
  58253. + */
  58254. + hc->multi_count = num_packets;
  58255. + }
  58256. +
  58257. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  58258. + set_pid_isoc(hc);
  58259. +
  58260. + hctsiz.b.xfersize = hc->xfer_len;
  58261. + }
  58262. +
  58263. + hc->start_pkt_count = num_packets;
  58264. + hctsiz.b.pktcnt = num_packets;
  58265. + hctsiz.b.pid = hc->data_pid_start;
  58266. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  58267. +
  58268. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58269. + DWC_DEBUGPL(DBG_HCDV, " Xfer Size: %d\n", hctsiz.b.xfersize);
  58270. + DWC_DEBUGPL(DBG_HCDV, " Num Pkts: %d\n", hctsiz.b.pktcnt);
  58271. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  58272. +
  58273. + if (core_if->dma_enable) {
  58274. + dwc_dma_t dma_addr;
  58275. + if (hc->align_buff) {
  58276. + dma_addr = hc->align_buff;
  58277. + } else {
  58278. + dma_addr = ((unsigned long)hc->xfer_buff & 0xffffffff);
  58279. + }
  58280. + DWC_WRITE_REG32(&hc_regs->hcdma, dma_addr);
  58281. + }
  58282. +
  58283. + /* Start the split */
  58284. + if (hc->do_split) {
  58285. + hcsplt_data_t hcsplt;
  58286. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  58287. + hcsplt.b.spltena = 1;
  58288. + DWC_WRITE_REG32(&hc_regs->hcsplt, hcsplt.d32);
  58289. + }
  58290. +
  58291. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58292. + hcchar.b.multicnt = hc->multi_count;
  58293. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  58294. +#ifdef DEBUG
  58295. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  58296. + if (hcchar.b.chdis) {
  58297. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  58298. + __func__, hc->hc_num, hcchar.d32);
  58299. + }
  58300. +#endif
  58301. +
  58302. + /* Set host channel enable after all other setup is complete. */
  58303. + hcchar.b.chen = 1;
  58304. + hcchar.b.chdis = 0;
  58305. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58306. +
  58307. + hc->xfer_started = 1;
  58308. + hc->requests++;
  58309. +
  58310. + if (!core_if->dma_enable && !hc->ep_is_in && hc->xfer_len > 0) {
  58311. + /* Load OUT packet into the appropriate Tx FIFO. */
  58312. + dwc_otg_hc_write_packet(core_if, hc);
  58313. + }
  58314. +#ifdef DEBUG
  58315. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  58316. + DWC_DEBUGPL(DBG_HCDV, "transfer %d from core_if %p\n",
  58317. + hc->hc_num, core_if);//GRAYG
  58318. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  58319. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  58320. +
  58321. + /* Start a timer for this transfer. */
  58322. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  58323. + }
  58324. +#endif
  58325. +}
  58326. +
  58327. +/**
  58328. + * This function does the setup for a data transfer for a host channel
  58329. + * and starts the transfer in Descriptor DMA mode.
  58330. + *
  58331. + * Initializes HCTSIZ register. For a PING transfer the Do Ping bit is set.
  58332. + * Sets PID and NTD values. For periodic transfers
  58333. + * initializes SCHED_INFO field with micro-frame bitmap.
  58334. + *
  58335. + * Initializes HCDMA register with descriptor list address and CTD value
  58336. + * then starts the transfer via enabling the channel.
  58337. + *
  58338. + * @param core_if Programming view of DWC_otg controller.
  58339. + * @param hc Information needed to initialize the host channel.
  58340. + */
  58341. +void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58342. +{
  58343. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58344. + hcchar_data_t hcchar;
  58345. + hctsiz_data_t hctsiz;
  58346. + hcdma_data_t hcdma;
  58347. +
  58348. + hctsiz.d32 = 0;
  58349. +
  58350. + if (hc->do_ping)
  58351. + hctsiz.b_ddma.dopng = 1;
  58352. +
  58353. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  58354. + set_pid_isoc(hc);
  58355. +
  58356. + /* Packet Count and Xfer Size are not used in Descriptor DMA mode */
  58357. + hctsiz.b_ddma.pid = hc->data_pid_start;
  58358. + hctsiz.b_ddma.ntd = hc->ntd - 1; /* 0 - 1 descriptor, 1 - 2 descriptors, etc. */
  58359. + hctsiz.b_ddma.schinfo = hc->schinfo; /* Non-zero only for high-speed interrupt endpoints */
  58360. +
  58361. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58362. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  58363. + DWC_DEBUGPL(DBG_HCDV, " NTD: %d\n", hctsiz.b_ddma.ntd);
  58364. +
  58365. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  58366. +
  58367. + hcdma.d32 = 0;
  58368. + hcdma.b.dma_addr = ((uint32_t) hc->desc_list_addr) >> 11;
  58369. +
  58370. + /* Always start from first descriptor. */
  58371. + hcdma.b.ctd = 0;
  58372. + DWC_WRITE_REG32(&hc_regs->hcdma, hcdma.d32);
  58373. +
  58374. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58375. + hcchar.b.multicnt = hc->multi_count;
  58376. +
  58377. +#ifdef DEBUG
  58378. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  58379. + if (hcchar.b.chdis) {
  58380. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  58381. + __func__, hc->hc_num, hcchar.d32);
  58382. + }
  58383. +#endif
  58384. +
  58385. + /* Set host channel enable after all other setup is complete. */
  58386. + hcchar.b.chen = 1;
  58387. + hcchar.b.chdis = 0;
  58388. +
  58389. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58390. +
  58391. + hc->xfer_started = 1;
  58392. + hc->requests++;
  58393. +
  58394. +#ifdef DEBUG
  58395. + if ((hc->ep_type != DWC_OTG_EP_TYPE_INTR)
  58396. + && (hc->ep_type != DWC_OTG_EP_TYPE_ISOC)) {
  58397. + DWC_DEBUGPL(DBG_HCDV, "DMA transfer %d from core_if %p\n",
  58398. + hc->hc_num, core_if);//GRAYG
  58399. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  58400. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  58401. + /* Start a timer for this transfer. */
  58402. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  58403. + }
  58404. +#endif
  58405. +
  58406. +}
  58407. +
  58408. +/**
  58409. + * This function continues a data transfer that was started by previous call
  58410. + * to <code>dwc_otg_hc_start_transfer</code>. The caller must ensure there is
  58411. + * sufficient space in the request queue and Tx Data FIFO. This function
  58412. + * should only be called in Slave mode. In DMA mode, the controller acts
  58413. + * autonomously to complete transfers programmed to a host channel.
  58414. + *
  58415. + * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
  58416. + * if there is any data remaining to be queued. For an IN transfer, another
  58417. + * data packet is always requested. For the SETUP phase of a control transfer,
  58418. + * this function does nothing.
  58419. + *
  58420. + * @return 1 if a new request is queued, 0 if no more requests are required
  58421. + * for this transfer.
  58422. + */
  58423. +int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58424. +{
  58425. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58426. +
  58427. + if (hc->do_split) {
  58428. + /* SPLITs always queue just once per channel */
  58429. + return 0;
  58430. + } else if (hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  58431. + /* SETUPs are queued only once since they can't be NAKed. */
  58432. + return 0;
  58433. + } else if (hc->ep_is_in) {
  58434. + /*
  58435. + * Always queue another request for other IN transfers. If
  58436. + * back-to-back INs are issued and NAKs are received for both,
  58437. + * the driver may still be processing the first NAK when the
  58438. + * second NAK is received. When the interrupt handler clears
  58439. + * the NAK interrupt for the first NAK, the second NAK will
  58440. + * not be seen. So we can't depend on the NAK interrupt
  58441. + * handler to requeue a NAKed request. Instead, IN requests
  58442. + * are issued each time this function is called. When the
  58443. + * transfer completes, the extra requests for the channel will
  58444. + * be flushed.
  58445. + */
  58446. + hcchar_data_t hcchar;
  58447. + dwc_otg_hc_regs_t *hc_regs =
  58448. + core_if->host_if->hc_regs[hc->hc_num];
  58449. +
  58450. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58451. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  58452. + hcchar.b.chen = 1;
  58453. + hcchar.b.chdis = 0;
  58454. + DWC_DEBUGPL(DBG_HCDV, " IN xfer: hcchar = 0x%08x\n",
  58455. + hcchar.d32);
  58456. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58457. + hc->requests++;
  58458. + return 1;
  58459. + } else {
  58460. + /* OUT transfers. */
  58461. + if (hc->xfer_count < hc->xfer_len) {
  58462. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  58463. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  58464. + hcchar_data_t hcchar;
  58465. + dwc_otg_hc_regs_t *hc_regs;
  58466. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58467. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58468. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  58469. + }
  58470. +
  58471. + /* Load OUT packet into the appropriate Tx FIFO. */
  58472. + dwc_otg_hc_write_packet(core_if, hc);
  58473. + hc->requests++;
  58474. + return 1;
  58475. + } else {
  58476. + return 0;
  58477. + }
  58478. + }
  58479. +}
  58480. +
  58481. +/**
  58482. + * Starts a PING transfer. This function should only be called in Slave mode.
  58483. + * The Do Ping bit is set in the HCTSIZ register, then the channel is enabled.
  58484. + */
  58485. +void dwc_otg_hc_do_ping(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58486. +{
  58487. + hcchar_data_t hcchar;
  58488. + hctsiz_data_t hctsiz;
  58489. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58490. +
  58491. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58492. +
  58493. + hctsiz.d32 = 0;
  58494. + hctsiz.b.dopng = 1;
  58495. + hctsiz.b.pktcnt = 1;
  58496. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  58497. +
  58498. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58499. + hcchar.b.chen = 1;
  58500. + hcchar.b.chdis = 0;
  58501. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58502. +}
  58503. +
  58504. +/*
  58505. + * This function writes a packet into the Tx FIFO associated with the Host
  58506. + * Channel. For a channel associated with a non-periodic EP, the non-periodic
  58507. + * Tx FIFO is written. For a channel associated with a periodic EP, the
  58508. + * periodic Tx FIFO is written. This function should only be called in Slave
  58509. + * mode.
  58510. + *
  58511. + * Upon return the xfer_buff and xfer_count fields in _hc are incremented by
  58512. + * then number of bytes written to the Tx FIFO.
  58513. + */
  58514. +void dwc_otg_hc_write_packet(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58515. +{
  58516. + uint32_t i;
  58517. + uint32_t remaining_count;
  58518. + uint32_t byte_count;
  58519. + uint32_t dword_count;
  58520. +
  58521. + uint32_t *data_buff = (uint32_t *) (hc->xfer_buff);
  58522. + uint32_t *data_fifo = core_if->data_fifo[hc->hc_num];
  58523. +
  58524. + remaining_count = hc->xfer_len - hc->xfer_count;
  58525. + if (remaining_count > hc->max_packet) {
  58526. + byte_count = hc->max_packet;
  58527. + } else {
  58528. + byte_count = remaining_count;
  58529. + }
  58530. +
  58531. + dword_count = (byte_count + 3) / 4;
  58532. +
  58533. + if ((((unsigned long)data_buff) & 0x3) == 0) {
  58534. + /* xfer_buff is DWORD aligned. */
  58535. + for (i = 0; i < dword_count; i++, data_buff++) {
  58536. + DWC_WRITE_REG32(data_fifo, *data_buff);
  58537. + }
  58538. + } else {
  58539. + /* xfer_buff is not DWORD aligned. */
  58540. + for (i = 0; i < dword_count; i++, data_buff++) {
  58541. + uint32_t data;
  58542. + data =
  58543. + (data_buff[0] | data_buff[1] << 8 | data_buff[2] <<
  58544. + 16 | data_buff[3] << 24);
  58545. + DWC_WRITE_REG32(data_fifo, data);
  58546. + }
  58547. + }
  58548. +
  58549. + hc->xfer_count += byte_count;
  58550. + hc->xfer_buff += byte_count;
  58551. +}
  58552. +
  58553. +/**
  58554. + * Gets the current USB frame number. This is the frame number from the last
  58555. + * SOF packet.
  58556. + */
  58557. +uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * core_if)
  58558. +{
  58559. + dsts_data_t dsts;
  58560. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  58561. +
  58562. + /* read current frame/microframe number from DSTS register */
  58563. + return dsts.b.soffn;
  58564. +}
  58565. +
  58566. +/**
  58567. + * Calculates and gets the frame Interval value of HFIR register according PHY
  58568. + * type and speed.The application can modify a value of HFIR register only after
  58569. + * the Port Enable bit of the Host Port Control and Status register
  58570. + * (HPRT.PrtEnaPort) has been set.
  58571. +*/
  58572. +
  58573. +uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if)
  58574. +{
  58575. + gusbcfg_data_t usbcfg;
  58576. + hwcfg2_data_t hwcfg2;
  58577. + hprt0_data_t hprt0;
  58578. + int clock = 60; // default value
  58579. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  58580. + hwcfg2.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  58581. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  58582. + if (!usbcfg.b.physel && usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  58583. + clock = 60;
  58584. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 3)
  58585. + clock = 48;
  58586. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  58587. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  58588. + clock = 30;
  58589. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  58590. + !usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  58591. + clock = 60;
  58592. + if (usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  58593. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  58594. + clock = 48;
  58595. + if (usbcfg.b.physel && !usbcfg.b.phyif && hwcfg2.b.fs_phy_type == 2)
  58596. + clock = 48;
  58597. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 1)
  58598. + clock = 48;
  58599. + if (hprt0.b.prtspd == 0)
  58600. + /* High speed case */
  58601. + return 125 * clock;
  58602. + else
  58603. + /* FS/LS case */
  58604. + return 1000 * clock;
  58605. +}
  58606. +
  58607. +/**
  58608. + * This function reads a setup packet from the Rx FIFO into the destination
  58609. + * buffer. This function is called from the Rx Status Queue Level (RxStsQLvl)
  58610. + * Interrupt routine when a SETUP packet has been received in Slave mode.
  58611. + *
  58612. + * @param core_if Programming view of DWC_otg controller.
  58613. + * @param dest Destination buffer for packet data.
  58614. + */
  58615. +void dwc_otg_read_setup_packet(dwc_otg_core_if_t * core_if, uint32_t * dest)
  58616. +{
  58617. + device_grxsts_data_t status;
  58618. + /* Get the 8 bytes of a setup transaction data */
  58619. +
  58620. + /* Pop 2 DWORDS off the receive data FIFO into memory */
  58621. + dest[0] = DWC_READ_REG32(core_if->data_fifo[0]);
  58622. + dest[1] = DWC_READ_REG32(core_if->data_fifo[0]);
  58623. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  58624. + status.d32 =
  58625. + DWC_READ_REG32(&core_if->core_global_regs->grxstsp);
  58626. + DWC_DEBUGPL(DBG_ANY,
  58627. + "EP:%d BCnt:%d " "pktsts:%x Frame:%d(0x%0x)\n",
  58628. + status.b.epnum, status.b.bcnt, status.b.pktsts,
  58629. + status.b.fn, status.b.fn);
  58630. + }
  58631. +}
  58632. +
  58633. +/**
  58634. + * This function enables EP0 OUT to receive SETUP packets and configures EP0
  58635. + * IN for transmitting packets. It is normally called when the
  58636. + * "Enumeration Done" interrupt occurs.
  58637. + *
  58638. + * @param core_if Programming view of DWC_otg controller.
  58639. + * @param ep The EP0 data.
  58640. + */
  58641. +void dwc_otg_ep0_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58642. +{
  58643. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  58644. + dsts_data_t dsts;
  58645. + depctl_data_t diepctl;
  58646. + depctl_data_t doepctl;
  58647. + dctl_data_t dctl = {.d32 = 0 };
  58648. +
  58649. + ep->stp_rollover = 0;
  58650. + /* Read the Device Status and Endpoint 0 Control registers */
  58651. + dsts.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dsts);
  58652. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  58653. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  58654. +
  58655. + /* Set the MPS of the IN EP based on the enumeration speed */
  58656. + switch (dsts.b.enumspd) {
  58657. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  58658. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  58659. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  58660. + diepctl.b.mps = DWC_DEP0CTL_MPS_64;
  58661. + break;
  58662. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  58663. + diepctl.b.mps = DWC_DEP0CTL_MPS_8;
  58664. + break;
  58665. + }
  58666. +
  58667. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  58668. +
  58669. + /* Enable OUT EP for receive */
  58670. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  58671. + doepctl.b.epena = 1;
  58672. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  58673. + }
  58674. +#ifdef VERBOSE
  58675. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  58676. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  58677. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  58678. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  58679. +#endif
  58680. + dctl.b.cgnpinnak = 1;
  58681. +
  58682. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  58683. + DWC_DEBUGPL(DBG_PCDV, "dctl=%0x\n",
  58684. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl));
  58685. +
  58686. +}
  58687. +
  58688. +/**
  58689. + * This function activates an EP. The Device EP control register for
  58690. + * the EP is configured as defined in the ep structure. Note: This
  58691. + * function is not used for EP0.
  58692. + *
  58693. + * @param core_if Programming view of DWC_otg controller.
  58694. + * @param ep The EP to activate.
  58695. + */
  58696. +void dwc_otg_ep_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58697. +{
  58698. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  58699. + depctl_data_t depctl;
  58700. + volatile uint32_t *addr;
  58701. + daint_data_t daintmsk = {.d32 = 0 };
  58702. + dcfg_data_t dcfg;
  58703. + uint8_t i;
  58704. +
  58705. + DWC_DEBUGPL(DBG_PCDV, "%s() EP%d-%s\n", __func__, ep->num,
  58706. + (ep->is_in ? "IN" : "OUT"));
  58707. +
  58708. +#ifdef DWC_UTE_PER_IO
  58709. + ep->xiso_frame_num = 0xFFFFFFFF;
  58710. + ep->xiso_active_xfers = 0;
  58711. + ep->xiso_queued_xfers = 0;
  58712. +#endif
  58713. + /* Read DEPCTLn register */
  58714. + if (ep->is_in == 1) {
  58715. + addr = &dev_if->in_ep_regs[ep->num]->diepctl;
  58716. + daintmsk.ep.in = 1 << ep->num;
  58717. + } else {
  58718. + addr = &dev_if->out_ep_regs[ep->num]->doepctl;
  58719. + daintmsk.ep.out = 1 << ep->num;
  58720. + }
  58721. +
  58722. + /* If the EP is already active don't change the EP Control
  58723. + * register. */
  58724. + depctl.d32 = DWC_READ_REG32(addr);
  58725. + if (!depctl.b.usbactep) {
  58726. + depctl.b.mps = ep->maxpacket;
  58727. + depctl.b.eptype = ep->type;
  58728. + depctl.b.txfnum = ep->tx_fifo_num;
  58729. +
  58730. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  58731. + depctl.b.setd0pid = 1; // ???
  58732. + } else {
  58733. + depctl.b.setd0pid = 1;
  58734. + }
  58735. + depctl.b.usbactep = 1;
  58736. +
  58737. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  58738. + if (!(depctl.b.eptype & 1) && (ep->is_in == 1)) { // NP IN EP
  58739. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  58740. + if (core_if->nextep_seq[i] == core_if->first_in_nextep_seq)
  58741. + break;
  58742. + }
  58743. + core_if->nextep_seq[i] = ep->num;
  58744. + core_if->nextep_seq[ep->num] = core_if->first_in_nextep_seq;
  58745. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  58746. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  58747. + dcfg.b.epmscnt++;
  58748. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  58749. +
  58750. + DWC_DEBUGPL(DBG_PCDV,
  58751. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  58752. + __func__, core_if->first_in_nextep_seq);
  58753. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  58754. + DWC_DEBUGPL(DBG_PCDV, "%2d\n",
  58755. + core_if->nextep_seq[i]);
  58756. + }
  58757. +
  58758. + }
  58759. +
  58760. +
  58761. + DWC_WRITE_REG32(addr, depctl.d32);
  58762. + DWC_DEBUGPL(DBG_PCDV, "DEPCTL=%08x\n", DWC_READ_REG32(addr));
  58763. + }
  58764. +
  58765. + /* Enable the Interrupt for this EP */
  58766. + if (core_if->multiproc_int_enable) {
  58767. + if (ep->is_in == 1) {
  58768. + diepmsk_data_t diepmsk = {.d32 = 0 };
  58769. + diepmsk.b.xfercompl = 1;
  58770. + diepmsk.b.timeout = 1;
  58771. + diepmsk.b.epdisabled = 1;
  58772. + diepmsk.b.ahberr = 1;
  58773. + diepmsk.b.intknepmis = 1;
  58774. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  58775. + diepmsk.b.intknepmis = 0;
  58776. + diepmsk.b.txfifoundrn = 1; //?????
  58777. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  58778. + diepmsk.b.nak = 1;
  58779. + }
  58780. +
  58781. +
  58782. +
  58783. +/*
  58784. + if (core_if->dma_desc_enable) {
  58785. + diepmsk.b.bna = 1;
  58786. + }
  58787. +*/
  58788. +/*
  58789. + if (core_if->dma_enable) {
  58790. + doepmsk.b.nak = 1;
  58791. + }
  58792. +*/
  58793. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  58794. + diepeachintmsk[ep->num], diepmsk.d32);
  58795. +
  58796. + } else {
  58797. + doepmsk_data_t doepmsk = {.d32 = 0 };
  58798. + doepmsk.b.xfercompl = 1;
  58799. + doepmsk.b.ahberr = 1;
  58800. + doepmsk.b.epdisabled = 1;
  58801. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  58802. + doepmsk.b.outtknepdis = 1;
  58803. +
  58804. +/*
  58805. +
  58806. + if (core_if->dma_desc_enable) {
  58807. + doepmsk.b.bna = 1;
  58808. + }
  58809. +*/
  58810. +/*
  58811. + doepmsk.b.babble = 1;
  58812. + doepmsk.b.nyet = 1;
  58813. + doepmsk.b.nak = 1;
  58814. +*/
  58815. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  58816. + doepeachintmsk[ep->num], doepmsk.d32);
  58817. + }
  58818. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->deachintmsk,
  58819. + 0, daintmsk.d32);
  58820. + } else {
  58821. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  58822. + if (ep->is_in) {
  58823. + diepmsk_data_t diepmsk = {.d32 = 0 };
  58824. + diepmsk.b.nak = 1;
  58825. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk, 0, diepmsk.d32);
  58826. + } else {
  58827. + doepmsk_data_t doepmsk = {.d32 = 0 };
  58828. + doepmsk.b.outtknepdis = 1;
  58829. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->doepmsk, 0, doepmsk.d32);
  58830. + }
  58831. + }
  58832. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->daintmsk,
  58833. + 0, daintmsk.d32);
  58834. + }
  58835. +
  58836. + DWC_DEBUGPL(DBG_PCDV, "DAINTMSK=%0x\n",
  58837. + DWC_READ_REG32(&dev_if->dev_global_regs->daintmsk));
  58838. +
  58839. + ep->stall_clear_flag = 0;
  58840. +
  58841. + return;
  58842. +}
  58843. +
  58844. +/**
  58845. + * This function deactivates an EP. This is done by clearing the USB Active
  58846. + * EP bit in the Device EP control register. Note: This function is not used
  58847. + * for EP0. EP0 cannot be deactivated.
  58848. + *
  58849. + * @param core_if Programming view of DWC_otg controller.
  58850. + * @param ep The EP to deactivate.
  58851. + */
  58852. +void dwc_otg_ep_deactivate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58853. +{
  58854. + depctl_data_t depctl = {.d32 = 0 };
  58855. + volatile uint32_t *addr;
  58856. + daint_data_t daintmsk = {.d32 = 0 };
  58857. + dcfg_data_t dcfg;
  58858. + uint8_t i = 0;
  58859. +
  58860. +#ifdef DWC_UTE_PER_IO
  58861. + ep->xiso_frame_num = 0xFFFFFFFF;
  58862. + ep->xiso_active_xfers = 0;
  58863. + ep->xiso_queued_xfers = 0;
  58864. +#endif
  58865. +
  58866. + /* Read DEPCTLn register */
  58867. + if (ep->is_in == 1) {
  58868. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  58869. + daintmsk.ep.in = 1 << ep->num;
  58870. + } else {
  58871. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  58872. + daintmsk.ep.out = 1 << ep->num;
  58873. + }
  58874. +
  58875. + depctl.d32 = DWC_READ_REG32(addr);
  58876. +
  58877. + depctl.b.usbactep = 0;
  58878. +
  58879. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  58880. + if (!(depctl.b.eptype & 1) && ep->is_in == 1) { // NP EP IN
  58881. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  58882. + if (core_if->nextep_seq[i] == ep->num)
  58883. + break;
  58884. + }
  58885. + core_if->nextep_seq[i] = core_if->nextep_seq[ep->num];
  58886. + if (core_if->first_in_nextep_seq == ep->num)
  58887. + core_if->first_in_nextep_seq = i;
  58888. + core_if->nextep_seq[ep->num] = 0xff;
  58889. + depctl.b.nextep = 0;
  58890. + dcfg.d32 =
  58891. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  58892. + dcfg.b.epmscnt--;
  58893. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  58894. + dcfg.d32);
  58895. +
  58896. + DWC_DEBUGPL(DBG_PCDV,
  58897. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  58898. + __func__, core_if->first_in_nextep_seq);
  58899. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  58900. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  58901. + }
  58902. + }
  58903. +
  58904. + if (ep->is_in == 1)
  58905. + depctl.b.txfnum = 0;
  58906. +
  58907. + if (core_if->dma_desc_enable)
  58908. + depctl.b.epdis = 1;
  58909. +
  58910. + DWC_WRITE_REG32(addr, depctl.d32);
  58911. + depctl.d32 = DWC_READ_REG32(addr);
  58912. + if (core_if->dma_enable && ep->type == DWC_OTG_EP_TYPE_ISOC
  58913. + && depctl.b.epena) {
  58914. + depctl_data_t depctl = {.d32 = 0};
  58915. + if (ep->is_in) {
  58916. + diepint_data_t diepint = {.d32 = 0};
  58917. +
  58918. + depctl.b.snak = 1;
  58919. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  58920. + diepctl, depctl.d32);
  58921. + do {
  58922. + dwc_udelay(10);
  58923. + diepint.d32 =
  58924. + DWC_READ_REG32(&core_if->
  58925. + dev_if->in_ep_regs[ep->num]->
  58926. + diepint);
  58927. + } while (!diepint.b.inepnakeff);
  58928. + diepint.b.inepnakeff = 1;
  58929. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  58930. + diepint, diepint.d32);
  58931. + depctl.d32 = 0;
  58932. + depctl.b.epdis = 1;
  58933. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  58934. + diepctl, depctl.d32);
  58935. + do {
  58936. + dwc_udelay(10);
  58937. + diepint.d32 =
  58938. + DWC_READ_REG32(&core_if->
  58939. + dev_if->in_ep_regs[ep->num]->
  58940. + diepint);
  58941. + } while (!diepint.b.epdisabled);
  58942. + diepint.b.epdisabled = 1;
  58943. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  58944. + diepint, diepint.d32);
  58945. + } else {
  58946. + dctl_data_t dctl = {.d32 = 0};
  58947. + gintmsk_data_t gintsts = {.d32 = 0};
  58948. + doepint_data_t doepint = {.d32 = 0};
  58949. + dctl.b.sgoutnak = 1;
  58950. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  58951. + dctl, 0, dctl.d32);
  58952. + do {
  58953. + dwc_udelay(10);
  58954. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  58955. + } while (!gintsts.b.goutnakeff);
  58956. + gintsts.d32 = 0;
  58957. + gintsts.b.goutnakeff = 1;
  58958. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  58959. +
  58960. + depctl.d32 = 0;
  58961. + depctl.b.epdis = 1;
  58962. + depctl.b.snak = 1;
  58963. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepctl, depctl.d32);
  58964. + do
  58965. + {
  58966. + dwc_udelay(10);
  58967. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  58968. + out_ep_regs[ep->num]->doepint);
  58969. + } while (!doepint.b.epdisabled);
  58970. +
  58971. + doepint.b.epdisabled = 1;
  58972. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepint, doepint.d32);
  58973. +
  58974. + dctl.d32 = 0;
  58975. + dctl.b.cgoutnak = 1;
  58976. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  58977. + }
  58978. + }
  58979. +
  58980. + /* Disable the Interrupt for this EP */
  58981. + if (core_if->multiproc_int_enable) {
  58982. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  58983. + daintmsk.d32, 0);
  58984. +
  58985. + if (ep->is_in == 1) {
  58986. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  58987. + diepeachintmsk[ep->num], 0);
  58988. + } else {
  58989. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  58990. + doepeachintmsk[ep->num], 0);
  58991. + }
  58992. + } else {
  58993. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->daintmsk,
  58994. + daintmsk.d32, 0);
  58995. + }
  58996. +
  58997. +}
  58998. +
  58999. +/**
  59000. + * This function initializes dma descriptor chain.
  59001. + *
  59002. + * @param core_if Programming view of DWC_otg controller.
  59003. + * @param ep The EP to start the transfer on.
  59004. + */
  59005. +static void init_dma_desc_chain(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59006. +{
  59007. + dwc_otg_dev_dma_desc_t *dma_desc;
  59008. + uint32_t offset;
  59009. + uint32_t xfer_est;
  59010. + int i;
  59011. + unsigned maxxfer_local, total_len;
  59012. +
  59013. + if (!ep->is_in && ep->type == DWC_OTG_EP_TYPE_INTR &&
  59014. + (ep->maxpacket%4)) {
  59015. + maxxfer_local = ep->maxpacket;
  59016. + total_len = ep->xfer_len;
  59017. + } else {
  59018. + maxxfer_local = ep->maxxfer;
  59019. + total_len = ep->total_len;
  59020. + }
  59021. +
  59022. + ep->desc_cnt = (total_len / maxxfer_local) +
  59023. + ((total_len % maxxfer_local) ? 1 : 0);
  59024. +
  59025. + if (!ep->desc_cnt)
  59026. + ep->desc_cnt = 1;
  59027. +
  59028. + if (ep->desc_cnt > MAX_DMA_DESC_CNT)
  59029. + ep->desc_cnt = MAX_DMA_DESC_CNT;
  59030. +
  59031. + dma_desc = ep->desc_addr;
  59032. + if (maxxfer_local == ep->maxpacket) {
  59033. + if ((total_len % maxxfer_local) &&
  59034. + (total_len/maxxfer_local < MAX_DMA_DESC_CNT)) {
  59035. + xfer_est = (ep->desc_cnt - 1) * maxxfer_local +
  59036. + (total_len % maxxfer_local);
  59037. + } else
  59038. + xfer_est = ep->desc_cnt * maxxfer_local;
  59039. + } else
  59040. + xfer_est = total_len;
  59041. + offset = 0;
  59042. + for (i = 0; i < ep->desc_cnt; ++i) {
  59043. + /** DMA Descriptor Setup */
  59044. + if (xfer_est > maxxfer_local) {
  59045. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59046. + dma_desc->status.b.l = 0;
  59047. + dma_desc->status.b.ioc = 0;
  59048. + dma_desc->status.b.sp = 0;
  59049. + dma_desc->status.b.bytes = maxxfer_local;
  59050. + dma_desc->buf = ep->dma_addr + offset;
  59051. + dma_desc->status.b.sts = 0;
  59052. + dma_desc->status.b.bs = BS_HOST_READY;
  59053. +
  59054. + xfer_est -= maxxfer_local;
  59055. + offset += maxxfer_local;
  59056. + } else {
  59057. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59058. + dma_desc->status.b.l = 1;
  59059. + dma_desc->status.b.ioc = 1;
  59060. + if (ep->is_in) {
  59061. + dma_desc->status.b.sp =
  59062. + (xfer_est %
  59063. + ep->maxpacket) ? 1 : ((ep->
  59064. + sent_zlp) ? 1 : 0);
  59065. + dma_desc->status.b.bytes = xfer_est;
  59066. + } else {
  59067. + if (maxxfer_local == ep->maxpacket)
  59068. + dma_desc->status.b.bytes = xfer_est;
  59069. + else
  59070. + dma_desc->status.b.bytes =
  59071. + xfer_est + ((4 - (xfer_est & 0x3)) & 0x3);
  59072. + }
  59073. +
  59074. + dma_desc->buf = ep->dma_addr + offset;
  59075. + dma_desc->status.b.sts = 0;
  59076. + dma_desc->status.b.bs = BS_HOST_READY;
  59077. + }
  59078. + dma_desc++;
  59079. + }
  59080. +}
  59081. +/**
  59082. + * This function is called when to write ISOC data into appropriate dedicated
  59083. + * periodic FIFO.
  59084. + */
  59085. +static int32_t write_isoc_tx_fifo(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  59086. +{
  59087. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  59088. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  59089. + dtxfsts_data_t txstatus = {.d32 = 0 };
  59090. + uint32_t len = 0;
  59091. + int epnum = dwc_ep->num;
  59092. + int dwords;
  59093. +
  59094. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  59095. +
  59096. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  59097. +
  59098. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  59099. +
  59100. + if (len > dwc_ep->maxpacket) {
  59101. + len = dwc_ep->maxpacket;
  59102. + }
  59103. +
  59104. + dwords = (len + 3) / 4;
  59105. +
  59106. + /* While there is space in the queue and space in the FIFO and
  59107. + * More data to tranfer, Write packets to the Tx FIFO */
  59108. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  59109. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  59110. +
  59111. + while (txstatus.b.txfspcavail > dwords &&
  59112. + dwc_ep->xfer_count < dwc_ep->xfer_len && dwc_ep->xfer_len != 0) {
  59113. + /* Write the FIFO */
  59114. + dwc_otg_ep_write_packet(core_if, dwc_ep, 0);
  59115. +
  59116. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  59117. + if (len > dwc_ep->maxpacket) {
  59118. + len = dwc_ep->maxpacket;
  59119. + }
  59120. +
  59121. + dwords = (len + 3) / 4;
  59122. + txstatus.d32 =
  59123. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  59124. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  59125. + txstatus.d32);
  59126. + }
  59127. +
  59128. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  59129. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  59130. +
  59131. + return 1;
  59132. +}
  59133. +/**
  59134. + * This function does the setup for a data transfer for an EP and
  59135. + * starts the transfer. For an IN transfer, the packets will be
  59136. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  59137. + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
  59138. + *
  59139. + * @param core_if Programming view of DWC_otg controller.
  59140. + * @param ep The EP to start the transfer on.
  59141. + */
  59142. +
  59143. +void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59144. +{
  59145. + depctl_data_t depctl;
  59146. + deptsiz_data_t deptsiz;
  59147. + gintmsk_data_t intr_mask = {.d32 = 0 };
  59148. +
  59149. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  59150. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  59151. + "xfer_buff=%p start_xfer_buff=%p, total_len = %d\n",
  59152. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  59153. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff,
  59154. + ep->total_len);
  59155. + /* IN endpoint */
  59156. + if (ep->is_in == 1) {
  59157. + dwc_otg_dev_in_ep_regs_t *in_regs =
  59158. + core_if->dev_if->in_ep_regs[ep->num];
  59159. +
  59160. + gnptxsts_data_t gtxstatus;
  59161. +
  59162. + gtxstatus.d32 =
  59163. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  59164. +
  59165. + if (core_if->en_multiple_tx_fifo == 0
  59166. + && gtxstatus.b.nptxqspcavail == 0 && !core_if->dma_enable) {
  59167. +#ifdef DEBUG
  59168. + DWC_PRINTF("TX Queue Full (0x%0x)\n", gtxstatus.d32);
  59169. +#endif
  59170. + return;
  59171. + }
  59172. +
  59173. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  59174. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  59175. +
  59176. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  59177. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  59178. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  59179. + else
  59180. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len - ep->xfer_len)) ?
  59181. + MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  59182. +
  59183. +
  59184. + /* Zero Length Packet? */
  59185. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  59186. + deptsiz.b.xfersize = 0;
  59187. + deptsiz.b.pktcnt = 1;
  59188. + } else {
  59189. + /* Program the transfer size and packet count
  59190. + * as follows: xfersize = N * maxpacket +
  59191. + * short_packet pktcnt = N + (short_packet
  59192. + * exist ? 1 : 0)
  59193. + */
  59194. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  59195. + deptsiz.b.pktcnt =
  59196. + (ep->xfer_len - ep->xfer_count - 1 +
  59197. + ep->maxpacket) / ep->maxpacket;
  59198. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  59199. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  59200. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  59201. + }
  59202. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  59203. + deptsiz.b.mc = deptsiz.b.pktcnt;
  59204. + }
  59205. +
  59206. + /* Write the DMA register */
  59207. + if (core_if->dma_enable) {
  59208. + if (core_if->dma_desc_enable == 0) {
  59209. + if (ep->type != DWC_OTG_EP_TYPE_ISOC)
  59210. + deptsiz.b.mc = 1;
  59211. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  59212. + deptsiz.d32);
  59213. + DWC_WRITE_REG32(&(in_regs->diepdma),
  59214. + (uint32_t) ep->dma_addr);
  59215. + } else {
  59216. +#ifdef DWC_UTE_CFI
  59217. + /* The descriptor chain should be already initialized by now */
  59218. + if (ep->buff_mode != BM_STANDARD) {
  59219. + DWC_WRITE_REG32(&in_regs->diepdma,
  59220. + ep->descs_dma_addr);
  59221. + } else {
  59222. +#endif
  59223. + init_dma_desc_chain(core_if, ep);
  59224. + /** DIEPDMAn Register write */
  59225. + DWC_WRITE_REG32(&in_regs->diepdma,
  59226. + ep->dma_desc_addr);
  59227. +#ifdef DWC_UTE_CFI
  59228. + }
  59229. +#endif
  59230. + }
  59231. + } else {
  59232. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  59233. + if (ep->type != DWC_OTG_EP_TYPE_ISOC) {
  59234. + /**
  59235. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  59236. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  59237. + * the data will be written into the fifo by the ISR.
  59238. + */
  59239. + if (core_if->en_multiple_tx_fifo == 0) {
  59240. + intr_mask.b.nptxfempty = 1;
  59241. + DWC_MODIFY_REG32
  59242. + (&core_if->core_global_regs->gintmsk,
  59243. + intr_mask.d32, intr_mask.d32);
  59244. + } else {
  59245. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  59246. + if (ep->xfer_len > 0) {
  59247. + uint32_t fifoemptymsk = 0;
  59248. + fifoemptymsk = 1 << ep->num;
  59249. + DWC_MODIFY_REG32
  59250. + (&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  59251. + 0, fifoemptymsk);
  59252. +
  59253. + }
  59254. + }
  59255. + } else {
  59256. + write_isoc_tx_fifo(core_if, ep);
  59257. + }
  59258. + }
  59259. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  59260. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59261. +
  59262. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  59263. + dsts_data_t dsts = {.d32 = 0};
  59264. + if (ep->bInterval == 1) {
  59265. + dsts.d32 =
  59266. + DWC_READ_REG32(&core_if->dev_if->
  59267. + dev_global_regs->dsts);
  59268. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  59269. + if (ep->frame_num > 0x3FFF) {
  59270. + ep->frm_overrun = 1;
  59271. + ep->frame_num &= 0x3FFF;
  59272. + } else
  59273. + ep->frm_overrun = 0;
  59274. + if (ep->frame_num & 0x1) {
  59275. + depctl.b.setd1pid = 1;
  59276. + } else {
  59277. + depctl.b.setd0pid = 1;
  59278. + }
  59279. + }
  59280. + }
  59281. + /* EP enable, IN data in FIFO */
  59282. + depctl.b.cnak = 1;
  59283. + depctl.b.epena = 1;
  59284. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  59285. +
  59286. + } else {
  59287. + /* OUT endpoint */
  59288. + dwc_otg_dev_out_ep_regs_t *out_regs =
  59289. + core_if->dev_if->out_ep_regs[ep->num];
  59290. +
  59291. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  59292. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  59293. +
  59294. + if (!core_if->dma_desc_enable) {
  59295. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  59296. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  59297. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  59298. + else
  59299. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len
  59300. + - ep->xfer_len)) ? MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  59301. + }
  59302. +
  59303. + /* Program the transfer size and packet count as follows:
  59304. + *
  59305. + * pktcnt = N
  59306. + * xfersize = N * maxpacket
  59307. + */
  59308. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  59309. + /* Zero Length Packet */
  59310. + deptsiz.b.xfersize = ep->maxpacket;
  59311. + deptsiz.b.pktcnt = 1;
  59312. + } else {
  59313. + deptsiz.b.pktcnt =
  59314. + (ep->xfer_len - ep->xfer_count +
  59315. + (ep->maxpacket - 1)) / ep->maxpacket;
  59316. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  59317. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  59318. + }
  59319. + if (!core_if->dma_desc_enable) {
  59320. + ep->xfer_len =
  59321. + deptsiz.b.pktcnt * ep->maxpacket + ep->xfer_count;
  59322. + }
  59323. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  59324. + }
  59325. +
  59326. + DWC_DEBUGPL(DBG_PCDV, "ep%d xfersize=%d pktcnt=%d\n",
  59327. + ep->num, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  59328. +
  59329. + if (core_if->dma_enable) {
  59330. + if (!core_if->dma_desc_enable) {
  59331. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  59332. + deptsiz.d32);
  59333. +
  59334. + DWC_WRITE_REG32(&(out_regs->doepdma),
  59335. + (uint32_t) ep->dma_addr);
  59336. + } else {
  59337. +#ifdef DWC_UTE_CFI
  59338. + /* The descriptor chain should be already initialized by now */
  59339. + if (ep->buff_mode != BM_STANDARD) {
  59340. + DWC_WRITE_REG32(&out_regs->doepdma,
  59341. + ep->descs_dma_addr);
  59342. + } else {
  59343. +#endif
  59344. + /** This is used for interrupt out transfers*/
  59345. + if (!ep->xfer_len)
  59346. + ep->xfer_len = ep->total_len;
  59347. + init_dma_desc_chain(core_if, ep);
  59348. +
  59349. + if (core_if->core_params->dev_out_nak) {
  59350. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  59351. + deptsiz.b.pktcnt = (ep->total_len +
  59352. + (ep->maxpacket - 1)) / ep->maxpacket;
  59353. + deptsiz.b.xfersize = ep->total_len;
  59354. + /* Remember initial value of doeptsiz */
  59355. + core_if->start_doeptsiz_val[ep->num] = deptsiz.d32;
  59356. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  59357. + deptsiz.d32);
  59358. + }
  59359. + }
  59360. + /** DOEPDMAn Register write */
  59361. + DWC_WRITE_REG32(&out_regs->doepdma,
  59362. + ep->dma_desc_addr);
  59363. +#ifdef DWC_UTE_CFI
  59364. + }
  59365. +#endif
  59366. + }
  59367. + } else {
  59368. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  59369. + }
  59370. +
  59371. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  59372. + dsts_data_t dsts = {.d32 = 0};
  59373. + if (ep->bInterval == 1) {
  59374. + dsts.d32 =
  59375. + DWC_READ_REG32(&core_if->dev_if->
  59376. + dev_global_regs->dsts);
  59377. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  59378. + if (ep->frame_num > 0x3FFF) {
  59379. + ep->frm_overrun = 1;
  59380. + ep->frame_num &= 0x3FFF;
  59381. + } else
  59382. + ep->frm_overrun = 0;
  59383. +
  59384. + if (ep->frame_num & 0x1) {
  59385. + depctl.b.setd1pid = 1;
  59386. + } else {
  59387. + depctl.b.setd0pid = 1;
  59388. + }
  59389. + }
  59390. + }
  59391. +
  59392. + /* EP enable */
  59393. + depctl.b.cnak = 1;
  59394. + depctl.b.epena = 1;
  59395. +
  59396. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  59397. +
  59398. + DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
  59399. + DWC_READ_REG32(&out_regs->doepctl),
  59400. + DWC_READ_REG32(&out_regs->doeptsiz));
  59401. + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
  59402. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  59403. + daintmsk),
  59404. + DWC_READ_REG32(&core_if->core_global_regs->
  59405. + gintmsk));
  59406. +
  59407. + /* Timer is scheduling only for out bulk transfers for
  59408. + * "Device DDMA OUT NAK Enhancement" feature to inform user
  59409. + * about received data payload in case of timeout
  59410. + */
  59411. + if (core_if->core_params->dev_out_nak) {
  59412. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  59413. + core_if->ep_xfer_info[ep->num].core_if = core_if;
  59414. + core_if->ep_xfer_info[ep->num].ep = ep;
  59415. + core_if->ep_xfer_info[ep->num].state = 1;
  59416. +
  59417. + /* Start a timer for this transfer. */
  59418. + DWC_TIMER_SCHEDULE(core_if->ep_xfer_timer[ep->num], 10000);
  59419. + }
  59420. + }
  59421. + }
  59422. +}
  59423. +
  59424. +/**
  59425. + * This function setup a zero length transfer in Buffer DMA and
  59426. + * Slave modes for usb requests with zero field set
  59427. + *
  59428. + * @param core_if Programming view of DWC_otg controller.
  59429. + * @param ep The EP to start the transfer on.
  59430. + *
  59431. + */
  59432. +void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59433. +{
  59434. +
  59435. + depctl_data_t depctl;
  59436. + deptsiz_data_t deptsiz;
  59437. + gintmsk_data_t intr_mask = {.d32 = 0 };
  59438. +
  59439. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  59440. + DWC_PRINTF("zero length transfer is called\n");
  59441. +
  59442. + /* IN endpoint */
  59443. + if (ep->is_in == 1) {
  59444. + dwc_otg_dev_in_ep_regs_t *in_regs =
  59445. + core_if->dev_if->in_ep_regs[ep->num];
  59446. +
  59447. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  59448. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  59449. +
  59450. + deptsiz.b.xfersize = 0;
  59451. + deptsiz.b.pktcnt = 1;
  59452. +
  59453. + /* Write the DMA register */
  59454. + if (core_if->dma_enable) {
  59455. + if (core_if->dma_desc_enable == 0) {
  59456. + deptsiz.b.mc = 1;
  59457. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  59458. + deptsiz.d32);
  59459. + DWC_WRITE_REG32(&(in_regs->diepdma),
  59460. + (uint32_t) ep->dma_addr);
  59461. + }
  59462. + } else {
  59463. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  59464. + /**
  59465. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  59466. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  59467. + * the data will be written into the fifo by the ISR.
  59468. + */
  59469. + if (core_if->en_multiple_tx_fifo == 0) {
  59470. + intr_mask.b.nptxfempty = 1;
  59471. + DWC_MODIFY_REG32(&core_if->
  59472. + core_global_regs->gintmsk,
  59473. + intr_mask.d32, intr_mask.d32);
  59474. + } else {
  59475. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  59476. + if (ep->xfer_len > 0) {
  59477. + uint32_t fifoemptymsk = 0;
  59478. + fifoemptymsk = 1 << ep->num;
  59479. + DWC_MODIFY_REG32(&core_if->
  59480. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  59481. + 0, fifoemptymsk);
  59482. + }
  59483. + }
  59484. + }
  59485. +
  59486. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  59487. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59488. + /* EP enable, IN data in FIFO */
  59489. + depctl.b.cnak = 1;
  59490. + depctl.b.epena = 1;
  59491. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  59492. +
  59493. + } else {
  59494. + /* OUT endpoint */
  59495. + dwc_otg_dev_out_ep_regs_t *out_regs =
  59496. + core_if->dev_if->out_ep_regs[ep->num];
  59497. +
  59498. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  59499. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  59500. +
  59501. + /* Zero Length Packet */
  59502. + deptsiz.b.xfersize = ep->maxpacket;
  59503. + deptsiz.b.pktcnt = 1;
  59504. +
  59505. + if (core_if->dma_enable) {
  59506. + if (!core_if->dma_desc_enable) {
  59507. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  59508. + deptsiz.d32);
  59509. +
  59510. + DWC_WRITE_REG32(&(out_regs->doepdma),
  59511. + (uint32_t) ep->dma_addr);
  59512. + }
  59513. + } else {
  59514. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  59515. + }
  59516. +
  59517. + /* EP enable */
  59518. + depctl.b.cnak = 1;
  59519. + depctl.b.epena = 1;
  59520. +
  59521. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  59522. +
  59523. + }
  59524. +}
  59525. +
  59526. +/**
  59527. + * This function does the setup for a data transfer for EP0 and starts
  59528. + * the transfer. For an IN transfer, the packets will be loaded into
  59529. + * the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are
  59530. + * unloaded from the Rx FIFO in the ISR.
  59531. + *
  59532. + * @param core_if Programming view of DWC_otg controller.
  59533. + * @param ep The EP0 data.
  59534. + */
  59535. +void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59536. +{
  59537. + depctl_data_t depctl;
  59538. + deptsiz0_data_t deptsiz;
  59539. + gintmsk_data_t intr_mask = {.d32 = 0 };
  59540. + dwc_otg_dev_dma_desc_t *dma_desc;
  59541. +
  59542. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  59543. + "xfer_buff=%p start_xfer_buff=%p \n",
  59544. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  59545. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff);
  59546. +
  59547. + ep->total_len = ep->xfer_len;
  59548. +
  59549. + /* IN endpoint */
  59550. + if (ep->is_in == 1) {
  59551. + dwc_otg_dev_in_ep_regs_t *in_regs =
  59552. + core_if->dev_if->in_ep_regs[0];
  59553. +
  59554. + gnptxsts_data_t gtxstatus;
  59555. +
  59556. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  59557. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  59558. + if (depctl.b.epena)
  59559. + return;
  59560. + }
  59561. +
  59562. + gtxstatus.d32 =
  59563. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  59564. +
  59565. + /* If dedicated FIFO every time flush fifo before enable ep*/
  59566. + if (core_if->en_multiple_tx_fifo && core_if->snpsid >= OTG_CORE_REV_3_00a)
  59567. + dwc_otg_flush_tx_fifo(core_if, ep->tx_fifo_num);
  59568. +
  59569. + if (core_if->en_multiple_tx_fifo == 0
  59570. + && gtxstatus.b.nptxqspcavail == 0
  59571. + && !core_if->dma_enable) {
  59572. +#ifdef DEBUG
  59573. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  59574. + DWC_DEBUGPL(DBG_PCD, "DIEPCTL0=%0x\n",
  59575. + DWC_READ_REG32(&in_regs->diepctl));
  59576. + DWC_DEBUGPL(DBG_PCD, "DIEPTSIZ0=%0x (sz=%d, pcnt=%d)\n",
  59577. + deptsiz.d32,
  59578. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  59579. + DWC_PRINTF("TX Queue or FIFO Full (0x%0x)\n",
  59580. + gtxstatus.d32);
  59581. +#endif
  59582. + return;
  59583. + }
  59584. +
  59585. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  59586. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  59587. +
  59588. + /* Zero Length Packet? */
  59589. + if (ep->xfer_len == 0) {
  59590. + deptsiz.b.xfersize = 0;
  59591. + deptsiz.b.pktcnt = 1;
  59592. + } else {
  59593. + /* Program the transfer size and packet count
  59594. + * as follows: xfersize = N * maxpacket +
  59595. + * short_packet pktcnt = N + (short_packet
  59596. + * exist ? 1 : 0)
  59597. + */
  59598. + if (ep->xfer_len > ep->maxpacket) {
  59599. + ep->xfer_len = ep->maxpacket;
  59600. + deptsiz.b.xfersize = ep->maxpacket;
  59601. + } else {
  59602. + deptsiz.b.xfersize = ep->xfer_len;
  59603. + }
  59604. + deptsiz.b.pktcnt = 1;
  59605. +
  59606. + }
  59607. + DWC_DEBUGPL(DBG_PCDV,
  59608. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  59609. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  59610. + deptsiz.d32);
  59611. +
  59612. + /* Write the DMA register */
  59613. + if (core_if->dma_enable) {
  59614. + if (core_if->dma_desc_enable == 0) {
  59615. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  59616. + deptsiz.d32);
  59617. +
  59618. + DWC_WRITE_REG32(&(in_regs->diepdma),
  59619. + (uint32_t) ep->dma_addr);
  59620. + } else {
  59621. + dma_desc = core_if->dev_if->in_desc_addr;
  59622. +
  59623. + /** DMA Descriptor Setup */
  59624. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59625. + dma_desc->status.b.l = 1;
  59626. + dma_desc->status.b.ioc = 1;
  59627. + dma_desc->status.b.sp =
  59628. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  59629. + dma_desc->status.b.bytes = ep->xfer_len;
  59630. + dma_desc->buf = ep->dma_addr;
  59631. + dma_desc->status.b.sts = 0;
  59632. + dma_desc->status.b.bs = BS_HOST_READY;
  59633. +
  59634. + /** DIEPDMA0 Register write */
  59635. + DWC_WRITE_REG32(&in_regs->diepdma,
  59636. + core_if->
  59637. + dev_if->dma_in_desc_addr);
  59638. + }
  59639. + } else {
  59640. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  59641. + }
  59642. +
  59643. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  59644. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59645. + /* EP enable, IN data in FIFO */
  59646. + depctl.b.cnak = 1;
  59647. + depctl.b.epena = 1;
  59648. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  59649. +
  59650. + /**
  59651. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  59652. + * data will be written into the fifo by the ISR.
  59653. + */
  59654. + if (!core_if->dma_enable) {
  59655. + if (core_if->en_multiple_tx_fifo == 0) {
  59656. + intr_mask.b.nptxfempty = 1;
  59657. + DWC_MODIFY_REG32(&core_if->
  59658. + core_global_regs->gintmsk,
  59659. + intr_mask.d32, intr_mask.d32);
  59660. + } else {
  59661. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  59662. + if (ep->xfer_len > 0) {
  59663. + uint32_t fifoemptymsk = 0;
  59664. + fifoemptymsk |= 1 << ep->num;
  59665. + DWC_MODIFY_REG32(&core_if->
  59666. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  59667. + 0, fifoemptymsk);
  59668. + }
  59669. + }
  59670. + }
  59671. + } else {
  59672. + /* OUT endpoint */
  59673. + dwc_otg_dev_out_ep_regs_t *out_regs =
  59674. + core_if->dev_if->out_ep_regs[0];
  59675. +
  59676. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  59677. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  59678. +
  59679. + /* Program the transfer size and packet count as follows:
  59680. + * xfersize = N * (maxpacket + 4 - (maxpacket % 4))
  59681. + * pktcnt = N */
  59682. + /* Zero Length Packet */
  59683. + deptsiz.b.xfersize = ep->maxpacket;
  59684. + deptsiz.b.pktcnt = 1;
  59685. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  59686. + deptsiz.b.supcnt = 3;
  59687. +
  59688. + DWC_DEBUGPL(DBG_PCDV, "len=%d xfersize=%d pktcnt=%d\n",
  59689. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  59690. +
  59691. + if (core_if->dma_enable) {
  59692. + if (!core_if->dma_desc_enable) {
  59693. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  59694. + deptsiz.d32);
  59695. +
  59696. + DWC_WRITE_REG32(&(out_regs->doepdma),
  59697. + (uint32_t) ep->dma_addr);
  59698. + } else {
  59699. + dma_desc = core_if->dev_if->out_desc_addr;
  59700. +
  59701. + /** DMA Descriptor Setup */
  59702. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59703. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  59704. + dma_desc->status.b.mtrf = 0;
  59705. + dma_desc->status.b.sr = 0;
  59706. + }
  59707. + dma_desc->status.b.l = 1;
  59708. + dma_desc->status.b.ioc = 1;
  59709. + dma_desc->status.b.bytes = ep->maxpacket;
  59710. + dma_desc->buf = ep->dma_addr;
  59711. + dma_desc->status.b.sts = 0;
  59712. + dma_desc->status.b.bs = BS_HOST_READY;
  59713. +
  59714. + /** DOEPDMA0 Register write */
  59715. + DWC_WRITE_REG32(&out_regs->doepdma,
  59716. + core_if->dev_if->
  59717. + dma_out_desc_addr);
  59718. + }
  59719. + } else {
  59720. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  59721. + }
  59722. +
  59723. + /* EP enable */
  59724. + depctl.b.cnak = 1;
  59725. + depctl.b.epena = 1;
  59726. + DWC_WRITE_REG32(&(out_regs->doepctl), depctl.d32);
  59727. + }
  59728. +}
  59729. +
  59730. +/**
  59731. + * This function continues control IN transfers started by
  59732. + * dwc_otg_ep0_start_transfer, when the transfer does not fit in a
  59733. + * single packet. NOTE: The DIEPCTL0/DOEPCTL0 registers only have one
  59734. + * bit for the packet count.
  59735. + *
  59736. + * @param core_if Programming view of DWC_otg controller.
  59737. + * @param ep The EP0 data.
  59738. + */
  59739. +void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59740. +{
  59741. + depctl_data_t depctl;
  59742. + deptsiz0_data_t deptsiz;
  59743. + gintmsk_data_t intr_mask = {.d32 = 0 };
  59744. + dwc_otg_dev_dma_desc_t *dma_desc;
  59745. +
  59746. + if (ep->is_in == 1) {
  59747. + dwc_otg_dev_in_ep_regs_t *in_regs =
  59748. + core_if->dev_if->in_ep_regs[0];
  59749. + gnptxsts_data_t tx_status = {.d32 = 0 };
  59750. +
  59751. + tx_status.d32 =
  59752. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  59753. + /** @todo Should there be check for room in the Tx
  59754. + * Status Queue. If not remove the code above this comment. */
  59755. +
  59756. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  59757. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  59758. +
  59759. + /* Program the transfer size and packet count
  59760. + * as follows: xfersize = N * maxpacket +
  59761. + * short_packet pktcnt = N + (short_packet
  59762. + * exist ? 1 : 0)
  59763. + */
  59764. +
  59765. + if (core_if->dma_desc_enable == 0) {
  59766. + deptsiz.b.xfersize =
  59767. + (ep->total_len - ep->xfer_count) >
  59768. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  59769. + ep->xfer_count);
  59770. + deptsiz.b.pktcnt = 1;
  59771. + if (core_if->dma_enable == 0) {
  59772. + ep->xfer_len += deptsiz.b.xfersize;
  59773. + } else {
  59774. + ep->xfer_len = deptsiz.b.xfersize;
  59775. + }
  59776. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  59777. + } else {
  59778. + ep->xfer_len =
  59779. + (ep->total_len - ep->xfer_count) >
  59780. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  59781. + ep->xfer_count);
  59782. +
  59783. + dma_desc = core_if->dev_if->in_desc_addr;
  59784. +
  59785. + /** DMA Descriptor Setup */
  59786. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59787. + dma_desc->status.b.l = 1;
  59788. + dma_desc->status.b.ioc = 1;
  59789. + dma_desc->status.b.sp =
  59790. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  59791. + dma_desc->status.b.bytes = ep->xfer_len;
  59792. + dma_desc->buf = ep->dma_addr;
  59793. + dma_desc->status.b.sts = 0;
  59794. + dma_desc->status.b.bs = BS_HOST_READY;
  59795. +
  59796. + /** DIEPDMA0 Register write */
  59797. + DWC_WRITE_REG32(&in_regs->diepdma,
  59798. + core_if->dev_if->dma_in_desc_addr);
  59799. + }
  59800. +
  59801. + DWC_DEBUGPL(DBG_PCDV,
  59802. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  59803. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  59804. + deptsiz.d32);
  59805. +
  59806. + /* Write the DMA register */
  59807. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  59808. + if (core_if->dma_desc_enable == 0)
  59809. + DWC_WRITE_REG32(&(in_regs->diepdma),
  59810. + (uint32_t) ep->dma_addr);
  59811. + }
  59812. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  59813. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59814. + /* EP enable, IN data in FIFO */
  59815. + depctl.b.cnak = 1;
  59816. + depctl.b.epena = 1;
  59817. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  59818. +
  59819. + /**
  59820. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  59821. + * data will be written into the fifo by the ISR.
  59822. + */
  59823. + if (!core_if->dma_enable) {
  59824. + if (core_if->en_multiple_tx_fifo == 0) {
  59825. + /* First clear it from GINTSTS */
  59826. + intr_mask.b.nptxfempty = 1;
  59827. + DWC_MODIFY_REG32(&core_if->
  59828. + core_global_regs->gintmsk,
  59829. + intr_mask.d32, intr_mask.d32);
  59830. +
  59831. + } else {
  59832. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  59833. + if (ep->xfer_len > 0) {
  59834. + uint32_t fifoemptymsk = 0;
  59835. + fifoemptymsk |= 1 << ep->num;
  59836. + DWC_MODIFY_REG32(&core_if->
  59837. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  59838. + 0, fifoemptymsk);
  59839. + }
  59840. + }
  59841. + }
  59842. + } else {
  59843. + dwc_otg_dev_out_ep_regs_t *out_regs =
  59844. + core_if->dev_if->out_ep_regs[0];
  59845. +
  59846. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  59847. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  59848. +
  59849. + /* Program the transfer size and packet count
  59850. + * as follows: xfersize = N * maxpacket +
  59851. + * short_packet pktcnt = N + (short_packet
  59852. + * exist ? 1 : 0)
  59853. + */
  59854. + deptsiz.b.xfersize = ep->maxpacket;
  59855. + deptsiz.b.pktcnt = 1;
  59856. +
  59857. + if (core_if->dma_desc_enable == 0) {
  59858. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  59859. + } else {
  59860. + dma_desc = core_if->dev_if->out_desc_addr;
  59861. +
  59862. + /** DMA Descriptor Setup */
  59863. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59864. + dma_desc->status.b.l = 1;
  59865. + dma_desc->status.b.ioc = 1;
  59866. + dma_desc->status.b.bytes = ep->maxpacket;
  59867. + dma_desc->buf = ep->dma_addr;
  59868. + dma_desc->status.b.sts = 0;
  59869. + dma_desc->status.b.bs = BS_HOST_READY;
  59870. +
  59871. + /** DOEPDMA0 Register write */
  59872. + DWC_WRITE_REG32(&out_regs->doepdma,
  59873. + core_if->dev_if->dma_out_desc_addr);
  59874. + }
  59875. +
  59876. + DWC_DEBUGPL(DBG_PCDV,
  59877. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  59878. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  59879. + deptsiz.d32);
  59880. +
  59881. + /* Write the DMA register */
  59882. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  59883. + if (core_if->dma_desc_enable == 0)
  59884. + DWC_WRITE_REG32(&(out_regs->doepdma),
  59885. + (uint32_t) ep->dma_addr);
  59886. +
  59887. + }
  59888. +
  59889. + /* EP enable, IN data in FIFO */
  59890. + depctl.b.cnak = 1;
  59891. + depctl.b.epena = 1;
  59892. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  59893. +
  59894. + }
  59895. +}
  59896. +
  59897. +#ifdef DEBUG
  59898. +void dump_msg(const u8 * buf, unsigned int length)
  59899. +{
  59900. + unsigned int start, num, i;
  59901. + char line[52], *p;
  59902. +
  59903. + if (length >= 512)
  59904. + return;
  59905. + start = 0;
  59906. + while (length > 0) {
  59907. + num = length < 16u ? length : 16u;
  59908. + p = line;
  59909. + for (i = 0; i < num; ++i) {
  59910. + if (i == 8)
  59911. + *p++ = ' ';
  59912. + DWC_SPRINTF(p, " %02x", buf[i]);
  59913. + p += 3;
  59914. + }
  59915. + *p = 0;
  59916. + DWC_PRINTF("%6x: %s\n", start, line);
  59917. + buf += num;
  59918. + start += num;
  59919. + length -= num;
  59920. + }
  59921. +}
  59922. +#else
  59923. +static inline void dump_msg(const u8 * buf, unsigned int length)
  59924. +{
  59925. +}
  59926. +#endif
  59927. +
  59928. +/**
  59929. + * This function writes a packet into the Tx FIFO associated with the
  59930. + * EP. For non-periodic EPs the non-periodic Tx FIFO is written. For
  59931. + * periodic EPs the periodic Tx FIFO associated with the EP is written
  59932. + * with all packets for the next micro-frame.
  59933. + *
  59934. + * @param core_if Programming view of DWC_otg controller.
  59935. + * @param ep The EP to write packet for.
  59936. + * @param dma Indicates if DMA is being used.
  59937. + */
  59938. +void dwc_otg_ep_write_packet(dwc_otg_core_if_t * core_if, dwc_ep_t * ep,
  59939. + int dma)
  59940. +{
  59941. + /**
  59942. + * The buffer is padded to DWORD on a per packet basis in
  59943. + * slave/dma mode if the MPS is not DWORD aligned. The last
  59944. + * packet, if short, is also padded to a multiple of DWORD.
  59945. + *
  59946. + * ep->xfer_buff always starts DWORD aligned in memory and is a
  59947. + * multiple of DWORD in length
  59948. + *
  59949. + * ep->xfer_len can be any number of bytes
  59950. + *
  59951. + * ep->xfer_count is a multiple of ep->maxpacket until the last
  59952. + * packet
  59953. + *
  59954. + * FIFO access is DWORD */
  59955. +
  59956. + uint32_t i;
  59957. + uint32_t byte_count;
  59958. + uint32_t dword_count;
  59959. + uint32_t *fifo;
  59960. + uint32_t *data_buff = (uint32_t *) ep->xfer_buff;
  59961. +
  59962. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p)\n", __func__, core_if,
  59963. + ep);
  59964. + if (ep->xfer_count >= ep->xfer_len) {
  59965. + DWC_WARN("%s() No data for EP%d!!!\n", __func__, ep->num);
  59966. + return;
  59967. + }
  59968. +
  59969. + /* Find the byte length of the packet either short packet or MPS */
  59970. + if ((ep->xfer_len - ep->xfer_count) < ep->maxpacket) {
  59971. + byte_count = ep->xfer_len - ep->xfer_count;
  59972. + } else {
  59973. + byte_count = ep->maxpacket;
  59974. + }
  59975. +
  59976. + /* Find the DWORD length, padded by extra bytes as neccessary if MPS
  59977. + * is not a multiple of DWORD */
  59978. + dword_count = (byte_count + 3) / 4;
  59979. +
  59980. +#ifdef VERBOSE
  59981. + dump_msg(ep->xfer_buff, byte_count);
  59982. +#endif
  59983. +
  59984. + /**@todo NGS Where are the Periodic Tx FIFO addresses
  59985. + * intialized? What should this be? */
  59986. +
  59987. + fifo = core_if->data_fifo[ep->num];
  59988. +
  59989. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "fifo=%p buff=%p *p=%08x bc=%d\n",
  59990. + fifo, data_buff, *data_buff, byte_count);
  59991. +
  59992. + if (!dma) {
  59993. + for (i = 0; i < dword_count; i++, data_buff++) {
  59994. + DWC_WRITE_REG32(fifo, *data_buff);
  59995. + }
  59996. + }
  59997. +
  59998. + ep->xfer_count += byte_count;
  59999. + ep->xfer_buff += byte_count;
  60000. + ep->dma_addr += byte_count;
  60001. +}
  60002. +
  60003. +/**
  60004. + * Set the EP STALL.
  60005. + *
  60006. + * @param core_if Programming view of DWC_otg controller.
  60007. + * @param ep The EP to set the stall on.
  60008. + */
  60009. +void dwc_otg_ep_set_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60010. +{
  60011. + depctl_data_t depctl;
  60012. + volatile uint32_t *depctl_addr;
  60013. +
  60014. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  60015. + (ep->is_in ? "IN" : "OUT"));
  60016. +
  60017. + if (ep->is_in == 1) {
  60018. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  60019. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  60020. +
  60021. + /* set the disable and stall bits */
  60022. + if (depctl.b.epena) {
  60023. + depctl.b.epdis = 1;
  60024. + }
  60025. + depctl.b.stall = 1;
  60026. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  60027. + } else {
  60028. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  60029. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  60030. +
  60031. + /* set the stall bit */
  60032. + depctl.b.stall = 1;
  60033. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  60034. + }
  60035. +
  60036. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  60037. +
  60038. + return;
  60039. +}
  60040. +
  60041. +/**
  60042. + * Clear the EP STALL.
  60043. + *
  60044. + * @param core_if Programming view of DWC_otg controller.
  60045. + * @param ep The EP to clear stall from.
  60046. + */
  60047. +void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60048. +{
  60049. + depctl_data_t depctl;
  60050. + volatile uint32_t *depctl_addr;
  60051. +
  60052. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  60053. + (ep->is_in ? "IN" : "OUT"));
  60054. +
  60055. + if (ep->is_in == 1) {
  60056. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  60057. + } else {
  60058. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  60059. + }
  60060. +
  60061. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  60062. +
  60063. + /* clear the stall bits */
  60064. + depctl.b.stall = 0;
  60065. +
  60066. + /*
  60067. + * USB Spec 9.4.5: For endpoints using data toggle, regardless
  60068. + * of whether an endpoint has the Halt feature set, a
  60069. + * ClearFeature(ENDPOINT_HALT) request always results in the
  60070. + * data toggle being reinitialized to DATA0.
  60071. + */
  60072. + if (ep->type == DWC_OTG_EP_TYPE_INTR ||
  60073. + ep->type == DWC_OTG_EP_TYPE_BULK) {
  60074. + depctl.b.setd0pid = 1; /* DATA0 */
  60075. + }
  60076. +
  60077. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  60078. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  60079. + return;
  60080. +}
  60081. +
  60082. +/**
  60083. + * This function reads a packet from the Rx FIFO into the destination
  60084. + * buffer. To read SETUP data use dwc_otg_read_setup_packet.
  60085. + *
  60086. + * @param core_if Programming view of DWC_otg controller.
  60087. + * @param dest Destination buffer for the packet.
  60088. + * @param bytes Number of bytes to copy to the destination.
  60089. + */
  60090. +void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  60091. + uint8_t * dest, uint16_t bytes)
  60092. +{
  60093. + int i;
  60094. + int word_count = (bytes + 3) / 4;
  60095. +
  60096. + volatile uint32_t *fifo = core_if->data_fifo[0];
  60097. + uint32_t *data_buff = (uint32_t *) dest;
  60098. +
  60099. + /**
  60100. + * @todo Account for the case where _dest is not dword aligned. This
  60101. + * requires reading data from the FIFO into a uint32_t temp buffer,
  60102. + * then moving it into the data buffer.
  60103. + */
  60104. +
  60105. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p,%d)\n", __func__,
  60106. + core_if, dest, bytes);
  60107. +
  60108. + for (i = 0; i < word_count; i++, data_buff++) {
  60109. + *data_buff = DWC_READ_REG32(fifo);
  60110. + }
  60111. +
  60112. + return;
  60113. +}
  60114. +
  60115. +/**
  60116. + * This functions reads the device registers and prints them
  60117. + *
  60118. + * @param core_if Programming view of DWC_otg controller.
  60119. + */
  60120. +void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * core_if)
  60121. +{
  60122. + int i;
  60123. + volatile uint32_t *addr;
  60124. +
  60125. + DWC_PRINTF("Device Global Registers\n");
  60126. + addr = &core_if->dev_if->dev_global_regs->dcfg;
  60127. + DWC_PRINTF("DCFG @0x%08lX : 0x%08X\n",
  60128. + (unsigned long)addr, DWC_READ_REG32(addr));
  60129. + addr = &core_if->dev_if->dev_global_regs->dctl;
  60130. + DWC_PRINTF("DCTL @0x%08lX : 0x%08X\n",
  60131. + (unsigned long)addr, DWC_READ_REG32(addr));
  60132. + addr = &core_if->dev_if->dev_global_regs->dsts;
  60133. + DWC_PRINTF("DSTS @0x%08lX : 0x%08X\n",
  60134. + (unsigned long)addr, DWC_READ_REG32(addr));
  60135. + addr = &core_if->dev_if->dev_global_regs->diepmsk;
  60136. + DWC_PRINTF("DIEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60137. + DWC_READ_REG32(addr));
  60138. + addr = &core_if->dev_if->dev_global_regs->doepmsk;
  60139. + DWC_PRINTF("DOEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60140. + DWC_READ_REG32(addr));
  60141. + addr = &core_if->dev_if->dev_global_regs->daint;
  60142. + DWC_PRINTF("DAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60143. + DWC_READ_REG32(addr));
  60144. + addr = &core_if->dev_if->dev_global_regs->daintmsk;
  60145. + DWC_PRINTF("DAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60146. + DWC_READ_REG32(addr));
  60147. + addr = &core_if->dev_if->dev_global_regs->dtknqr1;
  60148. + DWC_PRINTF("DTKNQR1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60149. + DWC_READ_REG32(addr));
  60150. + if (core_if->hwcfg2.b.dev_token_q_depth > 6) {
  60151. + addr = &core_if->dev_if->dev_global_regs->dtknqr2;
  60152. + DWC_PRINTF("DTKNQR2 @0x%08lX : 0x%08X\n",
  60153. + (unsigned long)addr, DWC_READ_REG32(addr));
  60154. + }
  60155. +
  60156. + addr = &core_if->dev_if->dev_global_regs->dvbusdis;
  60157. + DWC_PRINTF("DVBUSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60158. + DWC_READ_REG32(addr));
  60159. +
  60160. + addr = &core_if->dev_if->dev_global_regs->dvbuspulse;
  60161. + DWC_PRINTF("DVBUSPULSE @0x%08lX : 0x%08X\n",
  60162. + (unsigned long)addr, DWC_READ_REG32(addr));
  60163. +
  60164. + addr = &core_if->dev_if->dev_global_regs->dtknqr3_dthrctl;
  60165. + DWC_PRINTF("DTKNQR3_DTHRCTL @0x%08lX : 0x%08X\n",
  60166. + (unsigned long)addr, DWC_READ_REG32(addr));
  60167. +
  60168. + if (core_if->hwcfg2.b.dev_token_q_depth > 22) {
  60169. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  60170. + DWC_PRINTF("DTKNQR4 @0x%08lX : 0x%08X\n",
  60171. + (unsigned long)addr, DWC_READ_REG32(addr));
  60172. + }
  60173. +
  60174. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  60175. + DWC_PRINTF("FIFOEMPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60176. + DWC_READ_REG32(addr));
  60177. +
  60178. + if (core_if->hwcfg2.b.multi_proc_int) {
  60179. +
  60180. + addr = &core_if->dev_if->dev_global_regs->deachint;
  60181. + DWC_PRINTF("DEACHINT @0x%08lX : 0x%08X\n",
  60182. + (unsigned long)addr, DWC_READ_REG32(addr));
  60183. + addr = &core_if->dev_if->dev_global_regs->deachintmsk;
  60184. + DWC_PRINTF("DEACHINTMSK @0x%08lX : 0x%08X\n",
  60185. + (unsigned long)addr, DWC_READ_REG32(addr));
  60186. +
  60187. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  60188. + addr =
  60189. + &core_if->dev_if->
  60190. + dev_global_regs->diepeachintmsk[i];
  60191. + DWC_PRINTF("DIEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  60192. + i, (unsigned long)addr,
  60193. + DWC_READ_REG32(addr));
  60194. + }
  60195. +
  60196. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  60197. + addr =
  60198. + &core_if->dev_if->
  60199. + dev_global_regs->doepeachintmsk[i];
  60200. + DWC_PRINTF("DOEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  60201. + i, (unsigned long)addr,
  60202. + DWC_READ_REG32(addr));
  60203. + }
  60204. + }
  60205. +
  60206. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  60207. + DWC_PRINTF("Device IN EP %d Registers\n", i);
  60208. + addr = &core_if->dev_if->in_ep_regs[i]->diepctl;
  60209. + DWC_PRINTF("DIEPCTL @0x%08lX : 0x%08X\n",
  60210. + (unsigned long)addr, DWC_READ_REG32(addr));
  60211. + addr = &core_if->dev_if->in_ep_regs[i]->diepint;
  60212. + DWC_PRINTF("DIEPINT @0x%08lX : 0x%08X\n",
  60213. + (unsigned long)addr, DWC_READ_REG32(addr));
  60214. + addr = &core_if->dev_if->in_ep_regs[i]->dieptsiz;
  60215. + DWC_PRINTF("DIETSIZ @0x%08lX : 0x%08X\n",
  60216. + (unsigned long)addr, DWC_READ_REG32(addr));
  60217. + addr = &core_if->dev_if->in_ep_regs[i]->diepdma;
  60218. + DWC_PRINTF("DIEPDMA @0x%08lX : 0x%08X\n",
  60219. + (unsigned long)addr, DWC_READ_REG32(addr));
  60220. + addr = &core_if->dev_if->in_ep_regs[i]->dtxfsts;
  60221. + DWC_PRINTF("DTXFSTS @0x%08lX : 0x%08X\n",
  60222. + (unsigned long)addr, DWC_READ_REG32(addr));
  60223. + addr = &core_if->dev_if->in_ep_regs[i]->diepdmab;
  60224. + DWC_PRINTF("DIEPDMAB @0x%08lX : 0x%08X\n",
  60225. + (unsigned long)addr, 0 /*DWC_READ_REG32(addr) */ );
  60226. + }
  60227. +
  60228. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  60229. + DWC_PRINTF("Device OUT EP %d Registers\n", i);
  60230. + addr = &core_if->dev_if->out_ep_regs[i]->doepctl;
  60231. + DWC_PRINTF("DOEPCTL @0x%08lX : 0x%08X\n",
  60232. + (unsigned long)addr, DWC_READ_REG32(addr));
  60233. + addr = &core_if->dev_if->out_ep_regs[i]->doepint;
  60234. + DWC_PRINTF("DOEPINT @0x%08lX : 0x%08X\n",
  60235. + (unsigned long)addr, DWC_READ_REG32(addr));
  60236. + addr = &core_if->dev_if->out_ep_regs[i]->doeptsiz;
  60237. + DWC_PRINTF("DOETSIZ @0x%08lX : 0x%08X\n",
  60238. + (unsigned long)addr, DWC_READ_REG32(addr));
  60239. + addr = &core_if->dev_if->out_ep_regs[i]->doepdma;
  60240. + DWC_PRINTF("DOEPDMA @0x%08lX : 0x%08X\n",
  60241. + (unsigned long)addr, DWC_READ_REG32(addr));
  60242. + if (core_if->dma_enable) { /* Don't access this register in SLAVE mode */
  60243. + addr = &core_if->dev_if->out_ep_regs[i]->doepdmab;
  60244. + DWC_PRINTF("DOEPDMAB @0x%08lX : 0x%08X\n",
  60245. + (unsigned long)addr, DWC_READ_REG32(addr));
  60246. + }
  60247. +
  60248. + }
  60249. +}
  60250. +
  60251. +/**
  60252. + * This functions reads the SPRAM and prints its content
  60253. + *
  60254. + * @param core_if Programming view of DWC_otg controller.
  60255. + */
  60256. +void dwc_otg_dump_spram(dwc_otg_core_if_t * core_if)
  60257. +{
  60258. + volatile uint8_t *addr, *start_addr, *end_addr;
  60259. +
  60260. + DWC_PRINTF("SPRAM Data:\n");
  60261. + start_addr = (void *)core_if->core_global_regs;
  60262. + DWC_PRINTF("Base Address: 0x%8lX\n", (unsigned long)start_addr);
  60263. + start_addr += 0x00028000;
  60264. + end_addr = (void *)core_if->core_global_regs;
  60265. + end_addr += 0x000280e0;
  60266. +
  60267. + for (addr = start_addr; addr < end_addr; addr += 16) {
  60268. + DWC_PRINTF
  60269. + ("0x%8lX:\t%2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X\n",
  60270. + (unsigned long)addr, addr[0], addr[1], addr[2], addr[3],
  60271. + addr[4], addr[5], addr[6], addr[7], addr[8], addr[9],
  60272. + addr[10], addr[11], addr[12], addr[13], addr[14], addr[15]
  60273. + );
  60274. + }
  60275. +
  60276. + return;
  60277. +}
  60278. +
  60279. +/**
  60280. + * This function reads the host registers and prints them
  60281. + *
  60282. + * @param core_if Programming view of DWC_otg controller.
  60283. + */
  60284. +void dwc_otg_dump_host_registers(dwc_otg_core_if_t * core_if)
  60285. +{
  60286. + int i;
  60287. + volatile uint32_t *addr;
  60288. +
  60289. + DWC_PRINTF("Host Global Registers\n");
  60290. + addr = &core_if->host_if->host_global_regs->hcfg;
  60291. + DWC_PRINTF("HCFG @0x%08lX : 0x%08X\n",
  60292. + (unsigned long)addr, DWC_READ_REG32(addr));
  60293. + addr = &core_if->host_if->host_global_regs->hfir;
  60294. + DWC_PRINTF("HFIR @0x%08lX : 0x%08X\n",
  60295. + (unsigned long)addr, DWC_READ_REG32(addr));
  60296. + addr = &core_if->host_if->host_global_regs->hfnum;
  60297. + DWC_PRINTF("HFNUM @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60298. + DWC_READ_REG32(addr));
  60299. + addr = &core_if->host_if->host_global_regs->hptxsts;
  60300. + DWC_PRINTF("HPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60301. + DWC_READ_REG32(addr));
  60302. + addr = &core_if->host_if->host_global_regs->haint;
  60303. + DWC_PRINTF("HAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60304. + DWC_READ_REG32(addr));
  60305. + addr = &core_if->host_if->host_global_regs->haintmsk;
  60306. + DWC_PRINTF("HAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60307. + DWC_READ_REG32(addr));
  60308. + if (core_if->dma_desc_enable) {
  60309. + addr = &core_if->host_if->host_global_regs->hflbaddr;
  60310. + DWC_PRINTF("HFLBADDR @0x%08lX : 0x%08X\n",
  60311. + (unsigned long)addr, DWC_READ_REG32(addr));
  60312. + }
  60313. +
  60314. + addr = core_if->host_if->hprt0;
  60315. + DWC_PRINTF("HPRT0 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60316. + DWC_READ_REG32(addr));
  60317. +
  60318. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  60319. + DWC_PRINTF("Host Channel %d Specific Registers\n", i);
  60320. + addr = &core_if->host_if->hc_regs[i]->hcchar;
  60321. + DWC_PRINTF("HCCHAR @0x%08lX : 0x%08X\n",
  60322. + (unsigned long)addr, DWC_READ_REG32(addr));
  60323. + addr = &core_if->host_if->hc_regs[i]->hcsplt;
  60324. + DWC_PRINTF("HCSPLT @0x%08lX : 0x%08X\n",
  60325. + (unsigned long)addr, DWC_READ_REG32(addr));
  60326. + addr = &core_if->host_if->hc_regs[i]->hcint;
  60327. + DWC_PRINTF("HCINT @0x%08lX : 0x%08X\n",
  60328. + (unsigned long)addr, DWC_READ_REG32(addr));
  60329. + addr = &core_if->host_if->hc_regs[i]->hcintmsk;
  60330. + DWC_PRINTF("HCINTMSK @0x%08lX : 0x%08X\n",
  60331. + (unsigned long)addr, DWC_READ_REG32(addr));
  60332. + addr = &core_if->host_if->hc_regs[i]->hctsiz;
  60333. + DWC_PRINTF("HCTSIZ @0x%08lX : 0x%08X\n",
  60334. + (unsigned long)addr, DWC_READ_REG32(addr));
  60335. + addr = &core_if->host_if->hc_regs[i]->hcdma;
  60336. + DWC_PRINTF("HCDMA @0x%08lX : 0x%08X\n",
  60337. + (unsigned long)addr, DWC_READ_REG32(addr));
  60338. + if (core_if->dma_desc_enable) {
  60339. + addr = &core_if->host_if->hc_regs[i]->hcdmab;
  60340. + DWC_PRINTF("HCDMAB @0x%08lX : 0x%08X\n",
  60341. + (unsigned long)addr, DWC_READ_REG32(addr));
  60342. + }
  60343. +
  60344. + }
  60345. + return;
  60346. +}
  60347. +
  60348. +/**
  60349. + * This function reads the core global registers and prints them
  60350. + *
  60351. + * @param core_if Programming view of DWC_otg controller.
  60352. + */
  60353. +void dwc_otg_dump_global_registers(dwc_otg_core_if_t * core_if)
  60354. +{
  60355. + int i, ep_num;
  60356. + volatile uint32_t *addr;
  60357. + char *txfsiz;
  60358. +
  60359. + DWC_PRINTF("Core Global Registers\n");
  60360. + addr = &core_if->core_global_regs->gotgctl;
  60361. + DWC_PRINTF("GOTGCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60362. + DWC_READ_REG32(addr));
  60363. + addr = &core_if->core_global_regs->gotgint;
  60364. + DWC_PRINTF("GOTGINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60365. + DWC_READ_REG32(addr));
  60366. + addr = &core_if->core_global_regs->gahbcfg;
  60367. + DWC_PRINTF("GAHBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60368. + DWC_READ_REG32(addr));
  60369. + addr = &core_if->core_global_regs->gusbcfg;
  60370. + DWC_PRINTF("GUSBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60371. + DWC_READ_REG32(addr));
  60372. + addr = &core_if->core_global_regs->grstctl;
  60373. + DWC_PRINTF("GRSTCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60374. + DWC_READ_REG32(addr));
  60375. + addr = &core_if->core_global_regs->gintsts;
  60376. + DWC_PRINTF("GINTSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60377. + DWC_READ_REG32(addr));
  60378. + addr = &core_if->core_global_regs->gintmsk;
  60379. + DWC_PRINTF("GINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60380. + DWC_READ_REG32(addr));
  60381. + addr = &core_if->core_global_regs->grxstsr;
  60382. + DWC_PRINTF("GRXSTSR @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60383. + DWC_READ_REG32(addr));
  60384. + addr = &core_if->core_global_regs->grxfsiz;
  60385. + DWC_PRINTF("GRXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60386. + DWC_READ_REG32(addr));
  60387. + addr = &core_if->core_global_regs->gnptxfsiz;
  60388. + DWC_PRINTF("GNPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60389. + DWC_READ_REG32(addr));
  60390. + addr = &core_if->core_global_regs->gnptxsts;
  60391. + DWC_PRINTF("GNPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60392. + DWC_READ_REG32(addr));
  60393. + addr = &core_if->core_global_regs->gi2cctl;
  60394. + DWC_PRINTF("GI2CCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60395. + DWC_READ_REG32(addr));
  60396. + addr = &core_if->core_global_regs->gpvndctl;
  60397. + DWC_PRINTF("GPVNDCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60398. + DWC_READ_REG32(addr));
  60399. + addr = &core_if->core_global_regs->ggpio;
  60400. + DWC_PRINTF("GGPIO @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60401. + DWC_READ_REG32(addr));
  60402. + addr = &core_if->core_global_regs->guid;
  60403. + DWC_PRINTF("GUID @0x%08lX : 0x%08X\n",
  60404. + (unsigned long)addr, DWC_READ_REG32(addr));
  60405. + addr = &core_if->core_global_regs->gsnpsid;
  60406. + DWC_PRINTF("GSNPSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60407. + DWC_READ_REG32(addr));
  60408. + addr = &core_if->core_global_regs->ghwcfg1;
  60409. + DWC_PRINTF("GHWCFG1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60410. + DWC_READ_REG32(addr));
  60411. + addr = &core_if->core_global_regs->ghwcfg2;
  60412. + DWC_PRINTF("GHWCFG2 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60413. + DWC_READ_REG32(addr));
  60414. + addr = &core_if->core_global_regs->ghwcfg3;
  60415. + DWC_PRINTF("GHWCFG3 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60416. + DWC_READ_REG32(addr));
  60417. + addr = &core_if->core_global_regs->ghwcfg4;
  60418. + DWC_PRINTF("GHWCFG4 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60419. + DWC_READ_REG32(addr));
  60420. + addr = &core_if->core_global_regs->glpmcfg;
  60421. + DWC_PRINTF("GLPMCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60422. + DWC_READ_REG32(addr));
  60423. + addr = &core_if->core_global_regs->gpwrdn;
  60424. + DWC_PRINTF("GPWRDN @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60425. + DWC_READ_REG32(addr));
  60426. + addr = &core_if->core_global_regs->gdfifocfg;
  60427. + DWC_PRINTF("GDFIFOCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60428. + DWC_READ_REG32(addr));
  60429. + addr = &core_if->core_global_regs->adpctl;
  60430. + DWC_PRINTF("ADPCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60431. + dwc_otg_adp_read_reg(core_if));
  60432. + addr = &core_if->core_global_regs->hptxfsiz;
  60433. + DWC_PRINTF("HPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60434. + DWC_READ_REG32(addr));
  60435. +
  60436. + if (core_if->en_multiple_tx_fifo == 0) {
  60437. + ep_num = core_if->hwcfg4.b.num_dev_perio_in_ep;
  60438. + txfsiz = "DPTXFSIZ";
  60439. + } else {
  60440. + ep_num = core_if->hwcfg4.b.num_in_eps;
  60441. + txfsiz = "DIENPTXF";
  60442. + }
  60443. + for (i = 0; i < ep_num; i++) {
  60444. + addr = &core_if->core_global_regs->dtxfsiz[i];
  60445. + DWC_PRINTF("%s[%d] @0x%08lX : 0x%08X\n", txfsiz, i + 1,
  60446. + (unsigned long)addr, DWC_READ_REG32(addr));
  60447. + }
  60448. + addr = core_if->pcgcctl;
  60449. + DWC_PRINTF("PCGCCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60450. + DWC_READ_REG32(addr));
  60451. +}
  60452. +
  60453. +/**
  60454. + * Flush a Tx FIFO.
  60455. + *
  60456. + * @param core_if Programming view of DWC_otg controller.
  60457. + * @param num Tx FIFO to flush.
  60458. + */
  60459. +void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * core_if, const int num)
  60460. +{
  60461. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  60462. + volatile grstctl_t greset = {.d32 = 0 };
  60463. + int count = 0;
  60464. +
  60465. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "Flush Tx FIFO %d\n", num);
  60466. +
  60467. + greset.b.txfflsh = 1;
  60468. + greset.b.txfnum = num;
  60469. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  60470. +
  60471. + do {
  60472. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  60473. + if (++count > 10000) {
  60474. + DWC_WARN("%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
  60475. + __func__, greset.d32,
  60476. + DWC_READ_REG32(&global_regs->gnptxsts));
  60477. + break;
  60478. + }
  60479. + dwc_udelay(1);
  60480. + } while (greset.b.txfflsh == 1);
  60481. +
  60482. + /* Wait for 3 PHY Clocks */
  60483. + dwc_udelay(1);
  60484. +}
  60485. +
  60486. +/**
  60487. + * Flush Rx FIFO.
  60488. + *
  60489. + * @param core_if Programming view of DWC_otg controller.
  60490. + */
  60491. +void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * core_if)
  60492. +{
  60493. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  60494. + volatile grstctl_t greset = {.d32 = 0 };
  60495. + int count = 0;
  60496. +
  60497. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "%s\n", __func__);
  60498. + /*
  60499. + *
  60500. + */
  60501. + greset.b.rxfflsh = 1;
  60502. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  60503. +
  60504. + do {
  60505. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  60506. + if (++count > 10000) {
  60507. + DWC_WARN("%s() HANG! GRSTCTL=%0x\n", __func__,
  60508. + greset.d32);
  60509. + break;
  60510. + }
  60511. + dwc_udelay(1);
  60512. + } while (greset.b.rxfflsh == 1);
  60513. +
  60514. + /* Wait for 3 PHY Clocks */
  60515. + dwc_udelay(1);
  60516. +}
  60517. +
  60518. +/**
  60519. + * Do core a soft reset of the core. Be careful with this because it
  60520. + * resets all the internal state machines of the core.
  60521. + */
  60522. +void dwc_otg_core_reset(dwc_otg_core_if_t * core_if)
  60523. +{
  60524. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  60525. + volatile grstctl_t greset = {.d32 = 0 };
  60526. + int count = 0;
  60527. +
  60528. + DWC_DEBUGPL(DBG_CILV, "%s\n", __func__);
  60529. + /* Wait for AHB master IDLE state. */
  60530. + do {
  60531. + dwc_udelay(10);
  60532. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  60533. + if (++count > 100000) {
  60534. + DWC_WARN("%s() HANG! AHB Idle GRSTCTL=%0x\n", __func__,
  60535. + greset.d32);
  60536. + return;
  60537. + }
  60538. + }
  60539. + while (greset.b.ahbidle == 0);
  60540. +
  60541. + /* Core Soft Reset */
  60542. + count = 0;
  60543. + greset.b.csftrst = 1;
  60544. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  60545. + do {
  60546. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  60547. + if (++count > 10000) {
  60548. + DWC_WARN("%s() HANG! Soft Reset GRSTCTL=%0x\n",
  60549. + __func__, greset.d32);
  60550. + break;
  60551. + }
  60552. + dwc_udelay(1);
  60553. + }
  60554. + while (greset.b.csftrst == 1);
  60555. +
  60556. + /* Wait for 3 PHY Clocks */
  60557. + dwc_mdelay(100);
  60558. +}
  60559. +
  60560. +uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if)
  60561. +{
  60562. + return (dwc_otg_mode(_core_if) != DWC_HOST_MODE);
  60563. +}
  60564. +
  60565. +uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if)
  60566. +{
  60567. + return (dwc_otg_mode(_core_if) == DWC_HOST_MODE);
  60568. +}
  60569. +
  60570. +/**
  60571. + * Register HCD callbacks. The callbacks are used to start and stop
  60572. + * the HCD for interrupt processing.
  60573. + *
  60574. + * @param core_if Programming view of DWC_otg controller.
  60575. + * @param cb the HCD callback structure.
  60576. + * @param p pointer to be passed to callback function (usb_hcd*).
  60577. + */
  60578. +void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * core_if,
  60579. + dwc_otg_cil_callbacks_t * cb, void *p)
  60580. +{
  60581. + core_if->hcd_cb = cb;
  60582. + cb->p = p;
  60583. +}
  60584. +
  60585. +/**
  60586. + * Register PCD callbacks. The callbacks are used to start and stop
  60587. + * the PCD for interrupt processing.
  60588. + *
  60589. + * @param core_if Programming view of DWC_otg controller.
  60590. + * @param cb the PCD callback structure.
  60591. + * @param p pointer to be passed to callback function (pcd*).
  60592. + */
  60593. +void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * core_if,
  60594. + dwc_otg_cil_callbacks_t * cb, void *p)
  60595. +{
  60596. + core_if->pcd_cb = cb;
  60597. + cb->p = p;
  60598. +}
  60599. +
  60600. +#ifdef DWC_EN_ISOC
  60601. +
  60602. +/**
  60603. + * This function writes isoc data per 1 (micro)frame into tx fifo
  60604. + *
  60605. + * @param core_if Programming view of DWC_otg controller.
  60606. + * @param ep The EP to start the transfer on.
  60607. + *
  60608. + */
  60609. +void write_isoc_frame_data(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60610. +{
  60611. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  60612. + dtxfsts_data_t txstatus = {.d32 = 0 };
  60613. + uint32_t len = 0;
  60614. + uint32_t dwords;
  60615. +
  60616. + ep->xfer_len = ep->data_per_frame;
  60617. + ep->xfer_count = 0;
  60618. +
  60619. + ep_regs = core_if->dev_if->in_ep_regs[ep->num];
  60620. +
  60621. + len = ep->xfer_len - ep->xfer_count;
  60622. +
  60623. + if (len > ep->maxpacket) {
  60624. + len = ep->maxpacket;
  60625. + }
  60626. +
  60627. + dwords = (len + 3) / 4;
  60628. +
  60629. + /* While there is space in the queue and space in the FIFO and
  60630. + * More data to tranfer, Write packets to the Tx FIFO */
  60631. + txstatus.d32 =
  60632. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dtxfsts);
  60633. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", ep->num, txstatus.d32);
  60634. +
  60635. + while (txstatus.b.txfspcavail > dwords &&
  60636. + ep->xfer_count < ep->xfer_len && ep->xfer_len != 0) {
  60637. + /* Write the FIFO */
  60638. + dwc_otg_ep_write_packet(core_if, ep, 0);
  60639. +
  60640. + len = ep->xfer_len - ep->xfer_count;
  60641. + if (len > ep->maxpacket) {
  60642. + len = ep->maxpacket;
  60643. + }
  60644. +
  60645. + dwords = (len + 3) / 4;
  60646. + txstatus.d32 =
  60647. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  60648. + dtxfsts);
  60649. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", ep->num,
  60650. + txstatus.d32);
  60651. + }
  60652. +}
  60653. +
  60654. +/**
  60655. + * This function initializes a descriptor chain for Isochronous transfer
  60656. + *
  60657. + * @param core_if Programming view of DWC_otg controller.
  60658. + * @param ep The EP to start the transfer on.
  60659. + *
  60660. + */
  60661. +void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  60662. + dwc_ep_t * ep)
  60663. +{
  60664. + deptsiz_data_t deptsiz = {.d32 = 0 };
  60665. + depctl_data_t depctl = {.d32 = 0 };
  60666. + dsts_data_t dsts = {.d32 = 0 };
  60667. + volatile uint32_t *addr;
  60668. +
  60669. + if (ep->is_in) {
  60670. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  60671. + } else {
  60672. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  60673. + }
  60674. +
  60675. + ep->xfer_len = ep->data_per_frame;
  60676. + ep->xfer_count = 0;
  60677. + ep->xfer_buff = ep->cur_pkt_addr;
  60678. + ep->dma_addr = ep->cur_pkt_dma_addr;
  60679. +
  60680. + if (ep->is_in) {
  60681. + /* Program the transfer size and packet count
  60682. + * as follows: xfersize = N * maxpacket +
  60683. + * short_packet pktcnt = N + (short_packet
  60684. + * exist ? 1 : 0)
  60685. + */
  60686. + deptsiz.b.xfersize = ep->xfer_len;
  60687. + deptsiz.b.pktcnt =
  60688. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  60689. + deptsiz.b.mc = deptsiz.b.pktcnt;
  60690. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz,
  60691. + deptsiz.d32);
  60692. +
  60693. + /* Write the DMA register */
  60694. + if (core_if->dma_enable) {
  60695. + DWC_WRITE_REG32(&
  60696. + (core_if->dev_if->in_ep_regs[ep->num]->
  60697. + diepdma), (uint32_t) ep->dma_addr);
  60698. + }
  60699. + } else {
  60700. + deptsiz.b.pktcnt =
  60701. + (ep->xfer_len + (ep->maxpacket - 1)) / ep->maxpacket;
  60702. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  60703. +
  60704. + DWC_WRITE_REG32(&core_if->dev_if->
  60705. + out_ep_regs[ep->num]->doeptsiz, deptsiz.d32);
  60706. +
  60707. + if (core_if->dma_enable) {
  60708. + DWC_WRITE_REG32(&
  60709. + (core_if->dev_if->
  60710. + out_ep_regs[ep->num]->doepdma),
  60711. + (uint32_t) ep->dma_addr);
  60712. + }
  60713. + }
  60714. +
  60715. + /** Enable endpoint, clear nak */
  60716. +
  60717. + depctl.d32 = 0;
  60718. + if (ep->bInterval == 1) {
  60719. + dsts.d32 =
  60720. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  60721. + ep->next_frame = dsts.b.soffn + ep->bInterval;
  60722. +
  60723. + if (ep->next_frame & 0x1) {
  60724. + depctl.b.setd1pid = 1;
  60725. + } else {
  60726. + depctl.b.setd0pid = 1;
  60727. + }
  60728. + } else {
  60729. + ep->next_frame += ep->bInterval;
  60730. +
  60731. + if (ep->next_frame & 0x1) {
  60732. + depctl.b.setd1pid = 1;
  60733. + } else {
  60734. + depctl.b.setd0pid = 1;
  60735. + }
  60736. + }
  60737. + depctl.b.epena = 1;
  60738. + depctl.b.cnak = 1;
  60739. +
  60740. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  60741. + depctl.d32 = DWC_READ_REG32(addr);
  60742. +
  60743. + if (ep->is_in && core_if->dma_enable == 0) {
  60744. + write_isoc_frame_data(core_if, ep);
  60745. + }
  60746. +
  60747. +}
  60748. +#endif /* DWC_EN_ISOC */
  60749. +
  60750. +static void dwc_otg_set_uninitialized(int32_t * p, int size)
  60751. +{
  60752. + int i;
  60753. + for (i = 0; i < size; i++) {
  60754. + p[i] = -1;
  60755. + }
  60756. +}
  60757. +
  60758. +static int dwc_otg_param_initialized(int32_t val)
  60759. +{
  60760. + return val != -1;
  60761. +}
  60762. +
  60763. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if)
  60764. +{
  60765. + int i;
  60766. + core_if->core_params = DWC_ALLOC(sizeof(*core_if->core_params));
  60767. + if (!core_if->core_params) {
  60768. + return -DWC_E_NO_MEMORY;
  60769. + }
  60770. + dwc_otg_set_uninitialized((int32_t *) core_if->core_params,
  60771. + sizeof(*core_if->core_params) /
  60772. + sizeof(int32_t));
  60773. + DWC_PRINTF("Setting default values for core params\n");
  60774. + dwc_otg_set_param_otg_cap(core_if, dwc_param_otg_cap_default);
  60775. + dwc_otg_set_param_dma_enable(core_if, dwc_param_dma_enable_default);
  60776. + dwc_otg_set_param_dma_desc_enable(core_if,
  60777. + dwc_param_dma_desc_enable_default);
  60778. + dwc_otg_set_param_opt(core_if, dwc_param_opt_default);
  60779. + dwc_otg_set_param_dma_burst_size(core_if,
  60780. + dwc_param_dma_burst_size_default);
  60781. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  60782. + dwc_param_host_support_fs_ls_low_power_default);
  60783. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  60784. + dwc_param_enable_dynamic_fifo_default);
  60785. + dwc_otg_set_param_data_fifo_size(core_if,
  60786. + dwc_param_data_fifo_size_default);
  60787. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  60788. + dwc_param_dev_rx_fifo_size_default);
  60789. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  60790. + dwc_param_dev_nperio_tx_fifo_size_default);
  60791. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  60792. + dwc_param_host_rx_fifo_size_default);
  60793. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  60794. + dwc_param_host_nperio_tx_fifo_size_default);
  60795. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  60796. + dwc_param_host_perio_tx_fifo_size_default);
  60797. + dwc_otg_set_param_max_transfer_size(core_if,
  60798. + dwc_param_max_transfer_size_default);
  60799. + dwc_otg_set_param_max_packet_count(core_if,
  60800. + dwc_param_max_packet_count_default);
  60801. + dwc_otg_set_param_host_channels(core_if,
  60802. + dwc_param_host_channels_default);
  60803. + dwc_otg_set_param_dev_endpoints(core_if,
  60804. + dwc_param_dev_endpoints_default);
  60805. + dwc_otg_set_param_phy_type(core_if, dwc_param_phy_type_default);
  60806. + dwc_otg_set_param_speed(core_if, dwc_param_speed_default);
  60807. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  60808. + dwc_param_host_ls_low_power_phy_clk_default);
  60809. + dwc_otg_set_param_phy_ulpi_ddr(core_if, dwc_param_phy_ulpi_ddr_default);
  60810. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  60811. + dwc_param_phy_ulpi_ext_vbus_default);
  60812. + dwc_otg_set_param_phy_utmi_width(core_if,
  60813. + dwc_param_phy_utmi_width_default);
  60814. + dwc_otg_set_param_ts_dline(core_if, dwc_param_ts_dline_default);
  60815. + dwc_otg_set_param_i2c_enable(core_if, dwc_param_i2c_enable_default);
  60816. + dwc_otg_set_param_ulpi_fs_ls(core_if, dwc_param_ulpi_fs_ls_default);
  60817. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  60818. + dwc_param_en_multiple_tx_fifo_default);
  60819. + for (i = 0; i < 15; i++) {
  60820. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  60821. + dwc_param_dev_perio_tx_fifo_size_default,
  60822. + i);
  60823. + }
  60824. +
  60825. + for (i = 0; i < 15; i++) {
  60826. + dwc_otg_set_param_dev_tx_fifo_size(core_if,
  60827. + dwc_param_dev_tx_fifo_size_default,
  60828. + i);
  60829. + }
  60830. + dwc_otg_set_param_thr_ctl(core_if, dwc_param_thr_ctl_default);
  60831. + dwc_otg_set_param_mpi_enable(core_if, dwc_param_mpi_enable_default);
  60832. + dwc_otg_set_param_pti_enable(core_if, dwc_param_pti_enable_default);
  60833. + dwc_otg_set_param_lpm_enable(core_if, dwc_param_lpm_enable_default);
  60834. + dwc_otg_set_param_ic_usb_cap(core_if, dwc_param_ic_usb_cap_default);
  60835. + dwc_otg_set_param_tx_thr_length(core_if,
  60836. + dwc_param_tx_thr_length_default);
  60837. + dwc_otg_set_param_rx_thr_length(core_if,
  60838. + dwc_param_rx_thr_length_default);
  60839. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  60840. + dwc_param_ahb_thr_ratio_default);
  60841. + dwc_otg_set_param_power_down(core_if, dwc_param_power_down_default);
  60842. + dwc_otg_set_param_reload_ctl(core_if, dwc_param_reload_ctl_default);
  60843. + dwc_otg_set_param_dev_out_nak(core_if, dwc_param_dev_out_nak_default);
  60844. + dwc_otg_set_param_cont_on_bna(core_if, dwc_param_cont_on_bna_default);
  60845. + dwc_otg_set_param_ahb_single(core_if, dwc_param_ahb_single_default);
  60846. + dwc_otg_set_param_otg_ver(core_if, dwc_param_otg_ver_default);
  60847. + dwc_otg_set_param_adp_enable(core_if, dwc_param_adp_enable_default);
  60848. + DWC_PRINTF("Finished setting default values for core params\n");
  60849. +
  60850. + return 0;
  60851. +}
  60852. +
  60853. +uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if)
  60854. +{
  60855. + return core_if->dma_enable;
  60856. +}
  60857. +
  60858. +/* Checks if the parameter is outside of its valid range of values */
  60859. +#define DWC_OTG_PARAM_TEST(_param_, _low_, _high_) \
  60860. + (((_param_) < (_low_)) || \
  60861. + ((_param_) > (_high_)))
  60862. +
  60863. +/* Parameter access functions */
  60864. +int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val)
  60865. +{
  60866. + int valid;
  60867. + int retval = 0;
  60868. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  60869. + DWC_WARN("Wrong value for otg_cap parameter\n");
  60870. + DWC_WARN("otg_cap parameter must be 0,1 or 2\n");
  60871. + retval = -DWC_E_INVALID;
  60872. + goto out;
  60873. + }
  60874. +
  60875. + valid = 1;
  60876. + switch (val) {
  60877. + case DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE:
  60878. + if (core_if->hwcfg2.b.op_mode !=
  60879. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  60880. + valid = 0;
  60881. + break;
  60882. + case DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE:
  60883. + if ((core_if->hwcfg2.b.op_mode !=
  60884. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  60885. + && (core_if->hwcfg2.b.op_mode !=
  60886. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  60887. + && (core_if->hwcfg2.b.op_mode !=
  60888. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  60889. + && (core_if->hwcfg2.b.op_mode !=
  60890. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) {
  60891. + valid = 0;
  60892. + }
  60893. + break;
  60894. + case DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE:
  60895. + /* always valid */
  60896. + break;
  60897. + }
  60898. + if (!valid) {
  60899. + if (dwc_otg_param_initialized(core_if->core_params->otg_cap)) {
  60900. + DWC_ERROR
  60901. + ("%d invalid for otg_cap paremter. Check HW configuration.\n",
  60902. + val);
  60903. + }
  60904. + val =
  60905. + (((core_if->hwcfg2.b.op_mode ==
  60906. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  60907. + || (core_if->hwcfg2.b.op_mode ==
  60908. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  60909. + || (core_if->hwcfg2.b.op_mode ==
  60910. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  60911. + || (core_if->hwcfg2.b.op_mode ==
  60912. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) ?
  60913. + DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE :
  60914. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  60915. + retval = -DWC_E_INVALID;
  60916. + }
  60917. +
  60918. + core_if->core_params->otg_cap = val;
  60919. +out:
  60920. + return retval;
  60921. +}
  60922. +
  60923. +int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if)
  60924. +{
  60925. + return core_if->core_params->otg_cap;
  60926. +}
  60927. +
  60928. +int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val)
  60929. +{
  60930. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60931. + DWC_WARN("Wrong value for opt parameter\n");
  60932. + return -DWC_E_INVALID;
  60933. + }
  60934. + core_if->core_params->opt = val;
  60935. + return 0;
  60936. +}
  60937. +
  60938. +int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if)
  60939. +{
  60940. + return core_if->core_params->opt;
  60941. +}
  60942. +
  60943. +int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if, int32_t val)
  60944. +{
  60945. + int retval = 0;
  60946. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60947. + DWC_WARN("Wrong value for dma enable\n");
  60948. + return -DWC_E_INVALID;
  60949. + }
  60950. +
  60951. + if ((val == 1) && (core_if->hwcfg2.b.architecture == 0)) {
  60952. + if (dwc_otg_param_initialized(core_if->core_params->dma_enable)) {
  60953. + DWC_ERROR
  60954. + ("%d invalid for dma_enable paremter. Check HW configuration.\n",
  60955. + val);
  60956. + }
  60957. + val = 0;
  60958. + retval = -DWC_E_INVALID;
  60959. + }
  60960. +
  60961. + core_if->core_params->dma_enable = val;
  60962. + if (val == 0) {
  60963. + dwc_otg_set_param_dma_desc_enable(core_if, 0);
  60964. + }
  60965. + return retval;
  60966. +}
  60967. +
  60968. +int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if)
  60969. +{
  60970. + return core_if->core_params->dma_enable;
  60971. +}
  60972. +
  60973. +int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if, int32_t val)
  60974. +{
  60975. + int retval = 0;
  60976. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60977. + DWC_WARN("Wrong value for dma_enable\n");
  60978. + DWC_WARN("dma_desc_enable must be 0 or 1\n");
  60979. + return -DWC_E_INVALID;
  60980. + }
  60981. +
  60982. + if ((val == 1)
  60983. + && ((dwc_otg_get_param_dma_enable(core_if) == 0)
  60984. + || (core_if->hwcfg4.b.desc_dma == 0))) {
  60985. + if (dwc_otg_param_initialized
  60986. + (core_if->core_params->dma_desc_enable)) {
  60987. + DWC_ERROR
  60988. + ("%d invalid for dma_desc_enable paremter. Check HW configuration.\n",
  60989. + val);
  60990. + }
  60991. + val = 0;
  60992. + retval = -DWC_E_INVALID;
  60993. + }
  60994. + core_if->core_params->dma_desc_enable = val;
  60995. + return retval;
  60996. +}
  60997. +
  60998. +int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if)
  60999. +{
  61000. + return core_if->core_params->dma_desc_enable;
  61001. +}
  61002. +
  61003. +int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t * core_if,
  61004. + int32_t val)
  61005. +{
  61006. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61007. + DWC_WARN("Wrong value for host_support_fs_low_power\n");
  61008. + DWC_WARN("host_support_fs_low_power must be 0 or 1\n");
  61009. + return -DWC_E_INVALID;
  61010. + }
  61011. + core_if->core_params->host_support_fs_ls_low_power = val;
  61012. + return 0;
  61013. +}
  61014. +
  61015. +int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  61016. + core_if)
  61017. +{
  61018. + return core_if->core_params->host_support_fs_ls_low_power;
  61019. +}
  61020. +
  61021. +int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  61022. + int32_t val)
  61023. +{
  61024. + int retval = 0;
  61025. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61026. + DWC_WARN("Wrong value for enable_dynamic_fifo\n");
  61027. + DWC_WARN("enable_dynamic_fifo must be 0 or 1\n");
  61028. + return -DWC_E_INVALID;
  61029. + }
  61030. +
  61031. + if ((val == 1) && (core_if->hwcfg2.b.dynamic_fifo == 0)) {
  61032. + if (dwc_otg_param_initialized
  61033. + (core_if->core_params->enable_dynamic_fifo)) {
  61034. + DWC_ERROR
  61035. + ("%d invalid for enable_dynamic_fifo paremter. Check HW configuration.\n",
  61036. + val);
  61037. + }
  61038. + val = 0;
  61039. + retval = -DWC_E_INVALID;
  61040. + }
  61041. + core_if->core_params->enable_dynamic_fifo = val;
  61042. + return retval;
  61043. +}
  61044. +
  61045. +int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if)
  61046. +{
  61047. + return core_if->core_params->enable_dynamic_fifo;
  61048. +}
  61049. +
  61050. +int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  61051. +{
  61052. + int retval = 0;
  61053. + if (DWC_OTG_PARAM_TEST(val, 32, 32768)) {
  61054. + DWC_WARN("Wrong value for data_fifo_size\n");
  61055. + DWC_WARN("data_fifo_size must be 32-32768\n");
  61056. + return -DWC_E_INVALID;
  61057. + }
  61058. +
  61059. + if (val > core_if->hwcfg3.b.dfifo_depth) {
  61060. + if (dwc_otg_param_initialized
  61061. + (core_if->core_params->data_fifo_size)) {
  61062. + DWC_ERROR
  61063. + ("%d invalid for data_fifo_size parameter. Check HW configuration.\n",
  61064. + val);
  61065. + }
  61066. + val = core_if->hwcfg3.b.dfifo_depth;
  61067. + retval = -DWC_E_INVALID;
  61068. + }
  61069. +
  61070. + core_if->core_params->data_fifo_size = val;
  61071. + return retval;
  61072. +}
  61073. +
  61074. +int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if)
  61075. +{
  61076. + return core_if->core_params->data_fifo_size;
  61077. +}
  61078. +
  61079. +int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  61080. +{
  61081. + int retval = 0;
  61082. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61083. + DWC_WARN("Wrong value for dev_rx_fifo_size\n");
  61084. + DWC_WARN("dev_rx_fifo_size must be 16-32768\n");
  61085. + return -DWC_E_INVALID;
  61086. + }
  61087. +
  61088. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  61089. + if (dwc_otg_param_initialized(core_if->core_params->dev_rx_fifo_size)) {
  61090. + DWC_WARN("%d invalid for dev_rx_fifo_size parameter\n", val);
  61091. + }
  61092. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  61093. + retval = -DWC_E_INVALID;
  61094. + }
  61095. +
  61096. + core_if->core_params->dev_rx_fifo_size = val;
  61097. + return retval;
  61098. +}
  61099. +
  61100. +int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if)
  61101. +{
  61102. + return core_if->core_params->dev_rx_fifo_size;
  61103. +}
  61104. +
  61105. +int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61106. + int32_t val)
  61107. +{
  61108. + int retval = 0;
  61109. +
  61110. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61111. + DWC_WARN("Wrong value for dev_nperio_tx_fifo\n");
  61112. + DWC_WARN("dev_nperio_tx_fifo must be 16-32768\n");
  61113. + return -DWC_E_INVALID;
  61114. + }
  61115. +
  61116. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  61117. + if (dwc_otg_param_initialized
  61118. + (core_if->core_params->dev_nperio_tx_fifo_size)) {
  61119. + DWC_ERROR
  61120. + ("%d invalid for dev_nperio_tx_fifo_size. Check HW configuration.\n",
  61121. + val);
  61122. + }
  61123. + val =
  61124. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  61125. + 16);
  61126. + retval = -DWC_E_INVALID;
  61127. + }
  61128. +
  61129. + core_if->core_params->dev_nperio_tx_fifo_size = val;
  61130. + return retval;
  61131. +}
  61132. +
  61133. +int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  61134. +{
  61135. + return core_if->core_params->dev_nperio_tx_fifo_size;
  61136. +}
  61137. +
  61138. +int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  61139. + int32_t val)
  61140. +{
  61141. + int retval = 0;
  61142. +
  61143. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61144. + DWC_WARN("Wrong value for host_rx_fifo_size\n");
  61145. + DWC_WARN("host_rx_fifo_size must be 16-32768\n");
  61146. + return -DWC_E_INVALID;
  61147. + }
  61148. +
  61149. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  61150. + if (dwc_otg_param_initialized
  61151. + (core_if->core_params->host_rx_fifo_size)) {
  61152. + DWC_ERROR
  61153. + ("%d invalid for host_rx_fifo_size. Check HW configuration.\n",
  61154. + val);
  61155. + }
  61156. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  61157. + retval = -DWC_E_INVALID;
  61158. + }
  61159. +
  61160. + core_if->core_params->host_rx_fifo_size = val;
  61161. + return retval;
  61162. +
  61163. +}
  61164. +
  61165. +int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if)
  61166. +{
  61167. + return core_if->core_params->host_rx_fifo_size;
  61168. +}
  61169. +
  61170. +int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61171. + int32_t val)
  61172. +{
  61173. + int retval = 0;
  61174. +
  61175. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61176. + DWC_WARN("Wrong value for host_nperio_tx_fifo_size\n");
  61177. + DWC_WARN("host_nperio_tx_fifo_size must be 16-32768\n");
  61178. + return -DWC_E_INVALID;
  61179. + }
  61180. +
  61181. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  61182. + if (dwc_otg_param_initialized
  61183. + (core_if->core_params->host_nperio_tx_fifo_size)) {
  61184. + DWC_ERROR
  61185. + ("%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n",
  61186. + val);
  61187. + }
  61188. + val =
  61189. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  61190. + 16);
  61191. + retval = -DWC_E_INVALID;
  61192. + }
  61193. +
  61194. + core_if->core_params->host_nperio_tx_fifo_size = val;
  61195. + return retval;
  61196. +}
  61197. +
  61198. +int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  61199. +{
  61200. + return core_if->core_params->host_nperio_tx_fifo_size;
  61201. +}
  61202. +
  61203. +int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61204. + int32_t val)
  61205. +{
  61206. + int retval = 0;
  61207. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  61208. + DWC_WARN("Wrong value for host_perio_tx_fifo_size\n");
  61209. + DWC_WARN("host_perio_tx_fifo_size must be 16-32768\n");
  61210. + return -DWC_E_INVALID;
  61211. + }
  61212. +
  61213. + if (val > ((core_if->hptxfsiz.d32) >> 16)) {
  61214. + if (dwc_otg_param_initialized
  61215. + (core_if->core_params->host_perio_tx_fifo_size)) {
  61216. + DWC_ERROR
  61217. + ("%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n",
  61218. + val);
  61219. + }
  61220. + val = (core_if->hptxfsiz.d32) >> 16;
  61221. + retval = -DWC_E_INVALID;
  61222. + }
  61223. +
  61224. + core_if->core_params->host_perio_tx_fifo_size = val;
  61225. + return retval;
  61226. +}
  61227. +
  61228. +int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  61229. +{
  61230. + return core_if->core_params->host_perio_tx_fifo_size;
  61231. +}
  61232. +
  61233. +int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  61234. + int32_t val)
  61235. +{
  61236. + int retval = 0;
  61237. +
  61238. + if (DWC_OTG_PARAM_TEST(val, 2047, 524288)) {
  61239. + DWC_WARN("Wrong value for max_transfer_size\n");
  61240. + DWC_WARN("max_transfer_size must be 2047-524288\n");
  61241. + return -DWC_E_INVALID;
  61242. + }
  61243. +
  61244. + if (val >= (1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11))) {
  61245. + if (dwc_otg_param_initialized
  61246. + (core_if->core_params->max_transfer_size)) {
  61247. + DWC_ERROR
  61248. + ("%d invalid for max_transfer_size. Check HW configuration.\n",
  61249. + val);
  61250. + }
  61251. + val =
  61252. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 11)) -
  61253. + 1);
  61254. + retval = -DWC_E_INVALID;
  61255. + }
  61256. +
  61257. + core_if->core_params->max_transfer_size = val;
  61258. + return retval;
  61259. +}
  61260. +
  61261. +int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if)
  61262. +{
  61263. + return core_if->core_params->max_transfer_size;
  61264. +}
  61265. +
  61266. +int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if, int32_t val)
  61267. +{
  61268. + int retval = 0;
  61269. +
  61270. + if (DWC_OTG_PARAM_TEST(val, 15, 511)) {
  61271. + DWC_WARN("Wrong value for max_packet_count\n");
  61272. + DWC_WARN("max_packet_count must be 15-511\n");
  61273. + return -DWC_E_INVALID;
  61274. + }
  61275. +
  61276. + if (val > (1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4))) {
  61277. + if (dwc_otg_param_initialized
  61278. + (core_if->core_params->max_packet_count)) {
  61279. + DWC_ERROR
  61280. + ("%d invalid for max_packet_count. Check HW configuration.\n",
  61281. + val);
  61282. + }
  61283. + val =
  61284. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1);
  61285. + retval = -DWC_E_INVALID;
  61286. + }
  61287. +
  61288. + core_if->core_params->max_packet_count = val;
  61289. + return retval;
  61290. +}
  61291. +
  61292. +int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if)
  61293. +{
  61294. + return core_if->core_params->max_packet_count;
  61295. +}
  61296. +
  61297. +int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if, int32_t val)
  61298. +{
  61299. + int retval = 0;
  61300. +
  61301. + if (DWC_OTG_PARAM_TEST(val, 1, 16)) {
  61302. + DWC_WARN("Wrong value for host_channels\n");
  61303. + DWC_WARN("host_channels must be 1-16\n");
  61304. + return -DWC_E_INVALID;
  61305. + }
  61306. +
  61307. + if (val > (core_if->hwcfg2.b.num_host_chan + 1)) {
  61308. + if (dwc_otg_param_initialized
  61309. + (core_if->core_params->host_channels)) {
  61310. + DWC_ERROR
  61311. + ("%d invalid for host_channels. Check HW configurations.\n",
  61312. + val);
  61313. + }
  61314. + val = (core_if->hwcfg2.b.num_host_chan + 1);
  61315. + retval = -DWC_E_INVALID;
  61316. + }
  61317. +
  61318. + core_if->core_params->host_channels = val;
  61319. + return retval;
  61320. +}
  61321. +
  61322. +int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if)
  61323. +{
  61324. + return core_if->core_params->host_channels;
  61325. +}
  61326. +
  61327. +int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if, int32_t val)
  61328. +{
  61329. + int retval = 0;
  61330. +
  61331. + if (DWC_OTG_PARAM_TEST(val, 1, 15)) {
  61332. + DWC_WARN("Wrong value for dev_endpoints\n");
  61333. + DWC_WARN("dev_endpoints must be 1-15\n");
  61334. + return -DWC_E_INVALID;
  61335. + }
  61336. +
  61337. + if (val > (core_if->hwcfg2.b.num_dev_ep)) {
  61338. + if (dwc_otg_param_initialized
  61339. + (core_if->core_params->dev_endpoints)) {
  61340. + DWC_ERROR
  61341. + ("%d invalid for dev_endpoints. Check HW configurations.\n",
  61342. + val);
  61343. + }
  61344. + val = core_if->hwcfg2.b.num_dev_ep;
  61345. + retval = -DWC_E_INVALID;
  61346. + }
  61347. +
  61348. + core_if->core_params->dev_endpoints = val;
  61349. + return retval;
  61350. +}
  61351. +
  61352. +int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if)
  61353. +{
  61354. + return core_if->core_params->dev_endpoints;
  61355. +}
  61356. +
  61357. +int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val)
  61358. +{
  61359. + int retval = 0;
  61360. + int valid = 0;
  61361. +
  61362. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  61363. + DWC_WARN("Wrong value for phy_type\n");
  61364. + DWC_WARN("phy_type must be 0,1 or 2\n");
  61365. + return -DWC_E_INVALID;
  61366. + }
  61367. +#ifndef NO_FS_PHY_HW_CHECKS
  61368. + if ((val == DWC_PHY_TYPE_PARAM_UTMI) &&
  61369. + ((core_if->hwcfg2.b.hs_phy_type == 1) ||
  61370. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  61371. + valid = 1;
  61372. + } else if ((val == DWC_PHY_TYPE_PARAM_ULPI) &&
  61373. + ((core_if->hwcfg2.b.hs_phy_type == 2) ||
  61374. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  61375. + valid = 1;
  61376. + } else if ((val == DWC_PHY_TYPE_PARAM_FS) &&
  61377. + (core_if->hwcfg2.b.fs_phy_type == 1)) {
  61378. + valid = 1;
  61379. + }
  61380. + if (!valid) {
  61381. + if (dwc_otg_param_initialized(core_if->core_params->phy_type)) {
  61382. + DWC_ERROR
  61383. + ("%d invalid for phy_type. Check HW configurations.\n",
  61384. + val);
  61385. + }
  61386. + if (core_if->hwcfg2.b.hs_phy_type) {
  61387. + if ((core_if->hwcfg2.b.hs_phy_type == 3) ||
  61388. + (core_if->hwcfg2.b.hs_phy_type == 1)) {
  61389. + val = DWC_PHY_TYPE_PARAM_UTMI;
  61390. + } else {
  61391. + val = DWC_PHY_TYPE_PARAM_ULPI;
  61392. + }
  61393. + }
  61394. + retval = -DWC_E_INVALID;
  61395. + }
  61396. +#endif
  61397. + core_if->core_params->phy_type = val;
  61398. + return retval;
  61399. +}
  61400. +
  61401. +int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if)
  61402. +{
  61403. + return core_if->core_params->phy_type;
  61404. +}
  61405. +
  61406. +int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val)
  61407. +{
  61408. + int retval = 0;
  61409. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61410. + DWC_WARN("Wrong value for speed parameter\n");
  61411. + DWC_WARN("max_speed parameter must be 0 or 1\n");
  61412. + return -DWC_E_INVALID;
  61413. + }
  61414. + if ((val == 0)
  61415. + && dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS) {
  61416. + if (dwc_otg_param_initialized(core_if->core_params->speed)) {
  61417. + DWC_ERROR
  61418. + ("%d invalid for speed paremter. Check HW configuration.\n",
  61419. + val);
  61420. + }
  61421. + val =
  61422. + (dwc_otg_get_param_phy_type(core_if) ==
  61423. + DWC_PHY_TYPE_PARAM_FS ? 1 : 0);
  61424. + retval = -DWC_E_INVALID;
  61425. + }
  61426. + core_if->core_params->speed = val;
  61427. + return retval;
  61428. +}
  61429. +
  61430. +int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if)
  61431. +{
  61432. + return core_if->core_params->speed;
  61433. +}
  61434. +
  61435. +int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if,
  61436. + int32_t val)
  61437. +{
  61438. + int retval = 0;
  61439. +
  61440. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61441. + DWC_WARN
  61442. + ("Wrong value for host_ls_low_power_phy_clk parameter\n");
  61443. + DWC_WARN("host_ls_low_power_phy_clk must be 0 or 1\n");
  61444. + return -DWC_E_INVALID;
  61445. + }
  61446. +
  61447. + if ((val == DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ)
  61448. + && (dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS)) {
  61449. + if (dwc_otg_param_initialized
  61450. + (core_if->core_params->host_ls_low_power_phy_clk)) {
  61451. + DWC_ERROR
  61452. + ("%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n",
  61453. + val);
  61454. + }
  61455. + val =
  61456. + (dwc_otg_get_param_phy_type(core_if) ==
  61457. + DWC_PHY_TYPE_PARAM_FS) ?
  61458. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ :
  61459. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ;
  61460. + retval = -DWC_E_INVALID;
  61461. + }
  61462. +
  61463. + core_if->core_params->host_ls_low_power_phy_clk = val;
  61464. + return retval;
  61465. +}
  61466. +
  61467. +int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if)
  61468. +{
  61469. + return core_if->core_params->host_ls_low_power_phy_clk;
  61470. +}
  61471. +
  61472. +int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if, int32_t val)
  61473. +{
  61474. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61475. + DWC_WARN("Wrong value for phy_ulpi_ddr\n");
  61476. + DWC_WARN("phy_upli_ddr must be 0 or 1\n");
  61477. + return -DWC_E_INVALID;
  61478. + }
  61479. +
  61480. + core_if->core_params->phy_ulpi_ddr = val;
  61481. + return 0;
  61482. +}
  61483. +
  61484. +int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if)
  61485. +{
  61486. + return core_if->core_params->phy_ulpi_ddr;
  61487. +}
  61488. +
  61489. +int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  61490. + int32_t val)
  61491. +{
  61492. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61493. + DWC_WARN("Wrong valaue for phy_ulpi_ext_vbus\n");
  61494. + DWC_WARN("phy_ulpi_ext_vbus must be 0 or 1\n");
  61495. + return -DWC_E_INVALID;
  61496. + }
  61497. +
  61498. + core_if->core_params->phy_ulpi_ext_vbus = val;
  61499. + return 0;
  61500. +}
  61501. +
  61502. +int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if)
  61503. +{
  61504. + return core_if->core_params->phy_ulpi_ext_vbus;
  61505. +}
  61506. +
  61507. +int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if, int32_t val)
  61508. +{
  61509. + if (DWC_OTG_PARAM_TEST(val, 8, 8) && DWC_OTG_PARAM_TEST(val, 16, 16)) {
  61510. + DWC_WARN("Wrong valaue for phy_utmi_width\n");
  61511. + DWC_WARN("phy_utmi_width must be 8 or 16\n");
  61512. + return -DWC_E_INVALID;
  61513. + }
  61514. +
  61515. + core_if->core_params->phy_utmi_width = val;
  61516. + return 0;
  61517. +}
  61518. +
  61519. +int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if)
  61520. +{
  61521. + return core_if->core_params->phy_utmi_width;
  61522. +}
  61523. +
  61524. +int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if, int32_t val)
  61525. +{
  61526. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61527. + DWC_WARN("Wrong valaue for ulpi_fs_ls\n");
  61528. + DWC_WARN("ulpi_fs_ls must be 0 or 1\n");
  61529. + return -DWC_E_INVALID;
  61530. + }
  61531. +
  61532. + core_if->core_params->ulpi_fs_ls = val;
  61533. + return 0;
  61534. +}
  61535. +
  61536. +int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if)
  61537. +{
  61538. + return core_if->core_params->ulpi_fs_ls;
  61539. +}
  61540. +
  61541. +int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val)
  61542. +{
  61543. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61544. + DWC_WARN("Wrong valaue for ts_dline\n");
  61545. + DWC_WARN("ts_dline must be 0 or 1\n");
  61546. + return -DWC_E_INVALID;
  61547. + }
  61548. +
  61549. + core_if->core_params->ts_dline = val;
  61550. + return 0;
  61551. +}
  61552. +
  61553. +int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if)
  61554. +{
  61555. + return core_if->core_params->ts_dline;
  61556. +}
  61557. +
  61558. +int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61559. +{
  61560. + int retval = 0;
  61561. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61562. + DWC_WARN("Wrong valaue for i2c_enable\n");
  61563. + DWC_WARN("i2c_enable must be 0 or 1\n");
  61564. + return -DWC_E_INVALID;
  61565. + }
  61566. +#ifndef NO_FS_PHY_HW_CHECK
  61567. + if (val == 1 && core_if->hwcfg3.b.i2c == 0) {
  61568. + if (dwc_otg_param_initialized(core_if->core_params->i2c_enable)) {
  61569. + DWC_ERROR
  61570. + ("%d invalid for i2c_enable. Check HW configuration.\n",
  61571. + val);
  61572. + }
  61573. + val = 0;
  61574. + retval = -DWC_E_INVALID;
  61575. + }
  61576. +#endif
  61577. +
  61578. + core_if->core_params->i2c_enable = val;
  61579. + return retval;
  61580. +}
  61581. +
  61582. +int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if)
  61583. +{
  61584. + return core_if->core_params->i2c_enable;
  61585. +}
  61586. +
  61587. +int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61588. + int32_t val, int fifo_num)
  61589. +{
  61590. + int retval = 0;
  61591. +
  61592. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  61593. + DWC_WARN("Wrong value for dev_perio_tx_fifo_size\n");
  61594. + DWC_WARN("dev_perio_tx_fifo_size must be 4-768\n");
  61595. + return -DWC_E_INVALID;
  61596. + }
  61597. +
  61598. + if (val >
  61599. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  61600. + if (dwc_otg_param_initialized
  61601. + (core_if->core_params->dev_perio_tx_fifo_size[fifo_num])) {
  61602. + DWC_ERROR
  61603. + ("`%d' invalid for parameter `dev_perio_fifo_size_%d'. Check HW configuration.\n",
  61604. + val, fifo_num);
  61605. + }
  61606. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  61607. + retval = -DWC_E_INVALID;
  61608. + }
  61609. +
  61610. + core_if->core_params->dev_perio_tx_fifo_size[fifo_num] = val;
  61611. + return retval;
  61612. +}
  61613. +
  61614. +int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61615. + int fifo_num)
  61616. +{
  61617. + return core_if->core_params->dev_perio_tx_fifo_size[fifo_num];
  61618. +}
  61619. +
  61620. +int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  61621. + int32_t val)
  61622. +{
  61623. + int retval = 0;
  61624. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61625. + DWC_WARN("Wrong valaue for en_multiple_tx_fifo,\n");
  61626. + DWC_WARN("en_multiple_tx_fifo must be 0 or 1\n");
  61627. + return -DWC_E_INVALID;
  61628. + }
  61629. +
  61630. + if (val == 1 && core_if->hwcfg4.b.ded_fifo_en == 0) {
  61631. + if (dwc_otg_param_initialized
  61632. + (core_if->core_params->en_multiple_tx_fifo)) {
  61633. + DWC_ERROR
  61634. + ("%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n",
  61635. + val);
  61636. + }
  61637. + val = 0;
  61638. + retval = -DWC_E_INVALID;
  61639. + }
  61640. +
  61641. + core_if->core_params->en_multiple_tx_fifo = val;
  61642. + return retval;
  61643. +}
  61644. +
  61645. +int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if)
  61646. +{
  61647. + return core_if->core_params->en_multiple_tx_fifo;
  61648. +}
  61649. +
  61650. +int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val,
  61651. + int fifo_num)
  61652. +{
  61653. + int retval = 0;
  61654. +
  61655. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  61656. + DWC_WARN("Wrong value for dev_tx_fifo_size\n");
  61657. + DWC_WARN("dev_tx_fifo_size must be 4-768\n");
  61658. + return -DWC_E_INVALID;
  61659. + }
  61660. +
  61661. + if (val >
  61662. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  61663. + if (dwc_otg_param_initialized
  61664. + (core_if->core_params->dev_tx_fifo_size[fifo_num])) {
  61665. + DWC_ERROR
  61666. + ("`%d' invalid for parameter `dev_tx_fifo_size_%d'. Check HW configuration.\n",
  61667. + val, fifo_num);
  61668. + }
  61669. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  61670. + retval = -DWC_E_INVALID;
  61671. + }
  61672. +
  61673. + core_if->core_params->dev_tx_fifo_size[fifo_num] = val;
  61674. + return retval;
  61675. +}
  61676. +
  61677. +int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61678. + int fifo_num)
  61679. +{
  61680. + return core_if->core_params->dev_tx_fifo_size[fifo_num];
  61681. +}
  61682. +
  61683. +int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  61684. +{
  61685. + int retval = 0;
  61686. +
  61687. + if (DWC_OTG_PARAM_TEST(val, 0, 7)) {
  61688. + DWC_WARN("Wrong value for thr_ctl\n");
  61689. + DWC_WARN("thr_ctl must be 0-7\n");
  61690. + return -DWC_E_INVALID;
  61691. + }
  61692. +
  61693. + if ((val != 0) &&
  61694. + (!dwc_otg_get_param_dma_enable(core_if) ||
  61695. + !core_if->hwcfg4.b.ded_fifo_en)) {
  61696. + if (dwc_otg_param_initialized(core_if->core_params->thr_ctl)) {
  61697. + DWC_ERROR
  61698. + ("%d invalid for parameter thr_ctl. Check HW configuration.\n",
  61699. + val);
  61700. + }
  61701. + val = 0;
  61702. + retval = -DWC_E_INVALID;
  61703. + }
  61704. +
  61705. + core_if->core_params->thr_ctl = val;
  61706. + return retval;
  61707. +}
  61708. +
  61709. +int32_t dwc_otg_get_param_thr_ctl(dwc_otg_core_if_t * core_if)
  61710. +{
  61711. + return core_if->core_params->thr_ctl;
  61712. +}
  61713. +
  61714. +int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61715. +{
  61716. + int retval = 0;
  61717. +
  61718. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61719. + DWC_WARN("Wrong value for lpm_enable\n");
  61720. + DWC_WARN("lpm_enable must be 0 or 1\n");
  61721. + return -DWC_E_INVALID;
  61722. + }
  61723. +
  61724. + if (val && !core_if->hwcfg3.b.otg_lpm_en) {
  61725. + if (dwc_otg_param_initialized(core_if->core_params->lpm_enable)) {
  61726. + DWC_ERROR
  61727. + ("%d invalid for parameter lpm_enable. Check HW configuration.\n",
  61728. + val);
  61729. + }
  61730. + val = 0;
  61731. + retval = -DWC_E_INVALID;
  61732. + }
  61733. +
  61734. + core_if->core_params->lpm_enable = val;
  61735. + return retval;
  61736. +}
  61737. +
  61738. +int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if)
  61739. +{
  61740. + return core_if->core_params->lpm_enable;
  61741. +}
  61742. +
  61743. +int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  61744. +{
  61745. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  61746. + DWC_WARN("Wrong valaue for tx_thr_length\n");
  61747. + DWC_WARN("tx_thr_length must be 8 - 128\n");
  61748. + return -DWC_E_INVALID;
  61749. + }
  61750. +
  61751. + core_if->core_params->tx_thr_length = val;
  61752. + return 0;
  61753. +}
  61754. +
  61755. +int32_t dwc_otg_get_param_tx_thr_length(dwc_otg_core_if_t * core_if)
  61756. +{
  61757. + return core_if->core_params->tx_thr_length;
  61758. +}
  61759. +
  61760. +int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  61761. +{
  61762. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  61763. + DWC_WARN("Wrong valaue for rx_thr_length\n");
  61764. + DWC_WARN("rx_thr_length must be 8 - 128\n");
  61765. + return -DWC_E_INVALID;
  61766. + }
  61767. +
  61768. + core_if->core_params->rx_thr_length = val;
  61769. + return 0;
  61770. +}
  61771. +
  61772. +int32_t dwc_otg_get_param_rx_thr_length(dwc_otg_core_if_t * core_if)
  61773. +{
  61774. + return core_if->core_params->rx_thr_length;
  61775. +}
  61776. +
  61777. +int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if, int32_t val)
  61778. +{
  61779. + if (DWC_OTG_PARAM_TEST(val, 1, 1) &&
  61780. + DWC_OTG_PARAM_TEST(val, 4, 4) &&
  61781. + DWC_OTG_PARAM_TEST(val, 8, 8) &&
  61782. + DWC_OTG_PARAM_TEST(val, 16, 16) &&
  61783. + DWC_OTG_PARAM_TEST(val, 32, 32) &&
  61784. + DWC_OTG_PARAM_TEST(val, 64, 64) &&
  61785. + DWC_OTG_PARAM_TEST(val, 128, 128) &&
  61786. + DWC_OTG_PARAM_TEST(val, 256, 256)) {
  61787. + DWC_WARN("`%d' invalid for parameter `dma_burst_size'\n", val);
  61788. + return -DWC_E_INVALID;
  61789. + }
  61790. + core_if->core_params->dma_burst_size = val;
  61791. + return 0;
  61792. +}
  61793. +
  61794. +int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if)
  61795. +{
  61796. + return core_if->core_params->dma_burst_size;
  61797. +}
  61798. +
  61799. +int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61800. +{
  61801. + int retval = 0;
  61802. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61803. + DWC_WARN("`%d' invalid for parameter `pti_enable'\n", val);
  61804. + return -DWC_E_INVALID;
  61805. + }
  61806. + if (val && (core_if->snpsid < OTG_CORE_REV_2_72a)) {
  61807. + if (dwc_otg_param_initialized(core_if->core_params->pti_enable)) {
  61808. + DWC_ERROR
  61809. + ("%d invalid for parameter pti_enable. Check HW configuration.\n",
  61810. + val);
  61811. + }
  61812. + retval = -DWC_E_INVALID;
  61813. + val = 0;
  61814. + }
  61815. + core_if->core_params->pti_enable = val;
  61816. + return retval;
  61817. +}
  61818. +
  61819. +int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if)
  61820. +{
  61821. + return core_if->core_params->pti_enable;
  61822. +}
  61823. +
  61824. +int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61825. +{
  61826. + int retval = 0;
  61827. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61828. + DWC_WARN("`%d' invalid for parameter `mpi_enable'\n", val);
  61829. + return -DWC_E_INVALID;
  61830. + }
  61831. + if (val && (core_if->hwcfg2.b.multi_proc_int == 0)) {
  61832. + if (dwc_otg_param_initialized(core_if->core_params->mpi_enable)) {
  61833. + DWC_ERROR
  61834. + ("%d invalid for parameter mpi_enable. Check HW configuration.\n",
  61835. + val);
  61836. + }
  61837. + retval = -DWC_E_INVALID;
  61838. + val = 0;
  61839. + }
  61840. + core_if->core_params->mpi_enable = val;
  61841. + return retval;
  61842. +}
  61843. +
  61844. +int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if)
  61845. +{
  61846. + return core_if->core_params->mpi_enable;
  61847. +}
  61848. +
  61849. +int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61850. +{
  61851. + int retval = 0;
  61852. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61853. + DWC_WARN("`%d' invalid for parameter `adp_enable'\n", val);
  61854. + return -DWC_E_INVALID;
  61855. + }
  61856. + if (val && (core_if->hwcfg3.b.adp_supp == 0)) {
  61857. + if (dwc_otg_param_initialized
  61858. + (core_if->core_params->adp_supp_enable)) {
  61859. + DWC_ERROR
  61860. + ("%d invalid for parameter adp_enable. Check HW configuration.\n",
  61861. + val);
  61862. + }
  61863. + retval = -DWC_E_INVALID;
  61864. + val = 0;
  61865. + }
  61866. + core_if->core_params->adp_supp_enable = val;
  61867. + /*Set OTG version 2.0 in case of enabling ADP*/
  61868. + if (val)
  61869. + dwc_otg_set_param_otg_ver(core_if, 1);
  61870. +
  61871. + return retval;
  61872. +}
  61873. +
  61874. +int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if)
  61875. +{
  61876. + return core_if->core_params->adp_supp_enable;
  61877. +}
  61878. +
  61879. +int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if, int32_t val)
  61880. +{
  61881. + int retval = 0;
  61882. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61883. + DWC_WARN("`%d' invalid for parameter `ic_usb_cap'\n", val);
  61884. + DWC_WARN("ic_usb_cap must be 0 or 1\n");
  61885. + return -DWC_E_INVALID;
  61886. + }
  61887. +
  61888. + if (val && (core_if->hwcfg2.b.otg_enable_ic_usb == 0)) {
  61889. + if (dwc_otg_param_initialized(core_if->core_params->ic_usb_cap)) {
  61890. + DWC_ERROR
  61891. + ("%d invalid for parameter ic_usb_cap. Check HW configuration.\n",
  61892. + val);
  61893. + }
  61894. + retval = -DWC_E_INVALID;
  61895. + val = 0;
  61896. + }
  61897. + core_if->core_params->ic_usb_cap = val;
  61898. + return retval;
  61899. +}
  61900. +
  61901. +int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if)
  61902. +{
  61903. + return core_if->core_params->ic_usb_cap;
  61904. +}
  61905. +
  61906. +int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if, int32_t val)
  61907. +{
  61908. + int retval = 0;
  61909. + int valid = 1;
  61910. +
  61911. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  61912. + DWC_WARN("`%d' invalid for parameter `ahb_thr_ratio'\n", val);
  61913. + DWC_WARN("ahb_thr_ratio must be 0 - 3\n");
  61914. + return -DWC_E_INVALID;
  61915. + }
  61916. +
  61917. + if (val
  61918. + && (core_if->snpsid < OTG_CORE_REV_2_81a
  61919. + || !dwc_otg_get_param_thr_ctl(core_if))) {
  61920. + valid = 0;
  61921. + } else if (val
  61922. + && ((dwc_otg_get_param_tx_thr_length(core_if) / (1 << val)) <
  61923. + 4)) {
  61924. + valid = 0;
  61925. + }
  61926. + if (valid == 0) {
  61927. + if (dwc_otg_param_initialized
  61928. + (core_if->core_params->ahb_thr_ratio)) {
  61929. + DWC_ERROR
  61930. + ("%d invalid for parameter ahb_thr_ratio. Check HW configuration.\n",
  61931. + val);
  61932. + }
  61933. + retval = -DWC_E_INVALID;
  61934. + val = 0;
  61935. + }
  61936. +
  61937. + core_if->core_params->ahb_thr_ratio = val;
  61938. + return retval;
  61939. +}
  61940. +
  61941. +int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if)
  61942. +{
  61943. + return core_if->core_params->ahb_thr_ratio;
  61944. +}
  61945. +
  61946. +int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if, int32_t val)
  61947. +{
  61948. + int retval = 0;
  61949. + int valid = 1;
  61950. + hwcfg4_data_t hwcfg4 = {.d32 = 0 };
  61951. + hwcfg4.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  61952. +
  61953. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  61954. + DWC_WARN("`%d' invalid for parameter `power_down'\n", val);
  61955. + DWC_WARN("power_down must be 0 - 2\n");
  61956. + return -DWC_E_INVALID;
  61957. + }
  61958. +
  61959. + if ((val == 2) && (core_if->snpsid < OTG_CORE_REV_2_91a)) {
  61960. + valid = 0;
  61961. + }
  61962. + if ((val == 3)
  61963. + && ((core_if->snpsid < OTG_CORE_REV_3_00a)
  61964. + || (hwcfg4.b.xhiber == 0))) {
  61965. + valid = 0;
  61966. + }
  61967. + if (valid == 0) {
  61968. + if (dwc_otg_param_initialized(core_if->core_params->power_down)) {
  61969. + DWC_ERROR
  61970. + ("%d invalid for parameter power_down. Check HW configuration.\n",
  61971. + val);
  61972. + }
  61973. + retval = -DWC_E_INVALID;
  61974. + val = 0;
  61975. + }
  61976. + core_if->core_params->power_down = val;
  61977. + return retval;
  61978. +}
  61979. +
  61980. +int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if)
  61981. +{
  61982. + return core_if->core_params->power_down;
  61983. +}
  61984. +
  61985. +int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  61986. +{
  61987. + int retval = 0;
  61988. + int valid = 1;
  61989. +
  61990. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61991. + DWC_WARN("`%d' invalid for parameter `reload_ctl'\n", val);
  61992. + DWC_WARN("reload_ctl must be 0 or 1\n");
  61993. + return -DWC_E_INVALID;
  61994. + }
  61995. +
  61996. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_92a)) {
  61997. + valid = 0;
  61998. + }
  61999. + if (valid == 0) {
  62000. + if (dwc_otg_param_initialized(core_if->core_params->reload_ctl)) {
  62001. + DWC_ERROR("%d invalid for parameter reload_ctl."
  62002. + "Check HW configuration.\n", val);
  62003. + }
  62004. + retval = -DWC_E_INVALID;
  62005. + val = 0;
  62006. + }
  62007. + core_if->core_params->reload_ctl = val;
  62008. + return retval;
  62009. +}
  62010. +
  62011. +int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if)
  62012. +{
  62013. + return core_if->core_params->reload_ctl;
  62014. +}
  62015. +
  62016. +int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if, int32_t val)
  62017. +{
  62018. + int retval = 0;
  62019. + int valid = 1;
  62020. +
  62021. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62022. + DWC_WARN("`%d' invalid for parameter `dev_out_nak'\n", val);
  62023. + DWC_WARN("dev_out_nak must be 0 or 1\n");
  62024. + return -DWC_E_INVALID;
  62025. + }
  62026. +
  62027. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_93a) ||
  62028. + !(core_if->core_params->dma_desc_enable))) {
  62029. + valid = 0;
  62030. + }
  62031. + if (valid == 0) {
  62032. + if (dwc_otg_param_initialized(core_if->core_params->dev_out_nak)) {
  62033. + DWC_ERROR("%d invalid for parameter dev_out_nak."
  62034. + "Check HW configuration.\n", val);
  62035. + }
  62036. + retval = -DWC_E_INVALID;
  62037. + val = 0;
  62038. + }
  62039. + core_if->core_params->dev_out_nak = val;
  62040. + return retval;
  62041. +}
  62042. +
  62043. +int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if)
  62044. +{
  62045. + return core_if->core_params->dev_out_nak;
  62046. +}
  62047. +
  62048. +int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if, int32_t val)
  62049. +{
  62050. + int retval = 0;
  62051. + int valid = 1;
  62052. +
  62053. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62054. + DWC_WARN("`%d' invalid for parameter `cont_on_bna'\n", val);
  62055. + DWC_WARN("cont_on_bna must be 0 or 1\n");
  62056. + return -DWC_E_INVALID;
  62057. + }
  62058. +
  62059. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_94a) ||
  62060. + !(core_if->core_params->dma_desc_enable))) {
  62061. + valid = 0;
  62062. + }
  62063. + if (valid == 0) {
  62064. + if (dwc_otg_param_initialized(core_if->core_params->cont_on_bna)) {
  62065. + DWC_ERROR("%d invalid for parameter cont_on_bna."
  62066. + "Check HW configuration.\n", val);
  62067. + }
  62068. + retval = -DWC_E_INVALID;
  62069. + val = 0;
  62070. + }
  62071. + core_if->core_params->cont_on_bna = val;
  62072. + return retval;
  62073. +}
  62074. +
  62075. +int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if)
  62076. +{
  62077. + return core_if->core_params->cont_on_bna;
  62078. +}
  62079. +
  62080. +int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if, int32_t val)
  62081. +{
  62082. + int retval = 0;
  62083. + int valid = 1;
  62084. +
  62085. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62086. + DWC_WARN("`%d' invalid for parameter `ahb_single'\n", val);
  62087. + DWC_WARN("ahb_single must be 0 or 1\n");
  62088. + return -DWC_E_INVALID;
  62089. + }
  62090. +
  62091. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  62092. + valid = 0;
  62093. + }
  62094. + if (valid == 0) {
  62095. + if (dwc_otg_param_initialized(core_if->core_params->ahb_single)) {
  62096. + DWC_ERROR("%d invalid for parameter ahb_single."
  62097. + "Check HW configuration.\n", val);
  62098. + }
  62099. + retval = -DWC_E_INVALID;
  62100. + val = 0;
  62101. + }
  62102. + core_if->core_params->ahb_single = val;
  62103. + return retval;
  62104. +}
  62105. +
  62106. +int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if)
  62107. +{
  62108. + return core_if->core_params->ahb_single;
  62109. +}
  62110. +
  62111. +int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val)
  62112. +{
  62113. + int retval = 0;
  62114. +
  62115. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  62116. + DWC_WARN("`%d' invalid for parameter `otg_ver'\n", val);
  62117. + DWC_WARN
  62118. + ("otg_ver must be 0(for OTG 1.3 support) or 1(for OTG 2.0 support)\n");
  62119. + return -DWC_E_INVALID;
  62120. + }
  62121. +
  62122. + core_if->core_params->otg_ver = val;
  62123. + return retval;
  62124. +}
  62125. +
  62126. +int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if)
  62127. +{
  62128. + return core_if->core_params->otg_ver;
  62129. +}
  62130. +
  62131. +uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if)
  62132. +{
  62133. + gotgctl_data_t otgctl;
  62134. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  62135. + return otgctl.b.hstnegscs;
  62136. +}
  62137. +
  62138. +uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if)
  62139. +{
  62140. + gotgctl_data_t otgctl;
  62141. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  62142. + return otgctl.b.sesreqscs;
  62143. +}
  62144. +
  62145. +void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val)
  62146. +{
  62147. + if(core_if->otg_ver == 0) {
  62148. + gotgctl_data_t otgctl;
  62149. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  62150. + otgctl.b.hnpreq = val;
  62151. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, otgctl.d32);
  62152. + } else {
  62153. + core_if->otg_sts = val;
  62154. + }
  62155. +}
  62156. +
  62157. +uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if)
  62158. +{
  62159. + return core_if->snpsid;
  62160. +}
  62161. +
  62162. +uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if)
  62163. +{
  62164. + gintsts_data_t gintsts;
  62165. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  62166. + return gintsts.b.curmode;
  62167. +}
  62168. +
  62169. +uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if)
  62170. +{
  62171. + gusbcfg_data_t usbcfg;
  62172. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62173. + return usbcfg.b.hnpcap;
  62174. +}
  62175. +
  62176. +void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  62177. +{
  62178. + gusbcfg_data_t usbcfg;
  62179. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62180. + usbcfg.b.hnpcap = val;
  62181. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  62182. +}
  62183. +
  62184. +uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if)
  62185. +{
  62186. + gusbcfg_data_t usbcfg;
  62187. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62188. + return usbcfg.b.srpcap;
  62189. +}
  62190. +
  62191. +void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  62192. +{
  62193. + gusbcfg_data_t usbcfg;
  62194. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62195. + usbcfg.b.srpcap = val;
  62196. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  62197. +}
  62198. +
  62199. +uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if)
  62200. +{
  62201. + dcfg_data_t dcfg;
  62202. + /* originally: dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg); */
  62203. +
  62204. + dcfg.d32 = -1; //GRAYG
  62205. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)\n", __func__, core_if);
  62206. + if (NULL == core_if)
  62207. + DWC_ERROR("reg request with NULL core_if\n");
  62208. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)\n", __func__,
  62209. + core_if, core_if->dev_if);
  62210. + if (NULL == core_if->dev_if)
  62211. + DWC_ERROR("reg request with NULL dev_if\n");
  62212. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)->"
  62213. + "dev_global_regs(%p)\n", __func__,
  62214. + core_if, core_if->dev_if,
  62215. + core_if->dev_if->dev_global_regs);
  62216. + if (NULL == core_if->dev_if->dev_global_regs)
  62217. + DWC_ERROR("reg request with NULL dev_global_regs\n");
  62218. + else {
  62219. + DWC_DEBUGPL(DBG_CILV, "%s - &core_if(%p)->dev_if(%p)->"
  62220. + "dev_global_regs(%p)->dcfg = %p\n", __func__,
  62221. + core_if, core_if->dev_if,
  62222. + core_if->dev_if->dev_global_regs,
  62223. + &core_if->dev_if->dev_global_regs->dcfg);
  62224. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  62225. + }
  62226. + return dcfg.b.devspd;
  62227. +}
  62228. +
  62229. +void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val)
  62230. +{
  62231. + dcfg_data_t dcfg;
  62232. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  62233. + dcfg.b.devspd = val;
  62234. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  62235. +}
  62236. +
  62237. +uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if)
  62238. +{
  62239. + hprt0_data_t hprt0;
  62240. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  62241. + return hprt0.b.prtconnsts;
  62242. +}
  62243. +
  62244. +uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if)
  62245. +{
  62246. + dsts_data_t dsts;
  62247. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  62248. + return dsts.b.enumspd;
  62249. +}
  62250. +
  62251. +uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if)
  62252. +{
  62253. + hprt0_data_t hprt0;
  62254. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  62255. + return hprt0.b.prtpwr;
  62256. +
  62257. +}
  62258. +
  62259. +uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if)
  62260. +{
  62261. + return core_if->hibernation_suspend;
  62262. +}
  62263. +
  62264. +void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val)
  62265. +{
  62266. + hprt0_data_t hprt0;
  62267. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  62268. + hprt0.b.prtpwr = val;
  62269. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  62270. +}
  62271. +
  62272. +uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if)
  62273. +{
  62274. + hprt0_data_t hprt0;
  62275. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  62276. + return hprt0.b.prtsusp;
  62277. +
  62278. +}
  62279. +
  62280. +void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val)
  62281. +{
  62282. + hprt0_data_t hprt0;
  62283. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  62284. + hprt0.b.prtsusp = val;
  62285. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  62286. +}
  62287. +
  62288. +uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if)
  62289. +{
  62290. + hfir_data_t hfir;
  62291. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  62292. + return hfir.b.frint;
  62293. +
  62294. +}
  62295. +
  62296. +void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val)
  62297. +{
  62298. + hfir_data_t hfir;
  62299. + uint32_t fram_int;
  62300. + fram_int = calc_frame_interval(core_if);
  62301. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  62302. + if (!core_if->core_params->reload_ctl) {
  62303. + DWC_WARN("\nCannot reload HFIR register.HFIR.HFIRRldCtrl bit is"
  62304. + "not set to 1.\nShould load driver with reload_ctl=1"
  62305. + " module parameter\n");
  62306. + return;
  62307. + }
  62308. + switch (fram_int) {
  62309. + case 3750:
  62310. + if ((val < 3350) || (val > 4150)) {
  62311. + DWC_WARN("HFIR interval for HS core and 30 MHz"
  62312. + "clock freq should be from 3350 to 4150\n");
  62313. + return;
  62314. + }
  62315. + break;
  62316. + case 30000:
  62317. + if ((val < 26820) || (val > 33180)) {
  62318. + DWC_WARN("HFIR interval for FS/LS core and 30 MHz"
  62319. + "clock freq should be from 26820 to 33180\n");
  62320. + return;
  62321. + }
  62322. + break;
  62323. + case 6000:
  62324. + if ((val < 5360) || (val > 6640)) {
  62325. + DWC_WARN("HFIR interval for HS core and 48 MHz"
  62326. + "clock freq should be from 5360 to 6640\n");
  62327. + return;
  62328. + }
  62329. + break;
  62330. + case 48000:
  62331. + if ((val < 42912) || (val > 53088)) {
  62332. + DWC_WARN("HFIR interval for FS/LS core and 48 MHz"
  62333. + "clock freq should be from 42912 to 53088\n");
  62334. + return;
  62335. + }
  62336. + break;
  62337. + case 7500:
  62338. + if ((val < 6700) || (val > 8300)) {
  62339. + DWC_WARN("HFIR interval for HS core and 60 MHz"
  62340. + "clock freq should be from 6700 to 8300\n");
  62341. + return;
  62342. + }
  62343. + break;
  62344. + case 60000:
  62345. + if ((val < 53640) || (val > 65536)) {
  62346. + DWC_WARN("HFIR interval for FS/LS core and 60 MHz"
  62347. + "clock freq should be from 53640 to 65536\n");
  62348. + return;
  62349. + }
  62350. + break;
  62351. + default:
  62352. + DWC_WARN("Unknown frame interval\n");
  62353. + return;
  62354. + break;
  62355. +
  62356. + }
  62357. + hfir.b.frint = val;
  62358. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hfir.d32);
  62359. +}
  62360. +
  62361. +uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if)
  62362. +{
  62363. + hcfg_data_t hcfg;
  62364. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  62365. + return hcfg.b.modechtimen;
  62366. +
  62367. +}
  62368. +
  62369. +void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val)
  62370. +{
  62371. + hcfg_data_t hcfg;
  62372. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  62373. + hcfg.b.modechtimen = val;
  62374. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  62375. +}
  62376. +
  62377. +void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val)
  62378. +{
  62379. + hprt0_data_t hprt0;
  62380. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  62381. + hprt0.b.prtres = val;
  62382. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  62383. +}
  62384. +
  62385. +uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if)
  62386. +{
  62387. + dctl_data_t dctl;
  62388. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  62389. + return dctl.b.rmtwkupsig;
  62390. +}
  62391. +
  62392. +uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if)
  62393. +{
  62394. + glpmcfg_data_t lpmcfg;
  62395. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62396. +
  62397. + DWC_ASSERT(!
  62398. + ((core_if->lx_state == DWC_OTG_L1) ^ lpmcfg.b.prt_sleep_sts),
  62399. + "lx_state = %d, lmpcfg.prt_sleep_sts = %d\n",
  62400. + core_if->lx_state, lpmcfg.b.prt_sleep_sts);
  62401. +
  62402. + return lpmcfg.b.prt_sleep_sts;
  62403. +}
  62404. +
  62405. +uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if)
  62406. +{
  62407. + glpmcfg_data_t lpmcfg;
  62408. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62409. + return lpmcfg.b.rem_wkup_en;
  62410. +}
  62411. +
  62412. +uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if)
  62413. +{
  62414. + glpmcfg_data_t lpmcfg;
  62415. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62416. + return lpmcfg.b.appl_resp;
  62417. +}
  62418. +
  62419. +void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val)
  62420. +{
  62421. + glpmcfg_data_t lpmcfg;
  62422. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62423. + lpmcfg.b.appl_resp = val;
  62424. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  62425. +}
  62426. +
  62427. +uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if)
  62428. +{
  62429. + glpmcfg_data_t lpmcfg;
  62430. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62431. + return lpmcfg.b.hsic_connect;
  62432. +}
  62433. +
  62434. +void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val)
  62435. +{
  62436. + glpmcfg_data_t lpmcfg;
  62437. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62438. + lpmcfg.b.hsic_connect = val;
  62439. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  62440. +}
  62441. +
  62442. +uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if)
  62443. +{
  62444. + glpmcfg_data_t lpmcfg;
  62445. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62446. + return lpmcfg.b.inv_sel_hsic;
  62447. +
  62448. +}
  62449. +
  62450. +void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val)
  62451. +{
  62452. + glpmcfg_data_t lpmcfg;
  62453. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62454. + lpmcfg.b.inv_sel_hsic = val;
  62455. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  62456. +}
  62457. +
  62458. +uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if)
  62459. +{
  62460. + return DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  62461. +}
  62462. +
  62463. +void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val)
  62464. +{
  62465. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, val);
  62466. +}
  62467. +
  62468. +uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if)
  62469. +{
  62470. + return DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62471. +}
  62472. +
  62473. +void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val)
  62474. +{
  62475. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, val);
  62476. +}
  62477. +
  62478. +uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if)
  62479. +{
  62480. + return DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  62481. +}
  62482. +
  62483. +void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  62484. +{
  62485. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, val);
  62486. +}
  62487. +
  62488. +uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if)
  62489. +{
  62490. + return DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  62491. +}
  62492. +
  62493. +void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  62494. +{
  62495. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz, val);
  62496. +}
  62497. +
  62498. +uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if)
  62499. +{
  62500. + return DWC_READ_REG32(&core_if->core_global_regs->gpvndctl);
  62501. +}
  62502. +
  62503. +void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val)
  62504. +{
  62505. + DWC_WRITE_REG32(&core_if->core_global_regs->gpvndctl, val);
  62506. +}
  62507. +
  62508. +uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if)
  62509. +{
  62510. + return DWC_READ_REG32(&core_if->core_global_regs->ggpio);
  62511. +}
  62512. +
  62513. +void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val)
  62514. +{
  62515. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, val);
  62516. +}
  62517. +
  62518. +uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if)
  62519. +{
  62520. + return DWC_READ_REG32(core_if->host_if->hprt0);
  62521. +
  62522. +}
  62523. +
  62524. +void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val)
  62525. +{
  62526. + DWC_WRITE_REG32(core_if->host_if->hprt0, val);
  62527. +}
  62528. +
  62529. +uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if)
  62530. +{
  62531. + return DWC_READ_REG32(&core_if->core_global_regs->guid);
  62532. +}
  62533. +
  62534. +void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val)
  62535. +{
  62536. + DWC_WRITE_REG32(&core_if->core_global_regs->guid, val);
  62537. +}
  62538. +
  62539. +uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if)
  62540. +{
  62541. + return DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  62542. +}
  62543. +
  62544. +uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if)
  62545. +{
  62546. + return ((core_if->otg_ver == 1) ? (uint16_t)0x0200 : (uint16_t)0x0103);
  62547. +}
  62548. +
  62549. +/**
  62550. + * Start the SRP timer to detect when the SRP does not complete within
  62551. + * 6 seconds.
  62552. + *
  62553. + * @param core_if the pointer to core_if strucure.
  62554. + */
  62555. +void dwc_otg_pcd_start_srp_timer(dwc_otg_core_if_t * core_if)
  62556. +{
  62557. + core_if->srp_timer_started = 1;
  62558. + DWC_TIMER_SCHEDULE(core_if->srp_timer, 6000 /* 6 secs */ );
  62559. +}
  62560. +
  62561. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if)
  62562. +{
  62563. + uint32_t *addr = (uint32_t *) & (core_if->core_global_regs->gotgctl);
  62564. + gotgctl_data_t mem;
  62565. + gotgctl_data_t val;
  62566. +
  62567. + val.d32 = DWC_READ_REG32(addr);
  62568. + if (val.b.sesreq) {
  62569. + DWC_ERROR("Session Request Already active!\n");
  62570. + return;
  62571. + }
  62572. +
  62573. + DWC_INFO("Session Request Initated\n"); //NOTICE
  62574. + mem.d32 = DWC_READ_REG32(addr);
  62575. + mem.b.sesreq = 1;
  62576. + DWC_WRITE_REG32(addr, mem.d32);
  62577. +
  62578. + /* Start the SRP timer */
  62579. + dwc_otg_pcd_start_srp_timer(core_if);
  62580. + return;
  62581. +}
  62582. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_cil.h linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_cil.h
  62583. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_cil.h 1970-01-01 01:00:00.000000000 +0100
  62584. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_cil.h 2014-02-18 11:52:14.000000000 +0100
  62585. @@ -0,0 +1,1464 @@
  62586. +/* ==========================================================================
  62587. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.h $
  62588. + * $Revision: #123 $
  62589. + * $Date: 2012/08/10 $
  62590. + * $Change: 2047372 $
  62591. + *
  62592. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  62593. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  62594. + * otherwise expressly agreed to in writing between Synopsys and you.
  62595. + *
  62596. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  62597. + * any End User Software License Agreement or Agreement for Licensed Product
  62598. + * with Synopsys or any supplement thereto. You are permitted to use and
  62599. + * redistribute this Software in source and binary forms, with or without
  62600. + * modification, provided that redistributions of source code must retain this
  62601. + * notice. You may not view, use, disclose, copy or distribute this file or
  62602. + * any information contained herein except pursuant to this license grant from
  62603. + * Synopsys. If you do not agree with this notice, including the disclaimer
  62604. + * below, then you are not authorized to use the Software.
  62605. + *
  62606. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  62607. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  62608. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  62609. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  62610. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  62611. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  62612. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  62613. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  62614. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  62615. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  62616. + * DAMAGE.
  62617. + * ========================================================================== */
  62618. +
  62619. +#if !defined(__DWC_CIL_H__)
  62620. +#define __DWC_CIL_H__
  62621. +
  62622. +#include "dwc_list.h"
  62623. +#include "dwc_otg_dbg.h"
  62624. +#include "dwc_otg_regs.h"
  62625. +
  62626. +#include "dwc_otg_core_if.h"
  62627. +#include "dwc_otg_adp.h"
  62628. +
  62629. +/**
  62630. + * @file
  62631. + * This file contains the interface to the Core Interface Layer.
  62632. + */
  62633. +
  62634. +#ifdef DWC_UTE_CFI
  62635. +
  62636. +#define MAX_DMA_DESCS_PER_EP 256
  62637. +
  62638. +/**
  62639. + * Enumeration for the data buffer mode
  62640. + */
  62641. +typedef enum _data_buffer_mode {
  62642. + BM_STANDARD = 0, /* data buffer is in normal mode */
  62643. + BM_SG = 1, /* data buffer uses the scatter/gather mode */
  62644. + BM_CONCAT = 2, /* data buffer uses the concatenation mode */
  62645. + BM_CIRCULAR = 3, /* data buffer uses the circular DMA mode */
  62646. + BM_ALIGN = 4 /* data buffer is in buffer alignment mode */
  62647. +} data_buffer_mode_e;
  62648. +#endif //DWC_UTE_CFI
  62649. +
  62650. +/** Macros defined for DWC OTG HW Release version */
  62651. +
  62652. +#define OTG_CORE_REV_2_60a 0x4F54260A
  62653. +#define OTG_CORE_REV_2_71a 0x4F54271A
  62654. +#define OTG_CORE_REV_2_72a 0x4F54272A
  62655. +#define OTG_CORE_REV_2_80a 0x4F54280A
  62656. +#define OTG_CORE_REV_2_81a 0x4F54281A
  62657. +#define OTG_CORE_REV_2_90a 0x4F54290A
  62658. +#define OTG_CORE_REV_2_91a 0x4F54291A
  62659. +#define OTG_CORE_REV_2_92a 0x4F54292A
  62660. +#define OTG_CORE_REV_2_93a 0x4F54293A
  62661. +#define OTG_CORE_REV_2_94a 0x4F54294A
  62662. +#define OTG_CORE_REV_3_00a 0x4F54300A
  62663. +
  62664. +/**
  62665. + * Information for each ISOC packet.
  62666. + */
  62667. +typedef struct iso_pkt_info {
  62668. + uint32_t offset;
  62669. + uint32_t length;
  62670. + int32_t status;
  62671. +} iso_pkt_info_t;
  62672. +
  62673. +/**
  62674. + * The <code>dwc_ep</code> structure represents the state of a single
  62675. + * endpoint when acting in device mode. It contains the data items
  62676. + * needed for an endpoint to be activated and transfer packets.
  62677. + */
  62678. +typedef struct dwc_ep {
  62679. + /** EP number used for register address lookup */
  62680. + uint8_t num;
  62681. + /** EP direction 0 = OUT */
  62682. + unsigned is_in:1;
  62683. + /** EP active. */
  62684. + unsigned active:1;
  62685. +
  62686. + /**
  62687. + * Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic
  62688. + * Tx FIFO. If dedicated Tx FIFOs are enabled Tx FIFO # FOR IN EPs*/
  62689. + unsigned tx_fifo_num:4;
  62690. + /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
  62691. + unsigned type:2;
  62692. +#define DWC_OTG_EP_TYPE_CONTROL 0
  62693. +#define DWC_OTG_EP_TYPE_ISOC 1
  62694. +#define DWC_OTG_EP_TYPE_BULK 2
  62695. +#define DWC_OTG_EP_TYPE_INTR 3
  62696. +
  62697. + /** DATA start PID for INTR and BULK EP */
  62698. + unsigned data_pid_start:1;
  62699. + /** Frame (even/odd) for ISOC EP */
  62700. + unsigned even_odd_frame:1;
  62701. + /** Max Packet bytes */
  62702. + unsigned maxpacket:11;
  62703. +
  62704. + /** Max Transfer size */
  62705. + uint32_t maxxfer;
  62706. +
  62707. + /** @name Transfer state */
  62708. + /** @{ */
  62709. +
  62710. + /**
  62711. + * Pointer to the beginning of the transfer buffer -- do not modify
  62712. + * during transfer.
  62713. + */
  62714. +
  62715. + dwc_dma_t dma_addr;
  62716. +
  62717. + dwc_dma_t dma_desc_addr;
  62718. + dwc_otg_dev_dma_desc_t *desc_addr;
  62719. +
  62720. + uint8_t *start_xfer_buff;
  62721. + /** pointer to the transfer buffer */
  62722. + uint8_t *xfer_buff;
  62723. + /** Number of bytes to transfer */
  62724. + unsigned xfer_len:19;
  62725. + /** Number of bytes transferred. */
  62726. + unsigned xfer_count:19;
  62727. + /** Sent ZLP */
  62728. + unsigned sent_zlp:1;
  62729. + /** Total len for control transfer */
  62730. + unsigned total_len:19;
  62731. +
  62732. + /** stall clear flag */
  62733. + unsigned stall_clear_flag:1;
  62734. +
  62735. + /** SETUP pkt cnt rollover flag for EP0 out*/
  62736. + unsigned stp_rollover;
  62737. +
  62738. +#ifdef DWC_UTE_CFI
  62739. + /* The buffer mode */
  62740. + data_buffer_mode_e buff_mode;
  62741. +
  62742. + /* The chain of DMA descriptors.
  62743. + * MAX_DMA_DESCS_PER_EP will be allocated for each active EP.
  62744. + */
  62745. + dwc_otg_dma_desc_t *descs;
  62746. +
  62747. + /* The DMA address of the descriptors chain start */
  62748. + dma_addr_t descs_dma_addr;
  62749. + /** This variable stores the length of the last enqueued request */
  62750. + uint32_t cfi_req_len;
  62751. +#endif //DWC_UTE_CFI
  62752. +
  62753. +/** Max DMA Descriptor count for any EP */
  62754. +#define MAX_DMA_DESC_CNT 256
  62755. + /** Allocated DMA Desc count */
  62756. + uint32_t desc_cnt;
  62757. +
  62758. + /** bInterval */
  62759. + uint32_t bInterval;
  62760. + /** Next frame num to setup next ISOC transfer */
  62761. + uint32_t frame_num;
  62762. + /** Indicates SOF number overrun in DSTS */
  62763. + uint8_t frm_overrun;
  62764. +
  62765. +#ifdef DWC_UTE_PER_IO
  62766. + /** Next frame num for which will be setup DMA Desc */
  62767. + uint32_t xiso_frame_num;
  62768. + /** bInterval */
  62769. + uint32_t xiso_bInterval;
  62770. + /** Count of currently active transfers - shall be either 0 or 1 */
  62771. + int xiso_active_xfers;
  62772. + int xiso_queued_xfers;
  62773. +#endif
  62774. +#ifdef DWC_EN_ISOC
  62775. + /**
  62776. + * Variables specific for ISOC EPs
  62777. + *
  62778. + */
  62779. + /** DMA addresses of ISOC buffers */
  62780. + dwc_dma_t dma_addr0;
  62781. + dwc_dma_t dma_addr1;
  62782. +
  62783. + dwc_dma_t iso_dma_desc_addr;
  62784. + dwc_otg_dev_dma_desc_t *iso_desc_addr;
  62785. +
  62786. + /** pointer to the transfer buffers */
  62787. + uint8_t *xfer_buff0;
  62788. + uint8_t *xfer_buff1;
  62789. +
  62790. + /** number of ISOC Buffer is processing */
  62791. + uint32_t proc_buf_num;
  62792. + /** Interval of ISOC Buffer processing */
  62793. + uint32_t buf_proc_intrvl;
  62794. + /** Data size for regular frame */
  62795. + uint32_t data_per_frame;
  62796. +
  62797. + /* todo - pattern data support is to be implemented in the future */
  62798. + /** Data size for pattern frame */
  62799. + uint32_t data_pattern_frame;
  62800. + /** Frame number of pattern data */
  62801. + uint32_t sync_frame;
  62802. +
  62803. + /** bInterval */
  62804. + uint32_t bInterval;
  62805. + /** ISO Packet number per frame */
  62806. + uint32_t pkt_per_frm;
  62807. + /** Next frame num for which will be setup DMA Desc */
  62808. + uint32_t next_frame;
  62809. + /** Number of packets per buffer processing */
  62810. + uint32_t pkt_cnt;
  62811. + /** Info for all isoc packets */
  62812. + iso_pkt_info_t *pkt_info;
  62813. + /** current pkt number */
  62814. + uint32_t cur_pkt;
  62815. + /** current pkt number */
  62816. + uint8_t *cur_pkt_addr;
  62817. + /** current pkt number */
  62818. + uint32_t cur_pkt_dma_addr;
  62819. +#endif /* DWC_EN_ISOC */
  62820. +
  62821. +/** @} */
  62822. +} dwc_ep_t;
  62823. +
  62824. +/*
  62825. + * Reasons for halting a host channel.
  62826. + */
  62827. +typedef enum dwc_otg_halt_status {
  62828. + DWC_OTG_HC_XFER_NO_HALT_STATUS,
  62829. + DWC_OTG_HC_XFER_COMPLETE,
  62830. + DWC_OTG_HC_XFER_URB_COMPLETE,
  62831. + DWC_OTG_HC_XFER_ACK,
  62832. + DWC_OTG_HC_XFER_NAK,
  62833. + DWC_OTG_HC_XFER_NYET,
  62834. + DWC_OTG_HC_XFER_STALL,
  62835. + DWC_OTG_HC_XFER_XACT_ERR,
  62836. + DWC_OTG_HC_XFER_FRAME_OVERRUN,
  62837. + DWC_OTG_HC_XFER_BABBLE_ERR,
  62838. + DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
  62839. + DWC_OTG_HC_XFER_AHB_ERR,
  62840. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
  62841. + DWC_OTG_HC_XFER_URB_DEQUEUE
  62842. +} dwc_otg_halt_status_e;
  62843. +
  62844. +/**
  62845. + * Host channel descriptor. This structure represents the state of a single
  62846. + * host channel when acting in host mode. It contains the data items needed to
  62847. + * transfer packets to an endpoint via a host channel.
  62848. + */
  62849. +typedef struct dwc_hc {
  62850. + /** Host channel number used for register address lookup */
  62851. + uint8_t hc_num;
  62852. +
  62853. + /** Device to access */
  62854. + unsigned dev_addr:7;
  62855. +
  62856. + /** EP to access */
  62857. + unsigned ep_num:4;
  62858. +
  62859. + /** EP direction. 0: OUT, 1: IN */
  62860. + unsigned ep_is_in:1;
  62861. +
  62862. + /**
  62863. + * EP speed.
  62864. + * One of the following values:
  62865. + * - DWC_OTG_EP_SPEED_LOW
  62866. + * - DWC_OTG_EP_SPEED_FULL
  62867. + * - DWC_OTG_EP_SPEED_HIGH
  62868. + */
  62869. + unsigned speed:2;
  62870. +#define DWC_OTG_EP_SPEED_LOW 0
  62871. +#define DWC_OTG_EP_SPEED_FULL 1
  62872. +#define DWC_OTG_EP_SPEED_HIGH 2
  62873. +
  62874. + /**
  62875. + * Endpoint type.
  62876. + * One of the following values:
  62877. + * - DWC_OTG_EP_TYPE_CONTROL: 0
  62878. + * - DWC_OTG_EP_TYPE_ISOC: 1
  62879. + * - DWC_OTG_EP_TYPE_BULK: 2
  62880. + * - DWC_OTG_EP_TYPE_INTR: 3
  62881. + */
  62882. + unsigned ep_type:2;
  62883. +
  62884. + /** Max packet size in bytes */
  62885. + unsigned max_packet:11;
  62886. +
  62887. + /**
  62888. + * PID for initial transaction.
  62889. + * 0: DATA0,<br>
  62890. + * 1: DATA2,<br>
  62891. + * 2: DATA1,<br>
  62892. + * 3: MDATA (non-Control EP),
  62893. + * SETUP (Control EP)
  62894. + */
  62895. + unsigned data_pid_start:2;
  62896. +#define DWC_OTG_HC_PID_DATA0 0
  62897. +#define DWC_OTG_HC_PID_DATA2 1
  62898. +#define DWC_OTG_HC_PID_DATA1 2
  62899. +#define DWC_OTG_HC_PID_MDATA 3
  62900. +#define DWC_OTG_HC_PID_SETUP 3
  62901. +
  62902. + /** Number of periodic transactions per (micro)frame */
  62903. + unsigned multi_count:2;
  62904. +
  62905. + /** @name Transfer State */
  62906. + /** @{ */
  62907. +
  62908. + /** Pointer to the current transfer buffer position. */
  62909. + uint8_t *xfer_buff;
  62910. + /**
  62911. + * In Buffer DMA mode this buffer will be used
  62912. + * if xfer_buff is not DWORD aligned.
  62913. + */
  62914. + dwc_dma_t align_buff;
  62915. + /** Total number of bytes to transfer. */
  62916. + uint32_t xfer_len;
  62917. + /** Number of bytes transferred so far. */
  62918. + uint32_t xfer_count;
  62919. + /** Packet count at start of transfer.*/
  62920. + uint16_t start_pkt_count;
  62921. +
  62922. + /**
  62923. + * Flag to indicate whether the transfer has been started. Set to 1 if
  62924. + * it has been started, 0 otherwise.
  62925. + */
  62926. + uint8_t xfer_started;
  62927. +
  62928. + /**
  62929. + * Set to 1 to indicate that a PING request should be issued on this
  62930. + * channel. If 0, process normally.
  62931. + */
  62932. + uint8_t do_ping;
  62933. +
  62934. + /**
  62935. + * Set to 1 to indicate that the error count for this transaction is
  62936. + * non-zero. Set to 0 if the error count is 0.
  62937. + */
  62938. + uint8_t error_state;
  62939. +
  62940. + /**
  62941. + * Set to 1 to indicate that this channel should be halted the next
  62942. + * time a request is queued for the channel. This is necessary in
  62943. + * slave mode if no request queue space is available when an attempt
  62944. + * is made to halt the channel.
  62945. + */
  62946. + uint8_t halt_on_queue;
  62947. +
  62948. + /**
  62949. + * Set to 1 if the host channel has been halted, but the core is not
  62950. + * finished flushing queued requests. Otherwise 0.
  62951. + */
  62952. + uint8_t halt_pending;
  62953. +
  62954. + /**
  62955. + * Reason for halting the host channel.
  62956. + */
  62957. + dwc_otg_halt_status_e halt_status;
  62958. +
  62959. + /*
  62960. + * Split settings for the host channel
  62961. + */
  62962. + uint8_t do_split; /**< Enable split for the channel */
  62963. + uint8_t complete_split; /**< Enable complete split */
  62964. + uint8_t hub_addr; /**< Address of high speed hub */
  62965. +
  62966. + uint8_t port_addr; /**< Port of the low/full speed device */
  62967. + /** Split transaction position
  62968. + * One of the following values:
  62969. + * - DWC_HCSPLIT_XACTPOS_MID
  62970. + * - DWC_HCSPLIT_XACTPOS_BEGIN
  62971. + * - DWC_HCSPLIT_XACTPOS_END
  62972. + * - DWC_HCSPLIT_XACTPOS_ALL */
  62973. + uint8_t xact_pos;
  62974. +
  62975. + /** Set when the host channel does a short read. */
  62976. + uint8_t short_read;
  62977. +
  62978. + /**
  62979. + * Number of requests issued for this channel since it was assigned to
  62980. + * the current transfer (not counting PINGs).
  62981. + */
  62982. + uint8_t requests;
  62983. +
  62984. + /**
  62985. + * Queue Head for the transfer being processed by this channel.
  62986. + */
  62987. + struct dwc_otg_qh *qh;
  62988. +
  62989. + /** @} */
  62990. +
  62991. + /** Entry in list of host channels. */
  62992. + DWC_CIRCLEQ_ENTRY(dwc_hc) hc_list_entry;
  62993. +
  62994. + /** @name Descriptor DMA support */
  62995. + /** @{ */
  62996. +
  62997. + /** Number of Transfer Descriptors */
  62998. + uint16_t ntd;
  62999. +
  63000. + /** Descriptor List DMA address */
  63001. + dwc_dma_t desc_list_addr;
  63002. +
  63003. + /** Scheduling micro-frame bitmap. */
  63004. + uint8_t schinfo;
  63005. +
  63006. + /** @} */
  63007. +} dwc_hc_t;
  63008. +
  63009. +/**
  63010. + * The following parameters may be specified when starting the module. These
  63011. + * parameters define how the DWC_otg controller should be configured.
  63012. + */
  63013. +typedef struct dwc_otg_core_params {
  63014. + int32_t opt;
  63015. +
  63016. + /**
  63017. + * Specifies the OTG capabilities. The driver will automatically
  63018. + * detect the value for this parameter if none is specified.
  63019. + * 0 - HNP and SRP capable (default)
  63020. + * 1 - SRP Only capable
  63021. + * 2 - No HNP/SRP capable
  63022. + */
  63023. + int32_t otg_cap;
  63024. +
  63025. + /**
  63026. + * Specifies whether to use slave or DMA mode for accessing the data
  63027. + * FIFOs. The driver will automatically detect the value for this
  63028. + * parameter if none is specified.
  63029. + * 0 - Slave
  63030. + * 1 - DMA (default, if available)
  63031. + */
  63032. + int32_t dma_enable;
  63033. +
  63034. + /**
  63035. + * When DMA mode is enabled specifies whether to use address DMA or DMA
  63036. + * Descriptor mode for accessing the data FIFOs in device mode. The driver
  63037. + * will automatically detect the value for this if none is specified.
  63038. + * 0 - address DMA
  63039. + * 1 - DMA Descriptor(default, if available)
  63040. + */
  63041. + int32_t dma_desc_enable;
  63042. + /** The DMA Burst size (applicable only for External DMA
  63043. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  63044. + */
  63045. + int32_t dma_burst_size; /* Translate this to GAHBCFG values */
  63046. +
  63047. + /**
  63048. + * Specifies the maximum speed of operation in host and device mode.
  63049. + * The actual speed depends on the speed of the attached device and
  63050. + * the value of phy_type. The actual speed depends on the speed of the
  63051. + * attached device.
  63052. + * 0 - High Speed (default)
  63053. + * 1 - Full Speed
  63054. + */
  63055. + int32_t speed;
  63056. + /** Specifies whether low power mode is supported when attached
  63057. + * to a Full Speed or Low Speed device in host mode.
  63058. + * 0 - Don't support low power mode (default)
  63059. + * 1 - Support low power mode
  63060. + */
  63061. + int32_t host_support_fs_ls_low_power;
  63062. +
  63063. + /** Specifies the PHY clock rate in low power mode when connected to a
  63064. + * Low Speed device in host mode. This parameter is applicable only if
  63065. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  63066. + * then defaults to 6 MHZ otherwise 48 MHZ.
  63067. + *
  63068. + * 0 - 48 MHz
  63069. + * 1 - 6 MHz
  63070. + */
  63071. + int32_t host_ls_low_power_phy_clk;
  63072. +
  63073. + /**
  63074. + * 0 - Use cC FIFO size parameters
  63075. + * 1 - Allow dynamic FIFO sizing (default)
  63076. + */
  63077. + int32_t enable_dynamic_fifo;
  63078. +
  63079. + /** Total number of 4-byte words in the data FIFO memory. This
  63080. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  63081. + * Tx FIFOs.
  63082. + * 32 to 32768 (default 8192)
  63083. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  63084. + */
  63085. + int32_t data_fifo_size;
  63086. +
  63087. + /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  63088. + * FIFO sizing is enabled.
  63089. + * 16 to 32768 (default 1064)
  63090. + */
  63091. + int32_t dev_rx_fifo_size;
  63092. +
  63093. + /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  63094. + * when dynamic FIFO sizing is enabled.
  63095. + * 16 to 32768 (default 1024)
  63096. + */
  63097. + int32_t dev_nperio_tx_fifo_size;
  63098. +
  63099. + /** Number of 4-byte words in each of the periodic Tx FIFOs in device
  63100. + * mode when dynamic FIFO sizing is enabled.
  63101. + * 4 to 768 (default 256)
  63102. + */
  63103. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  63104. +
  63105. + /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  63106. + * FIFO sizing is enabled.
  63107. + * 16 to 32768 (default 1024)
  63108. + */
  63109. + int32_t host_rx_fifo_size;
  63110. +
  63111. + /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  63112. + * when Dynamic FIFO sizing is enabled in the core.
  63113. + * 16 to 32768 (default 1024)
  63114. + */
  63115. + int32_t host_nperio_tx_fifo_size;
  63116. +
  63117. + /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  63118. + * FIFO sizing is enabled.
  63119. + * 16 to 32768 (default 1024)
  63120. + */
  63121. + int32_t host_perio_tx_fifo_size;
  63122. +
  63123. + /** The maximum transfer size supported in bytes.
  63124. + * 2047 to 65,535 (default 65,535)
  63125. + */
  63126. + int32_t max_transfer_size;
  63127. +
  63128. + /** The maximum number of packets in a transfer.
  63129. + * 15 to 511 (default 511)
  63130. + */
  63131. + int32_t max_packet_count;
  63132. +
  63133. + /** The number of host channel registers to use.
  63134. + * 1 to 16 (default 12)
  63135. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  63136. + */
  63137. + int32_t host_channels;
  63138. +
  63139. + /** The number of endpoints in addition to EP0 available for device
  63140. + * mode operations.
  63141. + * 1 to 15 (default 6 IN and OUT)
  63142. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  63143. + * endpoints in addition to EP0.
  63144. + */
  63145. + int32_t dev_endpoints;
  63146. +
  63147. + /**
  63148. + * Specifies the type of PHY interface to use. By default, the driver
  63149. + * will automatically detect the phy_type.
  63150. + *
  63151. + * 0 - Full Speed PHY
  63152. + * 1 - UTMI+ (default)
  63153. + * 2 - ULPI
  63154. + */
  63155. + int32_t phy_type;
  63156. +
  63157. + /**
  63158. + * Specifies the UTMI+ Data Width. This parameter is
  63159. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  63160. + * PHY_TYPE, this parameter indicates the data width between
  63161. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  63162. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  63163. + * to "8 and 16 bits", meaning that the core has been
  63164. + * configured to work at either data path width.
  63165. + *
  63166. + * 8 or 16 bits (default 16)
  63167. + */
  63168. + int32_t phy_utmi_width;
  63169. +
  63170. + /**
  63171. + * Specifies whether the ULPI operates at double or single
  63172. + * data rate. This parameter is only applicable if PHY_TYPE is
  63173. + * ULPI.
  63174. + *
  63175. + * 0 - single data rate ULPI interface with 8 bit wide data
  63176. + * bus (default)
  63177. + * 1 - double data rate ULPI interface with 4 bit wide data
  63178. + * bus
  63179. + */
  63180. + int32_t phy_ulpi_ddr;
  63181. +
  63182. + /**
  63183. + * Specifies whether to use the internal or external supply to
  63184. + * drive the vbus with a ULPI phy.
  63185. + */
  63186. + int32_t phy_ulpi_ext_vbus;
  63187. +
  63188. + /**
  63189. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  63190. + * parameter is only applicable if PHY_TYPE is FS.
  63191. + * 0 - No (default)
  63192. + * 1 - Yes
  63193. + */
  63194. + int32_t i2c_enable;
  63195. +
  63196. + int32_t ulpi_fs_ls;
  63197. +
  63198. + int32_t ts_dline;
  63199. +
  63200. + /**
  63201. + * Specifies whether dedicated transmit FIFOs are
  63202. + * enabled for non periodic IN endpoints in device mode
  63203. + * 0 - No
  63204. + * 1 - Yes
  63205. + */
  63206. + int32_t en_multiple_tx_fifo;
  63207. +
  63208. + /** Number of 4-byte words in each of the Tx FIFOs in device
  63209. + * mode when dynamic FIFO sizing is enabled.
  63210. + * 4 to 768 (default 256)
  63211. + */
  63212. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  63213. +
  63214. + /** Thresholding enable flag-
  63215. + * bit 0 - enable non-ISO Tx thresholding
  63216. + * bit 1 - enable ISO Tx thresholding
  63217. + * bit 2 - enable Rx thresholding
  63218. + */
  63219. + uint32_t thr_ctl;
  63220. +
  63221. + /** Thresholding length for Tx
  63222. + * FIFOs in 32 bit DWORDs
  63223. + */
  63224. + uint32_t tx_thr_length;
  63225. +
  63226. + /** Thresholding length for Rx
  63227. + * FIFOs in 32 bit DWORDs
  63228. + */
  63229. + uint32_t rx_thr_length;
  63230. +
  63231. + /**
  63232. + * Specifies whether LPM (Link Power Management) support is enabled
  63233. + */
  63234. + int32_t lpm_enable;
  63235. +
  63236. + /** Per Transfer Interrupt
  63237. + * mode enable flag
  63238. + * 1 - Enabled
  63239. + * 0 - Disabled
  63240. + */
  63241. + int32_t pti_enable;
  63242. +
  63243. + /** Multi Processor Interrupt
  63244. + * mode enable flag
  63245. + * 1 - Enabled
  63246. + * 0 - Disabled
  63247. + */
  63248. + int32_t mpi_enable;
  63249. +
  63250. + /** IS_USB Capability
  63251. + * 1 - Enabled
  63252. + * 0 - Disabled
  63253. + */
  63254. + int32_t ic_usb_cap;
  63255. +
  63256. + /** AHB Threshold Ratio
  63257. + * 2'b00 AHB Threshold = MAC Threshold
  63258. + * 2'b01 AHB Threshold = 1/2 MAC Threshold
  63259. + * 2'b10 AHB Threshold = 1/4 MAC Threshold
  63260. + * 2'b11 AHB Threshold = 1/8 MAC Threshold
  63261. + */
  63262. + int32_t ahb_thr_ratio;
  63263. +
  63264. + /** ADP Support
  63265. + * 1 - Enabled
  63266. + * 0 - Disabled
  63267. + */
  63268. + int32_t adp_supp_enable;
  63269. +
  63270. + /** HFIR Reload Control
  63271. + * 0 - The HFIR cannot be reloaded dynamically.
  63272. + * 1 - Allow dynamic reloading of the HFIR register during runtime.
  63273. + */
  63274. + int32_t reload_ctl;
  63275. +
  63276. + /** DCFG: Enable device Out NAK
  63277. + * 0 - The core does not set NAK after Bulk Out transfer complete.
  63278. + * 1 - The core sets NAK after Bulk OUT transfer complete.
  63279. + */
  63280. + int32_t dev_out_nak;
  63281. +
  63282. + /** DCFG: Enable Continue on BNA
  63283. + * After receiving BNA interrupt the core disables the endpoint,when the
  63284. + * endpoint is re-enabled by the application the core starts processing
  63285. + * 0 - from the DOEPDMA descriptor
  63286. + * 1 - from the descriptor which received the BNA.
  63287. + */
  63288. + int32_t cont_on_bna;
  63289. +
  63290. + /** GAHBCFG: AHB Single Support
  63291. + * This bit when programmed supports SINGLE transfers for remainder
  63292. + * data in a transfer for DMA mode of operation.
  63293. + * 0 - in this case the remainder data will be sent using INCR burst size.
  63294. + * 1 - in this case the remainder data will be sent using SINGLE burst size.
  63295. + */
  63296. + int32_t ahb_single;
  63297. +
  63298. + /** Core Power down mode
  63299. + * 0 - No Power Down is enabled
  63300. + * 1 - Reserved
  63301. + * 2 - Complete Power Down (Hibernation)
  63302. + */
  63303. + int32_t power_down;
  63304. +
  63305. + /** OTG revision supported
  63306. + * 0 - OTG 1.3 revision
  63307. + * 1 - OTG 2.0 revision
  63308. + */
  63309. + int32_t otg_ver;
  63310. +
  63311. +} dwc_otg_core_params_t;
  63312. +
  63313. +#ifdef DEBUG
  63314. +struct dwc_otg_core_if;
  63315. +typedef struct hc_xfer_info {
  63316. + struct dwc_otg_core_if *core_if;
  63317. + dwc_hc_t *hc;
  63318. +} hc_xfer_info_t;
  63319. +#endif
  63320. +
  63321. +typedef struct ep_xfer_info {
  63322. + struct dwc_otg_core_if *core_if;
  63323. + dwc_ep_t *ep;
  63324. + uint8_t state;
  63325. +} ep_xfer_info_t;
  63326. +/*
  63327. + * Device States
  63328. + */
  63329. +typedef enum dwc_otg_lx_state {
  63330. + /** On state */
  63331. + DWC_OTG_L0,
  63332. + /** LPM sleep state*/
  63333. + DWC_OTG_L1,
  63334. + /** USB suspend state*/
  63335. + DWC_OTG_L2,
  63336. + /** Off state*/
  63337. + DWC_OTG_L3
  63338. +} dwc_otg_lx_state_e;
  63339. +
  63340. +struct dwc_otg_global_regs_backup {
  63341. + uint32_t gotgctl_local;
  63342. + uint32_t gintmsk_local;
  63343. + uint32_t gahbcfg_local;
  63344. + uint32_t gusbcfg_local;
  63345. + uint32_t grxfsiz_local;
  63346. + uint32_t gnptxfsiz_local;
  63347. +#ifdef CONFIG_USB_DWC_OTG_LPM
  63348. + uint32_t glpmcfg_local;
  63349. +#endif
  63350. + uint32_t gi2cctl_local;
  63351. + uint32_t hptxfsiz_local;
  63352. + uint32_t pcgcctl_local;
  63353. + uint32_t gdfifocfg_local;
  63354. + uint32_t dtxfsiz_local[MAX_EPS_CHANNELS];
  63355. + uint32_t gpwrdn_local;
  63356. + uint32_t xhib_pcgcctl;
  63357. + uint32_t xhib_gpwrdn;
  63358. +};
  63359. +
  63360. +struct dwc_otg_host_regs_backup {
  63361. + uint32_t hcfg_local;
  63362. + uint32_t haintmsk_local;
  63363. + uint32_t hcintmsk_local[MAX_EPS_CHANNELS];
  63364. + uint32_t hprt0_local;
  63365. + uint32_t hfir_local;
  63366. +};
  63367. +
  63368. +struct dwc_otg_dev_regs_backup {
  63369. + uint32_t dcfg;
  63370. + uint32_t dctl;
  63371. + uint32_t daintmsk;
  63372. + uint32_t diepmsk;
  63373. + uint32_t doepmsk;
  63374. + uint32_t diepctl[MAX_EPS_CHANNELS];
  63375. + uint32_t dieptsiz[MAX_EPS_CHANNELS];
  63376. + uint32_t diepdma[MAX_EPS_CHANNELS];
  63377. +};
  63378. +/**
  63379. + * The <code>dwc_otg_core_if</code> structure contains information needed to manage
  63380. + * the DWC_otg controller acting in either host or device mode. It
  63381. + * represents the programming view of the controller as a whole.
  63382. + */
  63383. +struct dwc_otg_core_if {
  63384. + /** Parameters that define how the core should be configured.*/
  63385. + dwc_otg_core_params_t *core_params;
  63386. +
  63387. + /** Core Global registers starting at offset 000h. */
  63388. + dwc_otg_core_global_regs_t *core_global_regs;
  63389. +
  63390. + /** Device-specific information */
  63391. + dwc_otg_dev_if_t *dev_if;
  63392. + /** Host-specific information */
  63393. + dwc_otg_host_if_t *host_if;
  63394. +
  63395. + /** Value from SNPSID register */
  63396. + uint32_t snpsid;
  63397. +
  63398. + /*
  63399. + * Set to 1 if the core PHY interface bits in USBCFG have been
  63400. + * initialized.
  63401. + */
  63402. + uint8_t phy_init_done;
  63403. +
  63404. + /*
  63405. + * SRP Success flag, set by srp success interrupt in FS I2C mode
  63406. + */
  63407. + uint8_t srp_success;
  63408. + uint8_t srp_timer_started;
  63409. + /** Timer for SRP. If it expires before SRP is successful
  63410. + * clear the SRP. */
  63411. + dwc_timer_t *srp_timer;
  63412. +
  63413. +#ifdef DWC_DEV_SRPCAP
  63414. + /* This timer is needed to power on the hibernated host core if SRP is not
  63415. + * initiated on connected SRP capable device for limited period of time
  63416. + */
  63417. + uint8_t pwron_timer_started;
  63418. + dwc_timer_t *pwron_timer;
  63419. +#endif
  63420. + /* Common configuration information */
  63421. + /** Power and Clock Gating Control Register */
  63422. + volatile uint32_t *pcgcctl;
  63423. +#define DWC_OTG_PCGCCTL_OFFSET 0xE00
  63424. +
  63425. + /** Push/pop addresses for endpoints or host channels.*/
  63426. + uint32_t *data_fifo[MAX_EPS_CHANNELS];
  63427. +#define DWC_OTG_DATA_FIFO_OFFSET 0x1000
  63428. +#define DWC_OTG_DATA_FIFO_SIZE 0x1000
  63429. +
  63430. + /** Total RAM for FIFOs (Bytes) */
  63431. + uint16_t total_fifo_size;
  63432. + /** Size of Rx FIFO (Bytes) */
  63433. + uint16_t rx_fifo_size;
  63434. + /** Size of Non-periodic Tx FIFO (Bytes) */
  63435. + uint16_t nperio_tx_fifo_size;
  63436. +
  63437. + /** 1 if DMA is enabled, 0 otherwise. */
  63438. + uint8_t dma_enable;
  63439. +
  63440. + /** 1 if DMA descriptor is enabled, 0 otherwise. */
  63441. + uint8_t dma_desc_enable;
  63442. +
  63443. + /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
  63444. + uint8_t pti_enh_enable;
  63445. +
  63446. + /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
  63447. + uint8_t multiproc_int_enable;
  63448. +
  63449. + /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
  63450. + uint8_t en_multiple_tx_fifo;
  63451. +
  63452. + /** Set to 1 if multiple packets of a high-bandwidth transfer is in
  63453. + * process of being queued */
  63454. + uint8_t queuing_high_bandwidth;
  63455. +
  63456. + /** Hardware Configuration -- stored here for convenience.*/
  63457. + hwcfg1_data_t hwcfg1;
  63458. + hwcfg2_data_t hwcfg2;
  63459. + hwcfg3_data_t hwcfg3;
  63460. + hwcfg4_data_t hwcfg4;
  63461. + fifosize_data_t hptxfsiz;
  63462. +
  63463. + /** Host and Device Configuration -- stored here for convenience.*/
  63464. + hcfg_data_t hcfg;
  63465. + dcfg_data_t dcfg;
  63466. +
  63467. + /** The operational State, during transations
  63468. + * (a_host>>a_peripherial and b_device=>b_host) this may not
  63469. + * match the core but allows the software to determine
  63470. + * transitions.
  63471. + */
  63472. + uint8_t op_state;
  63473. +
  63474. + /**
  63475. + * Set to 1 if the HCD needs to be restarted on a session request
  63476. + * interrupt. This is required if no connector ID status change has
  63477. + * occurred since the HCD was last disconnected.
  63478. + */
  63479. + uint8_t restart_hcd_on_session_req;
  63480. +
  63481. + /** HCD callbacks */
  63482. + /** A-Device is a_host */
  63483. +#define A_HOST (1)
  63484. + /** A-Device is a_suspend */
  63485. +#define A_SUSPEND (2)
  63486. + /** A-Device is a_peripherial */
  63487. +#define A_PERIPHERAL (3)
  63488. + /** B-Device is operating as a Peripheral. */
  63489. +#define B_PERIPHERAL (4)
  63490. + /** B-Device is operating as a Host. */
  63491. +#define B_HOST (5)
  63492. +
  63493. + /** HCD callbacks */
  63494. + struct dwc_otg_cil_callbacks *hcd_cb;
  63495. + /** PCD callbacks */
  63496. + struct dwc_otg_cil_callbacks *pcd_cb;
  63497. +
  63498. + /** Device mode Periodic Tx FIFO Mask */
  63499. + uint32_t p_tx_msk;
  63500. + /** Device mode Periodic Tx FIFO Mask */
  63501. + uint32_t tx_msk;
  63502. +
  63503. + /** Workqueue object used for handling several interrupts */
  63504. + dwc_workq_t *wq_otg;
  63505. +
  63506. + /** Timer object used for handling "Wakeup Detected" Interrupt */
  63507. + dwc_timer_t *wkp_timer;
  63508. + /** This arrays used for debug purposes for DEV OUT NAK enhancement */
  63509. + uint32_t start_doeptsiz_val[MAX_EPS_CHANNELS];
  63510. + ep_xfer_info_t ep_xfer_info[MAX_EPS_CHANNELS];
  63511. + dwc_timer_t *ep_xfer_timer[MAX_EPS_CHANNELS];
  63512. +#ifdef DEBUG
  63513. + uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
  63514. +
  63515. + hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
  63516. + dwc_timer_t *hc_xfer_timer[MAX_EPS_CHANNELS];
  63517. +
  63518. + uint32_t hfnum_7_samples;
  63519. + uint64_t hfnum_7_frrem_accum;
  63520. + uint32_t hfnum_0_samples;
  63521. + uint64_t hfnum_0_frrem_accum;
  63522. + uint32_t hfnum_other_samples;
  63523. + uint64_t hfnum_other_frrem_accum;
  63524. +#endif
  63525. +
  63526. +#ifdef DWC_UTE_CFI
  63527. + uint16_t pwron_rxfsiz;
  63528. + uint16_t pwron_gnptxfsiz;
  63529. + uint16_t pwron_txfsiz[15];
  63530. +
  63531. + uint16_t init_rxfsiz;
  63532. + uint16_t init_gnptxfsiz;
  63533. + uint16_t init_txfsiz[15];
  63534. +#endif
  63535. +
  63536. + /** Lx state of device */
  63537. + dwc_otg_lx_state_e lx_state;
  63538. +
  63539. + /** Saved Core Global registers */
  63540. + struct dwc_otg_global_regs_backup *gr_backup;
  63541. + /** Saved Host registers */
  63542. + struct dwc_otg_host_regs_backup *hr_backup;
  63543. + /** Saved Device registers */
  63544. + struct dwc_otg_dev_regs_backup *dr_backup;
  63545. +
  63546. + /** Power Down Enable */
  63547. + uint32_t power_down;
  63548. +
  63549. + /** ADP support Enable */
  63550. + uint32_t adp_enable;
  63551. +
  63552. + /** ADP structure object */
  63553. + dwc_otg_adp_t adp;
  63554. +
  63555. + /** hibernation/suspend flag */
  63556. + int hibernation_suspend;
  63557. +
  63558. + /** Device mode extended hibernation flag */
  63559. + int xhib;
  63560. +
  63561. + /** OTG revision supported */
  63562. + uint32_t otg_ver;
  63563. +
  63564. + /** OTG status flag used for HNP polling */
  63565. + uint8_t otg_sts;
  63566. +
  63567. + /** Pointer to either hcd->lock or pcd->lock */
  63568. + dwc_spinlock_t *lock;
  63569. +
  63570. + /** Start predict NextEP based on Learning Queue if equal 1,
  63571. + * also used as counter of disabled NP IN EP's */
  63572. + uint8_t start_predict;
  63573. +
  63574. + /** NextEp sequence, including EP0: nextep_seq[] = EP if non-periodic and
  63575. + * active, 0xff otherwise */
  63576. + uint8_t nextep_seq[MAX_EPS_CHANNELS];
  63577. +
  63578. + /** Index of fisrt EP in nextep_seq array which should be re-enabled **/
  63579. + uint8_t first_in_nextep_seq;
  63580. +
  63581. + /** Frame number while entering to ISR - needed for ISOCs **/
  63582. + uint32_t frame_num;
  63583. +
  63584. +};
  63585. +
  63586. +#ifdef DEBUG
  63587. +/*
  63588. + * This function is called when transfer is timed out.
  63589. + */
  63590. +extern void hc_xfer_timeout(void *ptr);
  63591. +#endif
  63592. +
  63593. +/*
  63594. + * This function is called when transfer is timed out on endpoint.
  63595. + */
  63596. +extern void ep_xfer_timeout(void *ptr);
  63597. +
  63598. +/*
  63599. + * The following functions are functions for works
  63600. + * using during handling some interrupts
  63601. + */
  63602. +extern void w_conn_id_status_change(void *p);
  63603. +
  63604. +extern void w_wakeup_detected(void *p);
  63605. +
  63606. +/** Saves global register values into system memory. */
  63607. +extern int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if);
  63608. +/** Saves device register values into system memory. */
  63609. +extern int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if);
  63610. +/** Saves host register values into system memory. */
  63611. +extern int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if);
  63612. +/** Restore global register values. */
  63613. +extern int dwc_otg_restore_global_regs(dwc_otg_core_if_t * core_if);
  63614. +/** Restore host register values. */
  63615. +extern int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset);
  63616. +/** Restore device register values. */
  63617. +extern int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if,
  63618. + int rem_wakeup);
  63619. +extern int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if);
  63620. +extern int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode,
  63621. + int is_host);
  63622. +
  63623. +extern int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  63624. + int restore_mode, int reset);
  63625. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  63626. + int rem_wakeup, int reset);
  63627. +
  63628. +/*
  63629. + * The following functions support initialization of the CIL driver component
  63630. + * and the DWC_otg controller.
  63631. + */
  63632. +extern void dwc_otg_core_host_init(dwc_otg_core_if_t * _core_if);
  63633. +extern void dwc_otg_core_dev_init(dwc_otg_core_if_t * _core_if);
  63634. +
  63635. +/** @name Device CIL Functions
  63636. + * The following functions support managing the DWC_otg controller in device
  63637. + * mode.
  63638. + */
  63639. +/**@{*/
  63640. +extern void dwc_otg_wakeup(dwc_otg_core_if_t * _core_if);
  63641. +extern void dwc_otg_read_setup_packet(dwc_otg_core_if_t * _core_if,
  63642. + uint32_t * _dest);
  63643. +extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * _core_if);
  63644. +extern void dwc_otg_ep0_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  63645. +extern void dwc_otg_ep_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  63646. +extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  63647. +extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * _core_if,
  63648. + dwc_ep_t * _ep);
  63649. +extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * _core_if,
  63650. + dwc_ep_t * _ep);
  63651. +extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * _core_if,
  63652. + dwc_ep_t * _ep);
  63653. +extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * _core_if,
  63654. + dwc_ep_t * _ep);
  63655. +extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t * _core_if,
  63656. + dwc_ep_t * _ep, int _dma);
  63657. +extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  63658. +extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * _core_if,
  63659. + dwc_ep_t * _ep);
  63660. +extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * _core_if);
  63661. +
  63662. +#ifdef DWC_EN_ISOC
  63663. +extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  63664. + dwc_ep_t * ep);
  63665. +extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  63666. + dwc_ep_t * ep);
  63667. +#endif /* DWC_EN_ISOC */
  63668. +/**@}*/
  63669. +
  63670. +/** @name Host CIL Functions
  63671. + * The following functions support managing the DWC_otg controller in host
  63672. + * mode.
  63673. + */
  63674. +/**@{*/
  63675. +extern void dwc_otg_hc_init(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  63676. +extern void dwc_otg_hc_halt(dwc_otg_core_if_t * _core_if,
  63677. + dwc_hc_t * _hc, dwc_otg_halt_status_e _halt_status);
  63678. +extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  63679. +extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * _core_if,
  63680. + dwc_hc_t * _hc);
  63681. +extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * _core_if,
  63682. + dwc_hc_t * _hc);
  63683. +extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  63684. +extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t * _core_if,
  63685. + dwc_hc_t * _hc);
  63686. +extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * _core_if);
  63687. +extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * _core_if);
  63688. +
  63689. +extern void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if,
  63690. + dwc_hc_t * hc);
  63691. +
  63692. +extern uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if);
  63693. +
  63694. +/* Macro used to clear one channel interrupt */
  63695. +#define clear_hc_int(_hc_regs_, _intr_) \
  63696. +do { \
  63697. + hcint_data_t hcint_clear = {.d32 = 0}; \
  63698. + hcint_clear.b._intr_ = 1; \
  63699. + DWC_WRITE_REG32(&(_hc_regs_)->hcint, hcint_clear.d32); \
  63700. +} while (0)
  63701. +
  63702. +/*
  63703. + * Macro used to disable one channel interrupt. Channel interrupts are
  63704. + * disabled when the channel is halted or released by the interrupt handler.
  63705. + * There is no need to handle further interrupts of that type until the
  63706. + * channel is re-assigned. In fact, subsequent handling may cause crashes
  63707. + * because the channel structures are cleaned up when the channel is released.
  63708. + */
  63709. +#define disable_hc_int(_hc_regs_, _intr_) \
  63710. +do { \
  63711. + hcintmsk_data_t hcintmsk = {.d32 = 0}; \
  63712. + hcintmsk.b._intr_ = 1; \
  63713. + DWC_MODIFY_REG32(&(_hc_regs_)->hcintmsk, hcintmsk.d32, 0); \
  63714. +} while (0)
  63715. +
  63716. +/**
  63717. + * This function Reads HPRT0 in preparation to modify. It keeps the
  63718. + * WC bits 0 so that if they are read as 1, they won't clear when you
  63719. + * write it back
  63720. + */
  63721. +static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t * _core_if)
  63722. +{
  63723. + hprt0_data_t hprt0;
  63724. + hprt0.d32 = DWC_READ_REG32(_core_if->host_if->hprt0);
  63725. + hprt0.b.prtena = 0;
  63726. + hprt0.b.prtconndet = 0;
  63727. + hprt0.b.prtenchng = 0;
  63728. + hprt0.b.prtovrcurrchng = 0;
  63729. + return hprt0.d32;
  63730. +}
  63731. +
  63732. +/**@}*/
  63733. +
  63734. +/** @name Common CIL Functions
  63735. + * The following functions support managing the DWC_otg controller in either
  63736. + * device or host mode.
  63737. + */
  63738. +/**@{*/
  63739. +
  63740. +extern void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  63741. + uint8_t * dest, uint16_t bytes);
  63742. +
  63743. +extern void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * _core_if, const int _num);
  63744. +extern void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * _core_if);
  63745. +extern void dwc_otg_core_reset(dwc_otg_core_if_t * _core_if);
  63746. +
  63747. +/**
  63748. + * This function returns the Core Interrupt register.
  63749. + */
  63750. +static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t * core_if)
  63751. +{
  63752. + return (DWC_READ_REG32(&core_if->core_global_regs->gintsts) &
  63753. + DWC_READ_REG32(&core_if->core_global_regs->gintmsk));
  63754. +}
  63755. +
  63756. +/**
  63757. + * This function returns the OTG Interrupt register.
  63758. + */
  63759. +static inline uint32_t dwc_otg_read_otg_intr(dwc_otg_core_if_t * core_if)
  63760. +{
  63761. + return (DWC_READ_REG32(&core_if->core_global_regs->gotgint));
  63762. +}
  63763. +
  63764. +/**
  63765. + * This function reads the Device All Endpoints Interrupt register and
  63766. + * returns the IN endpoint interrupt bits.
  63767. + */
  63768. +static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *
  63769. + core_if)
  63770. +{
  63771. +
  63772. + uint32_t v;
  63773. +
  63774. + if (core_if->multiproc_int_enable) {
  63775. + v = DWC_READ_REG32(&core_if->dev_if->
  63776. + dev_global_regs->deachint) &
  63777. + DWC_READ_REG32(&core_if->
  63778. + dev_if->dev_global_regs->deachintmsk);
  63779. + } else {
  63780. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  63781. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  63782. + }
  63783. + return (v & 0xffff);
  63784. +}
  63785. +
  63786. +/**
  63787. + * This function reads the Device All Endpoints Interrupt register and
  63788. + * returns the OUT endpoint interrupt bits.
  63789. + */
  63790. +static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *
  63791. + core_if)
  63792. +{
  63793. + uint32_t v;
  63794. +
  63795. + if (core_if->multiproc_int_enable) {
  63796. + v = DWC_READ_REG32(&core_if->dev_if->
  63797. + dev_global_regs->deachint) &
  63798. + DWC_READ_REG32(&core_if->
  63799. + dev_if->dev_global_regs->deachintmsk);
  63800. + } else {
  63801. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  63802. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  63803. + }
  63804. +
  63805. + return ((v & 0xffff0000) >> 16);
  63806. +}
  63807. +
  63808. +/**
  63809. + * This function returns the Device IN EP Interrupt register
  63810. + */
  63811. +static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t * core_if,
  63812. + dwc_ep_t * ep)
  63813. +{
  63814. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  63815. + uint32_t v, msk, emp;
  63816. +
  63817. + if (core_if->multiproc_int_enable) {
  63818. + msk =
  63819. + DWC_READ_REG32(&dev_if->
  63820. + dev_global_regs->diepeachintmsk[ep->num]);
  63821. + emp =
  63822. + DWC_READ_REG32(&dev_if->
  63823. + dev_global_regs->dtknqr4_fifoemptymsk);
  63824. + msk |= ((emp >> ep->num) & 0x1) << 7;
  63825. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  63826. + } else {
  63827. + msk = DWC_READ_REG32(&dev_if->dev_global_regs->diepmsk);
  63828. + emp =
  63829. + DWC_READ_REG32(&dev_if->
  63830. + dev_global_regs->dtknqr4_fifoemptymsk);
  63831. + msk |= ((emp >> ep->num) & 0x1) << 7;
  63832. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  63833. + }
  63834. +
  63835. + return v;
  63836. +}
  63837. +
  63838. +/**
  63839. + * This function returns the Device OUT EP Interrupt register
  63840. + */
  63841. +static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *
  63842. + _core_if, dwc_ep_t * _ep)
  63843. +{
  63844. + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
  63845. + uint32_t v;
  63846. + doepmsk_data_t msk = {.d32 = 0 };
  63847. +
  63848. + if (_core_if->multiproc_int_enable) {
  63849. + msk.d32 =
  63850. + DWC_READ_REG32(&dev_if->
  63851. + dev_global_regs->doepeachintmsk[_ep->num]);
  63852. + if (_core_if->pti_enh_enable) {
  63853. + msk.b.pktdrpsts = 1;
  63854. + }
  63855. + v = DWC_READ_REG32(&dev_if->
  63856. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  63857. + } else {
  63858. + msk.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->doepmsk);
  63859. + if (_core_if->pti_enh_enable) {
  63860. + msk.b.pktdrpsts = 1;
  63861. + }
  63862. + v = DWC_READ_REG32(&dev_if->
  63863. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  63864. + }
  63865. + return v;
  63866. +}
  63867. +
  63868. +/**
  63869. + * This function returns the Host All Channel Interrupt register
  63870. + */
  63871. +static inline uint32_t dwc_otg_read_host_all_channels_intr(dwc_otg_core_if_t *
  63872. + _core_if)
  63873. +{
  63874. + return (DWC_READ_REG32(&_core_if->host_if->host_global_regs->haint));
  63875. +}
  63876. +
  63877. +static inline uint32_t dwc_otg_read_host_channel_intr(dwc_otg_core_if_t *
  63878. + _core_if, dwc_hc_t * _hc)
  63879. +{
  63880. + return (DWC_READ_REG32
  63881. + (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
  63882. +}
  63883. +
  63884. +/**
  63885. + * This function returns the mode of the operation, host or device.
  63886. + *
  63887. + * @return 0 - Device Mode, 1 - Host Mode
  63888. + */
  63889. +static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t * _core_if)
  63890. +{
  63891. + return (DWC_READ_REG32(&_core_if->core_global_regs->gintsts) & 0x1);
  63892. +}
  63893. +
  63894. +/**@}*/
  63895. +
  63896. +/**
  63897. + * DWC_otg CIL callback structure. This structure allows the HCD and
  63898. + * PCD to register functions used for starting and stopping the PCD
  63899. + * and HCD for role change on for a DRD.
  63900. + */
  63901. +typedef struct dwc_otg_cil_callbacks {
  63902. + /** Start function for role change */
  63903. + int (*start) (void *_p);
  63904. + /** Stop Function for role change */
  63905. + int (*stop) (void *_p);
  63906. + /** Disconnect Function for role change */
  63907. + int (*disconnect) (void *_p);
  63908. + /** Resume/Remote wakeup Function */
  63909. + int (*resume_wakeup) (void *_p);
  63910. + /** Suspend function */
  63911. + int (*suspend) (void *_p);
  63912. + /** Session Start (SRP) */
  63913. + int (*session_start) (void *_p);
  63914. +#ifdef CONFIG_USB_DWC_OTG_LPM
  63915. + /** Sleep (switch to L0 state) */
  63916. + int (*sleep) (void *_p);
  63917. +#endif
  63918. + /** Pointer passed to start() and stop() */
  63919. + void *p;
  63920. +} dwc_otg_cil_callbacks_t;
  63921. +
  63922. +extern void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * _core_if,
  63923. + dwc_otg_cil_callbacks_t * _cb,
  63924. + void *_p);
  63925. +extern void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * _core_if,
  63926. + dwc_otg_cil_callbacks_t * _cb,
  63927. + void *_p);
  63928. +
  63929. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if);
  63930. +
  63931. +//////////////////////////////////////////////////////////////////////
  63932. +/** Start the HCD. Helper function for using the HCD callbacks.
  63933. + *
  63934. + * @param core_if Programming view of DWC_otg controller.
  63935. + */
  63936. +static inline void cil_hcd_start(dwc_otg_core_if_t * core_if)
  63937. +{
  63938. + if (core_if->hcd_cb && core_if->hcd_cb->start) {
  63939. + core_if->hcd_cb->start(core_if->hcd_cb->p);
  63940. + }
  63941. +}
  63942. +
  63943. +/** Stop the HCD. Helper function for using the HCD callbacks.
  63944. + *
  63945. + * @param core_if Programming view of DWC_otg controller.
  63946. + */
  63947. +static inline void cil_hcd_stop(dwc_otg_core_if_t * core_if)
  63948. +{
  63949. + if (core_if->hcd_cb && core_if->hcd_cb->stop) {
  63950. + core_if->hcd_cb->stop(core_if->hcd_cb->p);
  63951. + }
  63952. +}
  63953. +
  63954. +/** Disconnect the HCD. Helper function for using the HCD callbacks.
  63955. + *
  63956. + * @param core_if Programming view of DWC_otg controller.
  63957. + */
  63958. +static inline void cil_hcd_disconnect(dwc_otg_core_if_t * core_if)
  63959. +{
  63960. + if (core_if->hcd_cb && core_if->hcd_cb->disconnect) {
  63961. + core_if->hcd_cb->disconnect(core_if->hcd_cb->p);
  63962. + }
  63963. +}
  63964. +
  63965. +/** Inform the HCD the a New Session has begun. Helper function for
  63966. + * using the HCD callbacks.
  63967. + *
  63968. + * @param core_if Programming view of DWC_otg controller.
  63969. + */
  63970. +static inline void cil_hcd_session_start(dwc_otg_core_if_t * core_if)
  63971. +{
  63972. + if (core_if->hcd_cb && core_if->hcd_cb->session_start) {
  63973. + core_if->hcd_cb->session_start(core_if->hcd_cb->p);
  63974. + }
  63975. +}
  63976. +
  63977. +#ifdef CONFIG_USB_DWC_OTG_LPM
  63978. +/**
  63979. + * Inform the HCD about LPM sleep.
  63980. + * Helper function for using the HCD callbacks.
  63981. + *
  63982. + * @param core_if Programming view of DWC_otg controller.
  63983. + */
  63984. +static inline void cil_hcd_sleep(dwc_otg_core_if_t * core_if)
  63985. +{
  63986. + if (core_if->hcd_cb && core_if->hcd_cb->sleep) {
  63987. + core_if->hcd_cb->sleep(core_if->hcd_cb->p);
  63988. + }
  63989. +}
  63990. +#endif
  63991. +
  63992. +/** Resume the HCD. Helper function for using the HCD callbacks.
  63993. + *
  63994. + * @param core_if Programming view of DWC_otg controller.
  63995. + */
  63996. +static inline void cil_hcd_resume(dwc_otg_core_if_t * core_if)
  63997. +{
  63998. + if (core_if->hcd_cb && core_if->hcd_cb->resume_wakeup) {
  63999. + core_if->hcd_cb->resume_wakeup(core_if->hcd_cb->p);
  64000. + }
  64001. +}
  64002. +
  64003. +/** Start the PCD. Helper function for using the PCD callbacks.
  64004. + *
  64005. + * @param core_if Programming view of DWC_otg controller.
  64006. + */
  64007. +static inline void cil_pcd_start(dwc_otg_core_if_t * core_if)
  64008. +{
  64009. + if (core_if->pcd_cb && core_if->pcd_cb->start) {
  64010. + core_if->pcd_cb->start(core_if->pcd_cb->p);
  64011. + }
  64012. +}
  64013. +
  64014. +/** Stop the PCD. Helper function for using the PCD callbacks.
  64015. + *
  64016. + * @param core_if Programming view of DWC_otg controller.
  64017. + */
  64018. +static inline void cil_pcd_stop(dwc_otg_core_if_t * core_if)
  64019. +{
  64020. + if (core_if->pcd_cb && core_if->pcd_cb->stop) {
  64021. + core_if->pcd_cb->stop(core_if->pcd_cb->p);
  64022. + }
  64023. +}
  64024. +
  64025. +/** Suspend the PCD. Helper function for using the PCD callbacks.
  64026. + *
  64027. + * @param core_if Programming view of DWC_otg controller.
  64028. + */
  64029. +static inline void cil_pcd_suspend(dwc_otg_core_if_t * core_if)
  64030. +{
  64031. + if (core_if->pcd_cb && core_if->pcd_cb->suspend) {
  64032. + core_if->pcd_cb->suspend(core_if->pcd_cb->p);
  64033. + }
  64034. +}
  64035. +
  64036. +/** Resume the PCD. Helper function for using the PCD callbacks.
  64037. + *
  64038. + * @param core_if Programming view of DWC_otg controller.
  64039. + */
  64040. +static inline void cil_pcd_resume(dwc_otg_core_if_t * core_if)
  64041. +{
  64042. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  64043. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  64044. + }
  64045. +}
  64046. +
  64047. +//////////////////////////////////////////////////////////////////////
  64048. +
  64049. +#endif
  64050. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c
  64051. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 1970-01-01 01:00:00.000000000 +0100
  64052. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 2014-02-18 11:52:14.000000000 +0100
  64053. @@ -0,0 +1,1588 @@
  64054. +/* ==========================================================================
  64055. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil_intr.c $
  64056. + * $Revision: #32 $
  64057. + * $Date: 2012/08/10 $
  64058. + * $Change: 2047372 $
  64059. + *
  64060. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  64061. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  64062. + * otherwise expressly agreed to in writing between Synopsys and you.
  64063. + *
  64064. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  64065. + * any End User Software License Agreement or Agreement for Licensed Product
  64066. + * with Synopsys or any supplement thereto. You are permitted to use and
  64067. + * redistribute this Software in source and binary forms, with or without
  64068. + * modification, provided that redistributions of source code must retain this
  64069. + * notice. You may not view, use, disclose, copy or distribute this file or
  64070. + * any information contained herein except pursuant to this license grant from
  64071. + * Synopsys. If you do not agree with this notice, including the disclaimer
  64072. + * below, then you are not authorized to use the Software.
  64073. + *
  64074. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  64075. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  64076. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  64077. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  64078. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  64079. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  64080. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  64081. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  64082. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  64083. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  64084. + * DAMAGE.
  64085. + * ========================================================================== */
  64086. +
  64087. +/** @file
  64088. + *
  64089. + * The Core Interface Layer provides basic services for accessing and
  64090. + * managing the DWC_otg hardware. These services are used by both the
  64091. + * Host Controller Driver and the Peripheral Controller Driver.
  64092. + *
  64093. + * This file contains the Common Interrupt handlers.
  64094. + */
  64095. +#include "dwc_os.h"
  64096. +#include "dwc_otg_regs.h"
  64097. +#include "dwc_otg_cil.h"
  64098. +#include "dwc_otg_driver.h"
  64099. +#include "dwc_otg_pcd.h"
  64100. +#include "dwc_otg_hcd.h"
  64101. +#include "dwc_otg_mphi_fix.h"
  64102. +
  64103. +#ifdef DEBUG
  64104. +inline const char *op_state_str(dwc_otg_core_if_t * core_if)
  64105. +{
  64106. + return (core_if->op_state == A_HOST ? "a_host" :
  64107. + (core_if->op_state == A_SUSPEND ? "a_suspend" :
  64108. + (core_if->op_state == A_PERIPHERAL ? "a_peripheral" :
  64109. + (core_if->op_state == B_PERIPHERAL ? "b_peripheral" :
  64110. + (core_if->op_state == B_HOST ? "b_host" : "unknown")))));
  64111. +}
  64112. +#endif
  64113. +
  64114. +/** This function will log a debug message
  64115. + *
  64116. + * @param core_if Programming view of DWC_otg controller.
  64117. + */
  64118. +int32_t dwc_otg_handle_mode_mismatch_intr(dwc_otg_core_if_t * core_if)
  64119. +{
  64120. + gintsts_data_t gintsts;
  64121. + DWC_WARN("Mode Mismatch Interrupt: currently in %s mode\n",
  64122. + dwc_otg_mode(core_if) ? "Host" : "Device");
  64123. +
  64124. + /* Clear interrupt */
  64125. + gintsts.d32 = 0;
  64126. + gintsts.b.modemismatch = 1;
  64127. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64128. + return 1;
  64129. +}
  64130. +
  64131. +/**
  64132. + * This function handles the OTG Interrupts. It reads the OTG
  64133. + * Interrupt Register (GOTGINT) to determine what interrupt has
  64134. + * occurred.
  64135. + *
  64136. + * @param core_if Programming view of DWC_otg controller.
  64137. + */
  64138. +int32_t dwc_otg_handle_otg_intr(dwc_otg_core_if_t * core_if)
  64139. +{
  64140. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  64141. + gotgint_data_t gotgint;
  64142. + gotgctl_data_t gotgctl;
  64143. + gintmsk_data_t gintmsk;
  64144. + gpwrdn_data_t gpwrdn;
  64145. +
  64146. + gotgint.d32 = DWC_READ_REG32(&global_regs->gotgint);
  64147. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  64148. + DWC_DEBUGPL(DBG_CIL, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint.d32,
  64149. + op_state_str(core_if));
  64150. +
  64151. + if (gotgint.b.sesenddet) {
  64152. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  64153. + "Session End Detected++ (%s)\n",
  64154. + op_state_str(core_if));
  64155. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  64156. +
  64157. + if (core_if->op_state == B_HOST) {
  64158. + cil_pcd_start(core_if);
  64159. + core_if->op_state = B_PERIPHERAL;
  64160. + } else {
  64161. + /* If not B_HOST and Device HNP still set. HNP
  64162. + * Did not succeed!*/
  64163. + if (gotgctl.b.devhnpen) {
  64164. + DWC_DEBUGPL(DBG_ANY, "Session End Detected\n");
  64165. + __DWC_ERROR("Device Not Connected/Responding!\n");
  64166. + }
  64167. +
  64168. + /* If Session End Detected the B-Cable has
  64169. + * been disconnected. */
  64170. + /* Reset PCD and Gadget driver to a
  64171. + * clean state. */
  64172. + core_if->lx_state = DWC_OTG_L0;
  64173. + DWC_SPINUNLOCK(core_if->lock);
  64174. + cil_pcd_stop(core_if);
  64175. + DWC_SPINLOCK(core_if->lock);
  64176. +
  64177. + if (core_if->adp_enable) {
  64178. + if (core_if->power_down == 2) {
  64179. + gpwrdn.d32 = 0;
  64180. + gpwrdn.b.pwrdnswtch = 1;
  64181. + DWC_MODIFY_REG32(&core_if->
  64182. + core_global_regs->
  64183. + gpwrdn, gpwrdn.d32, 0);
  64184. + }
  64185. +
  64186. + gpwrdn.d32 = 0;
  64187. + gpwrdn.b.pmuintsel = 1;
  64188. + gpwrdn.b.pmuactv = 1;
  64189. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64190. + gpwrdn, 0, gpwrdn.d32);
  64191. +
  64192. + dwc_otg_adp_sense_start(core_if);
  64193. + }
  64194. + }
  64195. +
  64196. + gotgctl.d32 = 0;
  64197. + gotgctl.b.devhnpen = 1;
  64198. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  64199. + }
  64200. + if (gotgint.b.sesreqsucstschng) {
  64201. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  64202. + "Session Reqeust Success Status Change++\n");
  64203. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  64204. + if (gotgctl.b.sesreqscs) {
  64205. +
  64206. + if ((core_if->core_params->phy_type ==
  64207. + DWC_PHY_TYPE_PARAM_FS) && (core_if->core_params->i2c_enable)) {
  64208. + core_if->srp_success = 1;
  64209. + } else {
  64210. + DWC_SPINUNLOCK(core_if->lock);
  64211. + cil_pcd_resume(core_if);
  64212. + DWC_SPINLOCK(core_if->lock);
  64213. + /* Clear Session Request */
  64214. + gotgctl.d32 = 0;
  64215. + gotgctl.b.sesreq = 1;
  64216. + DWC_MODIFY_REG32(&global_regs->gotgctl,
  64217. + gotgctl.d32, 0);
  64218. + }
  64219. + }
  64220. + }
  64221. + if (gotgint.b.hstnegsucstschng) {
  64222. + /* Print statements during the HNP interrupt handling
  64223. + * can cause it to fail.*/
  64224. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  64225. + /* WA for 3.00a- HW is not setting cur_mode, even sometimes
  64226. + * this does not help*/
  64227. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  64228. + dwc_udelay(100);
  64229. + if (gotgctl.b.hstnegscs) {
  64230. + if (dwc_otg_is_host_mode(core_if)) {
  64231. + core_if->op_state = B_HOST;
  64232. + /*
  64233. + * Need to disable SOF interrupt immediately.
  64234. + * When switching from device to host, the PCD
  64235. + * interrupt handler won't handle the
  64236. + * interrupt if host mode is already set. The
  64237. + * HCD interrupt handler won't get called if
  64238. + * the HCD state is HALT. This means that the
  64239. + * interrupt does not get handled and Linux
  64240. + * complains loudly.
  64241. + */
  64242. + gintmsk.d32 = 0;
  64243. + gintmsk.b.sofintr = 1;
  64244. + DWC_MODIFY_REG32(&global_regs->gintmsk,
  64245. + gintmsk.d32, 0);
  64246. + /* Call callback function with spin lock released */
  64247. + DWC_SPINUNLOCK(core_if->lock);
  64248. + cil_pcd_stop(core_if);
  64249. + /*
  64250. + * Initialize the Core for Host mode.
  64251. + */
  64252. + cil_hcd_start(core_if);
  64253. + DWC_SPINLOCK(core_if->lock);
  64254. + core_if->op_state = B_HOST;
  64255. + }
  64256. + } else {
  64257. + gotgctl.d32 = 0;
  64258. + gotgctl.b.hnpreq = 1;
  64259. + gotgctl.b.devhnpen = 1;
  64260. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  64261. + DWC_DEBUGPL(DBG_ANY, "HNP Failed\n");
  64262. + __DWC_ERROR("Device Not Connected/Responding\n");
  64263. + }
  64264. + }
  64265. + if (gotgint.b.hstnegdet) {
  64266. + /* The disconnect interrupt is set at the same time as
  64267. + * Host Negotiation Detected. During the mode
  64268. + * switch all interrupts are cleared so the disconnect
  64269. + * interrupt handler will not get executed.
  64270. + */
  64271. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  64272. + "Host Negotiation Detected++ (%s)\n",
  64273. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  64274. + "Device"));
  64275. + if (dwc_otg_is_device_mode(core_if)) {
  64276. + DWC_DEBUGPL(DBG_ANY, "a_suspend->a_peripheral (%d)\n",
  64277. + core_if->op_state);
  64278. + DWC_SPINUNLOCK(core_if->lock);
  64279. + cil_hcd_disconnect(core_if);
  64280. + cil_pcd_start(core_if);
  64281. + DWC_SPINLOCK(core_if->lock);
  64282. + core_if->op_state = A_PERIPHERAL;
  64283. + } else {
  64284. + /*
  64285. + * Need to disable SOF interrupt immediately. When
  64286. + * switching from device to host, the PCD interrupt
  64287. + * handler won't handle the interrupt if host mode is
  64288. + * already set. The HCD interrupt handler won't get
  64289. + * called if the HCD state is HALT. This means that
  64290. + * the interrupt does not get handled and Linux
  64291. + * complains loudly.
  64292. + */
  64293. + gintmsk.d32 = 0;
  64294. + gintmsk.b.sofintr = 1;
  64295. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmsk.d32, 0);
  64296. + DWC_SPINUNLOCK(core_if->lock);
  64297. + cil_pcd_stop(core_if);
  64298. + cil_hcd_start(core_if);
  64299. + DWC_SPINLOCK(core_if->lock);
  64300. + core_if->op_state = A_HOST;
  64301. + }
  64302. + }
  64303. + if (gotgint.b.adevtoutchng) {
  64304. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  64305. + "A-Device Timeout Change++\n");
  64306. + }
  64307. + if (gotgint.b.debdone) {
  64308. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: " "Debounce Done++\n");
  64309. + }
  64310. +
  64311. + /* Clear GOTGINT */
  64312. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, gotgint.d32);
  64313. +
  64314. + return 1;
  64315. +}
  64316. +
  64317. +void w_conn_id_status_change(void *p)
  64318. +{
  64319. + dwc_otg_core_if_t *core_if = p;
  64320. + uint32_t count = 0;
  64321. + gotgctl_data_t gotgctl = {.d32 = 0 };
  64322. +
  64323. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  64324. + DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32);
  64325. + DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts);
  64326. +
  64327. + /* B-Device connector (Device Mode) */
  64328. + if (gotgctl.b.conidsts) {
  64329. + /* Wait for switch to device mode. */
  64330. + while (!dwc_otg_is_device_mode(core_if)) {
  64331. + DWC_PRINTF("Waiting for Peripheral Mode, Mode=%s\n",
  64332. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  64333. + "Peripheral"));
  64334. + dwc_mdelay(100);
  64335. + if (++count > 10000)
  64336. + break;
  64337. + }
  64338. + DWC_ASSERT(++count < 10000,
  64339. + "Connection id status change timed out");
  64340. + core_if->op_state = B_PERIPHERAL;
  64341. + dwc_otg_core_init(core_if);
  64342. + dwc_otg_enable_global_interrupts(core_if);
  64343. + cil_pcd_start(core_if);
  64344. + } else {
  64345. + /* A-Device connector (Host Mode) */
  64346. + while (!dwc_otg_is_host_mode(core_if)) {
  64347. + DWC_PRINTF("Waiting for Host Mode, Mode=%s\n",
  64348. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  64349. + "Peripheral"));
  64350. + dwc_mdelay(100);
  64351. + if (++count > 10000)
  64352. + break;
  64353. + }
  64354. + DWC_ASSERT(++count < 10000,
  64355. + "Connection id status change timed out");
  64356. + core_if->op_state = A_HOST;
  64357. + /*
  64358. + * Initialize the Core for Host mode.
  64359. + */
  64360. + dwc_otg_core_init(core_if);
  64361. + dwc_otg_enable_global_interrupts(core_if);
  64362. + cil_hcd_start(core_if);
  64363. + }
  64364. +}
  64365. +
  64366. +/**
  64367. + * This function handles the Connector ID Status Change Interrupt. It
  64368. + * reads the OTG Interrupt Register (GOTCTL) to determine whether this
  64369. + * is a Device to Host Mode transition or a Host Mode to Device
  64370. + * Transition.
  64371. + *
  64372. + * This only occurs when the cable is connected/removed from the PHY
  64373. + * connector.
  64374. + *
  64375. + * @param core_if Programming view of DWC_otg controller.
  64376. + */
  64377. +int32_t dwc_otg_handle_conn_id_status_change_intr(dwc_otg_core_if_t * core_if)
  64378. +{
  64379. +
  64380. + /*
  64381. + * Need to disable SOF interrupt immediately. If switching from device
  64382. + * to host, the PCD interrupt handler won't handle the interrupt if
  64383. + * host mode is already set. The HCD interrupt handler won't get
  64384. + * called if the HCD state is HALT. This means that the interrupt does
  64385. + * not get handled and Linux complains loudly.
  64386. + */
  64387. + gintmsk_data_t gintmsk = {.d32 = 0 };
  64388. + gintsts_data_t gintsts = {.d32 = 0 };
  64389. +
  64390. + gintmsk.b.sofintr = 1;
  64391. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  64392. +
  64393. + DWC_DEBUGPL(DBG_CIL,
  64394. + " ++Connector ID Status Change Interrupt++ (%s)\n",
  64395. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"));
  64396. +
  64397. + DWC_SPINUNLOCK(core_if->lock);
  64398. +
  64399. + /*
  64400. + * Need to schedule a work, as there are possible DELAY function calls
  64401. + * Release lock before scheduling workq as it holds spinlock during scheduling
  64402. + */
  64403. +
  64404. + DWC_WORKQ_SCHEDULE(core_if->wq_otg, w_conn_id_status_change,
  64405. + core_if, "connection id status change");
  64406. + DWC_SPINLOCK(core_if->lock);
  64407. +
  64408. + /* Set flag and clear interrupt */
  64409. + gintsts.b.conidstschng = 1;
  64410. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64411. +
  64412. + return 1;
  64413. +}
  64414. +
  64415. +/**
  64416. + * This interrupt indicates that a device is initiating the Session
  64417. + * Request Protocol to request the host to turn on bus power so a new
  64418. + * session can begin. The handler responds by turning on bus power. If
  64419. + * the DWC_otg controller is in low power mode, the handler brings the
  64420. + * controller out of low power mode before turning on bus power.
  64421. + *
  64422. + * @param core_if Programming view of DWC_otg controller.
  64423. + */
  64424. +int32_t dwc_otg_handle_session_req_intr(dwc_otg_core_if_t * core_if)
  64425. +{
  64426. + gintsts_data_t gintsts;
  64427. +
  64428. +#ifndef DWC_HOST_ONLY
  64429. + DWC_DEBUGPL(DBG_ANY, "++Session Request Interrupt++\n");
  64430. +
  64431. + if (dwc_otg_is_device_mode(core_if)) {
  64432. + DWC_PRINTF("SRP: Device mode\n");
  64433. + } else {
  64434. + hprt0_data_t hprt0;
  64435. + DWC_PRINTF("SRP: Host mode\n");
  64436. +
  64437. + /* Turn on the port power bit. */
  64438. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  64439. + hprt0.b.prtpwr = 1;
  64440. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  64441. +
  64442. + /* Start the Connection timer. So a message can be displayed
  64443. + * if connect does not occur within 10 seconds. */
  64444. + cil_hcd_session_start(core_if);
  64445. + }
  64446. +#endif
  64447. +
  64448. + /* Clear interrupt */
  64449. + gintsts.d32 = 0;
  64450. + gintsts.b.sessreqintr = 1;
  64451. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64452. +
  64453. + return 1;
  64454. +}
  64455. +
  64456. +void w_wakeup_detected(void *p)
  64457. +{
  64458. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) p;
  64459. + /*
  64460. + * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms
  64461. + * so that OPT tests pass with all PHYs).
  64462. + */
  64463. + hprt0_data_t hprt0 = {.d32 = 0 };
  64464. +#if 0
  64465. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64466. + /* Restart the Phy Clock */
  64467. + pcgcctl.b.stoppclk = 1;
  64468. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  64469. + dwc_udelay(10);
  64470. +#endif //0
  64471. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  64472. + DWC_DEBUGPL(DBG_ANY, "Resume: HPRT0=%0x\n", hprt0.d32);
  64473. +// dwc_mdelay(70);
  64474. + hprt0.b.prtres = 0; /* Resume */
  64475. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  64476. + DWC_DEBUGPL(DBG_ANY, "Clear Resume: HPRT0=%0x\n",
  64477. + DWC_READ_REG32(core_if->host_if->hprt0));
  64478. +
  64479. + cil_hcd_resume(core_if);
  64480. +
  64481. + /** Change to L0 state*/
  64482. + core_if->lx_state = DWC_OTG_L0;
  64483. +}
  64484. +
  64485. +/**
  64486. + * This interrupt indicates that the DWC_otg controller has detected a
  64487. + * resume or remote wakeup sequence. If the DWC_otg controller is in
  64488. + * low power mode, the handler must brings the controller out of low
  64489. + * power mode. The controller automatically begins resume
  64490. + * signaling. The handler schedules a time to stop resume signaling.
  64491. + */
  64492. +int32_t dwc_otg_handle_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  64493. +{
  64494. + gintsts_data_t gintsts;
  64495. +
  64496. + DWC_DEBUGPL(DBG_ANY,
  64497. + "++Resume and Remote Wakeup Detected Interrupt++\n");
  64498. +
  64499. + DWC_PRINTF("%s lxstate = %d\n", __func__, core_if->lx_state);
  64500. +
  64501. + if (dwc_otg_is_device_mode(core_if)) {
  64502. + dctl_data_t dctl = {.d32 = 0 };
  64503. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n",
  64504. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  64505. + dsts));
  64506. + if (core_if->lx_state == DWC_OTG_L2) {
  64507. +#ifdef PARTIAL_POWER_DOWN
  64508. + if (core_if->hwcfg4.b.power_optimiz) {
  64509. + pcgcctl_data_t power = {.d32 = 0 };
  64510. +
  64511. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  64512. + DWC_DEBUGPL(DBG_CIL, "PCGCCTL=%0x\n",
  64513. + power.d32);
  64514. +
  64515. + power.b.stoppclk = 0;
  64516. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  64517. +
  64518. + power.b.pwrclmp = 0;
  64519. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  64520. +
  64521. + power.b.rstpdwnmodule = 0;
  64522. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  64523. + }
  64524. +#endif
  64525. + /* Clear the Remote Wakeup Signaling */
  64526. + dctl.b.rmtwkupsig = 1;
  64527. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  64528. + dctl, dctl.d32, 0);
  64529. +
  64530. + DWC_SPINUNLOCK(core_if->lock);
  64531. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  64532. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  64533. + }
  64534. + DWC_SPINLOCK(core_if->lock);
  64535. + } else {
  64536. + glpmcfg_data_t lpmcfg;
  64537. + lpmcfg.d32 =
  64538. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  64539. + lpmcfg.b.hird_thres &= (~(1 << 4));
  64540. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  64541. + lpmcfg.d32);
  64542. + }
  64543. + /** Change to L0 state*/
  64544. + core_if->lx_state = DWC_OTG_L0;
  64545. + } else {
  64546. + if (core_if->lx_state != DWC_OTG_L1) {
  64547. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64548. +
  64549. + /* Restart the Phy Clock */
  64550. + pcgcctl.b.stoppclk = 1;
  64551. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  64552. + DWC_TIMER_SCHEDULE(core_if->wkp_timer, 71);
  64553. + } else {
  64554. + /** Change to L0 state*/
  64555. + core_if->lx_state = DWC_OTG_L0;
  64556. + }
  64557. + }
  64558. +
  64559. + /* Clear interrupt */
  64560. + gintsts.d32 = 0;
  64561. + gintsts.b.wkupintr = 1;
  64562. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64563. +
  64564. + return 1;
  64565. +}
  64566. +
  64567. +/**
  64568. + * This interrupt indicates that the Wakeup Logic has detected a
  64569. + * Device disconnect.
  64570. + */
  64571. +static int32_t dwc_otg_handle_pwrdn_disconnect_intr(dwc_otg_core_if_t *core_if)
  64572. +{
  64573. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  64574. + gpwrdn_data_t gpwrdn_temp = { .d32 = 0 };
  64575. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64576. +
  64577. + DWC_PRINTF("%s called\n", __FUNCTION__);
  64578. +
  64579. + if (!core_if->hibernation_suspend) {
  64580. + DWC_PRINTF("Already exited from Hibernation\n");
  64581. + return 1;
  64582. + }
  64583. +
  64584. + /* Switch on the voltage to the core */
  64585. + gpwrdn.b.pwrdnswtch = 1;
  64586. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64587. + dwc_udelay(10);
  64588. +
  64589. + /* Reset the core */
  64590. + gpwrdn.d32 = 0;
  64591. + gpwrdn.b.pwrdnrstn = 1;
  64592. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64593. + dwc_udelay(10);
  64594. +
  64595. + /* Disable power clamps*/
  64596. + gpwrdn.d32 = 0;
  64597. + gpwrdn.b.pwrdnclmp = 1;
  64598. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64599. +
  64600. + /* Remove reset the core signal */
  64601. + gpwrdn.d32 = 0;
  64602. + gpwrdn.b.pwrdnrstn = 1;
  64603. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  64604. + dwc_udelay(10);
  64605. +
  64606. + /* Disable PMU interrupt */
  64607. + gpwrdn.d32 = 0;
  64608. + gpwrdn.b.pmuintsel = 1;
  64609. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64610. +
  64611. + core_if->hibernation_suspend = 0;
  64612. +
  64613. + /* Disable PMU */
  64614. + gpwrdn.d32 = 0;
  64615. + gpwrdn.b.pmuactv = 1;
  64616. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64617. + dwc_udelay(10);
  64618. +
  64619. + if (gpwrdn_temp.b.idsts) {
  64620. + core_if->op_state = B_PERIPHERAL;
  64621. + dwc_otg_core_init(core_if);
  64622. + dwc_otg_enable_global_interrupts(core_if);
  64623. + cil_pcd_start(core_if);
  64624. + } else {
  64625. + core_if->op_state = A_HOST;
  64626. + dwc_otg_core_init(core_if);
  64627. + dwc_otg_enable_global_interrupts(core_if);
  64628. + cil_hcd_start(core_if);
  64629. + }
  64630. +
  64631. + return 1;
  64632. +}
  64633. +
  64634. +/**
  64635. + * This interrupt indicates that the Wakeup Logic has detected a
  64636. + * remote wakeup sequence.
  64637. + */
  64638. +static int32_t dwc_otg_handle_pwrdn_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  64639. +{
  64640. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64641. + DWC_DEBUGPL(DBG_ANY,
  64642. + "++Powerdown Remote Wakeup Detected Interrupt++\n");
  64643. +
  64644. + if (!core_if->hibernation_suspend) {
  64645. + DWC_PRINTF("Already exited from Hibernation\n");
  64646. + return 1;
  64647. + }
  64648. +
  64649. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64650. + if (gpwrdn.b.idsts) { // Device Mode
  64651. + if ((core_if->power_down == 2)
  64652. + && (core_if->hibernation_suspend == 1)) {
  64653. + dwc_otg_device_hibernation_restore(core_if, 0, 0);
  64654. + }
  64655. + } else {
  64656. + if ((core_if->power_down == 2)
  64657. + && (core_if->hibernation_suspend == 1)) {
  64658. + dwc_otg_host_hibernation_restore(core_if, 1, 0);
  64659. + }
  64660. + }
  64661. + return 1;
  64662. +}
  64663. +
  64664. +static int32_t dwc_otg_handle_pwrdn_idsts_change(dwc_otg_device_t *otg_dev)
  64665. +{
  64666. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64667. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  64668. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  64669. +
  64670. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  64671. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64672. + if (core_if->power_down == 2) {
  64673. + if (!core_if->hibernation_suspend) {
  64674. + DWC_PRINTF("Already exited from Hibernation\n");
  64675. + return 1;
  64676. + }
  64677. + DWC_DEBUGPL(DBG_ANY, "Exit from hibernation on ID sts change\n");
  64678. + /* Switch on the voltage to the core */
  64679. + gpwrdn.b.pwrdnswtch = 1;
  64680. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64681. + dwc_udelay(10);
  64682. +
  64683. + /* Reset the core */
  64684. + gpwrdn.d32 = 0;
  64685. + gpwrdn.b.pwrdnrstn = 1;
  64686. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64687. + dwc_udelay(10);
  64688. +
  64689. + /* Disable power clamps */
  64690. + gpwrdn.d32 = 0;
  64691. + gpwrdn.b.pwrdnclmp = 1;
  64692. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64693. +
  64694. + /* Remove reset the core signal */
  64695. + gpwrdn.d32 = 0;
  64696. + gpwrdn.b.pwrdnrstn = 1;
  64697. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  64698. + dwc_udelay(10);
  64699. +
  64700. + /* Disable PMU interrupt */
  64701. + gpwrdn.d32 = 0;
  64702. + gpwrdn.b.pmuintsel = 1;
  64703. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64704. +
  64705. + /*Indicates that we are exiting from hibernation */
  64706. + core_if->hibernation_suspend = 0;
  64707. +
  64708. + /* Disable PMU */
  64709. + gpwrdn.d32 = 0;
  64710. + gpwrdn.b.pmuactv = 1;
  64711. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64712. + dwc_udelay(10);
  64713. +
  64714. + gpwrdn.d32 = core_if->gr_backup->gpwrdn_local;
  64715. + if (gpwrdn.b.dis_vbus == 1) {
  64716. + gpwrdn.d32 = 0;
  64717. + gpwrdn.b.dis_vbus = 1;
  64718. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64719. + }
  64720. +
  64721. + if (gpwrdn_temp.b.idsts) {
  64722. + core_if->op_state = B_PERIPHERAL;
  64723. + dwc_otg_core_init(core_if);
  64724. + dwc_otg_enable_global_interrupts(core_if);
  64725. + cil_pcd_start(core_if);
  64726. + } else {
  64727. + core_if->op_state = A_HOST;
  64728. + dwc_otg_core_init(core_if);
  64729. + dwc_otg_enable_global_interrupts(core_if);
  64730. + cil_hcd_start(core_if);
  64731. + }
  64732. + }
  64733. +
  64734. + if (core_if->adp_enable) {
  64735. + uint8_t is_host = 0;
  64736. + DWC_SPINUNLOCK(core_if->lock);
  64737. + /* Change the core_if's lock to hcd/pcd lock depend on mode? */
  64738. +#ifndef DWC_HOST_ONLY
  64739. + if (gpwrdn_temp.b.idsts)
  64740. + core_if->lock = otg_dev->pcd->lock;
  64741. +#endif
  64742. +#ifndef DWC_DEVICE_ONLY
  64743. + if (!gpwrdn_temp.b.idsts) {
  64744. + core_if->lock = otg_dev->hcd->lock;
  64745. + is_host = 1;
  64746. + }
  64747. +#endif
  64748. + DWC_PRINTF("RESTART ADP\n");
  64749. + if (core_if->adp.probe_enabled)
  64750. + dwc_otg_adp_probe_stop(core_if);
  64751. + if (core_if->adp.sense_enabled)
  64752. + dwc_otg_adp_sense_stop(core_if);
  64753. + if (core_if->adp.sense_timer_started)
  64754. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  64755. + if (core_if->adp.vbuson_timer_started)
  64756. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  64757. + core_if->adp.probe_timer_values[0] = -1;
  64758. + core_if->adp.probe_timer_values[1] = -1;
  64759. + core_if->adp.sense_timer_started = 0;
  64760. + core_if->adp.vbuson_timer_started = 0;
  64761. + core_if->adp.probe_counter = 0;
  64762. + core_if->adp.gpwrdn = 0;
  64763. +
  64764. + /* Disable PMU and restart ADP */
  64765. + gpwrdn_temp.d32 = 0;
  64766. + gpwrdn_temp.b.pmuactv = 1;
  64767. + gpwrdn_temp.b.pmuintsel = 1;
  64768. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64769. + DWC_PRINTF("Check point 1\n");
  64770. + dwc_mdelay(110);
  64771. + dwc_otg_adp_start(core_if, is_host);
  64772. + DWC_SPINLOCK(core_if->lock);
  64773. + }
  64774. +
  64775. +
  64776. + return 1;
  64777. +}
  64778. +
  64779. +static int32_t dwc_otg_handle_pwrdn_session_change(dwc_otg_core_if_t * core_if)
  64780. +{
  64781. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64782. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  64783. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  64784. +
  64785. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64786. + if (core_if->power_down == 2) {
  64787. + if (!core_if->hibernation_suspend) {
  64788. + DWC_PRINTF("Already exited from Hibernation\n");
  64789. + return 1;
  64790. + }
  64791. +
  64792. + if ((otg_cap_param != DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  64793. + otg_cap_param != DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) &&
  64794. + gpwrdn.b.bsessvld == 0) {
  64795. + /* Save gpwrdn register for further usage if stschng interrupt */
  64796. + core_if->gr_backup->gpwrdn_local =
  64797. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64798. + /*Exit from ISR and wait for stschng interrupt with bsessvld = 1 */
  64799. + return 1;
  64800. + }
  64801. +
  64802. + /* Switch on the voltage to the core */
  64803. + gpwrdn.d32 = 0;
  64804. + gpwrdn.b.pwrdnswtch = 1;
  64805. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64806. + dwc_udelay(10);
  64807. +
  64808. + /* Reset the core */
  64809. + gpwrdn.d32 = 0;
  64810. + gpwrdn.b.pwrdnrstn = 1;
  64811. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64812. + dwc_udelay(10);
  64813. +
  64814. + /* Disable power clamps */
  64815. + gpwrdn.d32 = 0;
  64816. + gpwrdn.b.pwrdnclmp = 1;
  64817. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64818. +
  64819. + /* Remove reset the core signal */
  64820. + gpwrdn.d32 = 0;
  64821. + gpwrdn.b.pwrdnrstn = 1;
  64822. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  64823. + dwc_udelay(10);
  64824. +
  64825. + /* Disable PMU interrupt */
  64826. + gpwrdn.d32 = 0;
  64827. + gpwrdn.b.pmuintsel = 1;
  64828. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64829. + dwc_udelay(10);
  64830. +
  64831. + /*Indicates that we are exiting from hibernation */
  64832. + core_if->hibernation_suspend = 0;
  64833. +
  64834. + /* Disable PMU */
  64835. + gpwrdn.d32 = 0;
  64836. + gpwrdn.b.pmuactv = 1;
  64837. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64838. + dwc_udelay(10);
  64839. +
  64840. + core_if->op_state = B_PERIPHERAL;
  64841. + dwc_otg_core_init(core_if);
  64842. + dwc_otg_enable_global_interrupts(core_if);
  64843. + cil_pcd_start(core_if);
  64844. +
  64845. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  64846. + otg_cap_param == DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) {
  64847. + /*
  64848. + * Initiate SRP after initial ADP probe.
  64849. + */
  64850. + dwc_otg_initiate_srp(core_if);
  64851. + }
  64852. + }
  64853. +
  64854. + return 1;
  64855. +}
  64856. +/**
  64857. + * This interrupt indicates that the Wakeup Logic has detected a
  64858. + * status change either on IDDIG or BSessVld.
  64859. + */
  64860. +static uint32_t dwc_otg_handle_pwrdn_stschng_intr(dwc_otg_device_t *otg_dev)
  64861. +{
  64862. + int retval;
  64863. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64864. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  64865. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  64866. +
  64867. + DWC_PRINTF("%s called\n", __FUNCTION__);
  64868. +
  64869. + if (core_if->power_down == 2) {
  64870. + if (core_if->hibernation_suspend <= 0) {
  64871. + DWC_PRINTF("Already exited from Hibernation\n");
  64872. + return 1;
  64873. + } else
  64874. + gpwrdn_temp.d32 = core_if->gr_backup->gpwrdn_local;
  64875. +
  64876. + } else {
  64877. + gpwrdn_temp.d32 = core_if->adp.gpwrdn;
  64878. + }
  64879. +
  64880. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64881. +
  64882. + if (gpwrdn.b.idsts ^ gpwrdn_temp.b.idsts) {
  64883. + retval = dwc_otg_handle_pwrdn_idsts_change(otg_dev);
  64884. + } else if (gpwrdn.b.bsessvld ^ gpwrdn_temp.b.bsessvld) {
  64885. + retval = dwc_otg_handle_pwrdn_session_change(core_if);
  64886. + }
  64887. +
  64888. + return retval;
  64889. +}
  64890. +
  64891. +/**
  64892. + * This interrupt indicates that the Wakeup Logic has detected a
  64893. + * SRP.
  64894. + */
  64895. +static int32_t dwc_otg_handle_pwrdn_srp_intr(dwc_otg_core_if_t * core_if)
  64896. +{
  64897. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64898. +
  64899. + DWC_PRINTF("%s called\n", __FUNCTION__);
  64900. +
  64901. + if (!core_if->hibernation_suspend) {
  64902. + DWC_PRINTF("Already exited from Hibernation\n");
  64903. + return 1;
  64904. + }
  64905. +#ifdef DWC_DEV_SRPCAP
  64906. + if (core_if->pwron_timer_started) {
  64907. + core_if->pwron_timer_started = 0;
  64908. + DWC_TIMER_CANCEL(core_if->pwron_timer);
  64909. + }
  64910. +#endif
  64911. +
  64912. + /* Switch on the voltage to the core */
  64913. + gpwrdn.b.pwrdnswtch = 1;
  64914. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64915. + dwc_udelay(10);
  64916. +
  64917. + /* Reset the core */
  64918. + gpwrdn.d32 = 0;
  64919. + gpwrdn.b.pwrdnrstn = 1;
  64920. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64921. + dwc_udelay(10);
  64922. +
  64923. + /* Disable power clamps */
  64924. + gpwrdn.d32 = 0;
  64925. + gpwrdn.b.pwrdnclmp = 1;
  64926. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64927. +
  64928. + /* Remove reset the core signal */
  64929. + gpwrdn.d32 = 0;
  64930. + gpwrdn.b.pwrdnrstn = 1;
  64931. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  64932. + dwc_udelay(10);
  64933. +
  64934. + /* Disable PMU interrupt */
  64935. + gpwrdn.d32 = 0;
  64936. + gpwrdn.b.pmuintsel = 1;
  64937. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64938. +
  64939. + /* Indicates that we are exiting from hibernation */
  64940. + core_if->hibernation_suspend = 0;
  64941. +
  64942. + /* Disable PMU */
  64943. + gpwrdn.d32 = 0;
  64944. + gpwrdn.b.pmuactv = 1;
  64945. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64946. + dwc_udelay(10);
  64947. +
  64948. + /* Programm Disable VBUS to 0 */
  64949. + gpwrdn.d32 = 0;
  64950. + gpwrdn.b.dis_vbus = 1;
  64951. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64952. +
  64953. + /*Initialize the core as Host */
  64954. + core_if->op_state = A_HOST;
  64955. + dwc_otg_core_init(core_if);
  64956. + dwc_otg_enable_global_interrupts(core_if);
  64957. + cil_hcd_start(core_if);
  64958. +
  64959. + return 1;
  64960. +}
  64961. +
  64962. +/** This interrupt indicates that restore command after Hibernation
  64963. + * was completed by the core. */
  64964. +int32_t dwc_otg_handle_restore_done_intr(dwc_otg_core_if_t * core_if)
  64965. +{
  64966. + pcgcctl_data_t pcgcctl;
  64967. + DWC_DEBUGPL(DBG_ANY, "++Restore Done Interrupt++\n");
  64968. +
  64969. + //TODO De-assert restore signal. 8.a
  64970. + pcgcctl.d32 = DWC_READ_REG32(core_if->pcgcctl);
  64971. + if (pcgcctl.b.restoremode == 1) {
  64972. + gintmsk_data_t gintmsk = {.d32 = 0 };
  64973. + /*
  64974. + * If restore mode is Remote Wakeup,
  64975. + * unmask Remote Wakeup interrupt.
  64976. + */
  64977. + gintmsk.b.wkupintr = 1;
  64978. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  64979. + 0, gintmsk.d32);
  64980. + }
  64981. +
  64982. + return 1;
  64983. +}
  64984. +
  64985. +/**
  64986. + * This interrupt indicates that a device has been disconnected from
  64987. + * the root port.
  64988. + */
  64989. +int32_t dwc_otg_handle_disconnect_intr(dwc_otg_core_if_t * core_if)
  64990. +{
  64991. + gintsts_data_t gintsts;
  64992. +
  64993. + DWC_DEBUGPL(DBG_ANY, "++Disconnect Detected Interrupt++ (%s) %s\n",
  64994. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"),
  64995. + op_state_str(core_if));
  64996. +
  64997. +/** @todo Consolidate this if statement. */
  64998. +#ifndef DWC_HOST_ONLY
  64999. + if (core_if->op_state == B_HOST) {
  65000. + /* If in device mode Disconnect and stop the HCD, then
  65001. + * start the PCD. */
  65002. + DWC_SPINUNLOCK(core_if->lock);
  65003. + cil_hcd_disconnect(core_if);
  65004. + cil_pcd_start(core_if);
  65005. + DWC_SPINLOCK(core_if->lock);
  65006. + core_if->op_state = B_PERIPHERAL;
  65007. + } else if (dwc_otg_is_device_mode(core_if)) {
  65008. + gotgctl_data_t gotgctl = {.d32 = 0 };
  65009. + gotgctl.d32 =
  65010. + DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  65011. + if (gotgctl.b.hstsethnpen == 1) {
  65012. + /* Do nothing, if HNP in process the OTG
  65013. + * interrupt "Host Negotiation Detected"
  65014. + * interrupt will do the mode switch.
  65015. + */
  65016. + } else if (gotgctl.b.devhnpen == 0) {
  65017. + /* If in device mode Disconnect and stop the HCD, then
  65018. + * start the PCD. */
  65019. + DWC_SPINUNLOCK(core_if->lock);
  65020. + cil_hcd_disconnect(core_if);
  65021. + cil_pcd_start(core_if);
  65022. + DWC_SPINLOCK(core_if->lock);
  65023. + core_if->op_state = B_PERIPHERAL;
  65024. + } else {
  65025. + DWC_DEBUGPL(DBG_ANY, "!a_peripheral && !devhnpen\n");
  65026. + }
  65027. + } else {
  65028. + if (core_if->op_state == A_HOST) {
  65029. + /* A-Cable still connected but device disconnected. */
  65030. + cil_hcd_disconnect(core_if);
  65031. + if (core_if->adp_enable) {
  65032. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  65033. + cil_hcd_stop(core_if);
  65034. + /* Enable Power Down Logic */
  65035. + gpwrdn.b.pmuintsel = 1;
  65036. + gpwrdn.b.pmuactv = 1;
  65037. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65038. + gpwrdn, 0, gpwrdn.d32);
  65039. + dwc_otg_adp_probe_start(core_if);
  65040. +
  65041. + /* Power off the core */
  65042. + if (core_if->power_down == 2) {
  65043. + gpwrdn.d32 = 0;
  65044. + gpwrdn.b.pwrdnswtch = 1;
  65045. + DWC_MODIFY_REG32
  65046. + (&core_if->core_global_regs->gpwrdn,
  65047. + gpwrdn.d32, 0);
  65048. + }
  65049. + }
  65050. + }
  65051. + }
  65052. +#endif
  65053. + /* Change to L3(OFF) state */
  65054. + core_if->lx_state = DWC_OTG_L3;
  65055. +
  65056. + gintsts.d32 = 0;
  65057. + gintsts.b.disconnect = 1;
  65058. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65059. + return 1;
  65060. +}
  65061. +
  65062. +/**
  65063. + * This interrupt indicates that SUSPEND state has been detected on
  65064. + * the USB.
  65065. + *
  65066. + * For HNP the USB Suspend interrupt signals the change from
  65067. + * "a_peripheral" to "a_host".
  65068. + *
  65069. + * When power management is enabled the core will be put in low power
  65070. + * mode.
  65071. + */
  65072. +int32_t dwc_otg_handle_usb_suspend_intr(dwc_otg_core_if_t * core_if)
  65073. +{
  65074. + dsts_data_t dsts;
  65075. + gintsts_data_t gintsts;
  65076. + dcfg_data_t dcfg;
  65077. +
  65078. + DWC_DEBUGPL(DBG_ANY, "USB SUSPEND\n");
  65079. +
  65080. + if (dwc_otg_is_device_mode(core_if)) {
  65081. + /* Check the Device status register to determine if the Suspend
  65082. + * state is active. */
  65083. + dsts.d32 =
  65084. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  65085. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n", dsts.d32);
  65086. + DWC_DEBUGPL(DBG_PCD, "DSTS.Suspend Status=%d "
  65087. + "HWCFG4.power Optimize=%d\n",
  65088. + dsts.b.suspsts, core_if->hwcfg4.b.power_optimiz);
  65089. +
  65090. +#ifdef PARTIAL_POWER_DOWN
  65091. +/** @todo Add a module parameter for power management. */
  65092. +
  65093. + if (dsts.b.suspsts && core_if->hwcfg4.b.power_optimiz) {
  65094. + pcgcctl_data_t power = {.d32 = 0 };
  65095. + DWC_DEBUGPL(DBG_CIL, "suspend\n");
  65096. +
  65097. + power.b.pwrclmp = 1;
  65098. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  65099. +
  65100. + power.b.rstpdwnmodule = 1;
  65101. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  65102. +
  65103. + power.b.stoppclk = 1;
  65104. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  65105. +
  65106. + } else {
  65107. + DWC_DEBUGPL(DBG_ANY, "disconnect?\n");
  65108. + }
  65109. +#endif
  65110. + /* PCD callback for suspend. Release the lock inside of callback function */
  65111. + cil_pcd_suspend(core_if);
  65112. + if (core_if->power_down == 2)
  65113. + {
  65114. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  65115. + DWC_DEBUGPL(DBG_ANY,"lx_state = %08x\n",core_if->lx_state);
  65116. + DWC_DEBUGPL(DBG_ANY," device address = %08d\n",dcfg.b.devaddr);
  65117. +
  65118. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  65119. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65120. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65121. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  65122. +
  65123. + /* Change to L2(suspend) state */
  65124. + core_if->lx_state = DWC_OTG_L2;
  65125. +
  65126. + /* Clear interrupt in gintsts */
  65127. + gintsts.d32 = 0;
  65128. + gintsts.b.usbsuspend = 1;
  65129. + DWC_WRITE_REG32(&core_if->core_global_regs->
  65130. + gintsts, gintsts.d32);
  65131. + DWC_PRINTF("Start of hibernation completed\n");
  65132. + dwc_otg_save_global_regs(core_if);
  65133. + dwc_otg_save_dev_regs(core_if);
  65134. +
  65135. + gusbcfg.d32 =
  65136. + DWC_READ_REG32(&core_if->core_global_regs->
  65137. + gusbcfg);
  65138. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  65139. + /* ULPI interface */
  65140. + /* Suspend the Phy Clock */
  65141. + pcgcctl.d32 = 0;
  65142. + pcgcctl.b.stoppclk = 1;
  65143. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  65144. + pcgcctl.d32);
  65145. + dwc_udelay(10);
  65146. + gpwrdn.b.pmuactv = 1;
  65147. + DWC_MODIFY_REG32(&core_if->
  65148. + core_global_regs->
  65149. + gpwrdn, 0, gpwrdn.d32);
  65150. + } else {
  65151. + /* UTMI+ Interface */
  65152. + gpwrdn.b.pmuactv = 1;
  65153. + DWC_MODIFY_REG32(&core_if->
  65154. + core_global_regs->
  65155. + gpwrdn, 0, gpwrdn.d32);
  65156. + dwc_udelay(10);
  65157. + pcgcctl.b.stoppclk = 1;
  65158. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  65159. + pcgcctl.d32);
  65160. + dwc_udelay(10);
  65161. + }
  65162. +
  65163. + /* Set flag to indicate that we are in hibernation */
  65164. + core_if->hibernation_suspend = 1;
  65165. + /* Enable interrupts from wake up logic */
  65166. + gpwrdn.d32 = 0;
  65167. + gpwrdn.b.pmuintsel = 1;
  65168. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65169. + gpwrdn, 0, gpwrdn.d32);
  65170. + dwc_udelay(10);
  65171. +
  65172. + /* Unmask device mode interrupts in GPWRDN */
  65173. + gpwrdn.d32 = 0;
  65174. + gpwrdn.b.rst_det_msk = 1;
  65175. + gpwrdn.b.lnstchng_msk = 1;
  65176. + gpwrdn.b.sts_chngint_msk = 1;
  65177. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65178. + gpwrdn, 0, gpwrdn.d32);
  65179. + dwc_udelay(10);
  65180. +
  65181. + /* Enable Power Down Clamp */
  65182. + gpwrdn.d32 = 0;
  65183. + gpwrdn.b.pwrdnclmp = 1;
  65184. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65185. + gpwrdn, 0, gpwrdn.d32);
  65186. + dwc_udelay(10);
  65187. +
  65188. + /* Switch off VDD */
  65189. + gpwrdn.d32 = 0;
  65190. + gpwrdn.b.pwrdnswtch = 1;
  65191. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  65192. + gpwrdn, 0, gpwrdn.d32);
  65193. +
  65194. + /* Save gpwrdn register for further usage if stschng interrupt */
  65195. + core_if->gr_backup->gpwrdn_local =
  65196. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65197. + DWC_PRINTF("Hibernation completed\n");
  65198. +
  65199. + return 1;
  65200. + }
  65201. + } else if (core_if->power_down == 3) {
  65202. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65203. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  65204. + DWC_DEBUGPL(DBG_ANY, "lx_state = %08x\n",core_if->lx_state);
  65205. + DWC_DEBUGPL(DBG_ANY, " device address = %08d\n",dcfg.b.devaddr);
  65206. +
  65207. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  65208. + DWC_DEBUGPL(DBG_ANY, "Start entering to extended hibernation\n");
  65209. + core_if->xhib = 1;
  65210. +
  65211. + /* Clear interrupt in gintsts */
  65212. + gintsts.d32 = 0;
  65213. + gintsts.b.usbsuspend = 1;
  65214. + DWC_WRITE_REG32(&core_if->core_global_regs->
  65215. + gintsts, gintsts.d32);
  65216. +
  65217. + dwc_otg_save_global_regs(core_if);
  65218. + dwc_otg_save_dev_regs(core_if);
  65219. +
  65220. + /* Wait for 10 PHY clocks */
  65221. + dwc_udelay(10);
  65222. +
  65223. + /* Program GPIO register while entering to xHib */
  65224. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x1);
  65225. +
  65226. + pcgcctl.b.enbl_extnd_hiber = 1;
  65227. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  65228. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  65229. +
  65230. + pcgcctl.d32 = 0;
  65231. + pcgcctl.b.extnd_hiber_pwrclmp = 1;
  65232. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  65233. +
  65234. + pcgcctl.d32 = 0;
  65235. + pcgcctl.b.extnd_hiber_switch = 1;
  65236. + core_if->gr_backup->xhib_gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65237. + core_if->gr_backup->xhib_pcgcctl = DWC_READ_REG32(core_if->pcgcctl) | pcgcctl.d32;
  65238. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  65239. +
  65240. + DWC_DEBUGPL(DBG_ANY, "Finished entering to extended hibernation\n");
  65241. +
  65242. + return 1;
  65243. + }
  65244. + }
  65245. + } else {
  65246. + if (core_if->op_state == A_PERIPHERAL) {
  65247. + DWC_DEBUGPL(DBG_ANY, "a_peripheral->a_host\n");
  65248. + /* Clear the a_peripheral flag, back to a_host. */
  65249. + DWC_SPINUNLOCK(core_if->lock);
  65250. + cil_pcd_stop(core_if);
  65251. + cil_hcd_start(core_if);
  65252. + DWC_SPINLOCK(core_if->lock);
  65253. + core_if->op_state = A_HOST;
  65254. + }
  65255. + }
  65256. +
  65257. + /* Change to L2(suspend) state */
  65258. + core_if->lx_state = DWC_OTG_L2;
  65259. +
  65260. + /* Clear interrupt */
  65261. + gintsts.d32 = 0;
  65262. + gintsts.b.usbsuspend = 1;
  65263. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65264. +
  65265. + return 1;
  65266. +}
  65267. +
  65268. +static int32_t dwc_otg_handle_xhib_exit_intr(dwc_otg_core_if_t * core_if)
  65269. +{
  65270. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65271. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65272. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  65273. +
  65274. + dwc_udelay(10);
  65275. +
  65276. + /* Program GPIO register while entering to xHib */
  65277. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x0);
  65278. +
  65279. + pcgcctl.d32 = core_if->gr_backup->xhib_pcgcctl;
  65280. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  65281. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  65282. + dwc_udelay(10);
  65283. +
  65284. + gpwrdn.d32 = core_if->gr_backup->xhib_gpwrdn;
  65285. + gpwrdn.b.restore = 1;
  65286. + DWC_WRITE_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32);
  65287. + dwc_udelay(10);
  65288. +
  65289. + restore_lpm_i2c_regs(core_if);
  65290. +
  65291. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  65292. + pcgcctl.b.max_xcvrselect = 1;
  65293. + pcgcctl.b.ess_reg_restored = 0;
  65294. + pcgcctl.b.extnd_hiber_switch = 0;
  65295. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  65296. + pcgcctl.b.enbl_extnd_hiber = 1;
  65297. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  65298. +
  65299. + gahbcfg.d32 = core_if->gr_backup->gahbcfg_local;
  65300. + gahbcfg.b.glblintrmsk = 1;
  65301. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  65302. +
  65303. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  65304. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0x1 << 16);
  65305. +
  65306. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  65307. + core_if->gr_backup->gusbcfg_local);
  65308. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  65309. + core_if->dr_backup->dcfg);
  65310. +
  65311. + pcgcctl.d32 = 0;
  65312. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  65313. + pcgcctl.b.max_xcvrselect = 1;
  65314. + pcgcctl.d32 |= 0x608;
  65315. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  65316. + dwc_udelay(10);
  65317. +
  65318. + pcgcctl.d32 = 0;
  65319. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  65320. + pcgcctl.b.max_xcvrselect = 1;
  65321. + pcgcctl.b.ess_reg_restored = 1;
  65322. + pcgcctl.b.enbl_extnd_hiber = 1;
  65323. + pcgcctl.b.rstpdwnmodule = 1;
  65324. + pcgcctl.b.restoremode = 1;
  65325. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  65326. +
  65327. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  65328. +
  65329. + return 1;
  65330. +}
  65331. +
  65332. +#ifdef CONFIG_USB_DWC_OTG_LPM
  65333. +/**
  65334. + * This function hadles LPM transaction received interrupt.
  65335. + */
  65336. +static int32_t dwc_otg_handle_lpm_intr(dwc_otg_core_if_t * core_if)
  65337. +{
  65338. + glpmcfg_data_t lpmcfg;
  65339. + gintsts_data_t gintsts;
  65340. +
  65341. + if (!core_if->core_params->lpm_enable) {
  65342. + DWC_PRINTF("Unexpected LPM interrupt\n");
  65343. + }
  65344. +
  65345. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  65346. + DWC_PRINTF("LPM config register = 0x%08x\n", lpmcfg.d32);
  65347. +
  65348. + if (dwc_otg_is_host_mode(core_if)) {
  65349. + cil_hcd_sleep(core_if);
  65350. + } else {
  65351. + lpmcfg.b.hird_thres |= (1 << 4);
  65352. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  65353. + lpmcfg.d32);
  65354. + }
  65355. +
  65356. + /* Examine prt_sleep_sts after TL1TokenTetry period max (10 us) */
  65357. + dwc_udelay(10);
  65358. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  65359. + if (lpmcfg.b.prt_sleep_sts) {
  65360. + /* Save the current state */
  65361. + core_if->lx_state = DWC_OTG_L1;
  65362. + }
  65363. +
  65364. + /* Clear interrupt */
  65365. + gintsts.d32 = 0;
  65366. + gintsts.b.lpmtranrcvd = 1;
  65367. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65368. + return 1;
  65369. +}
  65370. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  65371. +
  65372. +/**
  65373. + * This function returns the Core Interrupt register.
  65374. + */
  65375. +static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t * core_if, gintmsk_data_t *reenable_gintmsk)
  65376. +{
  65377. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  65378. + gintsts_data_t gintsts;
  65379. + gintmsk_data_t gintmsk;
  65380. + gintmsk_data_t gintmsk_common = {.d32 = 0 };
  65381. + gintmsk_common.b.wkupintr = 1;
  65382. + gintmsk_common.b.sessreqintr = 1;
  65383. + gintmsk_common.b.conidstschng = 1;
  65384. + gintmsk_common.b.otgintr = 1;
  65385. + gintmsk_common.b.modemismatch = 1;
  65386. + gintmsk_common.b.disconnect = 1;
  65387. + gintmsk_common.b.usbsuspend = 1;
  65388. +#ifdef CONFIG_USB_DWC_OTG_LPM
  65389. + gintmsk_common.b.lpmtranrcvd = 1;
  65390. +#endif
  65391. + gintmsk_common.b.restoredone = 1;
  65392. + if(dwc_otg_is_device_mode(core_if))
  65393. + {
  65394. + /** @todo: The port interrupt occurs while in device
  65395. + * mode. Added code to CIL to clear the interrupt for now!
  65396. + */
  65397. + gintmsk_common.b.portintr = 1;
  65398. + }
  65399. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  65400. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  65401. + {
  65402. + unsigned long flags;
  65403. +
  65404. + // Re-enable the saved interrupts
  65405. + local_irq_save(flags);
  65406. + local_fiq_disable();
  65407. + gintmsk.d32 |= gintmsk_common.d32;
  65408. + gintsts_saved.d32 &= ~gintmsk_common.d32;
  65409. + reenable_gintmsk->d32 = gintmsk.d32;
  65410. + local_irq_restore(flags);
  65411. + }
  65412. +
  65413. + gahbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  65414. +
  65415. +#ifdef DEBUG
  65416. + /* if any common interrupts set */
  65417. + if (gintsts.d32 & gintmsk_common.d32) {
  65418. + DWC_DEBUGPL(DBG_ANY, "common_intr: gintsts=%08x gintmsk=%08x\n",
  65419. + gintsts.d32, gintmsk.d32);
  65420. + }
  65421. +#endif
  65422. + if (!fiq_fix_enable){
  65423. + if (gahbcfg.b.glblintrmsk)
  65424. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  65425. + else
  65426. + return 0;
  65427. + }
  65428. + else {
  65429. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  65430. + }
  65431. +
  65432. +}
  65433. +
  65434. +/* MACRO for clearing interupt bits in GPWRDN register */
  65435. +#define CLEAR_GPWRDN_INTR(__core_if,__intr) \
  65436. +do { \
  65437. + gpwrdn_data_t gpwrdn = {.d32=0}; \
  65438. + gpwrdn.b.__intr = 1; \
  65439. + DWC_MODIFY_REG32(&__core_if->core_global_regs->gpwrdn, \
  65440. + 0, gpwrdn.d32); \
  65441. +} while (0)
  65442. +
  65443. +/**
  65444. + * Common interrupt handler.
  65445. + *
  65446. + * The common interrupts are those that occur in both Host and Device mode.
  65447. + * This handler handles the following interrupts:
  65448. + * - Mode Mismatch Interrupt
  65449. + * - Disconnect Interrupt
  65450. + * - OTG Interrupt
  65451. + * - Connector ID Status Change Interrupt
  65452. + * - Session Request Interrupt.
  65453. + * - Resume / Remote Wakeup Detected Interrupt.
  65454. + * - LPM Transaction Received Interrupt
  65455. + * - ADP Transaction Received Interrupt
  65456. + *
  65457. + */
  65458. +int32_t dwc_otg_handle_common_intr(void *dev)
  65459. +{
  65460. + int retval = 0;
  65461. + gintsts_data_t gintsts;
  65462. + gintmsk_data_t reenable_gintmsk;
  65463. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65464. + dwc_otg_device_t *otg_dev = dev;
  65465. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  65466. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65467. + if (dwc_otg_is_device_mode(core_if))
  65468. + core_if->frame_num = dwc_otg_get_frame_number(core_if);
  65469. +
  65470. + if (core_if->lock)
  65471. + DWC_SPINLOCK(core_if->lock);
  65472. +
  65473. + if (core_if->power_down == 3 && core_if->xhib == 1) {
  65474. + DWC_DEBUGPL(DBG_ANY, "Exiting from xHIB state\n");
  65475. + retval |= dwc_otg_handle_xhib_exit_intr(core_if);
  65476. + core_if->xhib = 2;
  65477. + if (core_if->lock)
  65478. + DWC_SPINUNLOCK(core_if->lock);
  65479. +
  65480. + return retval;
  65481. + }
  65482. +
  65483. + if (core_if->hibernation_suspend <= 0) {
  65484. + gintsts.d32 = dwc_otg_read_common_intr(core_if, &reenable_gintmsk);
  65485. +
  65486. + if (gintsts.b.modemismatch) {
  65487. + retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
  65488. + }
  65489. + if (gintsts.b.otgintr) {
  65490. + retval |= dwc_otg_handle_otg_intr(core_if);
  65491. + }
  65492. + if (gintsts.b.conidstschng) {
  65493. + retval |=
  65494. + dwc_otg_handle_conn_id_status_change_intr(core_if);
  65495. + }
  65496. + if (gintsts.b.disconnect) {
  65497. + retval |= dwc_otg_handle_disconnect_intr(core_if);
  65498. + }
  65499. + if (gintsts.b.sessreqintr) {
  65500. + retval |= dwc_otg_handle_session_req_intr(core_if);
  65501. + }
  65502. + if (gintsts.b.wkupintr) {
  65503. + retval |= dwc_otg_handle_wakeup_detected_intr(core_if);
  65504. + }
  65505. + if (gintsts.b.usbsuspend) {
  65506. + retval |= dwc_otg_handle_usb_suspend_intr(core_if);
  65507. + }
  65508. +#ifdef CONFIG_USB_DWC_OTG_LPM
  65509. + if (gintsts.b.lpmtranrcvd) {
  65510. + retval |= dwc_otg_handle_lpm_intr(core_if);
  65511. + }
  65512. +#endif
  65513. + if (gintsts.b.restoredone) {
  65514. + gintsts.d32 = 0;
  65515. + if (core_if->power_down == 2)
  65516. + core_if->hibernation_suspend = -1;
  65517. + else if (core_if->power_down == 3 && core_if->xhib == 2) {
  65518. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65519. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65520. + dctl_data_t dctl = {.d32 = 0 };
  65521. +
  65522. + DWC_WRITE_REG32(&core_if->core_global_regs->
  65523. + gintsts, 0xFFFFFFFF);
  65524. +
  65525. + DWC_DEBUGPL(DBG_ANY,
  65526. + "RESTORE DONE generated\n");
  65527. +
  65528. + gpwrdn.b.restore = 1;
  65529. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65530. + dwc_udelay(10);
  65531. +
  65532. + pcgcctl.b.rstpdwnmodule = 1;
  65533. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  65534. +
  65535. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, core_if->gr_backup->gusbcfg_local);
  65536. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, core_if->dr_backup->dcfg);
  65537. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, core_if->dr_backup->dctl);
  65538. + dwc_udelay(50);
  65539. +
  65540. + dctl.b.pwronprgdone = 1;
  65541. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  65542. + dwc_udelay(10);
  65543. +
  65544. + dwc_otg_restore_global_regs(core_if);
  65545. + dwc_otg_restore_dev_regs(core_if, 0);
  65546. +
  65547. + dctl.d32 = 0;
  65548. + dctl.b.pwronprgdone = 1;
  65549. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  65550. + dwc_udelay(10);
  65551. +
  65552. + pcgcctl.d32 = 0;
  65553. + pcgcctl.b.enbl_extnd_hiber = 1;
  65554. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  65555. +
  65556. + /* The core will be in ON STATE */
  65557. + core_if->lx_state = DWC_OTG_L0;
  65558. + core_if->xhib = 0;
  65559. +
  65560. + DWC_SPINUNLOCK(core_if->lock);
  65561. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  65562. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  65563. + }
  65564. + DWC_SPINLOCK(core_if->lock);
  65565. +
  65566. + }
  65567. +
  65568. + gintsts.b.restoredone = 1;
  65569. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  65570. + DWC_PRINTF(" --Restore done interrupt received-- \n");
  65571. + retval |= 1;
  65572. + }
  65573. + if (gintsts.b.portintr && dwc_otg_is_device_mode(core_if)) {
  65574. + /* The port interrupt occurs while in device mode with HPRT0
  65575. + * Port Enable/Disable.
  65576. + */
  65577. + gintsts.d32 = 0;
  65578. + gintsts.b.portintr = 1;
  65579. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  65580. + retval |= 1;
  65581. + reenable_gintmsk.b.portintr = 1;
  65582. +
  65583. + }
  65584. +
  65585. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, reenable_gintmsk.d32);
  65586. +
  65587. + } else {
  65588. + DWC_DEBUGPL(DBG_ANY, "gpwrdn=%08x\n", gpwrdn.d32);
  65589. +
  65590. + if (gpwrdn.b.disconn_det && gpwrdn.b.disconn_det_msk) {
  65591. + CLEAR_GPWRDN_INTR(core_if, disconn_det);
  65592. + if (gpwrdn.b.linestate == 0) {
  65593. + dwc_otg_handle_pwrdn_disconnect_intr(core_if);
  65594. + } else {
  65595. + DWC_PRINTF("Disconnect detected while linestate is not 0\n");
  65596. + }
  65597. +
  65598. + retval |= 1;
  65599. + }
  65600. + if (gpwrdn.b.lnstschng && gpwrdn.b.lnstchng_msk) {
  65601. + CLEAR_GPWRDN_INTR(core_if, lnstschng);
  65602. + /* remote wakeup from hibernation */
  65603. + if (gpwrdn.b.linestate == 2 || gpwrdn.b.linestate == 1) {
  65604. + dwc_otg_handle_pwrdn_wakeup_detected_intr(core_if);
  65605. + } else {
  65606. + DWC_PRINTF("gpwrdn.linestate = %d\n", gpwrdn.b.linestate);
  65607. + }
  65608. + retval |= 1;
  65609. + }
  65610. + if (gpwrdn.b.rst_det && gpwrdn.b.rst_det_msk) {
  65611. + CLEAR_GPWRDN_INTR(core_if, rst_det);
  65612. + if (gpwrdn.b.linestate == 0) {
  65613. + DWC_PRINTF("Reset detected\n");
  65614. + retval |= dwc_otg_device_hibernation_restore(core_if, 0, 1);
  65615. + }
  65616. + }
  65617. + if (gpwrdn.b.srp_det && gpwrdn.b.srp_det_msk) {
  65618. + CLEAR_GPWRDN_INTR(core_if, srp_det);
  65619. + dwc_otg_handle_pwrdn_srp_intr(core_if);
  65620. + retval |= 1;
  65621. + }
  65622. + }
  65623. + /* Handle ADP interrupt here */
  65624. + if (gpwrdn.b.adp_int) {
  65625. + DWC_PRINTF("ADP interrupt\n");
  65626. + CLEAR_GPWRDN_INTR(core_if, adp_int);
  65627. + dwc_otg_adp_handle_intr(core_if);
  65628. + retval |= 1;
  65629. + }
  65630. + if (gpwrdn.b.sts_chngint && gpwrdn.b.sts_chngint_msk) {
  65631. + DWC_PRINTF("STS CHNG interrupt asserted\n");
  65632. + CLEAR_GPWRDN_INTR(core_if, sts_chngint);
  65633. + dwc_otg_handle_pwrdn_stschng_intr(otg_dev);
  65634. +
  65635. + retval |= 1;
  65636. + }
  65637. + if (core_if->lock)
  65638. + DWC_SPINUNLOCK(core_if->lock);
  65639. +
  65640. + return retval;
  65641. +}
  65642. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_core_if.h linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_core_if.h
  65643. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 1970-01-01 01:00:00.000000000 +0100
  65644. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 2014-02-18 11:52:14.000000000 +0100
  65645. @@ -0,0 +1,705 @@
  65646. +/* ==========================================================================
  65647. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_core_if.h $
  65648. + * $Revision: #13 $
  65649. + * $Date: 2012/08/10 $
  65650. + * $Change: 2047372 $
  65651. + *
  65652. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  65653. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  65654. + * otherwise expressly agreed to in writing between Synopsys and you.
  65655. + *
  65656. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  65657. + * any End User Software License Agreement or Agreement for Licensed Product
  65658. + * with Synopsys or any supplement thereto. You are permitted to use and
  65659. + * redistribute this Software in source and binary forms, with or without
  65660. + * modification, provided that redistributions of source code must retain this
  65661. + * notice. You may not view, use, disclose, copy or distribute this file or
  65662. + * any information contained herein except pursuant to this license grant from
  65663. + * Synopsys. If you do not agree with this notice, including the disclaimer
  65664. + * below, then you are not authorized to use the Software.
  65665. + *
  65666. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  65667. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  65668. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  65669. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  65670. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  65671. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  65672. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  65673. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  65674. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  65675. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  65676. + * DAMAGE.
  65677. + * ========================================================================== */
  65678. +#if !defined(__DWC_CORE_IF_H__)
  65679. +#define __DWC_CORE_IF_H__
  65680. +
  65681. +#include "dwc_os.h"
  65682. +
  65683. +/** @file
  65684. + * This file defines DWC_OTG Core API
  65685. + */
  65686. +
  65687. +struct dwc_otg_core_if;
  65688. +typedef struct dwc_otg_core_if dwc_otg_core_if_t;
  65689. +
  65690. +/** Maximum number of Periodic FIFOs */
  65691. +#define MAX_PERIO_FIFOS 15
  65692. +/** Maximum number of Periodic FIFOs */
  65693. +#define MAX_TX_FIFOS 15
  65694. +
  65695. +/** Maximum number of Endpoints/HostChannels */
  65696. +#define MAX_EPS_CHANNELS 16
  65697. +
  65698. +extern dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * _reg_base_addr);
  65699. +extern void dwc_otg_core_init(dwc_otg_core_if_t * _core_if);
  65700. +extern void dwc_otg_cil_remove(dwc_otg_core_if_t * _core_if);
  65701. +
  65702. +extern void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * _core_if);
  65703. +extern void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * _core_if);
  65704. +
  65705. +extern uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if);
  65706. +extern uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if);
  65707. +
  65708. +extern uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if);
  65709. +
  65710. +/** This function should be called on every hardware interrupt. */
  65711. +extern int32_t dwc_otg_handle_common_intr(void *otg_dev);
  65712. +
  65713. +/** @name OTG Core Parameters */
  65714. +/** @{ */
  65715. +
  65716. +/**
  65717. + * Specifies the OTG capabilities. The driver will automatically
  65718. + * detect the value for this parameter if none is specified.
  65719. + * 0 - HNP and SRP capable (default)
  65720. + * 1 - SRP Only capable
  65721. + * 2 - No HNP/SRP capable
  65722. + */
  65723. +extern int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val);
  65724. +extern int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if);
  65725. +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
  65726. +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
  65727. +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
  65728. +#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE
  65729. +
  65730. +extern int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val);
  65731. +extern int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if);
  65732. +#define dwc_param_opt_default 1
  65733. +
  65734. +/**
  65735. + * Specifies whether to use slave or DMA mode for accessing the data
  65736. + * FIFOs. The driver will automatically detect the value for this
  65737. + * parameter if none is specified.
  65738. + * 0 - Slave
  65739. + * 1 - DMA (default, if available)
  65740. + */
  65741. +extern int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if,
  65742. + int32_t val);
  65743. +extern int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if);
  65744. +#define dwc_param_dma_enable_default 1
  65745. +
  65746. +/**
  65747. + * When DMA mode is enabled specifies whether to use
  65748. + * address DMA or DMA Descritor mode for accessing the data
  65749. + * FIFOs in device mode. The driver will automatically detect
  65750. + * the value for this parameter if none is specified.
  65751. + * 0 - address DMA
  65752. + * 1 - DMA Descriptor(default, if available)
  65753. + */
  65754. +extern int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if,
  65755. + int32_t val);
  65756. +extern int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if);
  65757. +//#define dwc_param_dma_desc_enable_default 1
  65758. +#define dwc_param_dma_desc_enable_default 0 // Broadcom BCM2708
  65759. +
  65760. +/** The DMA Burst size (applicable only for External DMA
  65761. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  65762. + */
  65763. +extern int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if,
  65764. + int32_t val);
  65765. +extern int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if);
  65766. +#define dwc_param_dma_burst_size_default 32
  65767. +
  65768. +/**
  65769. + * Specifies the maximum speed of operation in host and device mode.
  65770. + * The actual speed depends on the speed of the attached device and
  65771. + * the value of phy_type. The actual speed depends on the speed of the
  65772. + * attached device.
  65773. + * 0 - High Speed (default)
  65774. + * 1 - Full Speed
  65775. + */
  65776. +extern int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val);
  65777. +extern int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if);
  65778. +#define dwc_param_speed_default 0
  65779. +#define DWC_SPEED_PARAM_HIGH 0
  65780. +#define DWC_SPEED_PARAM_FULL 1
  65781. +
  65782. +/** Specifies whether low power mode is supported when attached
  65783. + * to a Full Speed or Low Speed device in host mode.
  65784. + * 0 - Don't support low power mode (default)
  65785. + * 1 - Support low power mode
  65786. + */
  65787. +extern int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  65788. + core_if, int32_t val);
  65789. +extern int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t
  65790. + * core_if);
  65791. +#define dwc_param_host_support_fs_ls_low_power_default 0
  65792. +
  65793. +/** Specifies the PHY clock rate in low power mode when connected to a
  65794. + * Low Speed device in host mode. This parameter is applicable only if
  65795. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  65796. + * then defaults to 6 MHZ otherwise 48 MHZ.
  65797. + *
  65798. + * 0 - 48 MHz
  65799. + * 1 - 6 MHz
  65800. + */
  65801. +extern int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  65802. + core_if, int32_t val);
  65803. +extern int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  65804. + core_if);
  65805. +#define dwc_param_host_ls_low_power_phy_clk_default 0
  65806. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
  65807. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
  65808. +
  65809. +/**
  65810. + * 0 - Use cC FIFO size parameters
  65811. + * 1 - Allow dynamic FIFO sizing (default)
  65812. + */
  65813. +extern int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  65814. + int32_t val);
  65815. +extern int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t *
  65816. + core_if);
  65817. +#define dwc_param_enable_dynamic_fifo_default 1
  65818. +
  65819. +/** Total number of 4-byte words in the data FIFO memory. This
  65820. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  65821. + * Tx FIFOs.
  65822. + * 32 to 32768 (default 8192)
  65823. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  65824. + */
  65825. +extern int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if,
  65826. + int32_t val);
  65827. +extern int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if);
  65828. +//#define dwc_param_data_fifo_size_default 8192
  65829. +#define dwc_param_data_fifo_size_default 0xFF0 // Broadcom BCM2708
  65830. +
  65831. +/** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  65832. + * FIFO sizing is enabled.
  65833. + * 16 to 32768 (default 1064)
  65834. + */
  65835. +extern int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if,
  65836. + int32_t val);
  65837. +extern int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if);
  65838. +#define dwc_param_dev_rx_fifo_size_default 1064
  65839. +
  65840. +/** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  65841. + * when dynamic FIFO sizing is enabled.
  65842. + * 16 to 32768 (default 1024)
  65843. + */
  65844. +extern int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  65845. + core_if, int32_t val);
  65846. +extern int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  65847. + core_if);
  65848. +#define dwc_param_dev_nperio_tx_fifo_size_default 1024
  65849. +
  65850. +/** Number of 4-byte words in each of the periodic Tx FIFOs in device
  65851. + * mode when dynamic FIFO sizing is enabled.
  65852. + * 4 to 768 (default 256)
  65853. + */
  65854. +extern int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  65855. + int32_t val, int fifo_num);
  65856. +extern int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t *
  65857. + core_if, int fifo_num);
  65858. +#define dwc_param_dev_perio_tx_fifo_size_default 256
  65859. +
  65860. +/** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  65861. + * FIFO sizing is enabled.
  65862. + * 16 to 32768 (default 1024)
  65863. + */
  65864. +extern int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  65865. + int32_t val);
  65866. +extern int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if);
  65867. +//#define dwc_param_host_rx_fifo_size_default 1024
  65868. +#define dwc_param_host_rx_fifo_size_default 774 // Broadcom BCM2708
  65869. +
  65870. +/** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  65871. + * when Dynamic FIFO sizing is enabled in the core.
  65872. + * 16 to 32768 (default 1024)
  65873. + */
  65874. +extern int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  65875. + core_if, int32_t val);
  65876. +extern int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  65877. + core_if);
  65878. +//#define dwc_param_host_nperio_tx_fifo_size_default 1024
  65879. +#define dwc_param_host_nperio_tx_fifo_size_default 0x100 // Broadcom BCM2708
  65880. +
  65881. +/** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  65882. + * FIFO sizing is enabled.
  65883. + * 16 to 32768 (default 1024)
  65884. + */
  65885. +extern int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  65886. + core_if, int32_t val);
  65887. +extern int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  65888. + core_if);
  65889. +//#define dwc_param_host_perio_tx_fifo_size_default 1024
  65890. +#define dwc_param_host_perio_tx_fifo_size_default 0x200 // Broadcom BCM2708
  65891. +
  65892. +/** The maximum transfer size supported in bytes.
  65893. + * 2047 to 65,535 (default 65,535)
  65894. + */
  65895. +extern int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  65896. + int32_t val);
  65897. +extern int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if);
  65898. +#define dwc_param_max_transfer_size_default 65535
  65899. +
  65900. +/** The maximum number of packets in a transfer.
  65901. + * 15 to 511 (default 511)
  65902. + */
  65903. +extern int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if,
  65904. + int32_t val);
  65905. +extern int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if);
  65906. +#define dwc_param_max_packet_count_default 511
  65907. +
  65908. +/** The number of host channel registers to use.
  65909. + * 1 to 16 (default 12)
  65910. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  65911. + */
  65912. +extern int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if,
  65913. + int32_t val);
  65914. +extern int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if);
  65915. +//#define dwc_param_host_channels_default 12
  65916. +#define dwc_param_host_channels_default 8 // Broadcom BCM2708
  65917. +
  65918. +/** The number of endpoints in addition to EP0 available for device
  65919. + * mode operations.
  65920. + * 1 to 15 (default 6 IN and OUT)
  65921. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  65922. + * endpoints in addition to EP0.
  65923. + */
  65924. +extern int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if,
  65925. + int32_t val);
  65926. +extern int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if);
  65927. +#define dwc_param_dev_endpoints_default 6
  65928. +
  65929. +/**
  65930. + * Specifies the type of PHY interface to use. By default, the driver
  65931. + * will automatically detect the phy_type.
  65932. + *
  65933. + * 0 - Full Speed PHY
  65934. + * 1 - UTMI+ (default)
  65935. + * 2 - ULPI
  65936. + */
  65937. +extern int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val);
  65938. +extern int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if);
  65939. +#define DWC_PHY_TYPE_PARAM_FS 0
  65940. +#define DWC_PHY_TYPE_PARAM_UTMI 1
  65941. +#define DWC_PHY_TYPE_PARAM_ULPI 2
  65942. +#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
  65943. +
  65944. +/**
  65945. + * Specifies the UTMI+ Data Width. This parameter is
  65946. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  65947. + * PHY_TYPE, this parameter indicates the data width between
  65948. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  65949. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  65950. + * to "8 and 16 bits", meaning that the core has been
  65951. + * configured to work at either data path width.
  65952. + *
  65953. + * 8 or 16 bits (default 16)
  65954. + */
  65955. +extern int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if,
  65956. + int32_t val);
  65957. +extern int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if);
  65958. +//#define dwc_param_phy_utmi_width_default 16
  65959. +#define dwc_param_phy_utmi_width_default 8 // Broadcom BCM2708
  65960. +
  65961. +/**
  65962. + * Specifies whether the ULPI operates at double or single
  65963. + * data rate. This parameter is only applicable if PHY_TYPE is
  65964. + * ULPI.
  65965. + *
  65966. + * 0 - single data rate ULPI interface with 8 bit wide data
  65967. + * bus (default)
  65968. + * 1 - double data rate ULPI interface with 4 bit wide data
  65969. + * bus
  65970. + */
  65971. +extern int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if,
  65972. + int32_t val);
  65973. +extern int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if);
  65974. +#define dwc_param_phy_ulpi_ddr_default 0
  65975. +
  65976. +/**
  65977. + * Specifies whether to use the internal or external supply to
  65978. + * drive the vbus with a ULPI phy.
  65979. + */
  65980. +extern int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  65981. + int32_t val);
  65982. +extern int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if);
  65983. +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
  65984. +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
  65985. +#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
  65986. +
  65987. +/**
  65988. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  65989. + * parameter is only applicable if PHY_TYPE is FS.
  65990. + * 0 - No (default)
  65991. + * 1 - Yes
  65992. + */
  65993. +extern int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if,
  65994. + int32_t val);
  65995. +extern int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if);
  65996. +#define dwc_param_i2c_enable_default 0
  65997. +
  65998. +extern int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if,
  65999. + int32_t val);
  66000. +extern int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if);
  66001. +#define dwc_param_ulpi_fs_ls_default 0
  66002. +
  66003. +extern int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val);
  66004. +extern int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if);
  66005. +#define dwc_param_ts_dline_default 0
  66006. +
  66007. +/**
  66008. + * Specifies whether dedicated transmit FIFOs are
  66009. + * enabled for non periodic IN endpoints in device mode
  66010. + * 0 - No
  66011. + * 1 - Yes
  66012. + */
  66013. +extern int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  66014. + int32_t val);
  66015. +extern int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t *
  66016. + core_if);
  66017. +#define dwc_param_en_multiple_tx_fifo_default 1
  66018. +
  66019. +/** Number of 4-byte words in each of the Tx FIFOs in device
  66020. + * mode when dynamic FIFO sizing is enabled.
  66021. + * 4 to 768 (default 256)
  66022. + */
  66023. +extern int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  66024. + int fifo_num, int32_t val);
  66025. +extern int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  66026. + int fifo_num);
  66027. +#define dwc_param_dev_tx_fifo_size_default 768
  66028. +
  66029. +/** Thresholding enable flag-
  66030. + * bit 0 - enable non-ISO Tx thresholding
  66031. + * bit 1 - enable ISO Tx thresholding
  66032. + * bit 2 - enable Rx thresholding
  66033. + */
  66034. +extern int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val);
  66035. +extern int32_t dwc_otg_get_thr_ctl(dwc_otg_core_if_t * core_if, int fifo_num);
  66036. +#define dwc_param_thr_ctl_default 0
  66037. +
  66038. +/** Thresholding length for Tx
  66039. + * FIFOs in 32 bit DWORDs
  66040. + */
  66041. +extern int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if,
  66042. + int32_t val);
  66043. +extern int32_t dwc_otg_get_tx_thr_length(dwc_otg_core_if_t * core_if);
  66044. +#define dwc_param_tx_thr_length_default 64
  66045. +
  66046. +/** Thresholding length for Rx
  66047. + * FIFOs in 32 bit DWORDs
  66048. + */
  66049. +extern int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if,
  66050. + int32_t val);
  66051. +extern int32_t dwc_otg_get_rx_thr_length(dwc_otg_core_if_t * core_if);
  66052. +#define dwc_param_rx_thr_length_default 64
  66053. +
  66054. +/**
  66055. + * Specifies whether LPM (Link Power Management) support is enabled
  66056. + */
  66057. +extern int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if,
  66058. + int32_t val);
  66059. +extern int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if);
  66060. +#define dwc_param_lpm_enable_default 1
  66061. +
  66062. +/**
  66063. + * Specifies whether PTI enhancement is enabled
  66064. + */
  66065. +extern int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if,
  66066. + int32_t val);
  66067. +extern int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if);
  66068. +#define dwc_param_pti_enable_default 0
  66069. +
  66070. +/**
  66071. + * Specifies whether MPI enhancement is enabled
  66072. + */
  66073. +extern int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if,
  66074. + int32_t val);
  66075. +extern int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if);
  66076. +#define dwc_param_mpi_enable_default 0
  66077. +
  66078. +/**
  66079. + * Specifies whether ADP capability is enabled
  66080. + */
  66081. +extern int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if,
  66082. + int32_t val);
  66083. +extern int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if);
  66084. +#define dwc_param_adp_enable_default 0
  66085. +
  66086. +/**
  66087. + * Specifies whether IC_USB capability is enabled
  66088. + */
  66089. +
  66090. +extern int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if,
  66091. + int32_t val);
  66092. +extern int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if);
  66093. +#define dwc_param_ic_usb_cap_default 0
  66094. +
  66095. +extern int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if,
  66096. + int32_t val);
  66097. +extern int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if);
  66098. +#define dwc_param_ahb_thr_ratio_default 0
  66099. +
  66100. +extern int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if,
  66101. + int32_t val);
  66102. +extern int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if);
  66103. +#define dwc_param_power_down_default 0
  66104. +
  66105. +extern int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if,
  66106. + int32_t val);
  66107. +extern int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if);
  66108. +#define dwc_param_reload_ctl_default 0
  66109. +
  66110. +extern int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if,
  66111. + int32_t val);
  66112. +extern int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if);
  66113. +#define dwc_param_dev_out_nak_default 0
  66114. +
  66115. +extern int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if,
  66116. + int32_t val);
  66117. +extern int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if);
  66118. +#define dwc_param_cont_on_bna_default 0
  66119. +
  66120. +extern int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if,
  66121. + int32_t val);
  66122. +extern int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if);
  66123. +#define dwc_param_ahb_single_default 0
  66124. +
  66125. +extern int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val);
  66126. +extern int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if);
  66127. +#define dwc_param_otg_ver_default 0
  66128. +
  66129. +/** @} */
  66130. +
  66131. +/** @name Access to registers and bit-fields */
  66132. +
  66133. +/**
  66134. + * Dump core registers and SPRAM
  66135. + */
  66136. +extern void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * _core_if);
  66137. +extern void dwc_otg_dump_spram(dwc_otg_core_if_t * _core_if);
  66138. +extern void dwc_otg_dump_host_registers(dwc_otg_core_if_t * _core_if);
  66139. +extern void dwc_otg_dump_global_registers(dwc_otg_core_if_t * _core_if);
  66140. +
  66141. +/**
  66142. + * Get host negotiation status.
  66143. + */
  66144. +extern uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if);
  66145. +
  66146. +/**
  66147. + * Get srp status
  66148. + */
  66149. +extern uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if);
  66150. +
  66151. +/**
  66152. + * Set hnpreq bit in the GOTGCTL register.
  66153. + */
  66154. +extern void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val);
  66155. +
  66156. +/**
  66157. + * Get Content of SNPSID register.
  66158. + */
  66159. +extern uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if);
  66160. +
  66161. +/**
  66162. + * Get current mode.
  66163. + * Returns 0 if in device mode, and 1 if in host mode.
  66164. + */
  66165. +extern uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if);
  66166. +
  66167. +/**
  66168. + * Get value of hnpcapable field in the GUSBCFG register
  66169. + */
  66170. +extern uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if);
  66171. +/**
  66172. + * Set value of hnpcapable field in the GUSBCFG register
  66173. + */
  66174. +extern void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  66175. +
  66176. +/**
  66177. + * Get value of srpcapable field in the GUSBCFG register
  66178. + */
  66179. +extern uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if);
  66180. +/**
  66181. + * Set value of srpcapable field in the GUSBCFG register
  66182. + */
  66183. +extern void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  66184. +
  66185. +/**
  66186. + * Get value of devspeed field in the DCFG register
  66187. + */
  66188. +extern uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if);
  66189. +/**
  66190. + * Set value of devspeed field in the DCFG register
  66191. + */
  66192. +extern void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val);
  66193. +
  66194. +/**
  66195. + * Get the value of busconnected field from the HPRT0 register
  66196. + */
  66197. +extern uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if);
  66198. +
  66199. +/**
  66200. + * Gets the device enumeration Speed.
  66201. + */
  66202. +extern uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if);
  66203. +
  66204. +/**
  66205. + * Get value of prtpwr field from the HPRT0 register
  66206. + */
  66207. +extern uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if);
  66208. +
  66209. +/**
  66210. + * Get value of flag indicating core state - hibernated or not
  66211. + */
  66212. +extern uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if);
  66213. +
  66214. +/**
  66215. + * Set value of prtpwr field from the HPRT0 register
  66216. + */
  66217. +extern void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val);
  66218. +
  66219. +/**
  66220. + * Get value of prtsusp field from the HPRT0 regsiter
  66221. + */
  66222. +extern uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if);
  66223. +/**
  66224. + * Set value of prtpwr field from the HPRT0 register
  66225. + */
  66226. +extern void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val);
  66227. +
  66228. +/**
  66229. + * Get value of ModeChTimEn field from the HCFG regsiter
  66230. + */
  66231. +extern uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if);
  66232. +/**
  66233. + * Set value of ModeChTimEn field from the HCFG regsiter
  66234. + */
  66235. +extern void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val);
  66236. +
  66237. +/**
  66238. + * Get value of Fram Interval field from the HFIR regsiter
  66239. + */
  66240. +extern uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if);
  66241. +/**
  66242. + * Set value of Frame Interval field from the HFIR regsiter
  66243. + */
  66244. +extern void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val);
  66245. +
  66246. +/**
  66247. + * Set value of prtres field from the HPRT0 register
  66248. + *FIXME Remove?
  66249. + */
  66250. +extern void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val);
  66251. +
  66252. +/**
  66253. + * Get value of rmtwkupsig bit in DCTL register
  66254. + */
  66255. +extern uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if);
  66256. +
  66257. +/**
  66258. + * Get value of prt_sleep_sts field from the GLPMCFG register
  66259. + */
  66260. +extern uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if);
  66261. +
  66262. +/**
  66263. + * Get value of rem_wkup_en field from the GLPMCFG register
  66264. + */
  66265. +extern uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if);
  66266. +
  66267. +/**
  66268. + * Get value of appl_resp field from the GLPMCFG register
  66269. + */
  66270. +extern uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if);
  66271. +/**
  66272. + * Set value of appl_resp field from the GLPMCFG register
  66273. + */
  66274. +extern void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val);
  66275. +
  66276. +/**
  66277. + * Get value of hsic_connect field from the GLPMCFG register
  66278. + */
  66279. +extern uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if);
  66280. +/**
  66281. + * Set value of hsic_connect field from the GLPMCFG register
  66282. + */
  66283. +extern void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val);
  66284. +
  66285. +/**
  66286. + * Get value of inv_sel_hsic field from the GLPMCFG register.
  66287. + */
  66288. +extern uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if);
  66289. +/**
  66290. + * Set value of inv_sel_hsic field from the GLPMFG register.
  66291. + */
  66292. +extern void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val);
  66293. +
  66294. +/*
  66295. + * Some functions for accessing registers
  66296. + */
  66297. +
  66298. +/**
  66299. + * GOTGCTL register
  66300. + */
  66301. +extern uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if);
  66302. +extern void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val);
  66303. +
  66304. +/**
  66305. + * GUSBCFG register
  66306. + */
  66307. +extern uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if);
  66308. +extern void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val);
  66309. +
  66310. +/**
  66311. + * GRXFSIZ register
  66312. + */
  66313. +extern uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if);
  66314. +extern void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  66315. +
  66316. +/**
  66317. + * GNPTXFSIZ register
  66318. + */
  66319. +extern uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if);
  66320. +extern void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  66321. +
  66322. +extern uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if);
  66323. +extern void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val);
  66324. +
  66325. +/**
  66326. + * GGPIO register
  66327. + */
  66328. +extern uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if);
  66329. +extern void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val);
  66330. +
  66331. +/**
  66332. + * GUID register
  66333. + */
  66334. +extern uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if);
  66335. +extern void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val);
  66336. +
  66337. +/**
  66338. + * HPRT0 register
  66339. + */
  66340. +extern uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if);
  66341. +extern void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val);
  66342. +
  66343. +/**
  66344. + * GHPTXFSIZE
  66345. + */
  66346. +extern uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if);
  66347. +
  66348. +/** @} */
  66349. +
  66350. +#endif /* __DWC_CORE_IF_H__ */
  66351. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_dbg.h linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_dbg.h
  66352. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 1970-01-01 01:00:00.000000000 +0100
  66353. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 2014-02-18 11:52:14.000000000 +0100
  66354. @@ -0,0 +1,117 @@
  66355. +/* ==========================================================================
  66356. + *
  66357. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  66358. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  66359. + * otherwise expressly agreed to in writing between Synopsys and you.
  66360. + *
  66361. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  66362. + * any End User Software License Agreement or Agreement for Licensed Product
  66363. + * with Synopsys or any supplement thereto. You are permitted to use and
  66364. + * redistribute this Software in source and binary forms, with or without
  66365. + * modification, provided that redistributions of source code must retain this
  66366. + * notice. You may not view, use, disclose, copy or distribute this file or
  66367. + * any information contained herein except pursuant to this license grant from
  66368. + * Synopsys. If you do not agree with this notice, including the disclaimer
  66369. + * below, then you are not authorized to use the Software.
  66370. + *
  66371. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  66372. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66373. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  66374. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  66375. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  66376. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  66377. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  66378. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  66379. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  66380. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  66381. + * DAMAGE.
  66382. + * ========================================================================== */
  66383. +
  66384. +#ifndef __DWC_OTG_DBG_H__
  66385. +#define __DWC_OTG_DBG_H__
  66386. +
  66387. +/** @file
  66388. + * This file defines debug levels.
  66389. + * Debugging support vanishes in non-debug builds.
  66390. + */
  66391. +
  66392. +/**
  66393. + * The Debug Level bit-mask variable.
  66394. + */
  66395. +extern uint32_t g_dbg_lvl;
  66396. +/**
  66397. + * Set the Debug Level variable.
  66398. + */
  66399. +static inline uint32_t SET_DEBUG_LEVEL(const uint32_t new)
  66400. +{
  66401. + uint32_t old = g_dbg_lvl;
  66402. + g_dbg_lvl = new;
  66403. + return old;
  66404. +}
  66405. +
  66406. +#define DBG_USER (0x1)
  66407. +/** When debug level has the DBG_CIL bit set, display CIL Debug messages. */
  66408. +#define DBG_CIL (0x2)
  66409. +/** When debug level has the DBG_CILV bit set, display CIL Verbose debug
  66410. + * messages */
  66411. +#define DBG_CILV (0x20)
  66412. +/** When debug level has the DBG_PCD bit set, display PCD (Device) debug
  66413. + * messages */
  66414. +#define DBG_PCD (0x4)
  66415. +/** When debug level has the DBG_PCDV set, display PCD (Device) Verbose debug
  66416. + * messages */
  66417. +#define DBG_PCDV (0x40)
  66418. +/** When debug level has the DBG_HCD bit set, display Host debug messages */
  66419. +#define DBG_HCD (0x8)
  66420. +/** When debug level has the DBG_HCDV bit set, display Verbose Host debug
  66421. + * messages */
  66422. +#define DBG_HCDV (0x80)
  66423. +/** When debug level has the DBG_HCD_URB bit set, display enqueued URBs in host
  66424. + * mode. */
  66425. +#define DBG_HCD_URB (0x800)
  66426. +/** When debug level has the DBG_HCDI bit set, display host interrupt
  66427. + * messages. */
  66428. +#define DBG_HCDI (0x1000)
  66429. +
  66430. +/** When debug level has any bit set, display debug messages */
  66431. +#define DBG_ANY (0xFF)
  66432. +
  66433. +/** All debug messages off */
  66434. +#define DBG_OFF 0
  66435. +
  66436. +/** Prefix string for DWC_DEBUG print macros. */
  66437. +#define USB_DWC "DWC_otg: "
  66438. +
  66439. +/**
  66440. + * Print a debug message when the Global debug level variable contains
  66441. + * the bit defined in <code>lvl</code>.
  66442. + *
  66443. + * @param[in] lvl - Debug level, use one of the DBG_ constants above.
  66444. + * @param[in] x - like printf
  66445. + *
  66446. + * Example:<p>
  66447. + * <code>
  66448. + * DWC_DEBUGPL( DBG_ANY, "%s(%p)\n", __func__, _reg_base_addr);
  66449. + * </code>
  66450. + * <br>
  66451. + * results in:<br>
  66452. + * <code>
  66453. + * usb-DWC_otg: dwc_otg_cil_init(ca867000)
  66454. + * </code>
  66455. + */
  66456. +#ifdef DEBUG
  66457. +
  66458. +# define DWC_DEBUGPL(lvl, x...) do{ if ((lvl)&g_dbg_lvl)__DWC_DEBUG(USB_DWC x ); }while(0)
  66459. +# define DWC_DEBUGP(x...) DWC_DEBUGPL(DBG_ANY, x )
  66460. +
  66461. +# define CHK_DEBUG_LEVEL(level) ((level) & g_dbg_lvl)
  66462. +
  66463. +#else
  66464. +
  66465. +# define DWC_DEBUGPL(lvl, x...) do{}while(0)
  66466. +# define DWC_DEBUGP(x...)
  66467. +
  66468. +# define CHK_DEBUG_LEVEL(level) (0)
  66469. +
  66470. +#endif /*DEBUG*/
  66471. +#endif
  66472. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_driver.c linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_driver.c
  66473. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_driver.c 1970-01-01 01:00:00.000000000 +0100
  66474. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_driver.c 2014-02-18 11:52:14.000000000 +0100
  66475. @@ -0,0 +1,1742 @@
  66476. +/* ==========================================================================
  66477. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.c $
  66478. + * $Revision: #92 $
  66479. + * $Date: 2012/08/10 $
  66480. + * $Change: 2047372 $
  66481. + *
  66482. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  66483. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  66484. + * otherwise expressly agreed to in writing between Synopsys and you.
  66485. + *
  66486. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  66487. + * any End User Software License Agreement or Agreement for Licensed Product
  66488. + * with Synopsys or any supplement thereto. You are permitted to use and
  66489. + * redistribute this Software in source and binary forms, with or without
  66490. + * modification, provided that redistributions of source code must retain this
  66491. + * notice. You may not view, use, disclose, copy or distribute this file or
  66492. + * any information contained herein except pursuant to this license grant from
  66493. + * Synopsys. If you do not agree with this notice, including the disclaimer
  66494. + * below, then you are not authorized to use the Software.
  66495. + *
  66496. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  66497. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66498. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  66499. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  66500. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  66501. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  66502. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  66503. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  66504. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  66505. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  66506. + * DAMAGE.
  66507. + * ========================================================================== */
  66508. +
  66509. +/** @file
  66510. + * The dwc_otg_driver module provides the initialization and cleanup entry
  66511. + * points for the DWC_otg driver. This module will be dynamically installed
  66512. + * after Linux is booted using the insmod command. When the module is
  66513. + * installed, the dwc_otg_driver_init function is called. When the module is
  66514. + * removed (using rmmod), the dwc_otg_driver_cleanup function is called.
  66515. + *
  66516. + * This module also defines a data structure for the dwc_otg_driver, which is
  66517. + * used in conjunction with the standard ARM lm_device structure. These
  66518. + * structures allow the OTG driver to comply with the standard Linux driver
  66519. + * model in which devices and drivers are registered with a bus driver. This
  66520. + * has the benefit that Linux can expose attributes of the driver and device
  66521. + * in its special sysfs file system. Users can then read or write files in
  66522. + * this file system to perform diagnostics on the driver components or the
  66523. + * device.
  66524. + */
  66525. +
  66526. +#include "dwc_otg_os_dep.h"
  66527. +#include "dwc_os.h"
  66528. +#include "dwc_otg_dbg.h"
  66529. +#include "dwc_otg_driver.h"
  66530. +#include "dwc_otg_attr.h"
  66531. +#include "dwc_otg_core_if.h"
  66532. +#include "dwc_otg_pcd_if.h"
  66533. +#include "dwc_otg_hcd_if.h"
  66534. +
  66535. +#define DWC_DRIVER_VERSION "3.00a 10-AUG-2012"
  66536. +#define DWC_DRIVER_DESC "HS OTG USB Controller driver"
  66537. +
  66538. +bool microframe_schedule=true;
  66539. +
  66540. +static const char dwc_driver_name[] = "dwc_otg";
  66541. +
  66542. +extern void* dummy_send;
  66543. +
  66544. +extern int pcd_init(
  66545. +#ifdef LM_INTERFACE
  66546. + struct lm_device *_dev
  66547. +#elif defined(PCI_INTERFACE)
  66548. + struct pci_dev *_dev
  66549. +#elif defined(PLATFORM_INTERFACE)
  66550. + struct platform_device *dev
  66551. +#endif
  66552. + );
  66553. +extern int hcd_init(
  66554. +#ifdef LM_INTERFACE
  66555. + struct lm_device *_dev
  66556. +#elif defined(PCI_INTERFACE)
  66557. + struct pci_dev *_dev
  66558. +#elif defined(PLATFORM_INTERFACE)
  66559. + struct platform_device *dev
  66560. +#endif
  66561. + );
  66562. +
  66563. +extern int pcd_remove(
  66564. +#ifdef LM_INTERFACE
  66565. + struct lm_device *_dev
  66566. +#elif defined(PCI_INTERFACE)
  66567. + struct pci_dev *_dev
  66568. +#elif defined(PLATFORM_INTERFACE)
  66569. + struct platform_device *_dev
  66570. +#endif
  66571. + );
  66572. +
  66573. +extern void hcd_remove(
  66574. +#ifdef LM_INTERFACE
  66575. + struct lm_device *_dev
  66576. +#elif defined(PCI_INTERFACE)
  66577. + struct pci_dev *_dev
  66578. +#elif defined(PLATFORM_INTERFACE)
  66579. + struct platform_device *_dev
  66580. +#endif
  66581. + );
  66582. +
  66583. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  66584. +
  66585. +/*-------------------------------------------------------------------------*/
  66586. +/* Encapsulate the module parameter settings */
  66587. +
  66588. +struct dwc_otg_driver_module_params {
  66589. + int32_t opt;
  66590. + int32_t otg_cap;
  66591. + int32_t dma_enable;
  66592. + int32_t dma_desc_enable;
  66593. + int32_t dma_burst_size;
  66594. + int32_t speed;
  66595. + int32_t host_support_fs_ls_low_power;
  66596. + int32_t host_ls_low_power_phy_clk;
  66597. + int32_t enable_dynamic_fifo;
  66598. + int32_t data_fifo_size;
  66599. + int32_t dev_rx_fifo_size;
  66600. + int32_t dev_nperio_tx_fifo_size;
  66601. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  66602. + int32_t host_rx_fifo_size;
  66603. + int32_t host_nperio_tx_fifo_size;
  66604. + int32_t host_perio_tx_fifo_size;
  66605. + int32_t max_transfer_size;
  66606. + int32_t max_packet_count;
  66607. + int32_t host_channels;
  66608. + int32_t dev_endpoints;
  66609. + int32_t phy_type;
  66610. + int32_t phy_utmi_width;
  66611. + int32_t phy_ulpi_ddr;
  66612. + int32_t phy_ulpi_ext_vbus;
  66613. + int32_t i2c_enable;
  66614. + int32_t ulpi_fs_ls;
  66615. + int32_t ts_dline;
  66616. + int32_t en_multiple_tx_fifo;
  66617. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  66618. + uint32_t thr_ctl;
  66619. + uint32_t tx_thr_length;
  66620. + uint32_t rx_thr_length;
  66621. + int32_t pti_enable;
  66622. + int32_t mpi_enable;
  66623. + int32_t lpm_enable;
  66624. + int32_t ic_usb_cap;
  66625. + int32_t ahb_thr_ratio;
  66626. + int32_t power_down;
  66627. + int32_t reload_ctl;
  66628. + int32_t dev_out_nak;
  66629. + int32_t cont_on_bna;
  66630. + int32_t ahb_single;
  66631. + int32_t otg_ver;
  66632. + int32_t adp_enable;
  66633. +};
  66634. +
  66635. +static struct dwc_otg_driver_module_params dwc_otg_module_params = {
  66636. + .opt = -1,
  66637. + .otg_cap = -1,
  66638. + .dma_enable = -1,
  66639. + .dma_desc_enable = -1,
  66640. + .dma_burst_size = -1,
  66641. + .speed = -1,
  66642. + .host_support_fs_ls_low_power = -1,
  66643. + .host_ls_low_power_phy_clk = -1,
  66644. + .enable_dynamic_fifo = -1,
  66645. + .data_fifo_size = -1,
  66646. + .dev_rx_fifo_size = -1,
  66647. + .dev_nperio_tx_fifo_size = -1,
  66648. + .dev_perio_tx_fifo_size = {
  66649. + /* dev_perio_tx_fifo_size_1 */
  66650. + -1,
  66651. + -1,
  66652. + -1,
  66653. + -1,
  66654. + -1,
  66655. + -1,
  66656. + -1,
  66657. + -1,
  66658. + -1,
  66659. + -1,
  66660. + -1,
  66661. + -1,
  66662. + -1,
  66663. + -1,
  66664. + -1
  66665. + /* 15 */
  66666. + },
  66667. + .host_rx_fifo_size = -1,
  66668. + .host_nperio_tx_fifo_size = -1,
  66669. + .host_perio_tx_fifo_size = -1,
  66670. + .max_transfer_size = -1,
  66671. + .max_packet_count = -1,
  66672. + .host_channels = -1,
  66673. + .dev_endpoints = -1,
  66674. + .phy_type = -1,
  66675. + .phy_utmi_width = -1,
  66676. + .phy_ulpi_ddr = -1,
  66677. + .phy_ulpi_ext_vbus = -1,
  66678. + .i2c_enable = -1,
  66679. + .ulpi_fs_ls = -1,
  66680. + .ts_dline = -1,
  66681. + .en_multiple_tx_fifo = -1,
  66682. + .dev_tx_fifo_size = {
  66683. + /* dev_tx_fifo_size */
  66684. + -1,
  66685. + -1,
  66686. + -1,
  66687. + -1,
  66688. + -1,
  66689. + -1,
  66690. + -1,
  66691. + -1,
  66692. + -1,
  66693. + -1,
  66694. + -1,
  66695. + -1,
  66696. + -1,
  66697. + -1,
  66698. + -1
  66699. + /* 15 */
  66700. + },
  66701. + .thr_ctl = -1,
  66702. + .tx_thr_length = -1,
  66703. + .rx_thr_length = -1,
  66704. + .pti_enable = -1,
  66705. + .mpi_enable = -1,
  66706. + .lpm_enable = 0,
  66707. + .ic_usb_cap = -1,
  66708. + .ahb_thr_ratio = -1,
  66709. + .power_down = -1,
  66710. + .reload_ctl = -1,
  66711. + .dev_out_nak = -1,
  66712. + .cont_on_bna = -1,
  66713. + .ahb_single = -1,
  66714. + .otg_ver = -1,
  66715. + .adp_enable = -1,
  66716. +};
  66717. +
  66718. +//Global variable to switch the fiq fix on or off (declared in bcm2708.c)
  66719. +extern bool fiq_fix_enable;
  66720. +// Global variable to enable the split transaction fix
  66721. +bool fiq_split_enable = true;
  66722. +//Global variable to switch the nak holdoff on or off
  66723. +bool nak_holdoff_enable = true;
  66724. +
  66725. +
  66726. +/**
  66727. + * This function shows the Driver Version.
  66728. + */
  66729. +static ssize_t version_show(struct device_driver *dev, char *buf)
  66730. +{
  66731. + return snprintf(buf, sizeof(DWC_DRIVER_VERSION) + 2, "%s\n",
  66732. + DWC_DRIVER_VERSION);
  66733. +}
  66734. +
  66735. +static DRIVER_ATTR(version, S_IRUGO, version_show, NULL);
  66736. +
  66737. +/**
  66738. + * Global Debug Level Mask.
  66739. + */
  66740. +uint32_t g_dbg_lvl = 0; /* OFF */
  66741. +
  66742. +/**
  66743. + * This function shows the driver Debug Level.
  66744. + */
  66745. +static ssize_t dbg_level_show(struct device_driver *drv, char *buf)
  66746. +{
  66747. + return sprintf(buf, "0x%0x\n", g_dbg_lvl);
  66748. +}
  66749. +
  66750. +/**
  66751. + * This function stores the driver Debug Level.
  66752. + */
  66753. +static ssize_t dbg_level_store(struct device_driver *drv, const char *buf,
  66754. + size_t count)
  66755. +{
  66756. + g_dbg_lvl = simple_strtoul(buf, NULL, 16);
  66757. + return count;
  66758. +}
  66759. +
  66760. +static DRIVER_ATTR(debuglevel, S_IRUGO | S_IWUSR, dbg_level_show,
  66761. + dbg_level_store);
  66762. +
  66763. +/**
  66764. + * This function is called during module intialization
  66765. + * to pass module parameters to the DWC_OTG CORE.
  66766. + */
  66767. +static int set_parameters(dwc_otg_core_if_t * core_if)
  66768. +{
  66769. + int retval = 0;
  66770. + int i;
  66771. +
  66772. + if (dwc_otg_module_params.otg_cap != -1) {
  66773. + retval +=
  66774. + dwc_otg_set_param_otg_cap(core_if,
  66775. + dwc_otg_module_params.otg_cap);
  66776. + }
  66777. + if (dwc_otg_module_params.dma_enable != -1) {
  66778. + retval +=
  66779. + dwc_otg_set_param_dma_enable(core_if,
  66780. + dwc_otg_module_params.
  66781. + dma_enable);
  66782. + }
  66783. + if (dwc_otg_module_params.dma_desc_enable != -1) {
  66784. + retval +=
  66785. + dwc_otg_set_param_dma_desc_enable(core_if,
  66786. + dwc_otg_module_params.
  66787. + dma_desc_enable);
  66788. + }
  66789. + if (dwc_otg_module_params.opt != -1) {
  66790. + retval +=
  66791. + dwc_otg_set_param_opt(core_if, dwc_otg_module_params.opt);
  66792. + }
  66793. + if (dwc_otg_module_params.dma_burst_size != -1) {
  66794. + retval +=
  66795. + dwc_otg_set_param_dma_burst_size(core_if,
  66796. + dwc_otg_module_params.
  66797. + dma_burst_size);
  66798. + }
  66799. + if (dwc_otg_module_params.host_support_fs_ls_low_power != -1) {
  66800. + retval +=
  66801. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  66802. + dwc_otg_module_params.
  66803. + host_support_fs_ls_low_power);
  66804. + }
  66805. + if (dwc_otg_module_params.enable_dynamic_fifo != -1) {
  66806. + retval +=
  66807. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  66808. + dwc_otg_module_params.
  66809. + enable_dynamic_fifo);
  66810. + }
  66811. + if (dwc_otg_module_params.data_fifo_size != -1) {
  66812. + retval +=
  66813. + dwc_otg_set_param_data_fifo_size(core_if,
  66814. + dwc_otg_module_params.
  66815. + data_fifo_size);
  66816. + }
  66817. + if (dwc_otg_module_params.dev_rx_fifo_size != -1) {
  66818. + retval +=
  66819. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  66820. + dwc_otg_module_params.
  66821. + dev_rx_fifo_size);
  66822. + }
  66823. + if (dwc_otg_module_params.dev_nperio_tx_fifo_size != -1) {
  66824. + retval +=
  66825. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  66826. + dwc_otg_module_params.
  66827. + dev_nperio_tx_fifo_size);
  66828. + }
  66829. + if (dwc_otg_module_params.host_rx_fifo_size != -1) {
  66830. + retval +=
  66831. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  66832. + dwc_otg_module_params.host_rx_fifo_size);
  66833. + }
  66834. + if (dwc_otg_module_params.host_nperio_tx_fifo_size != -1) {
  66835. + retval +=
  66836. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  66837. + dwc_otg_module_params.
  66838. + host_nperio_tx_fifo_size);
  66839. + }
  66840. + if (dwc_otg_module_params.host_perio_tx_fifo_size != -1) {
  66841. + retval +=
  66842. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  66843. + dwc_otg_module_params.
  66844. + host_perio_tx_fifo_size);
  66845. + }
  66846. + if (dwc_otg_module_params.max_transfer_size != -1) {
  66847. + retval +=
  66848. + dwc_otg_set_param_max_transfer_size(core_if,
  66849. + dwc_otg_module_params.
  66850. + max_transfer_size);
  66851. + }
  66852. + if (dwc_otg_module_params.max_packet_count != -1) {
  66853. + retval +=
  66854. + dwc_otg_set_param_max_packet_count(core_if,
  66855. + dwc_otg_module_params.
  66856. + max_packet_count);
  66857. + }
  66858. + if (dwc_otg_module_params.host_channels != -1) {
  66859. + retval +=
  66860. + dwc_otg_set_param_host_channels(core_if,
  66861. + dwc_otg_module_params.
  66862. + host_channels);
  66863. + }
  66864. + if (dwc_otg_module_params.dev_endpoints != -1) {
  66865. + retval +=
  66866. + dwc_otg_set_param_dev_endpoints(core_if,
  66867. + dwc_otg_module_params.
  66868. + dev_endpoints);
  66869. + }
  66870. + if (dwc_otg_module_params.phy_type != -1) {
  66871. + retval +=
  66872. + dwc_otg_set_param_phy_type(core_if,
  66873. + dwc_otg_module_params.phy_type);
  66874. + }
  66875. + if (dwc_otg_module_params.speed != -1) {
  66876. + retval +=
  66877. + dwc_otg_set_param_speed(core_if,
  66878. + dwc_otg_module_params.speed);
  66879. + }
  66880. + if (dwc_otg_module_params.host_ls_low_power_phy_clk != -1) {
  66881. + retval +=
  66882. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  66883. + dwc_otg_module_params.
  66884. + host_ls_low_power_phy_clk);
  66885. + }
  66886. + if (dwc_otg_module_params.phy_ulpi_ddr != -1) {
  66887. + retval +=
  66888. + dwc_otg_set_param_phy_ulpi_ddr(core_if,
  66889. + dwc_otg_module_params.
  66890. + phy_ulpi_ddr);
  66891. + }
  66892. + if (dwc_otg_module_params.phy_ulpi_ext_vbus != -1) {
  66893. + retval +=
  66894. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  66895. + dwc_otg_module_params.
  66896. + phy_ulpi_ext_vbus);
  66897. + }
  66898. + if (dwc_otg_module_params.phy_utmi_width != -1) {
  66899. + retval +=
  66900. + dwc_otg_set_param_phy_utmi_width(core_if,
  66901. + dwc_otg_module_params.
  66902. + phy_utmi_width);
  66903. + }
  66904. + if (dwc_otg_module_params.ulpi_fs_ls != -1) {
  66905. + retval +=
  66906. + dwc_otg_set_param_ulpi_fs_ls(core_if,
  66907. + dwc_otg_module_params.ulpi_fs_ls);
  66908. + }
  66909. + if (dwc_otg_module_params.ts_dline != -1) {
  66910. + retval +=
  66911. + dwc_otg_set_param_ts_dline(core_if,
  66912. + dwc_otg_module_params.ts_dline);
  66913. + }
  66914. + if (dwc_otg_module_params.i2c_enable != -1) {
  66915. + retval +=
  66916. + dwc_otg_set_param_i2c_enable(core_if,
  66917. + dwc_otg_module_params.
  66918. + i2c_enable);
  66919. + }
  66920. + if (dwc_otg_module_params.en_multiple_tx_fifo != -1) {
  66921. + retval +=
  66922. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  66923. + dwc_otg_module_params.
  66924. + en_multiple_tx_fifo);
  66925. + }
  66926. + for (i = 0; i < 15; i++) {
  66927. + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] != -1) {
  66928. + retval +=
  66929. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  66930. + dwc_otg_module_params.
  66931. + dev_perio_tx_fifo_size
  66932. + [i], i);
  66933. + }
  66934. + }
  66935. +
  66936. + for (i = 0; i < 15; i++) {
  66937. + if (dwc_otg_module_params.dev_tx_fifo_size[i] != -1) {
  66938. + retval += dwc_otg_set_param_dev_tx_fifo_size(core_if,
  66939. + dwc_otg_module_params.
  66940. + dev_tx_fifo_size
  66941. + [i], i);
  66942. + }
  66943. + }
  66944. + if (dwc_otg_module_params.thr_ctl != -1) {
  66945. + retval +=
  66946. + dwc_otg_set_param_thr_ctl(core_if,
  66947. + dwc_otg_module_params.thr_ctl);
  66948. + }
  66949. + if (dwc_otg_module_params.mpi_enable != -1) {
  66950. + retval +=
  66951. + dwc_otg_set_param_mpi_enable(core_if,
  66952. + dwc_otg_module_params.
  66953. + mpi_enable);
  66954. + }
  66955. + if (dwc_otg_module_params.pti_enable != -1) {
  66956. + retval +=
  66957. + dwc_otg_set_param_pti_enable(core_if,
  66958. + dwc_otg_module_params.
  66959. + pti_enable);
  66960. + }
  66961. + if (dwc_otg_module_params.lpm_enable != -1) {
  66962. + retval +=
  66963. + dwc_otg_set_param_lpm_enable(core_if,
  66964. + dwc_otg_module_params.
  66965. + lpm_enable);
  66966. + }
  66967. + if (dwc_otg_module_params.ic_usb_cap != -1) {
  66968. + retval +=
  66969. + dwc_otg_set_param_ic_usb_cap(core_if,
  66970. + dwc_otg_module_params.
  66971. + ic_usb_cap);
  66972. + }
  66973. + if (dwc_otg_module_params.tx_thr_length != -1) {
  66974. + retval +=
  66975. + dwc_otg_set_param_tx_thr_length(core_if,
  66976. + dwc_otg_module_params.tx_thr_length);
  66977. + }
  66978. + if (dwc_otg_module_params.rx_thr_length != -1) {
  66979. + retval +=
  66980. + dwc_otg_set_param_rx_thr_length(core_if,
  66981. + dwc_otg_module_params.
  66982. + rx_thr_length);
  66983. + }
  66984. + if (dwc_otg_module_params.ahb_thr_ratio != -1) {
  66985. + retval +=
  66986. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  66987. + dwc_otg_module_params.ahb_thr_ratio);
  66988. + }
  66989. + if (dwc_otg_module_params.power_down != -1) {
  66990. + retval +=
  66991. + dwc_otg_set_param_power_down(core_if,
  66992. + dwc_otg_module_params.power_down);
  66993. + }
  66994. + if (dwc_otg_module_params.reload_ctl != -1) {
  66995. + retval +=
  66996. + dwc_otg_set_param_reload_ctl(core_if,
  66997. + dwc_otg_module_params.reload_ctl);
  66998. + }
  66999. +
  67000. + if (dwc_otg_module_params.dev_out_nak != -1) {
  67001. + retval +=
  67002. + dwc_otg_set_param_dev_out_nak(core_if,
  67003. + dwc_otg_module_params.dev_out_nak);
  67004. + }
  67005. +
  67006. + if (dwc_otg_module_params.cont_on_bna != -1) {
  67007. + retval +=
  67008. + dwc_otg_set_param_cont_on_bna(core_if,
  67009. + dwc_otg_module_params.cont_on_bna);
  67010. + }
  67011. +
  67012. + if (dwc_otg_module_params.ahb_single != -1) {
  67013. + retval +=
  67014. + dwc_otg_set_param_ahb_single(core_if,
  67015. + dwc_otg_module_params.ahb_single);
  67016. + }
  67017. +
  67018. + if (dwc_otg_module_params.otg_ver != -1) {
  67019. + retval +=
  67020. + dwc_otg_set_param_otg_ver(core_if,
  67021. + dwc_otg_module_params.otg_ver);
  67022. + }
  67023. + if (dwc_otg_module_params.adp_enable != -1) {
  67024. + retval +=
  67025. + dwc_otg_set_param_adp_enable(core_if,
  67026. + dwc_otg_module_params.
  67027. + adp_enable);
  67028. + }
  67029. + return retval;
  67030. +}
  67031. +
  67032. +/**
  67033. + * This function is the top level interrupt handler for the Common
  67034. + * (Device and host modes) interrupts.
  67035. + */
  67036. +static irqreturn_t dwc_otg_common_irq(int irq, void *dev)
  67037. +{
  67038. + int32_t retval = IRQ_NONE;
  67039. +
  67040. + retval = dwc_otg_handle_common_intr(dev);
  67041. + if (retval != 0) {
  67042. + S3C2410X_CLEAR_EINTPEND();
  67043. + }
  67044. + return IRQ_RETVAL(retval);
  67045. +}
  67046. +
  67047. +/**
  67048. + * This function is called when a lm_device is unregistered with the
  67049. + * dwc_otg_driver. This happens, for example, when the rmmod command is
  67050. + * executed. The device may or may not be electrically present. If it is
  67051. + * present, the driver stops device processing. Any resources used on behalf
  67052. + * of this device are freed.
  67053. + *
  67054. + * @param _dev
  67055. + */
  67056. +#ifdef LM_INTERFACE
  67057. +#define REM_RETVAL(n)
  67058. +static void dwc_otg_driver_remove( struct lm_device *_dev )
  67059. +{ dwc_otg_device_t *otg_dev = lm_get_drvdata(_dev);
  67060. +#elif defined(PCI_INTERFACE)
  67061. +#define REM_RETVAL(n)
  67062. +static void dwc_otg_driver_remove( struct pci_dev *_dev )
  67063. +{ dwc_otg_device_t *otg_dev = pci_get_drvdata(_dev);
  67064. +#elif defined(PLATFORM_INTERFACE)
  67065. +#define REM_RETVAL(n) n
  67066. +static int dwc_otg_driver_remove( struct platform_device *_dev )
  67067. +{ dwc_otg_device_t *otg_dev = platform_get_drvdata(_dev);
  67068. +#endif
  67069. +
  67070. + DWC_DEBUGPL(DBG_ANY, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  67071. +
  67072. + if (!otg_dev) {
  67073. + /* Memory allocation for the dwc_otg_device failed. */
  67074. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  67075. + return REM_RETVAL(-ENOMEM);
  67076. + }
  67077. +#ifndef DWC_DEVICE_ONLY
  67078. + if (otg_dev->hcd) {
  67079. + hcd_remove(_dev);
  67080. + } else {
  67081. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  67082. + return REM_RETVAL(-EINVAL);
  67083. + }
  67084. +#endif
  67085. +
  67086. +#ifndef DWC_HOST_ONLY
  67087. + if (otg_dev->pcd) {
  67088. + pcd_remove(_dev);
  67089. + } else {
  67090. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->pcd NULL!\n", __func__);
  67091. + return REM_RETVAL(-EINVAL);
  67092. + }
  67093. +#endif
  67094. + /*
  67095. + * Free the IRQ
  67096. + */
  67097. + if (otg_dev->common_irq_installed) {
  67098. +#ifdef PLATFORM_INTERFACE
  67099. + free_irq(platform_get_irq(_dev, 0), otg_dev);
  67100. +#else
  67101. + free_irq(_dev->irq, otg_dev);
  67102. +#endif
  67103. + } else {
  67104. + DWC_DEBUGPL(DBG_ANY, "%s: There is no installed irq!\n", __func__);
  67105. + return REM_RETVAL(-ENXIO);
  67106. + }
  67107. +
  67108. + if (otg_dev->core_if) {
  67109. + dwc_otg_cil_remove(otg_dev->core_if);
  67110. + } else {
  67111. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->core_if NULL!\n", __func__);
  67112. + return REM_RETVAL(-ENXIO);
  67113. + }
  67114. +
  67115. + /*
  67116. + * Remove the device attributes
  67117. + */
  67118. + dwc_otg_attr_remove(_dev);
  67119. +
  67120. + /*
  67121. + * Return the memory.
  67122. + */
  67123. + if (otg_dev->os_dep.base) {
  67124. + iounmap(otg_dev->os_dep.base);
  67125. + }
  67126. + DWC_FREE(otg_dev);
  67127. +
  67128. + /*
  67129. + * Clear the drvdata pointer.
  67130. + */
  67131. +#ifdef LM_INTERFACE
  67132. + lm_set_drvdata(_dev, 0);
  67133. +#elif defined(PCI_INTERFACE)
  67134. + release_mem_region(otg_dev->os_dep.rsrc_start,
  67135. + otg_dev->os_dep.rsrc_len);
  67136. + pci_set_drvdata(_dev, 0);
  67137. +#elif defined(PLATFORM_INTERFACE)
  67138. + platform_set_drvdata(_dev, 0);
  67139. +#endif
  67140. + return REM_RETVAL(0);
  67141. +}
  67142. +
  67143. +/**
  67144. + * This function is called when an lm_device is bound to a
  67145. + * dwc_otg_driver. It creates the driver components required to
  67146. + * control the device (CIL, HCD, and PCD) and it initializes the
  67147. + * device. The driver components are stored in a dwc_otg_device
  67148. + * structure. A reference to the dwc_otg_device is saved in the
  67149. + * lm_device. This allows the driver to access the dwc_otg_device
  67150. + * structure on subsequent calls to driver methods for this device.
  67151. + *
  67152. + * @param _dev Bus device
  67153. + */
  67154. +static int dwc_otg_driver_probe(
  67155. +#ifdef LM_INTERFACE
  67156. + struct lm_device *_dev
  67157. +#elif defined(PCI_INTERFACE)
  67158. + struct pci_dev *_dev,
  67159. + const struct pci_device_id *id
  67160. +#elif defined(PLATFORM_INTERFACE)
  67161. + struct platform_device *_dev
  67162. +#endif
  67163. + )
  67164. +{
  67165. + int retval = 0;
  67166. + dwc_otg_device_t *dwc_otg_device;
  67167. + int devirq;
  67168. +
  67169. + dev_dbg(&_dev->dev, "dwc_otg_driver_probe(%p)\n", _dev);
  67170. +#ifdef LM_INTERFACE
  67171. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)_dev->resource.start);
  67172. +#elif defined(PCI_INTERFACE)
  67173. + if (!id) {
  67174. + DWC_ERROR("Invalid pci_device_id %p", id);
  67175. + return -EINVAL;
  67176. + }
  67177. +
  67178. + if (!_dev || (pci_enable_device(_dev) < 0)) {
  67179. + DWC_ERROR("Invalid pci_device %p", _dev);
  67180. + return -ENODEV;
  67181. + }
  67182. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)pci_resource_start(_dev,0));
  67183. + /* other stuff needed as well? */
  67184. +
  67185. +#elif defined(PLATFORM_INTERFACE)
  67186. + dev_dbg(&_dev->dev, "start=0x%08x (len 0x%x)\n",
  67187. + (unsigned)_dev->resource->start,
  67188. + (unsigned)(_dev->resource->end - _dev->resource->start));
  67189. +#endif
  67190. +
  67191. + dwc_otg_device = DWC_ALLOC(sizeof(dwc_otg_device_t));
  67192. +
  67193. + if (!dwc_otg_device) {
  67194. + dev_err(&_dev->dev, "kmalloc of dwc_otg_device failed\n");
  67195. + return -ENOMEM;
  67196. + }
  67197. +
  67198. + memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
  67199. + dwc_otg_device->os_dep.reg_offset = 0xFFFFFFFF;
  67200. +
  67201. + /*
  67202. + * Map the DWC_otg Core memory into virtual address space.
  67203. + */
  67204. +#ifdef LM_INTERFACE
  67205. + dwc_otg_device->os_dep.base = ioremap(_dev->resource.start, SZ_256K);
  67206. +
  67207. + if (!dwc_otg_device->os_dep.base) {
  67208. + dev_err(&_dev->dev, "ioremap() failed\n");
  67209. + DWC_FREE(dwc_otg_device);
  67210. + return -ENOMEM;
  67211. + }
  67212. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  67213. + (unsigned)dwc_otg_device->os_dep.base);
  67214. +#elif defined(PCI_INTERFACE)
  67215. + _dev->current_state = PCI_D0;
  67216. + _dev->dev.power.power_state = PMSG_ON;
  67217. +
  67218. + if (!_dev->irq) {
  67219. + DWC_ERROR("Found HC with no IRQ. Check BIOS/PCI %s setup!",
  67220. + pci_name(_dev));
  67221. + iounmap(dwc_otg_device->os_dep.base);
  67222. + DWC_FREE(dwc_otg_device);
  67223. + return -ENODEV;
  67224. + }
  67225. +
  67226. + dwc_otg_device->os_dep.rsrc_start = pci_resource_start(_dev, 0);
  67227. + dwc_otg_device->os_dep.rsrc_len = pci_resource_len(_dev, 0);
  67228. + DWC_DEBUGPL(DBG_ANY, "PCI resource: start=%08x, len=%08x\n",
  67229. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  67230. + (unsigned)dwc_otg_device->os_dep.rsrc_len);
  67231. + if (!request_mem_region
  67232. + (dwc_otg_device->os_dep.rsrc_start, dwc_otg_device->os_dep.rsrc_len,
  67233. + "dwc_otg")) {
  67234. + dev_dbg(&_dev->dev, "error requesting memory\n");
  67235. + iounmap(dwc_otg_device->os_dep.base);
  67236. + DWC_FREE(dwc_otg_device);
  67237. + return -EFAULT;
  67238. + }
  67239. +
  67240. + dwc_otg_device->os_dep.base =
  67241. + ioremap_nocache(dwc_otg_device->os_dep.rsrc_start,
  67242. + dwc_otg_device->os_dep.rsrc_len);
  67243. + if (dwc_otg_device->os_dep.base == NULL) {
  67244. + dev_dbg(&_dev->dev, "error mapping memory\n");
  67245. + release_mem_region(dwc_otg_device->os_dep.rsrc_start,
  67246. + dwc_otg_device->os_dep.rsrc_len);
  67247. + iounmap(dwc_otg_device->os_dep.base);
  67248. + DWC_FREE(dwc_otg_device);
  67249. + return -EFAULT;
  67250. + }
  67251. + dev_dbg(&_dev->dev, "base=0x%p (before adjust) \n",
  67252. + dwc_otg_device->os_dep.base);
  67253. + dwc_otg_device->os_dep.base = (char *)dwc_otg_device->os_dep.base;
  67254. + dev_dbg(&_dev->dev, "base=0x%p (after adjust) \n",
  67255. + dwc_otg_device->os_dep.base);
  67256. + dev_dbg(&_dev->dev, "%s: mapped PA 0x%x to VA 0x%p\n", __func__,
  67257. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  67258. + dwc_otg_device->os_dep.base);
  67259. +
  67260. + pci_set_master(_dev);
  67261. + pci_set_drvdata(_dev, dwc_otg_device);
  67262. +#elif defined(PLATFORM_INTERFACE)
  67263. + DWC_DEBUGPL(DBG_ANY,"Platform resource: start=%08x, len=%08x\n",
  67264. + _dev->resource->start,
  67265. + _dev->resource->end - _dev->resource->start + 1);
  67266. +#if 1
  67267. + if (!request_mem_region(_dev->resource[0].start,
  67268. + _dev->resource[0].end - _dev->resource[0].start + 1,
  67269. + "dwc_otg")) {
  67270. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  67271. + retval = -EFAULT;
  67272. + goto fail;
  67273. + }
  67274. +
  67275. + dwc_otg_device->os_dep.base = ioremap_nocache(_dev->resource[0].start,
  67276. + _dev->resource[0].end -
  67277. + _dev->resource[0].start+1);
  67278. + if (fiq_fix_enable)
  67279. + {
  67280. + if (!request_mem_region(_dev->resource[1].start,
  67281. + _dev->resource[1].end - _dev->resource[1].start + 1,
  67282. + "dwc_otg")) {
  67283. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  67284. + retval = -EFAULT;
  67285. + goto fail;
  67286. + }
  67287. +
  67288. + dwc_otg_device->os_dep.mphi_base = ioremap_nocache(_dev->resource[1].start,
  67289. + _dev->resource[1].end -
  67290. + _dev->resource[1].start + 1);
  67291. + dummy_send = (void *) kmalloc(16, GFP_ATOMIC);
  67292. + }
  67293. +
  67294. +#else
  67295. + {
  67296. + struct map_desc desc = {
  67297. + .virtual = IO_ADDRESS((unsigned)_dev->resource->start),
  67298. + .pfn = __phys_to_pfn((unsigned)_dev->resource->start),
  67299. + .length = SZ_128K,
  67300. + .type = MT_DEVICE
  67301. + };
  67302. + iotable_init(&desc, 1);
  67303. + dwc_otg_device->os_dep.base = (void *)desc.virtual;
  67304. + }
  67305. +#endif
  67306. + if (!dwc_otg_device->os_dep.base) {
  67307. + dev_err(&_dev->dev, "ioremap() failed\n");
  67308. + retval = -ENOMEM;
  67309. + goto fail;
  67310. + }
  67311. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  67312. + (unsigned)dwc_otg_device->os_dep.base);
  67313. +#endif
  67314. +
  67315. + /*
  67316. + * Initialize driver data to point to the global DWC_otg
  67317. + * Device structure.
  67318. + */
  67319. +#ifdef LM_INTERFACE
  67320. + lm_set_drvdata(_dev, dwc_otg_device);
  67321. +#elif defined(PLATFORM_INTERFACE)
  67322. + platform_set_drvdata(_dev, dwc_otg_device);
  67323. +#endif
  67324. + dev_dbg(&_dev->dev, "dwc_otg_device=0x%p\n", dwc_otg_device);
  67325. +
  67326. + dwc_otg_device->core_if = dwc_otg_cil_init(dwc_otg_device->os_dep.base);
  67327. + DWC_DEBUGPL(DBG_HCDV, "probe of device %p given core_if %p\n",
  67328. + dwc_otg_device, dwc_otg_device->core_if);//GRAYG
  67329. +
  67330. + if (!dwc_otg_device->core_if) {
  67331. + dev_err(&_dev->dev, "CIL initialization failed!\n");
  67332. + retval = -ENOMEM;
  67333. + goto fail;
  67334. + }
  67335. +
  67336. + dev_dbg(&_dev->dev, "Calling get_gsnpsid\n");
  67337. + /*
  67338. + * Attempt to ensure this device is really a DWC_otg Controller.
  67339. + * Read and verify the SNPSID register contents. The value should be
  67340. + * 0x45F42XXX or 0x45F42XXX, which corresponds to either "OT2" or "OTG3",
  67341. + * as in "OTG version 2.XX" or "OTG version 3.XX".
  67342. + */
  67343. +
  67344. + if (((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F542000) &&
  67345. + ((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F543000)) {
  67346. + dev_err(&_dev->dev, "Bad value for SNPSID: 0x%08x\n",
  67347. + dwc_otg_get_gsnpsid(dwc_otg_device->core_if));
  67348. + retval = -EINVAL;
  67349. + goto fail;
  67350. + }
  67351. +
  67352. + /*
  67353. + * Validate parameter values.
  67354. + */
  67355. + dev_dbg(&_dev->dev, "Calling set_parameters\n");
  67356. + if (set_parameters(dwc_otg_device->core_if)) {
  67357. + retval = -EINVAL;
  67358. + goto fail;
  67359. + }
  67360. +
  67361. + /*
  67362. + * Create Device Attributes in sysfs
  67363. + */
  67364. + dev_dbg(&_dev->dev, "Calling attr_create\n");
  67365. + dwc_otg_attr_create(_dev);
  67366. +
  67367. + /*
  67368. + * Disable the global interrupt until all the interrupt
  67369. + * handlers are installed.
  67370. + */
  67371. + dev_dbg(&_dev->dev, "Calling disable_global_interrupts\n");
  67372. + dwc_otg_disable_global_interrupts(dwc_otg_device->core_if);
  67373. +
  67374. + /*
  67375. + * Install the interrupt handler for the common interrupts before
  67376. + * enabling common interrupts in core_init below.
  67377. + */
  67378. +
  67379. +#if defined(PLATFORM_INTERFACE)
  67380. + devirq = platform_get_irq(_dev, 0);
  67381. +#else
  67382. + devirq = _dev->irq;
  67383. +#endif
  67384. + DWC_DEBUGPL(DBG_CIL, "registering (common) handler for irq%d\n",
  67385. + devirq);
  67386. + dev_dbg(&_dev->dev, "Calling request_irq(%d)\n", devirq);
  67387. + retval = request_irq(devirq, dwc_otg_common_irq,
  67388. + IRQF_SHARED,
  67389. + "dwc_otg", dwc_otg_device);
  67390. + if (retval) {
  67391. + DWC_ERROR("request of irq%d failed\n", devirq);
  67392. + retval = -EBUSY;
  67393. + goto fail;
  67394. + } else {
  67395. + dwc_otg_device->common_irq_installed = 1;
  67396. + }
  67397. +
  67398. +#ifndef IRQF_TRIGGER_LOW
  67399. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  67400. + dev_dbg(&_dev->dev, "Calling set_irq_type\n");
  67401. + set_irq_type(devirq,
  67402. +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  67403. + IRQT_LOW
  67404. +#else
  67405. + IRQ_TYPE_LEVEL_LOW
  67406. +#endif
  67407. + );
  67408. +#endif
  67409. +#endif /*IRQF_TRIGGER_LOW*/
  67410. +
  67411. + /*
  67412. + * Initialize the DWC_otg core.
  67413. + */
  67414. + dev_dbg(&_dev->dev, "Calling dwc_otg_core_init\n");
  67415. + dwc_otg_core_init(dwc_otg_device->core_if);
  67416. +
  67417. +#ifndef DWC_HOST_ONLY
  67418. + /*
  67419. + * Initialize the PCD
  67420. + */
  67421. + dev_dbg(&_dev->dev, "Calling pcd_init\n");
  67422. + retval = pcd_init(_dev);
  67423. + if (retval != 0) {
  67424. + DWC_ERROR("pcd_init failed\n");
  67425. + dwc_otg_device->pcd = NULL;
  67426. + goto fail;
  67427. + }
  67428. +#endif
  67429. +#ifndef DWC_DEVICE_ONLY
  67430. + /*
  67431. + * Initialize the HCD
  67432. + */
  67433. + dev_dbg(&_dev->dev, "Calling hcd_init\n");
  67434. + retval = hcd_init(_dev);
  67435. + if (retval != 0) {
  67436. + DWC_ERROR("hcd_init failed\n");
  67437. + dwc_otg_device->hcd = NULL;
  67438. + goto fail;
  67439. + }
  67440. +#endif
  67441. + /* Recover from drvdata having been overwritten by hcd_init() */
  67442. +#ifdef LM_INTERFACE
  67443. + lm_set_drvdata(_dev, dwc_otg_device);
  67444. +#elif defined(PLATFORM_INTERFACE)
  67445. + platform_set_drvdata(_dev, dwc_otg_device);
  67446. +#elif defined(PCI_INTERFACE)
  67447. + pci_set_drvdata(_dev, dwc_otg_device);
  67448. + dwc_otg_device->os_dep.pcidev = _dev;
  67449. +#endif
  67450. +
  67451. + /*
  67452. + * Enable the global interrupt after all the interrupt
  67453. + * handlers are installed if there is no ADP support else
  67454. + * perform initial actions required for Internal ADP logic.
  67455. + */
  67456. + if (!dwc_otg_get_param_adp_enable(dwc_otg_device->core_if)) {
  67457. + dev_dbg(&_dev->dev, "Calling enable_global_interrupts\n");
  67458. + dwc_otg_enable_global_interrupts(dwc_otg_device->core_if);
  67459. + dev_dbg(&_dev->dev, "Done\n");
  67460. + } else
  67461. + dwc_otg_adp_start(dwc_otg_device->core_if,
  67462. + dwc_otg_is_host_mode(dwc_otg_device->core_if));
  67463. +
  67464. + return 0;
  67465. +
  67466. +fail:
  67467. + dwc_otg_driver_remove(_dev);
  67468. + return retval;
  67469. +}
  67470. +
  67471. +/**
  67472. + * This structure defines the methods to be called by a bus driver
  67473. + * during the lifecycle of a device on that bus. Both drivers and
  67474. + * devices are registered with a bus driver. The bus driver matches
  67475. + * devices to drivers based on information in the device and driver
  67476. + * structures.
  67477. + *
  67478. + * The probe function is called when the bus driver matches a device
  67479. + * to this driver. The remove function is called when a device is
  67480. + * unregistered with the bus driver.
  67481. + */
  67482. +#ifdef LM_INTERFACE
  67483. +static struct lm_driver dwc_otg_driver = {
  67484. + .drv = {.name = (char *)dwc_driver_name,},
  67485. + .probe = dwc_otg_driver_probe,
  67486. + .remove = dwc_otg_driver_remove,
  67487. + // 'suspend' and 'resume' absent
  67488. +};
  67489. +#elif defined(PCI_INTERFACE)
  67490. +static const struct pci_device_id pci_ids[] = { {
  67491. + PCI_DEVICE(0x16c3, 0xabcd),
  67492. + .driver_data =
  67493. + (unsigned long)0xdeadbeef,
  67494. + }, { /* end: all zeroes */ }
  67495. +};
  67496. +
  67497. +MODULE_DEVICE_TABLE(pci, pci_ids);
  67498. +
  67499. +/* pci driver glue; this is a "new style" PCI driver module */
  67500. +static struct pci_driver dwc_otg_driver = {
  67501. + .name = "dwc_otg",
  67502. + .id_table = pci_ids,
  67503. +
  67504. + .probe = dwc_otg_driver_probe,
  67505. + .remove = dwc_otg_driver_remove,
  67506. +
  67507. + .driver = {
  67508. + .name = (char *)dwc_driver_name,
  67509. + },
  67510. +};
  67511. +#elif defined(PLATFORM_INTERFACE)
  67512. +static struct platform_device_id platform_ids[] = {
  67513. + {
  67514. + .name = "bcm2708_usb",
  67515. + .driver_data = (kernel_ulong_t) 0xdeadbeef,
  67516. + },
  67517. + { /* end: all zeroes */ }
  67518. +};
  67519. +MODULE_DEVICE_TABLE(platform, platform_ids);
  67520. +
  67521. +static struct platform_driver dwc_otg_driver = {
  67522. + .driver = {
  67523. + .name = (char *)dwc_driver_name,
  67524. + },
  67525. + .id_table = platform_ids,
  67526. +
  67527. + .probe = dwc_otg_driver_probe,
  67528. + .remove = dwc_otg_driver_remove,
  67529. + // no 'shutdown', 'suspend', 'resume', 'suspend_late' or 'resume_early'
  67530. +};
  67531. +#endif
  67532. +
  67533. +/**
  67534. + * This function is called when the dwc_otg_driver is installed with the
  67535. + * insmod command. It registers the dwc_otg_driver structure with the
  67536. + * appropriate bus driver. This will cause the dwc_otg_driver_probe function
  67537. + * to be called. In addition, the bus driver will automatically expose
  67538. + * attributes defined for the device and driver in the special sysfs file
  67539. + * system.
  67540. + *
  67541. + * @return
  67542. + */
  67543. +static int __init dwc_otg_driver_init(void)
  67544. +{
  67545. + int retval = 0;
  67546. + int error;
  67547. + struct device_driver *drv;
  67548. +
  67549. + if(fiq_split_enable && !fiq_fix_enable) {
  67550. + printk(KERN_WARNING "dwc_otg: fiq_split_enable was set without fiq_fix_enable! Correcting.\n");
  67551. + fiq_fix_enable = 1;
  67552. + }
  67553. +
  67554. + printk(KERN_INFO "%s: version %s (%s bus)\n", dwc_driver_name,
  67555. + DWC_DRIVER_VERSION,
  67556. +#ifdef LM_INTERFACE
  67557. + "logicmodule");
  67558. + retval = lm_driver_register(&dwc_otg_driver);
  67559. + drv = &dwc_otg_driver.drv;
  67560. +#elif defined(PCI_INTERFACE)
  67561. + "pci");
  67562. + retval = pci_register_driver(&dwc_otg_driver);
  67563. + drv = &dwc_otg_driver.driver;
  67564. +#elif defined(PLATFORM_INTERFACE)
  67565. + "platform");
  67566. + retval = platform_driver_register(&dwc_otg_driver);
  67567. + drv = &dwc_otg_driver.driver;
  67568. +#endif
  67569. + if (retval < 0) {
  67570. + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
  67571. + return retval;
  67572. + }
  67573. + printk(KERN_DEBUG "dwc_otg: FIQ %s\n", fiq_fix_enable ? "enabled":"disabled");
  67574. + printk(KERN_DEBUG "dwc_otg: NAK holdoff %s\n", nak_holdoff_enable ? "enabled":"disabled");
  67575. + printk(KERN_DEBUG "dwc_otg: FIQ split fix %s\n", fiq_split_enable ? "enabled":"disabled");
  67576. +
  67577. + error = driver_create_file(drv, &driver_attr_version);
  67578. +#ifdef DEBUG
  67579. + error = driver_create_file(drv, &driver_attr_debuglevel);
  67580. +#endif
  67581. + return retval;
  67582. +}
  67583. +
  67584. +module_init(dwc_otg_driver_init);
  67585. +
  67586. +/**
  67587. + * This function is called when the driver is removed from the kernel
  67588. + * with the rmmod command. The driver unregisters itself with its bus
  67589. + * driver.
  67590. + *
  67591. + */
  67592. +static void __exit dwc_otg_driver_cleanup(void)
  67593. +{
  67594. + printk(KERN_DEBUG "dwc_otg_driver_cleanup()\n");
  67595. +
  67596. +#ifdef LM_INTERFACE
  67597. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_debuglevel);
  67598. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_version);
  67599. + lm_driver_unregister(&dwc_otg_driver);
  67600. +#elif defined(PCI_INTERFACE)
  67601. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  67602. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  67603. + pci_unregister_driver(&dwc_otg_driver);
  67604. +#elif defined(PLATFORM_INTERFACE)
  67605. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  67606. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  67607. + platform_driver_unregister(&dwc_otg_driver);
  67608. +#endif
  67609. +
  67610. + printk(KERN_INFO "%s module removed\n", dwc_driver_name);
  67611. +}
  67612. +
  67613. +module_exit(dwc_otg_driver_cleanup);
  67614. +
  67615. +MODULE_DESCRIPTION(DWC_DRIVER_DESC);
  67616. +MODULE_AUTHOR("Synopsys Inc.");
  67617. +MODULE_LICENSE("GPL");
  67618. +
  67619. +module_param_named(otg_cap, dwc_otg_module_params.otg_cap, int, 0444);
  67620. +MODULE_PARM_DESC(otg_cap, "OTG Capabilities 0=HNP&SRP 1=SRP Only 2=None");
  67621. +module_param_named(opt, dwc_otg_module_params.opt, int, 0444);
  67622. +MODULE_PARM_DESC(opt, "OPT Mode");
  67623. +module_param_named(dma_enable, dwc_otg_module_params.dma_enable, int, 0444);
  67624. +MODULE_PARM_DESC(dma_enable, "DMA Mode 0=Slave 1=DMA enabled");
  67625. +
  67626. +module_param_named(dma_desc_enable, dwc_otg_module_params.dma_desc_enable, int,
  67627. + 0444);
  67628. +MODULE_PARM_DESC(dma_desc_enable,
  67629. + "DMA Desc Mode 0=Address DMA 1=DMA Descriptor enabled");
  67630. +
  67631. +module_param_named(dma_burst_size, dwc_otg_module_params.dma_burst_size, int,
  67632. + 0444);
  67633. +MODULE_PARM_DESC(dma_burst_size,
  67634. + "DMA Burst Size 1, 4, 8, 16, 32, 64, 128, 256");
  67635. +module_param_named(speed, dwc_otg_module_params.speed, int, 0444);
  67636. +MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");
  67637. +module_param_named(host_support_fs_ls_low_power,
  67638. + dwc_otg_module_params.host_support_fs_ls_low_power, int,
  67639. + 0444);
  67640. +MODULE_PARM_DESC(host_support_fs_ls_low_power,
  67641. + "Support Low Power w/FS or LS 0=Support 1=Don't Support");
  67642. +module_param_named(host_ls_low_power_phy_clk,
  67643. + dwc_otg_module_params.host_ls_low_power_phy_clk, int, 0444);
  67644. +MODULE_PARM_DESC(host_ls_low_power_phy_clk,
  67645. + "Low Speed Low Power Clock 0=48Mhz 1=6Mhz");
  67646. +module_param_named(enable_dynamic_fifo,
  67647. + dwc_otg_module_params.enable_dynamic_fifo, int, 0444);
  67648. +MODULE_PARM_DESC(enable_dynamic_fifo, "0=cC Setting 1=Allow Dynamic Sizing");
  67649. +module_param_named(data_fifo_size, dwc_otg_module_params.data_fifo_size, int,
  67650. + 0444);
  67651. +MODULE_PARM_DESC(data_fifo_size,
  67652. + "Total number of words in the data FIFO memory 32-32768");
  67653. +module_param_named(dev_rx_fifo_size, dwc_otg_module_params.dev_rx_fifo_size,
  67654. + int, 0444);
  67655. +MODULE_PARM_DESC(dev_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  67656. +module_param_named(dev_nperio_tx_fifo_size,
  67657. + dwc_otg_module_params.dev_nperio_tx_fifo_size, int, 0444);
  67658. +MODULE_PARM_DESC(dev_nperio_tx_fifo_size,
  67659. + "Number of words in the non-periodic Tx FIFO 16-32768");
  67660. +module_param_named(dev_perio_tx_fifo_size_1,
  67661. + dwc_otg_module_params.dev_perio_tx_fifo_size[0], int, 0444);
  67662. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_1,
  67663. + "Number of words in the periodic Tx FIFO 4-768");
  67664. +module_param_named(dev_perio_tx_fifo_size_2,
  67665. + dwc_otg_module_params.dev_perio_tx_fifo_size[1], int, 0444);
  67666. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_2,
  67667. + "Number of words in the periodic Tx FIFO 4-768");
  67668. +module_param_named(dev_perio_tx_fifo_size_3,
  67669. + dwc_otg_module_params.dev_perio_tx_fifo_size[2], int, 0444);
  67670. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_3,
  67671. + "Number of words in the periodic Tx FIFO 4-768");
  67672. +module_param_named(dev_perio_tx_fifo_size_4,
  67673. + dwc_otg_module_params.dev_perio_tx_fifo_size[3], int, 0444);
  67674. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_4,
  67675. + "Number of words in the periodic Tx FIFO 4-768");
  67676. +module_param_named(dev_perio_tx_fifo_size_5,
  67677. + dwc_otg_module_params.dev_perio_tx_fifo_size[4], int, 0444);
  67678. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_5,
  67679. + "Number of words in the periodic Tx FIFO 4-768");
  67680. +module_param_named(dev_perio_tx_fifo_size_6,
  67681. + dwc_otg_module_params.dev_perio_tx_fifo_size[5], int, 0444);
  67682. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_6,
  67683. + "Number of words in the periodic Tx FIFO 4-768");
  67684. +module_param_named(dev_perio_tx_fifo_size_7,
  67685. + dwc_otg_module_params.dev_perio_tx_fifo_size[6], int, 0444);
  67686. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_7,
  67687. + "Number of words in the periodic Tx FIFO 4-768");
  67688. +module_param_named(dev_perio_tx_fifo_size_8,
  67689. + dwc_otg_module_params.dev_perio_tx_fifo_size[7], int, 0444);
  67690. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_8,
  67691. + "Number of words in the periodic Tx FIFO 4-768");
  67692. +module_param_named(dev_perio_tx_fifo_size_9,
  67693. + dwc_otg_module_params.dev_perio_tx_fifo_size[8], int, 0444);
  67694. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_9,
  67695. + "Number of words in the periodic Tx FIFO 4-768");
  67696. +module_param_named(dev_perio_tx_fifo_size_10,
  67697. + dwc_otg_module_params.dev_perio_tx_fifo_size[9], int, 0444);
  67698. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_10,
  67699. + "Number of words in the periodic Tx FIFO 4-768");
  67700. +module_param_named(dev_perio_tx_fifo_size_11,
  67701. + dwc_otg_module_params.dev_perio_tx_fifo_size[10], int, 0444);
  67702. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_11,
  67703. + "Number of words in the periodic Tx FIFO 4-768");
  67704. +module_param_named(dev_perio_tx_fifo_size_12,
  67705. + dwc_otg_module_params.dev_perio_tx_fifo_size[11], int, 0444);
  67706. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_12,
  67707. + "Number of words in the periodic Tx FIFO 4-768");
  67708. +module_param_named(dev_perio_tx_fifo_size_13,
  67709. + dwc_otg_module_params.dev_perio_tx_fifo_size[12], int, 0444);
  67710. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_13,
  67711. + "Number of words in the periodic Tx FIFO 4-768");
  67712. +module_param_named(dev_perio_tx_fifo_size_14,
  67713. + dwc_otg_module_params.dev_perio_tx_fifo_size[13], int, 0444);
  67714. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_14,
  67715. + "Number of words in the periodic Tx FIFO 4-768");
  67716. +module_param_named(dev_perio_tx_fifo_size_15,
  67717. + dwc_otg_module_params.dev_perio_tx_fifo_size[14], int, 0444);
  67718. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_15,
  67719. + "Number of words in the periodic Tx FIFO 4-768");
  67720. +module_param_named(host_rx_fifo_size, dwc_otg_module_params.host_rx_fifo_size,
  67721. + int, 0444);
  67722. +MODULE_PARM_DESC(host_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  67723. +module_param_named(host_nperio_tx_fifo_size,
  67724. + dwc_otg_module_params.host_nperio_tx_fifo_size, int, 0444);
  67725. +MODULE_PARM_DESC(host_nperio_tx_fifo_size,
  67726. + "Number of words in the non-periodic Tx FIFO 16-32768");
  67727. +module_param_named(host_perio_tx_fifo_size,
  67728. + dwc_otg_module_params.host_perio_tx_fifo_size, int, 0444);
  67729. +MODULE_PARM_DESC(host_perio_tx_fifo_size,
  67730. + "Number of words in the host periodic Tx FIFO 16-32768");
  67731. +module_param_named(max_transfer_size, dwc_otg_module_params.max_transfer_size,
  67732. + int, 0444);
  67733. +/** @todo Set the max to 512K, modify checks */
  67734. +MODULE_PARM_DESC(max_transfer_size,
  67735. + "The maximum transfer size supported in bytes 2047-65535");
  67736. +module_param_named(max_packet_count, dwc_otg_module_params.max_packet_count,
  67737. + int, 0444);
  67738. +MODULE_PARM_DESC(max_packet_count,
  67739. + "The maximum number of packets in a transfer 15-511");
  67740. +module_param_named(host_channels, dwc_otg_module_params.host_channels, int,
  67741. + 0444);
  67742. +MODULE_PARM_DESC(host_channels,
  67743. + "The number of host channel registers to use 1-16");
  67744. +module_param_named(dev_endpoints, dwc_otg_module_params.dev_endpoints, int,
  67745. + 0444);
  67746. +MODULE_PARM_DESC(dev_endpoints,
  67747. + "The number of endpoints in addition to EP0 available for device mode 1-15");
  67748. +module_param_named(phy_type, dwc_otg_module_params.phy_type, int, 0444);
  67749. +MODULE_PARM_DESC(phy_type, "0=Reserved 1=UTMI+ 2=ULPI");
  67750. +module_param_named(phy_utmi_width, dwc_otg_module_params.phy_utmi_width, int,
  67751. + 0444);
  67752. +MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");
  67753. +module_param_named(phy_ulpi_ddr, dwc_otg_module_params.phy_ulpi_ddr, int, 0444);
  67754. +MODULE_PARM_DESC(phy_ulpi_ddr,
  67755. + "ULPI at double or single data rate 0=Single 1=Double");
  67756. +module_param_named(phy_ulpi_ext_vbus, dwc_otg_module_params.phy_ulpi_ext_vbus,
  67757. + int, 0444);
  67758. +MODULE_PARM_DESC(phy_ulpi_ext_vbus,
  67759. + "ULPI PHY using internal or external vbus 0=Internal");
  67760. +module_param_named(i2c_enable, dwc_otg_module_params.i2c_enable, int, 0444);
  67761. +MODULE_PARM_DESC(i2c_enable, "FS PHY Interface");
  67762. +module_param_named(ulpi_fs_ls, dwc_otg_module_params.ulpi_fs_ls, int, 0444);
  67763. +MODULE_PARM_DESC(ulpi_fs_ls, "ULPI PHY FS/LS mode only");
  67764. +module_param_named(ts_dline, dwc_otg_module_params.ts_dline, int, 0444);
  67765. +MODULE_PARM_DESC(ts_dline, "Term select Dline pulsing for all PHYs");
  67766. +module_param_named(debug, g_dbg_lvl, int, 0444);
  67767. +MODULE_PARM_DESC(debug, "");
  67768. +
  67769. +module_param_named(en_multiple_tx_fifo,
  67770. + dwc_otg_module_params.en_multiple_tx_fifo, int, 0444);
  67771. +MODULE_PARM_DESC(en_multiple_tx_fifo,
  67772. + "Dedicated Non Periodic Tx FIFOs 0=disabled 1=enabled");
  67773. +module_param_named(dev_tx_fifo_size_1,
  67774. + dwc_otg_module_params.dev_tx_fifo_size[0], int, 0444);
  67775. +MODULE_PARM_DESC(dev_tx_fifo_size_1, "Number of words in the Tx FIFO 4-768");
  67776. +module_param_named(dev_tx_fifo_size_2,
  67777. + dwc_otg_module_params.dev_tx_fifo_size[1], int, 0444);
  67778. +MODULE_PARM_DESC(dev_tx_fifo_size_2, "Number of words in the Tx FIFO 4-768");
  67779. +module_param_named(dev_tx_fifo_size_3,
  67780. + dwc_otg_module_params.dev_tx_fifo_size[2], int, 0444);
  67781. +MODULE_PARM_DESC(dev_tx_fifo_size_3, "Number of words in the Tx FIFO 4-768");
  67782. +module_param_named(dev_tx_fifo_size_4,
  67783. + dwc_otg_module_params.dev_tx_fifo_size[3], int, 0444);
  67784. +MODULE_PARM_DESC(dev_tx_fifo_size_4, "Number of words in the Tx FIFO 4-768");
  67785. +module_param_named(dev_tx_fifo_size_5,
  67786. + dwc_otg_module_params.dev_tx_fifo_size[4], int, 0444);
  67787. +MODULE_PARM_DESC(dev_tx_fifo_size_5, "Number of words in the Tx FIFO 4-768");
  67788. +module_param_named(dev_tx_fifo_size_6,
  67789. + dwc_otg_module_params.dev_tx_fifo_size[5], int, 0444);
  67790. +MODULE_PARM_DESC(dev_tx_fifo_size_6, "Number of words in the Tx FIFO 4-768");
  67791. +module_param_named(dev_tx_fifo_size_7,
  67792. + dwc_otg_module_params.dev_tx_fifo_size[6], int, 0444);
  67793. +MODULE_PARM_DESC(dev_tx_fifo_size_7, "Number of words in the Tx FIFO 4-768");
  67794. +module_param_named(dev_tx_fifo_size_8,
  67795. + dwc_otg_module_params.dev_tx_fifo_size[7], int, 0444);
  67796. +MODULE_PARM_DESC(dev_tx_fifo_size_8, "Number of words in the Tx FIFO 4-768");
  67797. +module_param_named(dev_tx_fifo_size_9,
  67798. + dwc_otg_module_params.dev_tx_fifo_size[8], int, 0444);
  67799. +MODULE_PARM_DESC(dev_tx_fifo_size_9, "Number of words in the Tx FIFO 4-768");
  67800. +module_param_named(dev_tx_fifo_size_10,
  67801. + dwc_otg_module_params.dev_tx_fifo_size[9], int, 0444);
  67802. +MODULE_PARM_DESC(dev_tx_fifo_size_10, "Number of words in the Tx FIFO 4-768");
  67803. +module_param_named(dev_tx_fifo_size_11,
  67804. + dwc_otg_module_params.dev_tx_fifo_size[10], int, 0444);
  67805. +MODULE_PARM_DESC(dev_tx_fifo_size_11, "Number of words in the Tx FIFO 4-768");
  67806. +module_param_named(dev_tx_fifo_size_12,
  67807. + dwc_otg_module_params.dev_tx_fifo_size[11], int, 0444);
  67808. +MODULE_PARM_DESC(dev_tx_fifo_size_12, "Number of words in the Tx FIFO 4-768");
  67809. +module_param_named(dev_tx_fifo_size_13,
  67810. + dwc_otg_module_params.dev_tx_fifo_size[12], int, 0444);
  67811. +MODULE_PARM_DESC(dev_tx_fifo_size_13, "Number of words in the Tx FIFO 4-768");
  67812. +module_param_named(dev_tx_fifo_size_14,
  67813. + dwc_otg_module_params.dev_tx_fifo_size[13], int, 0444);
  67814. +MODULE_PARM_DESC(dev_tx_fifo_size_14, "Number of words in the Tx FIFO 4-768");
  67815. +module_param_named(dev_tx_fifo_size_15,
  67816. + dwc_otg_module_params.dev_tx_fifo_size[14], int, 0444);
  67817. +MODULE_PARM_DESC(dev_tx_fifo_size_15, "Number of words in the Tx FIFO 4-768");
  67818. +
  67819. +module_param_named(thr_ctl, dwc_otg_module_params.thr_ctl, int, 0444);
  67820. +MODULE_PARM_DESC(thr_ctl,
  67821. + "Thresholding enable flag bit 0 - non ISO Tx thr., 1 - ISO Tx thr., 2 - Rx thr.- bit 0=disabled 1=enabled");
  67822. +module_param_named(tx_thr_length, dwc_otg_module_params.tx_thr_length, int,
  67823. + 0444);
  67824. +MODULE_PARM_DESC(tx_thr_length, "Tx Threshold length in 32 bit DWORDs");
  67825. +module_param_named(rx_thr_length, dwc_otg_module_params.rx_thr_length, int,
  67826. + 0444);
  67827. +MODULE_PARM_DESC(rx_thr_length, "Rx Threshold length in 32 bit DWORDs");
  67828. +
  67829. +module_param_named(pti_enable, dwc_otg_module_params.pti_enable, int, 0444);
  67830. +module_param_named(mpi_enable, dwc_otg_module_params.mpi_enable, int, 0444);
  67831. +module_param_named(lpm_enable, dwc_otg_module_params.lpm_enable, int, 0444);
  67832. +MODULE_PARM_DESC(lpm_enable, "LPM Enable 0=LPM Disabled 1=LPM Enabled");
  67833. +module_param_named(ic_usb_cap, dwc_otg_module_params.ic_usb_cap, int, 0444);
  67834. +MODULE_PARM_DESC(ic_usb_cap,
  67835. + "IC_USB Capability 0=IC_USB Disabled 1=IC_USB Enabled");
  67836. +module_param_named(ahb_thr_ratio, dwc_otg_module_params.ahb_thr_ratio, int,
  67837. + 0444);
  67838. +MODULE_PARM_DESC(ahb_thr_ratio, "AHB Threshold Ratio");
  67839. +module_param_named(power_down, dwc_otg_module_params.power_down, int, 0444);
  67840. +MODULE_PARM_DESC(power_down, "Power Down Mode");
  67841. +module_param_named(reload_ctl, dwc_otg_module_params.reload_ctl, int, 0444);
  67842. +MODULE_PARM_DESC(reload_ctl, "HFIR Reload Control");
  67843. +module_param_named(dev_out_nak, dwc_otg_module_params.dev_out_nak, int, 0444);
  67844. +MODULE_PARM_DESC(dev_out_nak, "Enable Device OUT NAK");
  67845. +module_param_named(cont_on_bna, dwc_otg_module_params.cont_on_bna, int, 0444);
  67846. +MODULE_PARM_DESC(cont_on_bna, "Enable Enable Continue on BNA");
  67847. +module_param_named(ahb_single, dwc_otg_module_params.ahb_single, int, 0444);
  67848. +MODULE_PARM_DESC(ahb_single, "Enable AHB Single Support");
  67849. +module_param_named(adp_enable, dwc_otg_module_params.adp_enable, int, 0444);
  67850. +MODULE_PARM_DESC(adp_enable, "ADP Enable 0=ADP Disabled 1=ADP Enabled");
  67851. +module_param_named(otg_ver, dwc_otg_module_params.otg_ver, int, 0444);
  67852. +MODULE_PARM_DESC(otg_ver, "OTG revision supported 0=OTG 1.3 1=OTG 2.0");
  67853. +module_param(microframe_schedule, bool, 0444);
  67854. +MODULE_PARM_DESC(microframe_schedule, "Enable the microframe scheduler");
  67855. +
  67856. +module_param(fiq_fix_enable, bool, 0444);
  67857. +MODULE_PARM_DESC(fiq_fix_enable, "Enable the fiq fix");
  67858. +module_param(nak_holdoff_enable, bool, 0444);
  67859. +MODULE_PARM_DESC(nak_holdoff_enable, "Enable the NAK holdoff");
  67860. +module_param(fiq_split_enable, bool, 0444);
  67861. +MODULE_PARM_DESC(fiq_split_enable, "Enable the FIQ fix on split transactions");
  67862. +
  67863. +/** @page "Module Parameters"
  67864. + *
  67865. + * The following parameters may be specified when starting the module.
  67866. + * These parameters define how the DWC_otg controller should be
  67867. + * configured. Parameter values are passed to the CIL initialization
  67868. + * function dwc_otg_cil_init
  67869. + *
  67870. + * Example: <code>modprobe dwc_otg speed=1 otg_cap=1</code>
  67871. + *
  67872. +
  67873. + <table>
  67874. + <tr><td>Parameter Name</td><td>Meaning</td></tr>
  67875. +
  67876. + <tr>
  67877. + <td>otg_cap</td>
  67878. + <td>Specifies the OTG capabilities. The driver will automatically detect the
  67879. + value for this parameter if none is specified.
  67880. + - 0: HNP and SRP capable (default, if available)
  67881. + - 1: SRP Only capable
  67882. + - 2: No HNP/SRP capable
  67883. + </td></tr>
  67884. +
  67885. + <tr>
  67886. + <td>dma_enable</td>
  67887. + <td>Specifies whether to use slave or DMA mode for accessing the data FIFOs.
  67888. + The driver will automatically detect the value for this parameter if none is
  67889. + specified.
  67890. + - 0: Slave
  67891. + - 1: DMA (default, if available)
  67892. + </td></tr>
  67893. +
  67894. + <tr>
  67895. + <td>dma_burst_size</td>
  67896. + <td>The DMA Burst size (applicable only for External DMA Mode).
  67897. + - Values: 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  67898. + </td></tr>
  67899. +
  67900. + <tr>
  67901. + <td>speed</td>
  67902. + <td>Specifies the maximum speed of operation in host and device mode. The
  67903. + actual speed depends on the speed of the attached device and the value of
  67904. + phy_type.
  67905. + - 0: High Speed (default)
  67906. + - 1: Full Speed
  67907. + </td></tr>
  67908. +
  67909. + <tr>
  67910. + <td>host_support_fs_ls_low_power</td>
  67911. + <td>Specifies whether low power mode is supported when attached to a Full
  67912. + Speed or Low Speed device in host mode.
  67913. + - 0: Don't support low power mode (default)
  67914. + - 1: Support low power mode
  67915. + </td></tr>
  67916. +
  67917. + <tr>
  67918. + <td>host_ls_low_power_phy_clk</td>
  67919. + <td>Specifies the PHY clock rate in low power mode when connected to a Low
  67920. + Speed device in host mode. This parameter is applicable only if
  67921. + HOST_SUPPORT_FS_LS_LOW_POWER is enabled.
  67922. + - 0: 48 MHz (default)
  67923. + - 1: 6 MHz
  67924. + </td></tr>
  67925. +
  67926. + <tr>
  67927. + <td>enable_dynamic_fifo</td>
  67928. + <td> Specifies whether FIFOs may be resized by the driver software.
  67929. + - 0: Use cC FIFO size parameters
  67930. + - 1: Allow dynamic FIFO sizing (default)
  67931. + </td></tr>
  67932. +
  67933. + <tr>
  67934. + <td>data_fifo_size</td>
  67935. + <td>Total number of 4-byte words in the data FIFO memory. This memory
  67936. + includes the Rx FIFO, non-periodic Tx FIFO, and periodic Tx FIFOs.
  67937. + - Values: 32 to 32768 (default 8192)
  67938. +
  67939. + Note: The total FIFO memory depth in the FPGA configuration is 8192.
  67940. + </td></tr>
  67941. +
  67942. + <tr>
  67943. + <td>dev_rx_fifo_size</td>
  67944. + <td>Number of 4-byte words in the Rx FIFO in device mode when dynamic
  67945. + FIFO sizing is enabled.
  67946. + - Values: 16 to 32768 (default 1064)
  67947. + </td></tr>
  67948. +
  67949. + <tr>
  67950. + <td>dev_nperio_tx_fifo_size</td>
  67951. + <td>Number of 4-byte words in the non-periodic Tx FIFO in device mode when
  67952. + dynamic FIFO sizing is enabled.
  67953. + - Values: 16 to 32768 (default 1024)
  67954. + </td></tr>
  67955. +
  67956. + <tr>
  67957. + <td>dev_perio_tx_fifo_size_n (n = 1 to 15)</td>
  67958. + <td>Number of 4-byte words in each of the periodic Tx FIFOs in device mode
  67959. + when dynamic FIFO sizing is enabled.
  67960. + - Values: 4 to 768 (default 256)
  67961. + </td></tr>
  67962. +
  67963. + <tr>
  67964. + <td>host_rx_fifo_size</td>
  67965. + <td>Number of 4-byte words in the Rx FIFO in host mode when dynamic FIFO
  67966. + sizing is enabled.
  67967. + - Values: 16 to 32768 (default 1024)
  67968. + </td></tr>
  67969. +
  67970. + <tr>
  67971. + <td>host_nperio_tx_fifo_size</td>
  67972. + <td>Number of 4-byte words in the non-periodic Tx FIFO in host mode when
  67973. + dynamic FIFO sizing is enabled in the core.
  67974. + - Values: 16 to 32768 (default 1024)
  67975. + </td></tr>
  67976. +
  67977. + <tr>
  67978. + <td>host_perio_tx_fifo_size</td>
  67979. + <td>Number of 4-byte words in the host periodic Tx FIFO when dynamic FIFO
  67980. + sizing is enabled.
  67981. + - Values: 16 to 32768 (default 1024)
  67982. + </td></tr>
  67983. +
  67984. + <tr>
  67985. + <td>max_transfer_size</td>
  67986. + <td>The maximum transfer size supported in bytes.
  67987. + - Values: 2047 to 65,535 (default 65,535)
  67988. + </td></tr>
  67989. +
  67990. + <tr>
  67991. + <td>max_packet_count</td>
  67992. + <td>The maximum number of packets in a transfer.
  67993. + - Values: 15 to 511 (default 511)
  67994. + </td></tr>
  67995. +
  67996. + <tr>
  67997. + <td>host_channels</td>
  67998. + <td>The number of host channel registers to use.
  67999. + - Values: 1 to 16 (default 12)
  68000. +
  68001. + Note: The FPGA configuration supports a maximum of 12 host channels.
  68002. + </td></tr>
  68003. +
  68004. + <tr>
  68005. + <td>dev_endpoints</td>
  68006. + <td>The number of endpoints in addition to EP0 available for device mode
  68007. + operations.
  68008. + - Values: 1 to 15 (default 6 IN and OUT)
  68009. +
  68010. + Note: The FPGA configuration supports a maximum of 6 IN and OUT endpoints in
  68011. + addition to EP0.
  68012. + </td></tr>
  68013. +
  68014. + <tr>
  68015. + <td>phy_type</td>
  68016. + <td>Specifies the type of PHY interface to use. By default, the driver will
  68017. + automatically detect the phy_type.
  68018. + - 0: Full Speed
  68019. + - 1: UTMI+ (default, if available)
  68020. + - 2: ULPI
  68021. + </td></tr>
  68022. +
  68023. + <tr>
  68024. + <td>phy_utmi_width</td>
  68025. + <td>Specifies the UTMI+ Data Width. This parameter is applicable for a
  68026. + phy_type of UTMI+. Also, this parameter is applicable only if the
  68027. + OTG_HSPHY_WIDTH cC parameter was set to "8 and 16 bits", meaning that the
  68028. + core has been configured to work at either data path width.
  68029. + - Values: 8 or 16 bits (default 16)
  68030. + </td></tr>
  68031. +
  68032. + <tr>
  68033. + <td>phy_ulpi_ddr</td>
  68034. + <td>Specifies whether the ULPI operates at double or single data rate. This
  68035. + parameter is only applicable if phy_type is ULPI.
  68036. + - 0: single data rate ULPI interface with 8 bit wide data bus (default)
  68037. + - 1: double data rate ULPI interface with 4 bit wide data bus
  68038. + </td></tr>
  68039. +
  68040. + <tr>
  68041. + <td>i2c_enable</td>
  68042. + <td>Specifies whether to use the I2C interface for full speed PHY. This
  68043. + parameter is only applicable if PHY_TYPE is FS.
  68044. + - 0: Disabled (default)
  68045. + - 1: Enabled
  68046. + </td></tr>
  68047. +
  68048. + <tr>
  68049. + <td>ulpi_fs_ls</td>
  68050. + <td>Specifies whether to use ULPI FS/LS mode only.
  68051. + - 0: Disabled (default)
  68052. + - 1: Enabled
  68053. + </td></tr>
  68054. +
  68055. + <tr>
  68056. + <td>ts_dline</td>
  68057. + <td>Specifies whether term select D-Line pulsing for all PHYs is enabled.
  68058. + - 0: Disabled (default)
  68059. + - 1: Enabled
  68060. + </td></tr>
  68061. +
  68062. + <tr>
  68063. + <td>en_multiple_tx_fifo</td>
  68064. + <td>Specifies whether dedicatedto tx fifos are enabled for non periodic IN EPs.
  68065. + The driver will automatically detect the value for this parameter if none is
  68066. + specified.
  68067. + - 0: Disabled
  68068. + - 1: Enabled (default, if available)
  68069. + </td></tr>
  68070. +
  68071. + <tr>
  68072. + <td>dev_tx_fifo_size_n (n = 1 to 15)</td>
  68073. + <td>Number of 4-byte words in each of the Tx FIFOs in device mode
  68074. + when dynamic FIFO sizing is enabled.
  68075. + - Values: 4 to 768 (default 256)
  68076. + </td></tr>
  68077. +
  68078. + <tr>
  68079. + <td>tx_thr_length</td>
  68080. + <td>Transmit Threshold length in 32 bit double words
  68081. + - Values: 8 to 128 (default 64)
  68082. + </td></tr>
  68083. +
  68084. + <tr>
  68085. + <td>rx_thr_length</td>
  68086. + <td>Receive Threshold length in 32 bit double words
  68087. + - Values: 8 to 128 (default 64)
  68088. + </td></tr>
  68089. +
  68090. +<tr>
  68091. + <td>thr_ctl</td>
  68092. + <td>Specifies whether to enable Thresholding for Device mode. Bits 0, 1, 2 of
  68093. + this parmater specifies if thresholding is enabled for non-Iso Tx, Iso Tx and
  68094. + Rx transfers accordingly.
  68095. + The driver will automatically detect the value for this parameter if none is
  68096. + specified.
  68097. + - Values: 0 to 7 (default 0)
  68098. + Bit values indicate:
  68099. + - 0: Thresholding disabled
  68100. + - 1: Thresholding enabled
  68101. + </td></tr>
  68102. +
  68103. +<tr>
  68104. + <td>dma_desc_enable</td>
  68105. + <td>Specifies whether to enable Descriptor DMA mode.
  68106. + The driver will automatically detect the value for this parameter if none is
  68107. + specified.
  68108. + - 0: Descriptor DMA disabled
  68109. + - 1: Descriptor DMA (default, if available)
  68110. + </td></tr>
  68111. +
  68112. +<tr>
  68113. + <td>mpi_enable</td>
  68114. + <td>Specifies whether to enable MPI enhancement mode.
  68115. + The driver will automatically detect the value for this parameter if none is
  68116. + specified.
  68117. + - 0: MPI disabled (default)
  68118. + - 1: MPI enable
  68119. + </td></tr>
  68120. +
  68121. +<tr>
  68122. + <td>pti_enable</td>
  68123. + <td>Specifies whether to enable PTI enhancement support.
  68124. + The driver will automatically detect the value for this parameter if none is
  68125. + specified.
  68126. + - 0: PTI disabled (default)
  68127. + - 1: PTI enable
  68128. + </td></tr>
  68129. +
  68130. +<tr>
  68131. + <td>lpm_enable</td>
  68132. + <td>Specifies whether to enable LPM support.
  68133. + The driver will automatically detect the value for this parameter if none is
  68134. + specified.
  68135. + - 0: LPM disabled
  68136. + - 1: LPM enable (default, if available)
  68137. + </td></tr>
  68138. +
  68139. +<tr>
  68140. + <td>ic_usb_cap</td>
  68141. + <td>Specifies whether to enable IC_USB capability.
  68142. + The driver will automatically detect the value for this parameter if none is
  68143. + specified.
  68144. + - 0: IC_USB disabled (default, if available)
  68145. + - 1: IC_USB enable
  68146. + </td></tr>
  68147. +
  68148. +<tr>
  68149. + <td>ahb_thr_ratio</td>
  68150. + <td>Specifies AHB Threshold ratio.
  68151. + - Values: 0 to 3 (default 0)
  68152. + </td></tr>
  68153. +
  68154. +<tr>
  68155. + <td>power_down</td>
  68156. + <td>Specifies Power Down(Hibernation) Mode.
  68157. + The driver will automatically detect the value for this parameter if none is
  68158. + specified.
  68159. + - 0: Power Down disabled (default)
  68160. + - 2: Power Down enabled
  68161. + </td></tr>
  68162. +
  68163. + <tr>
  68164. + <td>reload_ctl</td>
  68165. + <td>Specifies whether dynamic reloading of the HFIR register is allowed during
  68166. + run time. The driver will automatically detect the value for this parameter if
  68167. + none is specified. In case the HFIR value is reloaded when HFIR.RldCtrl == 1'b0
  68168. + the core might misbehave.
  68169. + - 0: Reload Control disabled (default)
  68170. + - 1: Reload Control enabled
  68171. + </td></tr>
  68172. +
  68173. + <tr>
  68174. + <td>dev_out_nak</td>
  68175. + <td>Specifies whether Device OUT NAK enhancement enabled or no.
  68176. + The driver will automatically detect the value for this parameter if
  68177. + none is specified. This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  68178. + - 0: The core does not set NAK after Bulk OUT transfer complete (default)
  68179. + - 1: The core sets NAK after Bulk OUT transfer complete
  68180. + </td></tr>
  68181. +
  68182. + <tr>
  68183. + <td>cont_on_bna</td>
  68184. + <td>Specifies whether Enable Continue on BNA enabled or no.
  68185. + After receiving BNA interrupt the core disables the endpoint,when the
  68186. + endpoint is re-enabled by the application the
  68187. + - 0: Core starts processing from the DOEPDMA descriptor (default)
  68188. + - 1: Core starts processing from the descriptor which received the BNA.
  68189. + This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  68190. + </td></tr>
  68191. +
  68192. + <tr>
  68193. + <td>ahb_single</td>
  68194. + <td>This bit when programmed supports SINGLE transfers for remainder data
  68195. + in a transfer for DMA mode of operation.
  68196. + - 0: The remainder data will be sent using INCR burst size (default)
  68197. + - 1: The remainder data will be sent using SINGLE burst size.
  68198. + </td></tr>
  68199. +
  68200. +<tr>
  68201. + <td>adp_enable</td>
  68202. + <td>Specifies whether ADP feature is enabled.
  68203. + The driver will automatically detect the value for this parameter if none is
  68204. + specified.
  68205. + - 0: ADP feature disabled (default)
  68206. + - 1: ADP feature enabled
  68207. + </td></tr>
  68208. +
  68209. + <tr>
  68210. + <td>otg_ver</td>
  68211. + <td>Specifies whether OTG is performing as USB OTG Revision 2.0 or Revision 1.3
  68212. + USB OTG device.
  68213. + - 0: OTG 2.0 support disabled (default)
  68214. + - 1: OTG 2.0 support enabled
  68215. + </td></tr>
  68216. +
  68217. +*/
  68218. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_driver.h linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_driver.h
  68219. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_driver.h 1970-01-01 01:00:00.000000000 +0100
  68220. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_driver.h 2014-02-18 11:52:14.000000000 +0100
  68221. @@ -0,0 +1,86 @@
  68222. +/* ==========================================================================
  68223. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.h $
  68224. + * $Revision: #19 $
  68225. + * $Date: 2010/11/15 $
  68226. + * $Change: 1627671 $
  68227. + *
  68228. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  68229. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  68230. + * otherwise expressly agreed to in writing between Synopsys and you.
  68231. + *
  68232. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  68233. + * any End User Software License Agreement or Agreement for Licensed Product
  68234. + * with Synopsys or any supplement thereto. You are permitted to use and
  68235. + * redistribute this Software in source and binary forms, with or without
  68236. + * modification, provided that redistributions of source code must retain this
  68237. + * notice. You may not view, use, disclose, copy or distribute this file or
  68238. + * any information contained herein except pursuant to this license grant from
  68239. + * Synopsys. If you do not agree with this notice, including the disclaimer
  68240. + * below, then you are not authorized to use the Software.
  68241. + *
  68242. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  68243. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  68244. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  68245. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  68246. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  68247. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  68248. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  68249. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  68250. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  68251. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  68252. + * DAMAGE.
  68253. + * ========================================================================== */
  68254. +
  68255. +#ifndef __DWC_OTG_DRIVER_H__
  68256. +#define __DWC_OTG_DRIVER_H__
  68257. +
  68258. +/** @file
  68259. + * This file contains the interface to the Linux driver.
  68260. + */
  68261. +#include "dwc_otg_os_dep.h"
  68262. +#include "dwc_otg_core_if.h"
  68263. +
  68264. +/* Type declarations */
  68265. +struct dwc_otg_pcd;
  68266. +struct dwc_otg_hcd;
  68267. +
  68268. +/**
  68269. + * This structure is a wrapper that encapsulates the driver components used to
  68270. + * manage a single DWC_otg controller.
  68271. + */
  68272. +typedef struct dwc_otg_device {
  68273. + /** Structure containing OS-dependent stuff. KEEP THIS STRUCT AT THE
  68274. + * VERY BEGINNING OF THE DEVICE STRUCT. OSes such as FreeBSD and NetBSD
  68275. + * require this. */
  68276. + struct os_dependent os_dep;
  68277. +
  68278. + /** Pointer to the core interface structure. */
  68279. + dwc_otg_core_if_t *core_if;
  68280. +
  68281. + /** Pointer to the PCD structure. */
  68282. + struct dwc_otg_pcd *pcd;
  68283. +
  68284. + /** Pointer to the HCD structure. */
  68285. + struct dwc_otg_hcd *hcd;
  68286. +
  68287. + /** Flag to indicate whether the common IRQ handler is installed. */
  68288. + uint8_t common_irq_installed;
  68289. +
  68290. +} dwc_otg_device_t;
  68291. +
  68292. +/*We must clear S3C24XX_EINTPEND external interrupt register
  68293. + * because after clearing in this register trigerred IRQ from
  68294. + * H/W core in kernel interrupt can be occured again before OTG
  68295. + * handlers clear all IRQ sources of Core registers because of
  68296. + * timing latencies and Low Level IRQ Type.
  68297. + */
  68298. +#ifdef CONFIG_MACH_IPMATE
  68299. +#define S3C2410X_CLEAR_EINTPEND() \
  68300. +do { \
  68301. + __raw_writel(1UL << 11,S3C24XX_EINTPEND); \
  68302. +} while (0)
  68303. +#else
  68304. +#define S3C2410X_CLEAR_EINTPEND() do { } while (0)
  68305. +#endif
  68306. +
  68307. +#endif
  68308. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd.c linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
  68309. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 1970-01-01 01:00:00.000000000 +0100
  68310. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 2014-02-18 11:52:14.000000000 +0100
  68311. @@ -0,0 +1,3685 @@
  68312. +
  68313. +/* ==========================================================================
  68314. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.c $
  68315. + * $Revision: #104 $
  68316. + * $Date: 2011/10/24 $
  68317. + * $Change: 1871159 $
  68318. + *
  68319. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  68320. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  68321. + * otherwise expressly agreed to in writing between Synopsys and you.
  68322. + *
  68323. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  68324. + * any End User Software License Agreement or Agreement for Licensed Product
  68325. + * with Synopsys or any supplement thereto. You are permitted to use and
  68326. + * redistribute this Software in source and binary forms, with or without
  68327. + * modification, provided that redistributions of source code must retain this
  68328. + * notice. You may not view, use, disclose, copy or distribute this file or
  68329. + * any information contained herein except pursuant to this license grant from
  68330. + * Synopsys. If you do not agree with this notice, including the disclaimer
  68331. + * below, then you are not authorized to use the Software.
  68332. + *
  68333. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  68334. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  68335. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  68336. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  68337. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  68338. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  68339. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  68340. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  68341. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  68342. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  68343. + * DAMAGE.
  68344. + * ========================================================================== */
  68345. +#ifndef DWC_DEVICE_ONLY
  68346. +
  68347. +/** @file
  68348. + * This file implements HCD Core. All code in this file is portable and doesn't
  68349. + * use any OS specific functions.
  68350. + * Interface provided by HCD Core is defined in <code><hcd_if.h></code>
  68351. + * header file.
  68352. + */
  68353. +
  68354. +#include <linux/usb.h>
  68355. +#include <linux/usb/hcd.h>
  68356. +
  68357. +#include "dwc_otg_hcd.h"
  68358. +#include "dwc_otg_regs.h"
  68359. +#include "dwc_otg_mphi_fix.h"
  68360. +
  68361. +extern bool microframe_schedule, nak_holdoff_enable;
  68362. +
  68363. +//#define DEBUG_HOST_CHANNELS
  68364. +#ifdef DEBUG_HOST_CHANNELS
  68365. +static int last_sel_trans_num_per_scheduled = 0;
  68366. +static int last_sel_trans_num_nonper_scheduled = 0;
  68367. +static int last_sel_trans_num_avail_hc_at_start = 0;
  68368. +static int last_sel_trans_num_avail_hc_at_end = 0;
  68369. +#endif /* DEBUG_HOST_CHANNELS */
  68370. +
  68371. +extern int g_next_sched_frame, g_np_count, g_np_sent;
  68372. +
  68373. +extern haint_data_t haint_saved;
  68374. +extern hcintmsk_data_t hcintmsk_saved[MAX_EPS_CHANNELS];
  68375. +extern hcint_data_t hcint_saved[MAX_EPS_CHANNELS];
  68376. +extern gintsts_data_t ginsts_saved;
  68377. +
  68378. +dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void)
  68379. +{
  68380. + return DWC_ALLOC(sizeof(dwc_otg_hcd_t));
  68381. +}
  68382. +
  68383. +/**
  68384. + * Connection timeout function. An OTG host is required to display a
  68385. + * message if the device does not connect within 10 seconds.
  68386. + */
  68387. +void dwc_otg_hcd_connect_timeout(void *ptr)
  68388. +{
  68389. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, ptr);
  68390. + DWC_PRINTF("Connect Timeout\n");
  68391. + __DWC_ERROR("Device Not Connected/Responding\n");
  68392. +}
  68393. +
  68394. +#if defined(DEBUG)
  68395. +static void dump_channel_info(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  68396. +{
  68397. + if (qh->channel != NULL) {
  68398. + dwc_hc_t *hc = qh->channel;
  68399. + dwc_list_link_t *item;
  68400. + dwc_otg_qh_t *qh_item;
  68401. + int num_channels = hcd->core_if->core_params->host_channels;
  68402. + int i;
  68403. +
  68404. + dwc_otg_hc_regs_t *hc_regs;
  68405. + hcchar_data_t hcchar;
  68406. + hcsplt_data_t hcsplt;
  68407. + hctsiz_data_t hctsiz;
  68408. + uint32_t hcdma;
  68409. +
  68410. + hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  68411. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  68412. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  68413. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  68414. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  68415. +
  68416. + DWC_PRINTF(" Assigned to channel %p:\n", hc);
  68417. + DWC_PRINTF(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32,
  68418. + hcsplt.d32);
  68419. + DWC_PRINTF(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32,
  68420. + hcdma);
  68421. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  68422. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  68423. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  68424. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  68425. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  68426. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  68427. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  68428. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  68429. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  68430. + DWC_PRINTF(" qh: %p\n", hc->qh);
  68431. + DWC_PRINTF(" NP inactive sched:\n");
  68432. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_inactive) {
  68433. + qh_item =
  68434. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  68435. + DWC_PRINTF(" %p\n", qh_item);
  68436. + }
  68437. + DWC_PRINTF(" NP active sched:\n");
  68438. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_active) {
  68439. + qh_item =
  68440. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  68441. + DWC_PRINTF(" %p\n", qh_item);
  68442. + }
  68443. + DWC_PRINTF(" Channels: \n");
  68444. + for (i = 0; i < num_channels; i++) {
  68445. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  68446. + DWC_PRINTF(" %2d: %p\n", i, hc);
  68447. + }
  68448. + }
  68449. +}
  68450. +#else
  68451. +#define dump_channel_info(hcd, qh)
  68452. +#endif /* DEBUG */
  68453. +
  68454. +/**
  68455. + * Work queue function for starting the HCD when A-Cable is connected.
  68456. + * The hcd_start() must be called in a process context.
  68457. + */
  68458. +static void hcd_start_func(void *_vp)
  68459. +{
  68460. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) _vp;
  68461. +
  68462. + DWC_DEBUGPL(DBG_HCDV, "%s() %p\n", __func__, hcd);
  68463. + if (hcd) {
  68464. + hcd->fops->start(hcd);
  68465. + }
  68466. +}
  68467. +
  68468. +static void del_xfer_timers(dwc_otg_hcd_t * hcd)
  68469. +{
  68470. +#ifdef DEBUG
  68471. + int i;
  68472. + int num_channels = hcd->core_if->core_params->host_channels;
  68473. + for (i = 0; i < num_channels; i++) {
  68474. + DWC_TIMER_CANCEL(hcd->core_if->hc_xfer_timer[i]);
  68475. + }
  68476. +#endif
  68477. +}
  68478. +
  68479. +static void del_timers(dwc_otg_hcd_t * hcd)
  68480. +{
  68481. + del_xfer_timers(hcd);
  68482. + DWC_TIMER_CANCEL(hcd->conn_timer);
  68483. +}
  68484. +
  68485. +/**
  68486. + * Processes all the URBs in a single list of QHs. Completes them with
  68487. + * -ESHUTDOWN and frees the QTD.
  68488. + */
  68489. +static void kill_urbs_in_qh_list(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  68490. +{
  68491. + dwc_list_link_t *qh_item, *qh_tmp;
  68492. + dwc_otg_qh_t *qh;
  68493. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  68494. +
  68495. + DWC_LIST_FOREACH_SAFE(qh_item, qh_tmp, qh_list) {
  68496. + qh = DWC_LIST_ENTRY(qh_item, dwc_otg_qh_t, qh_list_entry);
  68497. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp,
  68498. + &qh->qtd_list, qtd_list_entry) {
  68499. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  68500. + if (qtd->urb != NULL) {
  68501. + hcd->fops->complete(hcd, qtd->urb->priv,
  68502. + qtd->urb, -DWC_E_SHUTDOWN);
  68503. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  68504. + }
  68505. +
  68506. + }
  68507. + if(qh->channel) {
  68508. + /* Using hcchar.chen == 1 is not a reliable test.
  68509. + * It is possible that the channel has already halted
  68510. + * but not yet been through the IRQ handler.
  68511. + */
  68512. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  68513. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  68514. + if(microframe_schedule)
  68515. + hcd->available_host_channels++;
  68516. + qh->channel = NULL;
  68517. + }
  68518. + dwc_otg_hcd_qh_remove(hcd, qh);
  68519. + }
  68520. +}
  68521. +
  68522. +/**
  68523. + * Responds with an error status of ESHUTDOWN to all URBs in the non-periodic
  68524. + * and periodic schedules. The QTD associated with each URB is removed from
  68525. + * the schedule and freed. This function may be called when a disconnect is
  68526. + * detected or when the HCD is being stopped.
  68527. + */
  68528. +static void kill_all_urbs(dwc_otg_hcd_t * hcd)
  68529. +{
  68530. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_inactive);
  68531. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_active);
  68532. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_inactive);
  68533. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_ready);
  68534. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_assigned);
  68535. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_queued);
  68536. +}
  68537. +
  68538. +/**
  68539. + * Start the connection timer. An OTG host is required to display a
  68540. + * message if the device does not connect within 10 seconds. The
  68541. + * timer is deleted if a port connect interrupt occurs before the
  68542. + * timer expires.
  68543. + */
  68544. +static void dwc_otg_hcd_start_connect_timer(dwc_otg_hcd_t * hcd)
  68545. +{
  68546. + DWC_TIMER_SCHEDULE(hcd->conn_timer, 10000 /* 10 secs */ );
  68547. +}
  68548. +
  68549. +/**
  68550. + * HCD Callback function for disconnect of the HCD.
  68551. + *
  68552. + * @param p void pointer to the <code>struct usb_hcd</code>
  68553. + */
  68554. +static int32_t dwc_otg_hcd_session_start_cb(void *p)
  68555. +{
  68556. + dwc_otg_hcd_t *dwc_otg_hcd;
  68557. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  68558. + dwc_otg_hcd = p;
  68559. + dwc_otg_hcd_start_connect_timer(dwc_otg_hcd);
  68560. + return 1;
  68561. +}
  68562. +
  68563. +/**
  68564. + * HCD Callback function for starting the HCD when A-Cable is
  68565. + * connected.
  68566. + *
  68567. + * @param p void pointer to the <code>struct usb_hcd</code>
  68568. + */
  68569. +static int32_t dwc_otg_hcd_start_cb(void *p)
  68570. +{
  68571. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  68572. + dwc_otg_core_if_t *core_if;
  68573. + hprt0_data_t hprt0;
  68574. +
  68575. + core_if = dwc_otg_hcd->core_if;
  68576. +
  68577. + if (core_if->op_state == B_HOST) {
  68578. + /*
  68579. + * Reset the port. During a HNP mode switch the reset
  68580. + * needs to occur within 1ms and have a duration of at
  68581. + * least 50ms.
  68582. + */
  68583. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  68584. + hprt0.b.prtrst = 1;
  68585. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  68586. + }
  68587. + DWC_WORKQ_SCHEDULE_DELAYED(core_if->wq_otg,
  68588. + hcd_start_func, dwc_otg_hcd, 50,
  68589. + "start hcd");
  68590. +
  68591. + return 1;
  68592. +}
  68593. +
  68594. +/**
  68595. + * HCD Callback function for disconnect of the HCD.
  68596. + *
  68597. + * @param p void pointer to the <code>struct usb_hcd</code>
  68598. + */
  68599. +static int32_t dwc_otg_hcd_disconnect_cb(void *p)
  68600. +{
  68601. + gintsts_data_t intr;
  68602. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  68603. +
  68604. + /*
  68605. + * Set status flags for the hub driver.
  68606. + */
  68607. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  68608. + dwc_otg_hcd->flags.b.port_connect_status = 0;
  68609. + if(fiq_fix_enable)
  68610. + local_fiq_disable();
  68611. + /*
  68612. + * Shutdown any transfers in process by clearing the Tx FIFO Empty
  68613. + * interrupt mask and status bits and disabling subsequent host
  68614. + * channel interrupts.
  68615. + */
  68616. + intr.d32 = 0;
  68617. + intr.b.nptxfempty = 1;
  68618. + intr.b.ptxfempty = 1;
  68619. + intr.b.hcintr = 1;
  68620. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk,
  68621. + intr.d32, 0);
  68622. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintsts,
  68623. + intr.d32, 0);
  68624. +
  68625. + del_timers(dwc_otg_hcd);
  68626. +
  68627. + /*
  68628. + * Turn off the vbus power only if the core has transitioned to device
  68629. + * mode. If still in host mode, need to keep power on to detect a
  68630. + * reconnection.
  68631. + */
  68632. + if (dwc_otg_is_device_mode(dwc_otg_hcd->core_if)) {
  68633. + if (dwc_otg_hcd->core_if->op_state != A_SUSPEND) {
  68634. + hprt0_data_t hprt0 = {.d32 = 0 };
  68635. + DWC_PRINTF("Disconnect: PortPower off\n");
  68636. + hprt0.b.prtpwr = 0;
  68637. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0,
  68638. + hprt0.d32);
  68639. + }
  68640. +
  68641. + dwc_otg_disable_host_interrupts(dwc_otg_hcd->core_if);
  68642. + }
  68643. +
  68644. + /* Respond with an error status to all URBs in the schedule. */
  68645. + kill_all_urbs(dwc_otg_hcd);
  68646. +
  68647. + if (dwc_otg_is_host_mode(dwc_otg_hcd->core_if)) {
  68648. + /* Clean up any host channels that were in use. */
  68649. + int num_channels;
  68650. + int i;
  68651. + dwc_hc_t *channel;
  68652. + dwc_otg_hc_regs_t *hc_regs;
  68653. + hcchar_data_t hcchar;
  68654. +
  68655. + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
  68656. +
  68657. + if (!dwc_otg_hcd->core_if->dma_enable) {
  68658. + /* Flush out any channel requests in slave mode. */
  68659. + for (i = 0; i < num_channels; i++) {
  68660. + channel = dwc_otg_hcd->hc_ptr_array[i];
  68661. + if (DWC_CIRCLEQ_EMPTY_ENTRY
  68662. + (channel, hc_list_entry)) {
  68663. + hc_regs =
  68664. + dwc_otg_hcd->core_if->
  68665. + host_if->hc_regs[i];
  68666. + hcchar.d32 =
  68667. + DWC_READ_REG32(&hc_regs->hcchar);
  68668. + if (hcchar.b.chen) {
  68669. + hcchar.b.chen = 0;
  68670. + hcchar.b.chdis = 1;
  68671. + hcchar.b.epdir = 0;
  68672. + DWC_WRITE_REG32
  68673. + (&hc_regs->hcchar,
  68674. + hcchar.d32);
  68675. + }
  68676. + }
  68677. + }
  68678. + }
  68679. +
  68680. + for (i = 0; i < num_channels; i++) {
  68681. + channel = dwc_otg_hcd->hc_ptr_array[i];
  68682. + if (DWC_CIRCLEQ_EMPTY_ENTRY(channel, hc_list_entry)) {
  68683. + hc_regs =
  68684. + dwc_otg_hcd->core_if->host_if->hc_regs[i];
  68685. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  68686. + if (hcchar.b.chen) {
  68687. + /* Halt the channel. */
  68688. + hcchar.b.chdis = 1;
  68689. + DWC_WRITE_REG32(&hc_regs->hcchar,
  68690. + hcchar.d32);
  68691. + }
  68692. +
  68693. + dwc_otg_hc_cleanup(dwc_otg_hcd->core_if,
  68694. + channel);
  68695. + DWC_CIRCLEQ_INSERT_TAIL
  68696. + (&dwc_otg_hcd->free_hc_list, channel,
  68697. + hc_list_entry);
  68698. + /*
  68699. + * Added for Descriptor DMA to prevent channel double cleanup
  68700. + * in release_channel_ddma(). Which called from ep_disable
  68701. + * when device disconnect.
  68702. + */
  68703. + channel->qh = NULL;
  68704. + }
  68705. + }
  68706. + if(fiq_split_enable) {
  68707. + for(i=0; i < 128; i++) {
  68708. + dwc_otg_hcd->hub_port[i] = 0;
  68709. + }
  68710. + haint_saved.d32 = 0;
  68711. + for(i=0; i < MAX_EPS_CHANNELS; i++) {
  68712. + hcint_saved[i].d32 = 0;
  68713. + hcintmsk_saved[i].d32 = 0;
  68714. + }
  68715. + }
  68716. +
  68717. + }
  68718. +
  68719. + if(fiq_fix_enable)
  68720. + local_fiq_enable();
  68721. +
  68722. + if (dwc_otg_hcd->fops->disconnect) {
  68723. + dwc_otg_hcd->fops->disconnect(dwc_otg_hcd);
  68724. + }
  68725. +
  68726. + return 1;
  68727. +}
  68728. +
  68729. +/**
  68730. + * HCD Callback function for stopping the HCD.
  68731. + *
  68732. + * @param p void pointer to the <code>struct usb_hcd</code>
  68733. + */
  68734. +static int32_t dwc_otg_hcd_stop_cb(void *p)
  68735. +{
  68736. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  68737. +
  68738. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  68739. + dwc_otg_hcd_stop(dwc_otg_hcd);
  68740. + return 1;
  68741. +}
  68742. +
  68743. +#ifdef CONFIG_USB_DWC_OTG_LPM
  68744. +/**
  68745. + * HCD Callback function for sleep of HCD.
  68746. + *
  68747. + * @param p void pointer to the <code>struct usb_hcd</code>
  68748. + */
  68749. +static int dwc_otg_hcd_sleep_cb(void *p)
  68750. +{
  68751. + dwc_otg_hcd_t *hcd = p;
  68752. +
  68753. + dwc_otg_hcd_free_hc_from_lpm(hcd);
  68754. +
  68755. + return 0;
  68756. +}
  68757. +#endif
  68758. +
  68759. +
  68760. +/**
  68761. + * HCD Callback function for Remote Wakeup.
  68762. + *
  68763. + * @param p void pointer to the <code>struct usb_hcd</code>
  68764. + */
  68765. +static int dwc_otg_hcd_rem_wakeup_cb(void *p)
  68766. +{
  68767. + dwc_otg_hcd_t *hcd = p;
  68768. +
  68769. + if (hcd->core_if->lx_state == DWC_OTG_L2) {
  68770. + hcd->flags.b.port_suspend_change = 1;
  68771. + }
  68772. +#ifdef CONFIG_USB_DWC_OTG_LPM
  68773. + else {
  68774. + hcd->flags.b.port_l1_change = 1;
  68775. + }
  68776. +#endif
  68777. + return 0;
  68778. +}
  68779. +
  68780. +/**
  68781. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  68782. + * stopped.
  68783. + */
  68784. +void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd)
  68785. +{
  68786. + hprt0_data_t hprt0 = {.d32 = 0 };
  68787. +
  68788. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD STOP\n");
  68789. +
  68790. + /*
  68791. + * The root hub should be disconnected before this function is called.
  68792. + * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
  68793. + * and the QH lists (via ..._hcd_endpoint_disable).
  68794. + */
  68795. +
  68796. + /* Turn off all host-specific interrupts. */
  68797. + dwc_otg_disable_host_interrupts(hcd->core_if);
  68798. +
  68799. + /* Turn off the vbus power */
  68800. + DWC_PRINTF("PortPower off\n");
  68801. + hprt0.b.prtpwr = 0;
  68802. + DWC_WRITE_REG32(hcd->core_if->host_if->hprt0, hprt0.d32);
  68803. + dwc_mdelay(1);
  68804. +}
  68805. +
  68806. +int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * hcd,
  68807. + dwc_otg_hcd_urb_t * dwc_otg_urb, void **ep_handle,
  68808. + int atomic_alloc)
  68809. +{
  68810. + int retval = 0;
  68811. + uint8_t needs_scheduling = 0;
  68812. + dwc_otg_transaction_type_e tr_type;
  68813. + dwc_otg_qtd_t *qtd;
  68814. + gintmsk_data_t intr_mask = {.d32 = 0 };
  68815. + hprt0_data_t hprt0 = { .d32 = 0 };
  68816. +
  68817. +#ifdef DEBUG /* integrity checks (Broadcom) */
  68818. + if (NULL == hcd->core_if) {
  68819. + DWC_ERROR("**** DWC OTG HCD URB Enqueue - HCD has NULL core_if\n");
  68820. + /* No longer connected. */
  68821. + return -DWC_E_INVALID;
  68822. + }
  68823. +#endif
  68824. + if (!hcd->flags.b.port_connect_status) {
  68825. + /* No longer connected. */
  68826. + DWC_ERROR("Not connected\n");
  68827. + return -DWC_E_NO_DEVICE;
  68828. + }
  68829. +
  68830. + /* Some core configurations cannot support LS traffic on a FS root port */
  68831. + if ((hcd->fops->speed(hcd, dwc_otg_urb->priv) == USB_SPEED_LOW) &&
  68832. + (hcd->core_if->hwcfg2.b.fs_phy_type == 1) &&
  68833. + (hcd->core_if->hwcfg2.b.hs_phy_type == 1)) {
  68834. + hprt0.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  68835. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_FULL_SPEED) {
  68836. + return -DWC_E_NO_DEVICE;
  68837. + }
  68838. + }
  68839. +
  68840. + qtd = dwc_otg_hcd_qtd_create(dwc_otg_urb, atomic_alloc);
  68841. + if (qtd == NULL) {
  68842. + DWC_ERROR("DWC OTG HCD URB Enqueue failed creating QTD\n");
  68843. + return -DWC_E_NO_MEMORY;
  68844. + }
  68845. +#ifdef DEBUG /* integrity checks (Broadcom) */
  68846. + if (qtd->urb == NULL) {
  68847. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD with no URBs\n");
  68848. + return -DWC_E_NO_MEMORY;
  68849. + }
  68850. + if (qtd->urb->priv == NULL) {
  68851. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD URB with no URB handle\n");
  68852. + return -DWC_E_NO_MEMORY;
  68853. + }
  68854. +#endif
  68855. + intr_mask.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->gintmsk);
  68856. + if(!intr_mask.b.sofintr) needs_scheduling = 1;
  68857. + if((((dwc_otg_qh_t *)ep_handle)->ep_type == UE_BULK) && !(qtd->urb->flags & URB_GIVEBACK_ASAP))
  68858. + /* Do not schedule SG transactions until qtd has URB_GIVEBACK_ASAP set */
  68859. + needs_scheduling = 0;
  68860. +
  68861. + retval = dwc_otg_hcd_qtd_add(qtd, hcd, (dwc_otg_qh_t **) ep_handle, atomic_alloc);
  68862. + // creates a new queue in ep_handle if it doesn't exist already
  68863. + if (retval < 0) {
  68864. + DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
  68865. + "Error status %d\n", retval);
  68866. + dwc_otg_hcd_qtd_free(qtd);
  68867. + return retval;
  68868. + }
  68869. +
  68870. + if(needs_scheduling) {
  68871. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  68872. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  68873. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  68874. + }
  68875. + }
  68876. + return retval;
  68877. +}
  68878. +
  68879. +int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * hcd,
  68880. + dwc_otg_hcd_urb_t * dwc_otg_urb)
  68881. +{
  68882. + dwc_otg_qh_t *qh;
  68883. + dwc_otg_qtd_t *urb_qtd;
  68884. + BUG_ON(!hcd);
  68885. + BUG_ON(!dwc_otg_urb);
  68886. +
  68887. +#ifdef DEBUG /* integrity checks (Broadcom) */
  68888. +
  68889. + if (hcd == NULL) {
  68890. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL HCD\n");
  68891. + return -DWC_E_INVALID;
  68892. + }
  68893. + if (dwc_otg_urb == NULL) {
  68894. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL URB\n");
  68895. + return -DWC_E_INVALID;
  68896. + }
  68897. + if (dwc_otg_urb->qtd == NULL) {
  68898. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with NULL QTD\n");
  68899. + return -DWC_E_INVALID;
  68900. + }
  68901. + urb_qtd = dwc_otg_urb->qtd;
  68902. + BUG_ON(!urb_qtd);
  68903. + if (urb_qtd->qh == NULL) {
  68904. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with QTD with NULL Q handler\n");
  68905. + return -DWC_E_INVALID;
  68906. + }
  68907. +#else
  68908. + urb_qtd = dwc_otg_urb->qtd;
  68909. + BUG_ON(!urb_qtd);
  68910. +#endif
  68911. + qh = urb_qtd->qh;
  68912. + BUG_ON(!qh);
  68913. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  68914. + if (urb_qtd->in_process) {
  68915. + dump_channel_info(hcd, qh);
  68916. + }
  68917. + }
  68918. +#ifdef DEBUG /* integrity checks (Broadcom) */
  68919. + if (hcd->core_if == NULL) {
  68920. + DWC_ERROR("**** DWC OTG HCD URB Dequeue HCD has NULL core_if\n");
  68921. + return -DWC_E_INVALID;
  68922. + }
  68923. +#endif
  68924. + if (urb_qtd->in_process && qh->channel) {
  68925. + /* The QTD is in process (it has been assigned to a channel). */
  68926. + if (hcd->flags.b.port_connect_status) {
  68927. + /*
  68928. + * If still connected (i.e. in host mode), halt the
  68929. + * channel so it can be used for other transfers. If
  68930. + * no longer connected, the host registers can't be
  68931. + * written to halt the channel since the core is in
  68932. + * device mode.
  68933. + */
  68934. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  68935. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  68936. +
  68937. + dwc_otg_hcd_release_port(hcd, qh);
  68938. + }
  68939. + }
  68940. +
  68941. + /*
  68942. + * Free the QTD and clean up the associated QH. Leave the QH in the
  68943. + * schedule if it has any remaining QTDs.
  68944. + */
  68945. +
  68946. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue - "
  68947. + "delete %sQueue handler\n",
  68948. + hcd->core_if->dma_desc_enable?"DMA ":"");
  68949. + if (!hcd->core_if->dma_desc_enable) {
  68950. + uint8_t b = urb_qtd->in_process;
  68951. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  68952. + if (b) {
  68953. + dwc_otg_hcd_qh_deactivate(hcd, qh, 0);
  68954. + qh->channel = NULL;
  68955. + } else if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  68956. + dwc_otg_hcd_qh_remove(hcd, qh);
  68957. + }
  68958. + } else {
  68959. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  68960. + }
  68961. + return 0;
  68962. +}
  68963. +
  68964. +int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  68965. + int retry)
  68966. +{
  68967. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  68968. + int retval = 0;
  68969. + dwc_irqflags_t flags;
  68970. +
  68971. + if (retry < 0) {
  68972. + retval = -DWC_E_INVALID;
  68973. + goto done;
  68974. + }
  68975. +
  68976. + if (!qh) {
  68977. + retval = -DWC_E_INVALID;
  68978. + goto done;
  68979. + }
  68980. +
  68981. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  68982. +
  68983. + while (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list) && retry) {
  68984. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  68985. + retry--;
  68986. + dwc_msleep(5);
  68987. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  68988. + }
  68989. +
  68990. + dwc_otg_hcd_qh_remove(hcd, qh);
  68991. +
  68992. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  68993. + /*
  68994. + * Split dwc_otg_hcd_qh_remove_and_free() into qh_remove
  68995. + * and qh_free to prevent stack dump on DWC_DMA_FREE() with
  68996. + * irq_disabled (spinlock_irqsave) in dwc_otg_hcd_desc_list_free()
  68997. + * and dwc_otg_hcd_frame_list_alloc().
  68998. + */
  68999. + dwc_otg_hcd_qh_free(hcd, qh);
  69000. +
  69001. +done:
  69002. + return retval;
  69003. +}
  69004. +
  69005. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  69006. +int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle)
  69007. +{
  69008. + int retval = 0;
  69009. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  69010. + if (!qh)
  69011. + return -DWC_E_INVALID;
  69012. +
  69013. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  69014. + return retval;
  69015. +}
  69016. +#endif
  69017. +
  69018. +/**
  69019. + * HCD Callback structure for handling mode switching.
  69020. + */
  69021. +static dwc_otg_cil_callbacks_t hcd_cil_callbacks = {
  69022. + .start = dwc_otg_hcd_start_cb,
  69023. + .stop = dwc_otg_hcd_stop_cb,
  69024. + .disconnect = dwc_otg_hcd_disconnect_cb,
  69025. + .session_start = dwc_otg_hcd_session_start_cb,
  69026. + .resume_wakeup = dwc_otg_hcd_rem_wakeup_cb,
  69027. +#ifdef CONFIG_USB_DWC_OTG_LPM
  69028. + .sleep = dwc_otg_hcd_sleep_cb,
  69029. +#endif
  69030. + .p = 0,
  69031. +};
  69032. +
  69033. +/**
  69034. + * Reset tasklet function
  69035. + */
  69036. +static void reset_tasklet_func(void *data)
  69037. +{
  69038. + dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t *) data;
  69039. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  69040. + hprt0_data_t hprt0;
  69041. +
  69042. + DWC_DEBUGPL(DBG_HCDV, "USB RESET tasklet called\n");
  69043. +
  69044. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  69045. + hprt0.b.prtrst = 1;
  69046. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  69047. + dwc_mdelay(60);
  69048. +
  69049. + hprt0.b.prtrst = 0;
  69050. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  69051. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  69052. +}
  69053. +
  69054. +static void completion_tasklet_func(void *ptr)
  69055. +{
  69056. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) ptr;
  69057. + struct urb *urb;
  69058. + urb_tq_entry_t *item;
  69059. + dwc_irqflags_t flags;
  69060. +
  69061. + /* This could just be spin_lock_irq */
  69062. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  69063. + while (!DWC_TAILQ_EMPTY(&hcd->completed_urb_list)) {
  69064. + item = DWC_TAILQ_FIRST(&hcd->completed_urb_list);
  69065. + urb = item->urb;
  69066. + DWC_TAILQ_REMOVE(&hcd->completed_urb_list, item,
  69067. + urb_tq_entries);
  69068. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  69069. + DWC_FREE(item);
  69070. +
  69071. + usb_hcd_giveback_urb(hcd->priv, urb, urb->status);
  69072. +
  69073. + fiq_print(FIQDBG_PORTHUB, "COMPLETE");
  69074. +
  69075. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  69076. + }
  69077. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  69078. + return;
  69079. +}
  69080. +
  69081. +static void qh_list_free(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  69082. +{
  69083. + dwc_list_link_t *item;
  69084. + dwc_otg_qh_t *qh;
  69085. + dwc_irqflags_t flags;
  69086. +
  69087. + if (!qh_list->next) {
  69088. + /* The list hasn't been initialized yet. */
  69089. + return;
  69090. + }
  69091. + /*
  69092. + * Hold spinlock here. Not needed in that case if bellow
  69093. + * function is being called from ISR
  69094. + */
  69095. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  69096. + /* Ensure there are no QTDs or URBs left. */
  69097. + kill_urbs_in_qh_list(hcd, qh_list);
  69098. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  69099. +
  69100. + DWC_LIST_FOREACH(item, qh_list) {
  69101. + qh = DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  69102. + dwc_otg_hcd_qh_remove_and_free(hcd, qh);
  69103. + }
  69104. +}
  69105. +
  69106. +/**
  69107. + * Exit from Hibernation if Host did not detect SRP from connected SRP capable
  69108. + * Device during SRP time by host power up.
  69109. + */
  69110. +void dwc_otg_hcd_power_up(void *ptr)
  69111. +{
  69112. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  69113. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  69114. +
  69115. + DWC_PRINTF("%s called\n", __FUNCTION__);
  69116. +
  69117. + if (!core_if->hibernation_suspend) {
  69118. + DWC_PRINTF("Already exited from Hibernation\n");
  69119. + return;
  69120. + }
  69121. +
  69122. + /* Switch on the voltage to the core */
  69123. + gpwrdn.b.pwrdnswtch = 1;
  69124. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  69125. + dwc_udelay(10);
  69126. +
  69127. + /* Reset the core */
  69128. + gpwrdn.d32 = 0;
  69129. + gpwrdn.b.pwrdnrstn = 1;
  69130. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  69131. + dwc_udelay(10);
  69132. +
  69133. + /* Disable power clamps */
  69134. + gpwrdn.d32 = 0;
  69135. + gpwrdn.b.pwrdnclmp = 1;
  69136. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  69137. +
  69138. + /* Remove reset the core signal */
  69139. + gpwrdn.d32 = 0;
  69140. + gpwrdn.b.pwrdnrstn = 1;
  69141. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  69142. + dwc_udelay(10);
  69143. +
  69144. + /* Disable PMU interrupt */
  69145. + gpwrdn.d32 = 0;
  69146. + gpwrdn.b.pmuintsel = 1;
  69147. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  69148. +
  69149. + core_if->hibernation_suspend = 0;
  69150. +
  69151. + /* Disable PMU */
  69152. + gpwrdn.d32 = 0;
  69153. + gpwrdn.b.pmuactv = 1;
  69154. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  69155. + dwc_udelay(10);
  69156. +
  69157. + /* Enable VBUS */
  69158. + gpwrdn.d32 = 0;
  69159. + gpwrdn.b.dis_vbus = 1;
  69160. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  69161. +
  69162. + core_if->op_state = A_HOST;
  69163. + dwc_otg_core_init(core_if);
  69164. + dwc_otg_enable_global_interrupts(core_if);
  69165. + cil_hcd_start(core_if);
  69166. +}
  69167. +
  69168. +/**
  69169. + * Frees secondary storage associated with the dwc_otg_hcd structure contained
  69170. + * in the struct usb_hcd field.
  69171. + */
  69172. +static void dwc_otg_hcd_free(dwc_otg_hcd_t * dwc_otg_hcd)
  69173. +{
  69174. + int i;
  69175. +
  69176. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD FREE\n");
  69177. +
  69178. + del_timers(dwc_otg_hcd);
  69179. +
  69180. + /* Free memory for QH/QTD lists */
  69181. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_inactive);
  69182. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_active);
  69183. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_inactive);
  69184. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_ready);
  69185. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_assigned);
  69186. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_queued);
  69187. +
  69188. + /* Free memory for the host channels. */
  69189. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  69190. + dwc_hc_t *hc = dwc_otg_hcd->hc_ptr_array[i];
  69191. +
  69192. +#ifdef DEBUG
  69193. + if (dwc_otg_hcd->core_if->hc_xfer_timer[i]) {
  69194. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->hc_xfer_timer[i]);
  69195. + }
  69196. +#endif
  69197. + if (hc != NULL) {
  69198. + DWC_DEBUGPL(DBG_HCDV, "HCD Free channel #%i, hc=%p\n",
  69199. + i, hc);
  69200. + DWC_FREE(hc);
  69201. + }
  69202. + }
  69203. +
  69204. + if (dwc_otg_hcd->core_if->dma_enable) {
  69205. + if (dwc_otg_hcd->status_buf_dma) {
  69206. + DWC_DMA_FREE(DWC_OTG_HCD_STATUS_BUF_SIZE,
  69207. + dwc_otg_hcd->status_buf,
  69208. + dwc_otg_hcd->status_buf_dma);
  69209. + }
  69210. + } else if (dwc_otg_hcd->status_buf != NULL) {
  69211. + DWC_FREE(dwc_otg_hcd->status_buf);
  69212. + }
  69213. + DWC_SPINLOCK_FREE(dwc_otg_hcd->channel_lock);
  69214. + DWC_SPINLOCK_FREE(dwc_otg_hcd->lock);
  69215. + /* Set core_if's lock pointer to NULL */
  69216. + dwc_otg_hcd->core_if->lock = NULL;
  69217. +
  69218. + DWC_TIMER_FREE(dwc_otg_hcd->conn_timer);
  69219. + DWC_TASK_FREE(dwc_otg_hcd->reset_tasklet);
  69220. + DWC_TASK_FREE(dwc_otg_hcd->completion_tasklet);
  69221. +
  69222. +#ifdef DWC_DEV_SRPCAP
  69223. + if (dwc_otg_hcd->core_if->power_down == 2 &&
  69224. + dwc_otg_hcd->core_if->pwron_timer) {
  69225. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->pwron_timer);
  69226. + }
  69227. +#endif
  69228. + DWC_FREE(dwc_otg_hcd);
  69229. +}
  69230. +
  69231. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd);
  69232. +
  69233. +int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if)
  69234. +{
  69235. + int retval = 0;
  69236. + int num_channels;
  69237. + int i;
  69238. + dwc_hc_t *channel;
  69239. +
  69240. + hcd->lock = DWC_SPINLOCK_ALLOC();
  69241. + hcd->channel_lock = DWC_SPINLOCK_ALLOC();
  69242. + DWC_DEBUGPL(DBG_HCDV, "init of HCD %p given core_if %p\n",
  69243. + hcd, core_if);
  69244. + if (!hcd->lock) {
  69245. + DWC_ERROR("Could not allocate lock for pcd");
  69246. + DWC_FREE(hcd);
  69247. + retval = -DWC_E_NO_MEMORY;
  69248. + goto out;
  69249. + }
  69250. + hcd->core_if = core_if;
  69251. +
  69252. + /* Register the HCD CIL Callbacks */
  69253. + dwc_otg_cil_register_hcd_callbacks(hcd->core_if,
  69254. + &hcd_cil_callbacks, hcd);
  69255. +
  69256. + /* Initialize the non-periodic schedule. */
  69257. + DWC_LIST_INIT(&hcd->non_periodic_sched_inactive);
  69258. + DWC_LIST_INIT(&hcd->non_periodic_sched_active);
  69259. +
  69260. + /* Initialize the periodic schedule. */
  69261. + DWC_LIST_INIT(&hcd->periodic_sched_inactive);
  69262. + DWC_LIST_INIT(&hcd->periodic_sched_ready);
  69263. + DWC_LIST_INIT(&hcd->periodic_sched_assigned);
  69264. + DWC_LIST_INIT(&hcd->periodic_sched_queued);
  69265. + DWC_TAILQ_INIT(&hcd->completed_urb_list);
  69266. + /*
  69267. + * Create a host channel descriptor for each host channel implemented
  69268. + * in the controller. Initialize the channel descriptor array.
  69269. + */
  69270. + DWC_CIRCLEQ_INIT(&hcd->free_hc_list);
  69271. + num_channels = hcd->core_if->core_params->host_channels;
  69272. + DWC_MEMSET(hcd->hc_ptr_array, 0, sizeof(hcd->hc_ptr_array));
  69273. + for (i = 0; i < num_channels; i++) {
  69274. + channel = DWC_ALLOC(sizeof(dwc_hc_t));
  69275. + if (channel == NULL) {
  69276. + retval = -DWC_E_NO_MEMORY;
  69277. + DWC_ERROR("%s: host channel allocation failed\n",
  69278. + __func__);
  69279. + dwc_otg_hcd_free(hcd);
  69280. + goto out;
  69281. + }
  69282. + channel->hc_num = i;
  69283. + hcd->hc_ptr_array[i] = channel;
  69284. +#ifdef DEBUG
  69285. + hcd->core_if->hc_xfer_timer[i] =
  69286. + DWC_TIMER_ALLOC("hc timer", hc_xfer_timeout,
  69287. + &hcd->core_if->hc_xfer_info[i]);
  69288. +#endif
  69289. + DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i,
  69290. + channel);
  69291. + }
  69292. +
  69293. + /* Initialize the Connection timeout timer. */
  69294. + hcd->conn_timer = DWC_TIMER_ALLOC("Connection timer",
  69295. + dwc_otg_hcd_connect_timeout, 0);
  69296. +
  69297. + printk(KERN_DEBUG "dwc_otg: Microframe scheduler %s\n", microframe_schedule ? "enabled":"disabled");
  69298. + if (microframe_schedule)
  69299. + init_hcd_usecs(hcd);
  69300. +
  69301. + /* Initialize reset tasklet. */
  69302. + hcd->reset_tasklet = DWC_TASK_ALLOC("reset_tasklet", reset_tasklet_func, hcd);
  69303. +
  69304. + hcd->completion_tasklet = DWC_TASK_ALLOC("completion_tasklet",
  69305. + completion_tasklet_func, hcd);
  69306. +#ifdef DWC_DEV_SRPCAP
  69307. + if (hcd->core_if->power_down == 2) {
  69308. + /* Initialize Power on timer for Host power up in case hibernation */
  69309. + hcd->core_if->pwron_timer = DWC_TIMER_ALLOC("PWRON TIMER",
  69310. + dwc_otg_hcd_power_up, core_if);
  69311. + }
  69312. +#endif
  69313. +
  69314. + /*
  69315. + * Allocate space for storing data on status transactions. Normally no
  69316. + * data is sent, but this space acts as a bit bucket. This must be
  69317. + * done after usb_add_hcd since that function allocates the DMA buffer
  69318. + * pool.
  69319. + */
  69320. + if (hcd->core_if->dma_enable) {
  69321. + hcd->status_buf =
  69322. + DWC_DMA_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE,
  69323. + &hcd->status_buf_dma);
  69324. + } else {
  69325. + hcd->status_buf = DWC_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE);
  69326. + }
  69327. + if (!hcd->status_buf) {
  69328. + retval = -DWC_E_NO_MEMORY;
  69329. + DWC_ERROR("%s: status_buf allocation failed\n", __func__);
  69330. + dwc_otg_hcd_free(hcd);
  69331. + goto out;
  69332. + }
  69333. +
  69334. + hcd->otg_port = 1;
  69335. + hcd->frame_list = NULL;
  69336. + hcd->frame_list_dma = 0;
  69337. + hcd->periodic_qh_count = 0;
  69338. +
  69339. + DWC_MEMSET(hcd->hub_port, 0, sizeof(hcd->hub_port));
  69340. +#ifdef FIQ_DEBUG
  69341. + DWC_MEMSET(hcd->hub_port_alloc, -1, sizeof(hcd->hub_port_alloc));
  69342. +#endif
  69343. +
  69344. +out:
  69345. + return retval;
  69346. +}
  69347. +
  69348. +void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd)
  69349. +{
  69350. + /* Turn off all host-specific interrupts. */
  69351. + dwc_otg_disable_host_interrupts(hcd->core_if);
  69352. +
  69353. + dwc_otg_hcd_free(hcd);
  69354. +}
  69355. +
  69356. +/**
  69357. + * Initializes dynamic portions of the DWC_otg HCD state.
  69358. + */
  69359. +static void dwc_otg_hcd_reinit(dwc_otg_hcd_t * hcd)
  69360. +{
  69361. + int num_channels;
  69362. + int i;
  69363. + dwc_hc_t *channel;
  69364. + dwc_hc_t *channel_tmp;
  69365. +
  69366. + hcd->flags.d32 = 0;
  69367. +
  69368. + hcd->non_periodic_qh_ptr = &hcd->non_periodic_sched_active;
  69369. + if (!microframe_schedule) {
  69370. + hcd->non_periodic_channels = 0;
  69371. + hcd->periodic_channels = 0;
  69372. + } else {
  69373. + hcd->available_host_channels = hcd->core_if->core_params->host_channels;
  69374. + }
  69375. + /*
  69376. + * Put all channels in the free channel list and clean up channel
  69377. + * states.
  69378. + */
  69379. + DWC_CIRCLEQ_FOREACH_SAFE(channel, channel_tmp,
  69380. + &hcd->free_hc_list, hc_list_entry) {
  69381. + DWC_CIRCLEQ_REMOVE(&hcd->free_hc_list, channel, hc_list_entry);
  69382. + }
  69383. +
  69384. + num_channels = hcd->core_if->core_params->host_channels;
  69385. + for (i = 0; i < num_channels; i++) {
  69386. + channel = hcd->hc_ptr_array[i];
  69387. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, channel,
  69388. + hc_list_entry);
  69389. + dwc_otg_hc_cleanup(hcd->core_if, channel);
  69390. + }
  69391. +
  69392. + /* Initialize the DWC core for host mode operation. */
  69393. + dwc_otg_core_host_init(hcd->core_if);
  69394. +
  69395. + /* Set core_if's lock pointer to the hcd->lock */
  69396. + hcd->core_if->lock = hcd->lock;
  69397. +}
  69398. +
  69399. +/**
  69400. + * Assigns transactions from a QTD to a free host channel and initializes the
  69401. + * host channel to perform the transactions. The host channel is removed from
  69402. + * the free list.
  69403. + *
  69404. + * @param hcd The HCD state structure.
  69405. + * @param qh Transactions from the first QTD for this QH are selected and
  69406. + * assigned to a free host channel.
  69407. + */
  69408. +static void assign_and_init_hc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  69409. +{
  69410. + dwc_hc_t *hc;
  69411. + dwc_otg_qtd_t *qtd;
  69412. + dwc_otg_hcd_urb_t *urb;
  69413. + void* ptr = NULL;
  69414. +
  69415. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  69416. +
  69417. + urb = qtd->urb;
  69418. +
  69419. + DWC_DEBUGPL(DBG_HCDV, "%s(%p,%p) - urb %x, actual_length %d\n", __func__, hcd, qh, (unsigned int)urb, urb->actual_length);
  69420. +
  69421. + if (((urb->actual_length < 0) || (urb->actual_length > urb->length)) && !dwc_otg_hcd_is_pipe_in(&urb->pipe_info))
  69422. + urb->actual_length = urb->length;
  69423. +
  69424. +
  69425. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  69426. +
  69427. + /* Remove the host channel from the free list. */
  69428. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  69429. +
  69430. + qh->channel = hc;
  69431. +
  69432. + qtd->in_process = 1;
  69433. +
  69434. + /*
  69435. + * Use usb_pipedevice to determine device address. This address is
  69436. + * 0 before the SET_ADDRESS command and the correct address afterward.
  69437. + */
  69438. + hc->dev_addr = dwc_otg_hcd_get_dev_addr(&urb->pipe_info);
  69439. + hc->ep_num = dwc_otg_hcd_get_ep_num(&urb->pipe_info);
  69440. + hc->speed = qh->dev_speed;
  69441. + hc->max_packet = dwc_max_packet(qh->maxp);
  69442. +
  69443. + hc->xfer_started = 0;
  69444. + hc->halt_status = DWC_OTG_HC_XFER_NO_HALT_STATUS;
  69445. + hc->error_state = (qtd->error_count > 0);
  69446. + hc->halt_on_queue = 0;
  69447. + hc->halt_pending = 0;
  69448. + hc->requests = 0;
  69449. +
  69450. + /*
  69451. + * The following values may be modified in the transfer type section
  69452. + * below. The xfer_len value may be reduced when the transfer is
  69453. + * started to accommodate the max widths of the XferSize and PktCnt
  69454. + * fields in the HCTSIZn register.
  69455. + */
  69456. +
  69457. + hc->ep_is_in = (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) != 0);
  69458. + if (hc->ep_is_in) {
  69459. + hc->do_ping = 0;
  69460. + } else {
  69461. + hc->do_ping = qh->ping_state;
  69462. + }
  69463. +
  69464. + hc->data_pid_start = qh->data_toggle;
  69465. + hc->multi_count = 1;
  69466. +
  69467. + if (hcd->core_if->dma_enable) {
  69468. + hc->xfer_buff = (uint8_t *) urb->dma + urb->actual_length;
  69469. +
  69470. + /* For non-dword aligned case */
  69471. + if (((unsigned long)hc->xfer_buff & 0x3)
  69472. + && !hcd->core_if->dma_desc_enable) {
  69473. + ptr = (uint8_t *) urb->buf + urb->actual_length;
  69474. + }
  69475. + } else {
  69476. + hc->xfer_buff = (uint8_t *) urb->buf + urb->actual_length;
  69477. + }
  69478. + hc->xfer_len = urb->length - urb->actual_length;
  69479. + hc->xfer_count = 0;
  69480. +
  69481. + /*
  69482. + * Set the split attributes
  69483. + */
  69484. + hc->do_split = 0;
  69485. + if (qh->do_split) {
  69486. + uint32_t hub_addr, port_addr;
  69487. + hc->do_split = 1;
  69488. + hc->xact_pos = qtd->isoc_split_pos;
  69489. + /* We don't need to do complete splits anymore */
  69490. + if(fiq_split_enable)
  69491. + hc->complete_split = qtd->complete_split = 0;
  69492. + else
  69493. + hc->complete_split = qtd->complete_split;
  69494. +
  69495. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &port_addr);
  69496. + hc->hub_addr = (uint8_t) hub_addr;
  69497. + hc->port_addr = (uint8_t) port_addr;
  69498. + }
  69499. +
  69500. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  69501. + case UE_CONTROL:
  69502. + hc->ep_type = DWC_OTG_EP_TYPE_CONTROL;
  69503. + switch (qtd->control_phase) {
  69504. + case DWC_OTG_CONTROL_SETUP:
  69505. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction\n");
  69506. + hc->do_ping = 0;
  69507. + hc->ep_is_in = 0;
  69508. + hc->data_pid_start = DWC_OTG_HC_PID_SETUP;
  69509. + if (hcd->core_if->dma_enable) {
  69510. + hc->xfer_buff = (uint8_t *) urb->setup_dma;
  69511. + } else {
  69512. + hc->xfer_buff = (uint8_t *) urb->setup_packet;
  69513. + }
  69514. + hc->xfer_len = 8;
  69515. + ptr = NULL;
  69516. + break;
  69517. + case DWC_OTG_CONTROL_DATA:
  69518. + DWC_DEBUGPL(DBG_HCDV, " Control data transaction\n");
  69519. + hc->data_pid_start = qtd->data_toggle;
  69520. + break;
  69521. + case DWC_OTG_CONTROL_STATUS:
  69522. + /*
  69523. + * Direction is opposite of data direction or IN if no
  69524. + * data.
  69525. + */
  69526. + DWC_DEBUGPL(DBG_HCDV, " Control status transaction\n");
  69527. + if (urb->length == 0) {
  69528. + hc->ep_is_in = 1;
  69529. + } else {
  69530. + hc->ep_is_in =
  69531. + dwc_otg_hcd_is_pipe_out(&urb->pipe_info);
  69532. + }
  69533. + if (hc->ep_is_in) {
  69534. + hc->do_ping = 0;
  69535. + }
  69536. +
  69537. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  69538. +
  69539. + hc->xfer_len = 0;
  69540. + if (hcd->core_if->dma_enable) {
  69541. + hc->xfer_buff = (uint8_t *) hcd->status_buf_dma;
  69542. + } else {
  69543. + hc->xfer_buff = (uint8_t *) hcd->status_buf;
  69544. + }
  69545. + ptr = NULL;
  69546. + break;
  69547. + }
  69548. + break;
  69549. + case UE_BULK:
  69550. + hc->ep_type = DWC_OTG_EP_TYPE_BULK;
  69551. + break;
  69552. + case UE_INTERRUPT:
  69553. + hc->ep_type = DWC_OTG_EP_TYPE_INTR;
  69554. + break;
  69555. + case UE_ISOCHRONOUS:
  69556. + {
  69557. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  69558. +
  69559. + hc->ep_type = DWC_OTG_EP_TYPE_ISOC;
  69560. +
  69561. + if (hcd->core_if->dma_desc_enable)
  69562. + break;
  69563. +
  69564. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  69565. +
  69566. + frame_desc->status = 0;
  69567. +
  69568. + if (hcd->core_if->dma_enable) {
  69569. + hc->xfer_buff = (uint8_t *) urb->dma;
  69570. + } else {
  69571. + hc->xfer_buff = (uint8_t *) urb->buf;
  69572. + }
  69573. + hc->xfer_buff +=
  69574. + frame_desc->offset + qtd->isoc_split_offset;
  69575. + hc->xfer_len =
  69576. + frame_desc->length - qtd->isoc_split_offset;
  69577. +
  69578. + /* For non-dword aligned buffers */
  69579. + if (((unsigned long)hc->xfer_buff & 0x3)
  69580. + && hcd->core_if->dma_enable) {
  69581. + ptr =
  69582. + (uint8_t *) urb->buf + frame_desc->offset +
  69583. + qtd->isoc_split_offset;
  69584. + } else
  69585. + ptr = NULL;
  69586. +
  69587. + if (hc->xact_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  69588. + if (hc->xfer_len <= 188) {
  69589. + hc->xact_pos = DWC_HCSPLIT_XACTPOS_ALL;
  69590. + } else {
  69591. + hc->xact_pos =
  69592. + DWC_HCSPLIT_XACTPOS_BEGIN;
  69593. + }
  69594. + }
  69595. + }
  69596. + break;
  69597. + }
  69598. + /* non DWORD-aligned buffer case */
  69599. + if (ptr) {
  69600. + uint32_t buf_size;
  69601. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  69602. + buf_size = hcd->core_if->core_params->max_transfer_size;
  69603. + } else {
  69604. + buf_size = 4096;
  69605. + }
  69606. + if (!qh->dw_align_buf) {
  69607. + qh->dw_align_buf = DWC_DMA_ALLOC_ATOMIC(buf_size,
  69608. + &qh->dw_align_buf_dma);
  69609. + if (!qh->dw_align_buf) {
  69610. + DWC_ERROR
  69611. + ("%s: Failed to allocate memory to handle "
  69612. + "non-dword aligned buffer case\n",
  69613. + __func__);
  69614. + return;
  69615. + }
  69616. + }
  69617. + if (!hc->ep_is_in) {
  69618. + dwc_memcpy(qh->dw_align_buf, ptr, hc->xfer_len);
  69619. + }
  69620. + hc->align_buff = qh->dw_align_buf_dma;
  69621. + } else {
  69622. + hc->align_buff = 0;
  69623. + }
  69624. +
  69625. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  69626. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  69627. + /*
  69628. + * This value may be modified when the transfer is started to
  69629. + * reflect the actual transfer length.
  69630. + */
  69631. + hc->multi_count = dwc_hb_mult(qh->maxp);
  69632. + }
  69633. +
  69634. + if (hcd->core_if->dma_desc_enable)
  69635. + hc->desc_list_addr = qh->desc_list_dma;
  69636. +
  69637. + dwc_otg_hc_init(hcd->core_if, hc);
  69638. + hc->qh = qh;
  69639. +}
  69640. +
  69641. +/*
  69642. +** Check the transaction to see if the port / hub has already been assigned for
  69643. +** a split transaction
  69644. +**
  69645. +** Return 0 - Port is already in use
  69646. +*/
  69647. +int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
  69648. +{
  69649. + uint32_t hub_addr, port_addr;
  69650. +
  69651. + if(!fiq_split_enable)
  69652. + return 0;
  69653. +
  69654. + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
  69655. +
  69656. + if(hcd->hub_port[hub_addr] & (1 << port_addr))
  69657. + {
  69658. + fiq_print(FIQDBG_PORTHUB, "H%dP%d:S%02d", hub_addr, port_addr, qh->skip_count);
  69659. +
  69660. + qh->skip_count++;
  69661. +
  69662. + if(qh->skip_count > 40000)
  69663. + {
  69664. + printk_once(KERN_ERR "Error: Having to skip port allocation");
  69665. + local_fiq_disable();
  69666. + BUG();
  69667. + return 0;
  69668. + }
  69669. + return 1;
  69670. + }
  69671. + else
  69672. + {
  69673. + qh->skip_count = 0;
  69674. + hcd->hub_port[hub_addr] |= 1 << port_addr;
  69675. + fiq_print(FIQDBG_PORTHUB, "H%dP%d:A %d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
  69676. +#ifdef FIQ_DEBUG
  69677. + hcd->hub_port_alloc[hub_addr * 16 + port_addr] = dwc_otg_hcd_get_frame_number(hcd);
  69678. +#endif
  69679. + return 0;
  69680. + }
  69681. +}
  69682. +void dwc_otg_hcd_release_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
  69683. +{
  69684. + uint32_t hub_addr, port_addr;
  69685. +
  69686. + if(!fiq_split_enable)
  69687. + return;
  69688. +
  69689. + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
  69690. +
  69691. + hcd->hub_port[hub_addr] &= ~(1 << port_addr);
  69692. +#ifdef FIQ_DEBUG
  69693. + hcd->hub_port_alloc[hub_addr * 16 + port_addr] = -1;
  69694. +#endif
  69695. + fiq_print(FIQDBG_PORTHUB, "H%dP%d:RO%d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
  69696. +
  69697. +}
  69698. +
  69699. +
  69700. +/**
  69701. + * This function selects transactions from the HCD transfer schedule and
  69702. + * assigns them to available host channels. It is called from HCD interrupt
  69703. + * handler functions.
  69704. + *
  69705. + * @param hcd The HCD state structure.
  69706. + *
  69707. + * @return The types of new transactions that were assigned to host channels.
  69708. + */
  69709. +dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t * hcd)
  69710. +{
  69711. + dwc_list_link_t *qh_ptr;
  69712. + dwc_otg_qh_t *qh;
  69713. + dwc_otg_qtd_t *qtd;
  69714. + int num_channels;
  69715. + dwc_irqflags_t flags;
  69716. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  69717. + dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
  69718. +
  69719. +#ifdef DEBUG_SOF
  69720. + DWC_DEBUGPL(DBG_HCD, " Select Transactions\n");
  69721. +#endif
  69722. +
  69723. +#ifdef DEBUG_HOST_CHANNELS
  69724. + last_sel_trans_num_per_scheduled = 0;
  69725. + last_sel_trans_num_nonper_scheduled = 0;
  69726. + last_sel_trans_num_avail_hc_at_start = hcd->available_host_channels;
  69727. +#endif /* DEBUG_HOST_CHANNELS */
  69728. +
  69729. + /* Process entries in the periodic ready list. */
  69730. + qh_ptr = DWC_LIST_FIRST(&hcd->periodic_sched_ready);
  69731. +
  69732. + while (qh_ptr != &hcd->periodic_sched_ready &&
  69733. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  69734. +
  69735. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  69736. +
  69737. + if(qh->do_split) {
  69738. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  69739. + if(!(qh->ep_type == UE_ISOCHRONOUS &&
  69740. + (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
  69741. + qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END))) {
  69742. + if(dwc_otg_hcd_allocate_port(hcd, qh))
  69743. + {
  69744. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  69745. + g_next_sched_frame = dwc_frame_num_inc(dwc_otg_hcd_get_frame_number(hcd), 1);
  69746. + continue;
  69747. + }
  69748. + }
  69749. + }
  69750. +
  69751. + if (microframe_schedule) {
  69752. + // Make sure we leave one channel for non periodic transactions.
  69753. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  69754. + if (hcd->available_host_channels <= 1) {
  69755. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  69756. + if(qh->do_split) dwc_otg_hcd_release_port(hcd, qh);
  69757. + break;
  69758. + }
  69759. + hcd->available_host_channels--;
  69760. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  69761. +#ifdef DEBUG_HOST_CHANNELS
  69762. + last_sel_trans_num_per_scheduled++;
  69763. +#endif /* DEBUG_HOST_CHANNELS */
  69764. + }
  69765. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  69766. + assign_and_init_hc(hcd, qh);
  69767. +
  69768. + /*
  69769. + * Move the QH from the periodic ready schedule to the
  69770. + * periodic assigned schedule.
  69771. + */
  69772. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  69773. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  69774. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  69775. + &qh->qh_list_entry);
  69776. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  69777. + }
  69778. +
  69779. + /*
  69780. + * Process entries in the inactive portion of the non-periodic
  69781. + * schedule. Some free host channels may not be used if they are
  69782. + * reserved for periodic transfers.
  69783. + */
  69784. + qh_ptr = hcd->non_periodic_sched_inactive.next;
  69785. + num_channels = hcd->core_if->core_params->host_channels;
  69786. + while (qh_ptr != &hcd->non_periodic_sched_inactive &&
  69787. + (microframe_schedule || hcd->non_periodic_channels <
  69788. + num_channels - hcd->periodic_channels) &&
  69789. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  69790. +
  69791. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  69792. +
  69793. + /*
  69794. + * Check to see if this is a NAK'd retransmit, in which case ignore for retransmission
  69795. + * we hold off on bulk retransmissions to reduce NAK interrupt overhead for full-speed
  69796. + * cheeky devices that just hold off using NAKs
  69797. + */
  69798. + if (nak_holdoff_enable && qh->do_split) {
  69799. + if (qh->nak_frame != 0xffff &&
  69800. + dwc_full_frame_num(qh->nak_frame) ==
  69801. + dwc_full_frame_num(dwc_otg_hcd_get_frame_number(hcd))) {
  69802. + /*
  69803. + * Revisit: Need to avoid trampling on periodic scheduling.
  69804. + * Currently we are safe because g_np_count != g_np_sent whenever we hit this,
  69805. + * but if this behaviour is changed then periodic endpoints will get a slower
  69806. + * polling rate.
  69807. + */
  69808. + g_next_sched_frame = ((qh->nak_frame + 8) & ~7) & DWC_HFNUM_MAX_FRNUM;
  69809. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  69810. + continue;
  69811. + } else {
  69812. + qh->nak_frame = 0xffff;
  69813. + }
  69814. + }
  69815. +
  69816. + if (microframe_schedule) {
  69817. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  69818. + if (hcd->available_host_channels < 1) {
  69819. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  69820. + break;
  69821. + }
  69822. + hcd->available_host_channels--;
  69823. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  69824. +#ifdef DEBUG_HOST_CHANNELS
  69825. + last_sel_trans_num_nonper_scheduled++;
  69826. +#endif /* DEBUG_HOST_CHANNELS */
  69827. + }
  69828. +
  69829. + assign_and_init_hc(hcd, qh);
  69830. +
  69831. + /*
  69832. + * Move the QH from the non-periodic inactive schedule to the
  69833. + * non-periodic active schedule.
  69834. + */
  69835. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  69836. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  69837. + DWC_LIST_MOVE_HEAD(&hcd->non_periodic_sched_active,
  69838. + &qh->qh_list_entry);
  69839. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  69840. +
  69841. + g_np_sent++;
  69842. +
  69843. + if (!microframe_schedule)
  69844. + hcd->non_periodic_channels++;
  69845. + }
  69846. +
  69847. + if(!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned))
  69848. + ret_val |= DWC_OTG_TRANSACTION_PERIODIC;
  69849. +
  69850. + if(!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active))
  69851. + ret_val |= DWC_OTG_TRANSACTION_NON_PERIODIC;
  69852. +
  69853. +
  69854. +#ifdef DEBUG_HOST_CHANNELS
  69855. + last_sel_trans_num_avail_hc_at_end = hcd->available_host_channels;
  69856. +#endif /* DEBUG_HOST_CHANNELS */
  69857. + return ret_val;
  69858. +}
  69859. +
  69860. +/**
  69861. + * Attempts to queue a single transaction request for a host channel
  69862. + * associated with either a periodic or non-periodic transfer. This function
  69863. + * assumes that there is space available in the appropriate request queue. For
  69864. + * an OUT transfer or SETUP transaction in Slave mode, it checks whether space
  69865. + * is available in the appropriate Tx FIFO.
  69866. + *
  69867. + * @param hcd The HCD state structure.
  69868. + * @param hc Host channel descriptor associated with either a periodic or
  69869. + * non-periodic transfer.
  69870. + * @param fifo_dwords_avail Number of DWORDs available in the periodic Tx
  69871. + * FIFO for periodic transfers or the non-periodic Tx FIFO for non-periodic
  69872. + * transfers.
  69873. + *
  69874. + * @return 1 if a request is queued and more requests may be needed to
  69875. + * complete the transfer, 0 if no more requests are required for this
  69876. + * transfer, -1 if there is insufficient space in the Tx FIFO.
  69877. + */
  69878. +static int queue_transaction(dwc_otg_hcd_t * hcd,
  69879. + dwc_hc_t * hc, uint16_t fifo_dwords_avail)
  69880. +{
  69881. + int retval;
  69882. +
  69883. + if (hcd->core_if->dma_enable) {
  69884. + if (hcd->core_if->dma_desc_enable) {
  69885. + if (!hc->xfer_started
  69886. + || (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)) {
  69887. + dwc_otg_hcd_start_xfer_ddma(hcd, hc->qh);
  69888. + hc->qh->ping_state = 0;
  69889. + }
  69890. + } else if (!hc->xfer_started) {
  69891. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  69892. + hc->qh->ping_state = 0;
  69893. + }
  69894. + retval = 0;
  69895. + } else if (hc->halt_pending) {
  69896. + /* Don't queue a request if the channel has been halted. */
  69897. + retval = 0;
  69898. + } else if (hc->halt_on_queue) {
  69899. + dwc_otg_hc_halt(hcd->core_if, hc, hc->halt_status);
  69900. + retval = 0;
  69901. + } else if (hc->do_ping) {
  69902. + if (!hc->xfer_started) {
  69903. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  69904. + }
  69905. + retval = 0;
  69906. + } else if (!hc->ep_is_in || hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  69907. + if ((fifo_dwords_avail * 4) >= hc->max_packet) {
  69908. + if (!hc->xfer_started) {
  69909. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  69910. + retval = 1;
  69911. + } else {
  69912. + retval =
  69913. + dwc_otg_hc_continue_transfer(hcd->core_if,
  69914. + hc);
  69915. + }
  69916. + } else {
  69917. + retval = -1;
  69918. + }
  69919. + } else {
  69920. + if (!hc->xfer_started) {
  69921. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  69922. + retval = 1;
  69923. + } else {
  69924. + retval = dwc_otg_hc_continue_transfer(hcd->core_if, hc);
  69925. + }
  69926. + }
  69927. +
  69928. + return retval;
  69929. +}
  69930. +
  69931. +/**
  69932. + * Processes periodic channels for the next frame and queues transactions for
  69933. + * these channels to the DWC_otg controller. After queueing transactions, the
  69934. + * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
  69935. + * to queue as Periodic Tx FIFO or request queue space becomes available.
  69936. + * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
  69937. + */
  69938. +static void process_periodic_channels(dwc_otg_hcd_t * hcd)
  69939. +{
  69940. + hptxsts_data_t tx_status;
  69941. + dwc_list_link_t *qh_ptr;
  69942. + dwc_otg_qh_t *qh;
  69943. + int status;
  69944. + int no_queue_space = 0;
  69945. + int no_fifo_space = 0;
  69946. +
  69947. + dwc_otg_host_global_regs_t *host_regs;
  69948. + host_regs = hcd->core_if->host_if->host_global_regs;
  69949. +
  69950. + DWC_DEBUGPL(DBG_HCDV, "Queue periodic transactions\n");
  69951. +#ifdef DEBUG
  69952. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  69953. + DWC_DEBUGPL(DBG_HCDV,
  69954. + " P Tx Req Queue Space Avail (before queue): %d\n",
  69955. + tx_status.b.ptxqspcavail);
  69956. + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (before queue): %d\n",
  69957. + tx_status.b.ptxfspcavail);
  69958. +#endif
  69959. +
  69960. + qh_ptr = hcd->periodic_sched_assigned.next;
  69961. + while (qh_ptr != &hcd->periodic_sched_assigned) {
  69962. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  69963. + if (tx_status.b.ptxqspcavail == 0) {
  69964. + no_queue_space = 1;
  69965. + break;
  69966. + }
  69967. +
  69968. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  69969. +
  69970. + // Do not send a split start transaction any later than frame .6
  69971. + // Note, we have to schedule a periodic in .5 to make it go in .6
  69972. + if(fiq_split_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
  69973. + {
  69974. + qh_ptr = qh_ptr->next;
  69975. + g_next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
  69976. + continue;
  69977. + }
  69978. +
  69979. + /*
  69980. + * Set a flag if we're queuing high-bandwidth in slave mode.
  69981. + * The flag prevents any halts to get into the request queue in
  69982. + * the middle of multiple high-bandwidth packets getting queued.
  69983. + */
  69984. + if (!hcd->core_if->dma_enable && qh->channel->multi_count > 1) {
  69985. + hcd->core_if->queuing_high_bandwidth = 1;
  69986. + }
  69987. + status =
  69988. + queue_transaction(hcd, qh->channel,
  69989. + tx_status.b.ptxfspcavail);
  69990. + if (status < 0) {
  69991. + no_fifo_space = 1;
  69992. + break;
  69993. + }
  69994. +
  69995. + /*
  69996. + * In Slave mode, stay on the current transfer until there is
  69997. + * nothing more to do or the high-bandwidth request count is
  69998. + * reached. In DMA mode, only need to queue one request. The
  69999. + * controller automatically handles multiple packets for
  70000. + * high-bandwidth transfers.
  70001. + */
  70002. + if (hcd->core_if->dma_enable || status == 0 ||
  70003. + qh->channel->requests == qh->channel->multi_count) {
  70004. + qh_ptr = qh_ptr->next;
  70005. + /*
  70006. + * Move the QH from the periodic assigned schedule to
  70007. + * the periodic queued schedule.
  70008. + */
  70009. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_queued,
  70010. + &qh->qh_list_entry);
  70011. +
  70012. + /* done queuing high bandwidth */
  70013. + hcd->core_if->queuing_high_bandwidth = 0;
  70014. + }
  70015. + }
  70016. +
  70017. + if (!hcd->core_if->dma_enable) {
  70018. + dwc_otg_core_global_regs_t *global_regs;
  70019. + gintmsk_data_t intr_mask = {.d32 = 0 };
  70020. +
  70021. + global_regs = hcd->core_if->core_global_regs;
  70022. + intr_mask.b.ptxfempty = 1;
  70023. +#ifdef DEBUG
  70024. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  70025. + DWC_DEBUGPL(DBG_HCDV,
  70026. + " P Tx Req Queue Space Avail (after queue): %d\n",
  70027. + tx_status.b.ptxqspcavail);
  70028. + DWC_DEBUGPL(DBG_HCDV,
  70029. + " P Tx FIFO Space Avail (after queue): %d\n",
  70030. + tx_status.b.ptxfspcavail);
  70031. +#endif
  70032. + if (!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned) ||
  70033. + no_queue_space || no_fifo_space) {
  70034. + /*
  70035. + * May need to queue more transactions as the request
  70036. + * queue or Tx FIFO empties. Enable the periodic Tx
  70037. + * FIFO empty interrupt. (Always use the half-empty
  70038. + * level to ensure that new requests are loaded as
  70039. + * soon as possible.)
  70040. + */
  70041. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  70042. + intr_mask.d32);
  70043. + } else {
  70044. + /*
  70045. + * Disable the Tx FIFO empty interrupt since there are
  70046. + * no more transactions that need to be queued right
  70047. + * now. This function is called from interrupt
  70048. + * handlers to queue more transactions as transfer
  70049. + * states change.
  70050. + */
  70051. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  70052. + 0);
  70053. + }
  70054. + }
  70055. +}
  70056. +
  70057. +/**
  70058. + * Processes active non-periodic channels and queues transactions for these
  70059. + * channels to the DWC_otg controller. After queueing transactions, the NP Tx
  70060. + * FIFO Empty interrupt is enabled if there are more transactions to queue as
  70061. + * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
  70062. + * FIFO Empty interrupt is disabled.
  70063. + */
  70064. +static void process_non_periodic_channels(dwc_otg_hcd_t * hcd)
  70065. +{
  70066. + gnptxsts_data_t tx_status;
  70067. + dwc_list_link_t *orig_qh_ptr;
  70068. + dwc_otg_qh_t *qh;
  70069. + int status;
  70070. + int no_queue_space = 0;
  70071. + int no_fifo_space = 0;
  70072. + int more_to_do = 0;
  70073. +
  70074. + dwc_otg_core_global_regs_t *global_regs =
  70075. + hcd->core_if->core_global_regs;
  70076. +
  70077. + DWC_DEBUGPL(DBG_HCDV, "Queue non-periodic transactions\n");
  70078. +#ifdef DEBUG
  70079. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  70080. + DWC_DEBUGPL(DBG_HCDV,
  70081. + " NP Tx Req Queue Space Avail (before queue): %d\n",
  70082. + tx_status.b.nptxqspcavail);
  70083. + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (before queue): %d\n",
  70084. + tx_status.b.nptxfspcavail);
  70085. +#endif
  70086. + /*
  70087. + * Keep track of the starting point. Skip over the start-of-list
  70088. + * entry.
  70089. + */
  70090. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  70091. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  70092. + }
  70093. + orig_qh_ptr = hcd->non_periodic_qh_ptr;
  70094. +
  70095. + /*
  70096. + * Process once through the active list or until no more space is
  70097. + * available in the request queue or the Tx FIFO.
  70098. + */
  70099. + do {
  70100. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  70101. + if (!hcd->core_if->dma_enable && tx_status.b.nptxqspcavail == 0) {
  70102. + no_queue_space = 1;
  70103. + break;
  70104. + }
  70105. +
  70106. + qh = DWC_LIST_ENTRY(hcd->non_periodic_qh_ptr, dwc_otg_qh_t,
  70107. + qh_list_entry);
  70108. +
  70109. + // Do not send a split start transaction any later than frame .5
  70110. + // non periodic transactions will start immediately in this uframe
  70111. + if(fiq_split_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
  70112. + {
  70113. + g_next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
  70114. + break;
  70115. + }
  70116. +
  70117. + status =
  70118. + queue_transaction(hcd, qh->channel,
  70119. + tx_status.b.nptxfspcavail);
  70120. +
  70121. + if (status > 0) {
  70122. + more_to_do = 1;
  70123. + } else if (status < 0) {
  70124. + no_fifo_space = 1;
  70125. + break;
  70126. + }
  70127. +
  70128. + /* Advance to next QH, skipping start-of-list entry. */
  70129. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  70130. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  70131. + hcd->non_periodic_qh_ptr =
  70132. + hcd->non_periodic_qh_ptr->next;
  70133. + }
  70134. +
  70135. + } while (hcd->non_periodic_qh_ptr != orig_qh_ptr);
  70136. +
  70137. + if (!hcd->core_if->dma_enable) {
  70138. + gintmsk_data_t intr_mask = {.d32 = 0 };
  70139. + intr_mask.b.nptxfempty = 1;
  70140. +
  70141. +#ifdef DEBUG
  70142. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  70143. + DWC_DEBUGPL(DBG_HCDV,
  70144. + " NP Tx Req Queue Space Avail (after queue): %d\n",
  70145. + tx_status.b.nptxqspcavail);
  70146. + DWC_DEBUGPL(DBG_HCDV,
  70147. + " NP Tx FIFO Space Avail (after queue): %d\n",
  70148. + tx_status.b.nptxfspcavail);
  70149. +#endif
  70150. + if (more_to_do || no_queue_space || no_fifo_space) {
  70151. + /*
  70152. + * May need to queue more transactions as the request
  70153. + * queue or Tx FIFO empties. Enable the non-periodic
  70154. + * Tx FIFO empty interrupt. (Always use the half-empty
  70155. + * level to ensure that new requests are loaded as
  70156. + * soon as possible.)
  70157. + */
  70158. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  70159. + intr_mask.d32);
  70160. + } else {
  70161. + /*
  70162. + * Disable the Tx FIFO empty interrupt since there are
  70163. + * no more transactions that need to be queued right
  70164. + * now. This function is called from interrupt
  70165. + * handlers to queue more transactions as transfer
  70166. + * states change.
  70167. + */
  70168. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  70169. + 0);
  70170. + }
  70171. + }
  70172. +}
  70173. +
  70174. +/**
  70175. + * This function processes the currently active host channels and queues
  70176. + * transactions for these channels to the DWC_otg controller. It is called
  70177. + * from HCD interrupt handler functions.
  70178. + *
  70179. + * @param hcd The HCD state structure.
  70180. + * @param tr_type The type(s) of transactions to queue (non-periodic,
  70181. + * periodic, or both).
  70182. + */
  70183. +void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  70184. + dwc_otg_transaction_type_e tr_type)
  70185. +{
  70186. +#ifdef DEBUG_SOF
  70187. + DWC_DEBUGPL(DBG_HCD, "Queue Transactions\n");
  70188. +#endif
  70189. + /* Process host channels associated with periodic transfers. */
  70190. + if ((tr_type == DWC_OTG_TRANSACTION_PERIODIC ||
  70191. + tr_type == DWC_OTG_TRANSACTION_ALL) &&
  70192. + !DWC_LIST_EMPTY(&hcd->periodic_sched_assigned)) {
  70193. +
  70194. + process_periodic_channels(hcd);
  70195. + }
  70196. +
  70197. + /* Process host channels associated with non-periodic transfers. */
  70198. + if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC ||
  70199. + tr_type == DWC_OTG_TRANSACTION_ALL) {
  70200. + if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active)) {
  70201. + process_non_periodic_channels(hcd);
  70202. + } else {
  70203. + /*
  70204. + * Ensure NP Tx FIFO empty interrupt is disabled when
  70205. + * there are no non-periodic transfers to process.
  70206. + */
  70207. + gintmsk_data_t gintmsk = {.d32 = 0 };
  70208. + gintmsk.b.nptxfempty = 1;
  70209. + DWC_MODIFY_REG32(&hcd->core_if->
  70210. + core_global_regs->gintmsk, gintmsk.d32,
  70211. + 0);
  70212. + }
  70213. + }
  70214. +}
  70215. +
  70216. +#ifdef DWC_HS_ELECT_TST
  70217. +/*
  70218. + * Quick and dirty hack to implement the HS Electrical Test
  70219. + * SINGLE_STEP_GET_DEVICE_DESCRIPTOR feature.
  70220. + *
  70221. + * This code was copied from our userspace app "hset". It sends a
  70222. + * Get Device Descriptor control sequence in two parts, first the
  70223. + * Setup packet by itself, followed some time later by the In and
  70224. + * Ack packets. Rather than trying to figure out how to add this
  70225. + * functionality to the normal driver code, we just hijack the
  70226. + * hardware, using these two function to drive the hardware
  70227. + * directly.
  70228. + */
  70229. +
  70230. +static dwc_otg_core_global_regs_t *global_regs;
  70231. +static dwc_otg_host_global_regs_t *hc_global_regs;
  70232. +static dwc_otg_hc_regs_t *hc_regs;
  70233. +static uint32_t *data_fifo;
  70234. +
  70235. +static void do_setup(void)
  70236. +{
  70237. + gintsts_data_t gintsts;
  70238. + hctsiz_data_t hctsiz;
  70239. + hcchar_data_t hcchar;
  70240. + haint_data_t haint;
  70241. + hcint_data_t hcint;
  70242. +
  70243. + /* Enable HAINTs */
  70244. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  70245. +
  70246. + /* Enable HCINTs */
  70247. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  70248. +
  70249. + /* Read GINTSTS */
  70250. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70251. +
  70252. + /* Read HAINT */
  70253. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  70254. +
  70255. + /* Read HCINT */
  70256. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  70257. +
  70258. + /* Read HCCHAR */
  70259. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70260. +
  70261. + /* Clear HCINT */
  70262. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  70263. +
  70264. + /* Clear HAINT */
  70265. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  70266. +
  70267. + /* Clear GINTSTS */
  70268. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70269. +
  70270. + /* Read GINTSTS */
  70271. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70272. +
  70273. + /*
  70274. + * Send Setup packet (Get Device Descriptor)
  70275. + */
  70276. +
  70277. + /* Make sure channel is disabled */
  70278. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70279. + if (hcchar.b.chen) {
  70280. + hcchar.b.chdis = 1;
  70281. +// hcchar.b.chen = 1;
  70282. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  70283. + //sleep(1);
  70284. + dwc_mdelay(1000);
  70285. +
  70286. + /* Read GINTSTS */
  70287. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70288. +
  70289. + /* Read HAINT */
  70290. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  70291. +
  70292. + /* Read HCINT */
  70293. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  70294. +
  70295. + /* Read HCCHAR */
  70296. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70297. +
  70298. + /* Clear HCINT */
  70299. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  70300. +
  70301. + /* Clear HAINT */
  70302. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  70303. +
  70304. + /* Clear GINTSTS */
  70305. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70306. +
  70307. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70308. + }
  70309. +
  70310. + /* Set HCTSIZ */
  70311. + hctsiz.d32 = 0;
  70312. + hctsiz.b.xfersize = 8;
  70313. + hctsiz.b.pktcnt = 1;
  70314. + hctsiz.b.pid = DWC_OTG_HC_PID_SETUP;
  70315. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  70316. +
  70317. + /* Set HCCHAR */
  70318. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70319. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  70320. + hcchar.b.epdir = 0;
  70321. + hcchar.b.epnum = 0;
  70322. + hcchar.b.mps = 8;
  70323. + hcchar.b.chen = 1;
  70324. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  70325. +
  70326. + /* Fill FIFO with Setup data for Get Device Descriptor */
  70327. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  70328. + DWC_WRITE_REG32(data_fifo++, 0x01000680);
  70329. + DWC_WRITE_REG32(data_fifo++, 0x00080000);
  70330. +
  70331. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70332. +
  70333. + /* Wait for host channel interrupt */
  70334. + do {
  70335. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70336. + } while (gintsts.b.hcintr == 0);
  70337. +
  70338. + /* Disable HCINTs */
  70339. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  70340. +
  70341. + /* Disable HAINTs */
  70342. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  70343. +
  70344. + /* Read HAINT */
  70345. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  70346. +
  70347. + /* Read HCINT */
  70348. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  70349. +
  70350. + /* Read HCCHAR */
  70351. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70352. +
  70353. + /* Clear HCINT */
  70354. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  70355. +
  70356. + /* Clear HAINT */
  70357. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  70358. +
  70359. + /* Clear GINTSTS */
  70360. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70361. +
  70362. + /* Read GINTSTS */
  70363. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70364. +}
  70365. +
  70366. +static void do_in_ack(void)
  70367. +{
  70368. + gintsts_data_t gintsts;
  70369. + hctsiz_data_t hctsiz;
  70370. + hcchar_data_t hcchar;
  70371. + haint_data_t haint;
  70372. + hcint_data_t hcint;
  70373. + host_grxsts_data_t grxsts;
  70374. +
  70375. + /* Enable HAINTs */
  70376. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  70377. +
  70378. + /* Enable HCINTs */
  70379. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  70380. +
  70381. + /* Read GINTSTS */
  70382. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70383. +
  70384. + /* Read HAINT */
  70385. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  70386. +
  70387. + /* Read HCINT */
  70388. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  70389. +
  70390. + /* Read HCCHAR */
  70391. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70392. +
  70393. + /* Clear HCINT */
  70394. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  70395. +
  70396. + /* Clear HAINT */
  70397. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  70398. +
  70399. + /* Clear GINTSTS */
  70400. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70401. +
  70402. + /* Read GINTSTS */
  70403. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70404. +
  70405. + /*
  70406. + * Receive Control In packet
  70407. + */
  70408. +
  70409. + /* Make sure channel is disabled */
  70410. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70411. + if (hcchar.b.chen) {
  70412. + hcchar.b.chdis = 1;
  70413. + hcchar.b.chen = 1;
  70414. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  70415. + //sleep(1);
  70416. + dwc_mdelay(1000);
  70417. +
  70418. + /* Read GINTSTS */
  70419. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70420. +
  70421. + /* Read HAINT */
  70422. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  70423. +
  70424. + /* Read HCINT */
  70425. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  70426. +
  70427. + /* Read HCCHAR */
  70428. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70429. +
  70430. + /* Clear HCINT */
  70431. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  70432. +
  70433. + /* Clear HAINT */
  70434. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  70435. +
  70436. + /* Clear GINTSTS */
  70437. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70438. +
  70439. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70440. + }
  70441. +
  70442. + /* Set HCTSIZ */
  70443. + hctsiz.d32 = 0;
  70444. + hctsiz.b.xfersize = 8;
  70445. + hctsiz.b.pktcnt = 1;
  70446. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  70447. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  70448. +
  70449. + /* Set HCCHAR */
  70450. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70451. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  70452. + hcchar.b.epdir = 1;
  70453. + hcchar.b.epnum = 0;
  70454. + hcchar.b.mps = 8;
  70455. + hcchar.b.chen = 1;
  70456. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  70457. +
  70458. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70459. +
  70460. + /* Wait for receive status queue interrupt */
  70461. + do {
  70462. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70463. + } while (gintsts.b.rxstsqlvl == 0);
  70464. +
  70465. + /* Read RXSTS */
  70466. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  70467. +
  70468. + /* Clear RXSTSQLVL in GINTSTS */
  70469. + gintsts.d32 = 0;
  70470. + gintsts.b.rxstsqlvl = 1;
  70471. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70472. +
  70473. + switch (grxsts.b.pktsts) {
  70474. + case DWC_GRXSTS_PKTSTS_IN:
  70475. + /* Read the data into the host buffer */
  70476. + if (grxsts.b.bcnt > 0) {
  70477. + int i;
  70478. + int word_count = (grxsts.b.bcnt + 3) / 4;
  70479. +
  70480. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  70481. +
  70482. + for (i = 0; i < word_count; i++) {
  70483. + (void)DWC_READ_REG32(data_fifo++);
  70484. + }
  70485. + }
  70486. + break;
  70487. +
  70488. + default:
  70489. + break;
  70490. + }
  70491. +
  70492. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70493. +
  70494. + /* Wait for receive status queue interrupt */
  70495. + do {
  70496. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70497. + } while (gintsts.b.rxstsqlvl == 0);
  70498. +
  70499. + /* Read RXSTS */
  70500. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  70501. +
  70502. + /* Clear RXSTSQLVL in GINTSTS */
  70503. + gintsts.d32 = 0;
  70504. + gintsts.b.rxstsqlvl = 1;
  70505. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70506. +
  70507. + switch (grxsts.b.pktsts) {
  70508. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  70509. + break;
  70510. +
  70511. + default:
  70512. + break;
  70513. + }
  70514. +
  70515. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70516. +
  70517. + /* Wait for host channel interrupt */
  70518. + do {
  70519. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70520. + } while (gintsts.b.hcintr == 0);
  70521. +
  70522. + /* Read HAINT */
  70523. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  70524. +
  70525. + /* Read HCINT */
  70526. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  70527. +
  70528. + /* Read HCCHAR */
  70529. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70530. +
  70531. + /* Clear HCINT */
  70532. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  70533. +
  70534. + /* Clear HAINT */
  70535. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  70536. +
  70537. + /* Clear GINTSTS */
  70538. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70539. +
  70540. + /* Read GINTSTS */
  70541. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70542. +
  70543. +// usleep(100000);
  70544. +// mdelay(100);
  70545. + dwc_mdelay(1);
  70546. +
  70547. + /*
  70548. + * Send handshake packet
  70549. + */
  70550. +
  70551. + /* Read HAINT */
  70552. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  70553. +
  70554. + /* Read HCINT */
  70555. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  70556. +
  70557. + /* Read HCCHAR */
  70558. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70559. +
  70560. + /* Clear HCINT */
  70561. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  70562. +
  70563. + /* Clear HAINT */
  70564. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  70565. +
  70566. + /* Clear GINTSTS */
  70567. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70568. +
  70569. + /* Read GINTSTS */
  70570. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70571. +
  70572. + /* Make sure channel is disabled */
  70573. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70574. + if (hcchar.b.chen) {
  70575. + hcchar.b.chdis = 1;
  70576. + hcchar.b.chen = 1;
  70577. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  70578. + //sleep(1);
  70579. + dwc_mdelay(1000);
  70580. +
  70581. + /* Read GINTSTS */
  70582. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70583. +
  70584. + /* Read HAINT */
  70585. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  70586. +
  70587. + /* Read HCINT */
  70588. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  70589. +
  70590. + /* Read HCCHAR */
  70591. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70592. +
  70593. + /* Clear HCINT */
  70594. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  70595. +
  70596. + /* Clear HAINT */
  70597. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  70598. +
  70599. + /* Clear GINTSTS */
  70600. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70601. +
  70602. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70603. + }
  70604. +
  70605. + /* Set HCTSIZ */
  70606. + hctsiz.d32 = 0;
  70607. + hctsiz.b.xfersize = 0;
  70608. + hctsiz.b.pktcnt = 1;
  70609. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  70610. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  70611. +
  70612. + /* Set HCCHAR */
  70613. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70614. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  70615. + hcchar.b.epdir = 0;
  70616. + hcchar.b.epnum = 0;
  70617. + hcchar.b.mps = 8;
  70618. + hcchar.b.chen = 1;
  70619. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  70620. +
  70621. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70622. +
  70623. + /* Wait for host channel interrupt */
  70624. + do {
  70625. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70626. + } while (gintsts.b.hcintr == 0);
  70627. +
  70628. + /* Disable HCINTs */
  70629. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  70630. +
  70631. + /* Disable HAINTs */
  70632. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  70633. +
  70634. + /* Read HAINT */
  70635. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  70636. +
  70637. + /* Read HCINT */
  70638. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  70639. +
  70640. + /* Read HCCHAR */
  70641. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70642. +
  70643. + /* Clear HCINT */
  70644. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  70645. +
  70646. + /* Clear HAINT */
  70647. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  70648. +
  70649. + /* Clear GINTSTS */
  70650. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70651. +
  70652. + /* Read GINTSTS */
  70653. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70654. +}
  70655. +#endif
  70656. +
  70657. +/** Handles hub class-specific requests. */
  70658. +int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  70659. + uint16_t typeReq,
  70660. + uint16_t wValue,
  70661. + uint16_t wIndex, uint8_t * buf, uint16_t wLength)
  70662. +{
  70663. + int retval = 0;
  70664. +
  70665. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  70666. + usb_hub_descriptor_t *hub_desc;
  70667. + hprt0_data_t hprt0 = {.d32 = 0 };
  70668. +
  70669. + uint32_t port_status;
  70670. +
  70671. + switch (typeReq) {
  70672. + case UCR_CLEAR_HUB_FEATURE:
  70673. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70674. + "ClearHubFeature 0x%x\n", wValue);
  70675. + switch (wValue) {
  70676. + case UHF_C_HUB_LOCAL_POWER:
  70677. + case UHF_C_HUB_OVER_CURRENT:
  70678. + /* Nothing required here */
  70679. + break;
  70680. + default:
  70681. + retval = -DWC_E_INVALID;
  70682. + DWC_ERROR("DWC OTG HCD - "
  70683. + "ClearHubFeature request %xh unknown\n",
  70684. + wValue);
  70685. + }
  70686. + break;
  70687. + case UCR_CLEAR_PORT_FEATURE:
  70688. +#ifdef CONFIG_USB_DWC_OTG_LPM
  70689. + if (wValue != UHF_PORT_L1)
  70690. +#endif
  70691. + if (!wIndex || wIndex > 1)
  70692. + goto error;
  70693. +
  70694. + switch (wValue) {
  70695. + case UHF_PORT_ENABLE:
  70696. + DWC_DEBUGPL(DBG_ANY, "DWC OTG HCD HUB CONTROL - "
  70697. + "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
  70698. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70699. + hprt0.b.prtena = 1;
  70700. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70701. + break;
  70702. + case UHF_PORT_SUSPEND:
  70703. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70704. + "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
  70705. +
  70706. + if (core_if->power_down == 2) {
  70707. + dwc_otg_host_hibernation_restore(core_if, 0, 0);
  70708. + } else {
  70709. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  70710. + dwc_mdelay(5);
  70711. +
  70712. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70713. + hprt0.b.prtres = 1;
  70714. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70715. + hprt0.b.prtsusp = 0;
  70716. + /* Clear Resume bit */
  70717. + dwc_mdelay(100);
  70718. + hprt0.b.prtres = 0;
  70719. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70720. + }
  70721. + break;
  70722. +#ifdef CONFIG_USB_DWC_OTG_LPM
  70723. + case UHF_PORT_L1:
  70724. + {
  70725. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  70726. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  70727. +
  70728. + lpmcfg.d32 =
  70729. + DWC_READ_REG32(&core_if->
  70730. + core_global_regs->glpmcfg);
  70731. + lpmcfg.b.en_utmi_sleep = 0;
  70732. + lpmcfg.b.hird_thres &= (~(1 << 4));
  70733. + lpmcfg.b.prt_sleep_sts = 1;
  70734. + DWC_WRITE_REG32(&core_if->
  70735. + core_global_regs->glpmcfg,
  70736. + lpmcfg.d32);
  70737. +
  70738. + /* Clear Enbl_L1Gating bit. */
  70739. + pcgcctl.b.enbl_sleep_gating = 1;
  70740. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32,
  70741. + 0);
  70742. +
  70743. + dwc_mdelay(5);
  70744. +
  70745. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70746. + hprt0.b.prtres = 1;
  70747. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  70748. + hprt0.d32);
  70749. + /* This bit will be cleared in wakeup interrupt handle */
  70750. + break;
  70751. + }
  70752. +#endif
  70753. + case UHF_PORT_POWER:
  70754. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70755. + "ClearPortFeature USB_PORT_FEAT_POWER\n");
  70756. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70757. + hprt0.b.prtpwr = 0;
  70758. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70759. + break;
  70760. + case UHF_PORT_INDICATOR:
  70761. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70762. + "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
  70763. + /* Port inidicator not supported */
  70764. + break;
  70765. + case UHF_C_PORT_CONNECTION:
  70766. + /* Clears drivers internal connect status change
  70767. + * flag */
  70768. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70769. + "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
  70770. + dwc_otg_hcd->flags.b.port_connect_status_change = 0;
  70771. + break;
  70772. + case UHF_C_PORT_RESET:
  70773. + /* Clears the driver's internal Port Reset Change
  70774. + * flag */
  70775. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70776. + "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
  70777. + dwc_otg_hcd->flags.b.port_reset_change = 0;
  70778. + break;
  70779. + case UHF_C_PORT_ENABLE:
  70780. + /* Clears the driver's internal Port
  70781. + * Enable/Disable Change flag */
  70782. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70783. + "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
  70784. + dwc_otg_hcd->flags.b.port_enable_change = 0;
  70785. + break;
  70786. + case UHF_C_PORT_SUSPEND:
  70787. + /* Clears the driver's internal Port Suspend
  70788. + * Change flag, which is set when resume signaling on
  70789. + * the host port is complete */
  70790. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70791. + "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
  70792. + dwc_otg_hcd->flags.b.port_suspend_change = 0;
  70793. + break;
  70794. +#ifdef CONFIG_USB_DWC_OTG_LPM
  70795. + case UHF_C_PORT_L1:
  70796. + dwc_otg_hcd->flags.b.port_l1_change = 0;
  70797. + break;
  70798. +#endif
  70799. + case UHF_C_PORT_OVER_CURRENT:
  70800. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70801. + "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
  70802. + dwc_otg_hcd->flags.b.port_over_current_change = 0;
  70803. + break;
  70804. + default:
  70805. + retval = -DWC_E_INVALID;
  70806. + DWC_ERROR("DWC OTG HCD - "
  70807. + "ClearPortFeature request %xh "
  70808. + "unknown or unsupported\n", wValue);
  70809. + }
  70810. + break;
  70811. + case UCR_GET_HUB_DESCRIPTOR:
  70812. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70813. + "GetHubDescriptor\n");
  70814. + hub_desc = (usb_hub_descriptor_t *) buf;
  70815. + hub_desc->bDescLength = 9;
  70816. + hub_desc->bDescriptorType = 0x29;
  70817. + hub_desc->bNbrPorts = 1;
  70818. + USETW(hub_desc->wHubCharacteristics, 0x08);
  70819. + hub_desc->bPwrOn2PwrGood = 1;
  70820. + hub_desc->bHubContrCurrent = 0;
  70821. + hub_desc->DeviceRemovable[0] = 0;
  70822. + hub_desc->DeviceRemovable[1] = 0xff;
  70823. + break;
  70824. + case UCR_GET_HUB_STATUS:
  70825. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70826. + "GetHubStatus\n");
  70827. + DWC_MEMSET(buf, 0, 4);
  70828. + break;
  70829. + case UCR_GET_PORT_STATUS:
  70830. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70831. + "GetPortStatus wIndex = 0x%04x FLAGS=0x%08x\n",
  70832. + wIndex, dwc_otg_hcd->flags.d32);
  70833. + if (!wIndex || wIndex > 1)
  70834. + goto error;
  70835. +
  70836. + port_status = 0;
  70837. +
  70838. + if (dwc_otg_hcd->flags.b.port_connect_status_change)
  70839. + port_status |= (1 << UHF_C_PORT_CONNECTION);
  70840. +
  70841. + if (dwc_otg_hcd->flags.b.port_enable_change)
  70842. + port_status |= (1 << UHF_C_PORT_ENABLE);
  70843. +
  70844. + if (dwc_otg_hcd->flags.b.port_suspend_change)
  70845. + port_status |= (1 << UHF_C_PORT_SUSPEND);
  70846. +
  70847. + if (dwc_otg_hcd->flags.b.port_l1_change)
  70848. + port_status |= (1 << UHF_C_PORT_L1);
  70849. +
  70850. + if (dwc_otg_hcd->flags.b.port_reset_change) {
  70851. + port_status |= (1 << UHF_C_PORT_RESET);
  70852. + }
  70853. +
  70854. + if (dwc_otg_hcd->flags.b.port_over_current_change) {
  70855. + DWC_WARN("Overcurrent change detected\n");
  70856. + port_status |= (1 << UHF_C_PORT_OVER_CURRENT);
  70857. + }
  70858. +
  70859. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  70860. + /*
  70861. + * The port is disconnected, which means the core is
  70862. + * either in device mode or it soon will be. Just
  70863. + * return 0's for the remainder of the port status
  70864. + * since the port register can't be read if the core
  70865. + * is in device mode.
  70866. + */
  70867. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  70868. + break;
  70869. + }
  70870. +
  70871. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  70872. + DWC_DEBUGPL(DBG_HCDV, " HPRT0: 0x%08x\n", hprt0.d32);
  70873. +
  70874. + if (hprt0.b.prtconnsts)
  70875. + port_status |= (1 << UHF_PORT_CONNECTION);
  70876. +
  70877. + if (hprt0.b.prtena)
  70878. + port_status |= (1 << UHF_PORT_ENABLE);
  70879. +
  70880. + if (hprt0.b.prtsusp)
  70881. + port_status |= (1 << UHF_PORT_SUSPEND);
  70882. +
  70883. + if (hprt0.b.prtovrcurract)
  70884. + port_status |= (1 << UHF_PORT_OVER_CURRENT);
  70885. +
  70886. + if (hprt0.b.prtrst)
  70887. + port_status |= (1 << UHF_PORT_RESET);
  70888. +
  70889. + if (hprt0.b.prtpwr)
  70890. + port_status |= (1 << UHF_PORT_POWER);
  70891. +
  70892. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  70893. + port_status |= (1 << UHF_PORT_HIGH_SPEED);
  70894. + else if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED)
  70895. + port_status |= (1 << UHF_PORT_LOW_SPEED);
  70896. +
  70897. + if (hprt0.b.prttstctl)
  70898. + port_status |= (1 << UHF_PORT_TEST);
  70899. + if (dwc_otg_get_lpm_portsleepstatus(dwc_otg_hcd->core_if)) {
  70900. + port_status |= (1 << UHF_PORT_L1);
  70901. + }
  70902. + /*
  70903. + For Synopsys HW emulation of Power down wkup_control asserts the
  70904. + hreset_n and prst_n on suspned. This causes the HPRT0 to be zero.
  70905. + We intentionally tell the software that port is in L2Suspend state.
  70906. + Only for STE.
  70907. + */
  70908. + if ((core_if->power_down == 2)
  70909. + && (core_if->hibernation_suspend == 1)) {
  70910. + port_status |= (1 << UHF_PORT_SUSPEND);
  70911. + }
  70912. + /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
  70913. +
  70914. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  70915. +
  70916. + break;
  70917. + case UCR_SET_HUB_FEATURE:
  70918. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70919. + "SetHubFeature\n");
  70920. + /* No HUB features supported */
  70921. + break;
  70922. + case UCR_SET_PORT_FEATURE:
  70923. + if (wValue != UHF_PORT_TEST && (!wIndex || wIndex > 1))
  70924. + goto error;
  70925. +
  70926. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  70927. + /*
  70928. + * The port is disconnected, which means the core is
  70929. + * either in device mode or it soon will be. Just
  70930. + * return without doing anything since the port
  70931. + * register can't be written if the core is in device
  70932. + * mode.
  70933. + */
  70934. + break;
  70935. + }
  70936. +
  70937. + switch (wValue) {
  70938. + case UHF_PORT_SUSPEND:
  70939. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70940. + "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
  70941. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) != wIndex) {
  70942. + goto error;
  70943. + }
  70944. + if (core_if->power_down == 2) {
  70945. + int timeout = 300;
  70946. + dwc_irqflags_t flags;
  70947. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  70948. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  70949. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  70950. +#ifdef DWC_DEV_SRPCAP
  70951. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  70952. +#endif
  70953. + DWC_PRINTF("Preparing for complete power-off\n");
  70954. +
  70955. + /* Save registers before hibernation */
  70956. + dwc_otg_save_global_regs(core_if);
  70957. + dwc_otg_save_host_regs(core_if);
  70958. +
  70959. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70960. + hprt0.b.prtsusp = 1;
  70961. + hprt0.b.prtena = 0;
  70962. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70963. + /* Spin hprt0.b.prtsusp to became 1 */
  70964. + do {
  70965. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70966. + if (hprt0.b.prtsusp) {
  70967. + break;
  70968. + }
  70969. + dwc_mdelay(1);
  70970. + } while (--timeout);
  70971. + if (!timeout) {
  70972. + DWC_WARN("Suspend wasn't genereted\n");
  70973. + }
  70974. + dwc_udelay(10);
  70975. +
  70976. + /*
  70977. + * We need to disable interrupts to prevent servicing of any IRQ
  70978. + * during going to hibernation
  70979. + */
  70980. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  70981. + core_if->lx_state = DWC_OTG_L2;
  70982. +#ifdef DWC_DEV_SRPCAP
  70983. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70984. + hprt0.b.prtpwr = 0;
  70985. + hprt0.b.prtena = 0;
  70986. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  70987. + hprt0.d32);
  70988. +#endif
  70989. + gusbcfg.d32 =
  70990. + DWC_READ_REG32(&core_if->core_global_regs->
  70991. + gusbcfg);
  70992. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  70993. + /* ULPI interface */
  70994. + /* Suspend the Phy Clock */
  70995. + pcgcctl.d32 = 0;
  70996. + pcgcctl.b.stoppclk = 1;
  70997. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  70998. + pcgcctl.d32);
  70999. + dwc_udelay(10);
  71000. + gpwrdn.b.pmuactv = 1;
  71001. + DWC_MODIFY_REG32(&core_if->
  71002. + core_global_regs->
  71003. + gpwrdn, 0, gpwrdn.d32);
  71004. + } else {
  71005. + /* UTMI+ Interface */
  71006. + gpwrdn.b.pmuactv = 1;
  71007. + DWC_MODIFY_REG32(&core_if->
  71008. + core_global_regs->
  71009. + gpwrdn, 0, gpwrdn.d32);
  71010. + dwc_udelay(10);
  71011. + pcgcctl.b.stoppclk = 1;
  71012. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  71013. + dwc_udelay(10);
  71014. + }
  71015. +#ifdef DWC_DEV_SRPCAP
  71016. + gpwrdn.d32 = 0;
  71017. + gpwrdn.b.dis_vbus = 1;
  71018. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  71019. + gpwrdn, 0, gpwrdn.d32);
  71020. +#endif
  71021. + gpwrdn.d32 = 0;
  71022. + gpwrdn.b.pmuintsel = 1;
  71023. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  71024. + gpwrdn, 0, gpwrdn.d32);
  71025. + dwc_udelay(10);
  71026. +
  71027. + gpwrdn.d32 = 0;
  71028. +#ifdef DWC_DEV_SRPCAP
  71029. + gpwrdn.b.srp_det_msk = 1;
  71030. +#endif
  71031. + gpwrdn.b.disconn_det_msk = 1;
  71032. + gpwrdn.b.lnstchng_msk = 1;
  71033. + gpwrdn.b.sts_chngint_msk = 1;
  71034. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  71035. + gpwrdn, 0, gpwrdn.d32);
  71036. + dwc_udelay(10);
  71037. +
  71038. + /* Enable Power Down Clamp and all interrupts in GPWRDN */
  71039. + gpwrdn.d32 = 0;
  71040. + gpwrdn.b.pwrdnclmp = 1;
  71041. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  71042. + gpwrdn, 0, gpwrdn.d32);
  71043. + dwc_udelay(10);
  71044. +
  71045. + /* Switch off VDD */
  71046. + gpwrdn.d32 = 0;
  71047. + gpwrdn.b.pwrdnswtch = 1;
  71048. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  71049. + gpwrdn, 0, gpwrdn.d32);
  71050. +
  71051. +#ifdef DWC_DEV_SRPCAP
  71052. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE)
  71053. + {
  71054. + core_if->pwron_timer_started = 1;
  71055. + DWC_TIMER_SCHEDULE(core_if->pwron_timer, 6000 /* 6 secs */ );
  71056. + }
  71057. +#endif
  71058. + /* Save gpwrdn register for further usage if stschng interrupt */
  71059. + core_if->gr_backup->gpwrdn_local =
  71060. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  71061. +
  71062. + /* Set flag to indicate that we are in hibernation */
  71063. + core_if->hibernation_suspend = 1;
  71064. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock,flags);
  71065. +
  71066. + DWC_PRINTF("Host hibernation completed\n");
  71067. + // Exit from case statement
  71068. + break;
  71069. +
  71070. + }
  71071. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) == wIndex &&
  71072. + dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  71073. + gotgctl_data_t gotgctl = {.d32 = 0 };
  71074. + gotgctl.b.hstsethnpen = 1;
  71075. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  71076. + gotgctl, 0, gotgctl.d32);
  71077. + core_if->op_state = A_SUSPEND;
  71078. + }
  71079. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71080. + hprt0.b.prtsusp = 1;
  71081. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71082. + {
  71083. + dwc_irqflags_t flags;
  71084. + /* Update lx_state */
  71085. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  71086. + core_if->lx_state = DWC_OTG_L2;
  71087. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  71088. + }
  71089. + /* Suspend the Phy Clock */
  71090. + {
  71091. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  71092. + pcgcctl.b.stoppclk = 1;
  71093. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  71094. + pcgcctl.d32);
  71095. + dwc_udelay(10);
  71096. + }
  71097. +
  71098. + /* For HNP the bus must be suspended for at least 200ms. */
  71099. + if (dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  71100. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  71101. + pcgcctl.b.stoppclk = 1;
  71102. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  71103. + dwc_mdelay(200);
  71104. + }
  71105. +
  71106. + /** @todo - check how sw can wait for 1 sec to check asesvld??? */
  71107. +#if 0 //vahrama !!!!!!!!!!!!!!!!!!
  71108. + if (core_if->adp_enable) {
  71109. + gotgctl_data_t gotgctl = {.d32 = 0 };
  71110. + gpwrdn_data_t gpwrdn;
  71111. +
  71112. + while (gotgctl.b.asesvld == 1) {
  71113. + gotgctl.d32 =
  71114. + DWC_READ_REG32(&core_if->
  71115. + core_global_regs->
  71116. + gotgctl);
  71117. + dwc_mdelay(100);
  71118. + }
  71119. +
  71120. + /* Enable Power Down Logic */
  71121. + gpwrdn.d32 = 0;
  71122. + gpwrdn.b.pmuactv = 1;
  71123. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  71124. + gpwrdn, 0, gpwrdn.d32);
  71125. +
  71126. + /* Unmask SRP detected interrupt from Power Down Logic */
  71127. + gpwrdn.d32 = 0;
  71128. + gpwrdn.b.srp_det_msk = 1;
  71129. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  71130. + gpwrdn, 0, gpwrdn.d32);
  71131. +
  71132. + dwc_otg_adp_probe_start(core_if);
  71133. + }
  71134. +#endif
  71135. + break;
  71136. + case UHF_PORT_POWER:
  71137. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  71138. + "SetPortFeature - USB_PORT_FEAT_POWER\n");
  71139. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71140. + hprt0.b.prtpwr = 1;
  71141. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71142. + break;
  71143. + case UHF_PORT_RESET:
  71144. + if ((core_if->power_down == 2)
  71145. + && (core_if->hibernation_suspend == 1)) {
  71146. + /* If we are going to exit from Hibernated
  71147. + * state via USB RESET.
  71148. + */
  71149. + dwc_otg_host_hibernation_restore(core_if, 0, 1);
  71150. + } else {
  71151. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71152. +
  71153. + DWC_DEBUGPL(DBG_HCD,
  71154. + "DWC OTG HCD HUB CONTROL - "
  71155. + "SetPortFeature - USB_PORT_FEAT_RESET\n");
  71156. + {
  71157. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  71158. + pcgcctl.b.enbl_sleep_gating = 1;
  71159. + pcgcctl.b.stoppclk = 1;
  71160. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  71161. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  71162. + }
  71163. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71164. + {
  71165. + glpmcfg_data_t lpmcfg;
  71166. + lpmcfg.d32 =
  71167. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  71168. + if (lpmcfg.b.prt_sleep_sts) {
  71169. + lpmcfg.b.en_utmi_sleep = 0;
  71170. + lpmcfg.b.hird_thres &= (~(1 << 4));
  71171. + DWC_WRITE_REG32
  71172. + (&core_if->core_global_regs->glpmcfg,
  71173. + lpmcfg.d32);
  71174. + dwc_mdelay(1);
  71175. + }
  71176. + }
  71177. +#endif
  71178. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71179. + /* Clear suspend bit if resetting from suspended state. */
  71180. + hprt0.b.prtsusp = 0;
  71181. + /* When B-Host the Port reset bit is set in
  71182. + * the Start HCD Callback function, so that
  71183. + * the reset is started within 1ms of the HNP
  71184. + * success interrupt. */
  71185. + if (!dwc_otg_hcd_is_b_host(dwc_otg_hcd)) {
  71186. + hprt0.b.prtpwr = 1;
  71187. + hprt0.b.prtrst = 1;
  71188. + DWC_PRINTF("Indeed it is in host mode hprt0 = %08x\n",hprt0.d32);
  71189. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  71190. + hprt0.d32);
  71191. + }
  71192. + /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
  71193. + dwc_mdelay(60);
  71194. + hprt0.b.prtrst = 0;
  71195. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71196. + core_if->lx_state = DWC_OTG_L0; /* Now back to the on state */
  71197. + }
  71198. + break;
  71199. +#ifdef DWC_HS_ELECT_TST
  71200. + case UHF_PORT_TEST:
  71201. + {
  71202. + uint32_t t;
  71203. + gintmsk_data_t gintmsk;
  71204. +
  71205. + t = (wIndex >> 8); /* MSB wIndex USB */
  71206. + DWC_DEBUGPL(DBG_HCD,
  71207. + "DWC OTG HCD HUB CONTROL - "
  71208. + "SetPortFeature - USB_PORT_FEAT_TEST %d\n",
  71209. + t);
  71210. + DWC_WARN("USB_PORT_FEAT_TEST %d\n", t);
  71211. + if (t < 6) {
  71212. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71213. + hprt0.b.prttstctl = t;
  71214. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  71215. + hprt0.d32);
  71216. + } else {
  71217. + /* Setup global vars with reg addresses (quick and
  71218. + * dirty hack, should be cleaned up)
  71219. + */
  71220. + global_regs = core_if->core_global_regs;
  71221. + hc_global_regs =
  71222. + core_if->host_if->host_global_regs;
  71223. + hc_regs =
  71224. + (dwc_otg_hc_regs_t *) ((char *)
  71225. + global_regs +
  71226. + 0x500);
  71227. + data_fifo =
  71228. + (uint32_t *) ((char *)global_regs +
  71229. + 0x1000);
  71230. +
  71231. + if (t == 6) { /* HS_HOST_PORT_SUSPEND_RESUME */
  71232. + /* Save current interrupt mask */
  71233. + gintmsk.d32 =
  71234. + DWC_READ_REG32
  71235. + (&global_regs->gintmsk);
  71236. +
  71237. + /* Disable all interrupts while we muck with
  71238. + * the hardware directly
  71239. + */
  71240. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  71241. +
  71242. + /* 15 second delay per the test spec */
  71243. + dwc_mdelay(15000);
  71244. +
  71245. + /* Drive suspend on the root port */
  71246. + hprt0.d32 =
  71247. + dwc_otg_read_hprt0(core_if);
  71248. + hprt0.b.prtsusp = 1;
  71249. + hprt0.b.prtres = 0;
  71250. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71251. +
  71252. + /* 15 second delay per the test spec */
  71253. + dwc_mdelay(15000);
  71254. +
  71255. + /* Drive resume on the root port */
  71256. + hprt0.d32 =
  71257. + dwc_otg_read_hprt0(core_if);
  71258. + hprt0.b.prtsusp = 0;
  71259. + hprt0.b.prtres = 1;
  71260. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71261. + dwc_mdelay(100);
  71262. +
  71263. + /* Clear the resume bit */
  71264. + hprt0.b.prtres = 0;
  71265. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71266. +
  71267. + /* Restore interrupts */
  71268. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  71269. + } else if (t == 7) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  71270. + /* Save current interrupt mask */
  71271. + gintmsk.d32 =
  71272. + DWC_READ_REG32
  71273. + (&global_regs->gintmsk);
  71274. +
  71275. + /* Disable all interrupts while we muck with
  71276. + * the hardware directly
  71277. + */
  71278. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  71279. +
  71280. + /* 15 second delay per the test spec */
  71281. + dwc_mdelay(15000);
  71282. +
  71283. + /* Send the Setup packet */
  71284. + do_setup();
  71285. +
  71286. + /* 15 second delay so nothing else happens for awhile */
  71287. + dwc_mdelay(15000);
  71288. +
  71289. + /* Restore interrupts */
  71290. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  71291. + } else if (t == 8) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  71292. + /* Save current interrupt mask */
  71293. + gintmsk.d32 =
  71294. + DWC_READ_REG32
  71295. + (&global_regs->gintmsk);
  71296. +
  71297. + /* Disable all interrupts while we muck with
  71298. + * the hardware directly
  71299. + */
  71300. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  71301. +
  71302. + /* Send the Setup packet */
  71303. + do_setup();
  71304. +
  71305. + /* 15 second delay so nothing else happens for awhile */
  71306. + dwc_mdelay(15000);
  71307. +
  71308. + /* Send the In and Ack packets */
  71309. + do_in_ack();
  71310. +
  71311. + /* 15 second delay so nothing else happens for awhile */
  71312. + dwc_mdelay(15000);
  71313. +
  71314. + /* Restore interrupts */
  71315. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  71316. + }
  71317. + }
  71318. + break;
  71319. + }
  71320. +#endif /* DWC_HS_ELECT_TST */
  71321. +
  71322. + case UHF_PORT_INDICATOR:
  71323. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  71324. + "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
  71325. + /* Not supported */
  71326. + break;
  71327. + default:
  71328. + retval = -DWC_E_INVALID;
  71329. + DWC_ERROR("DWC OTG HCD - "
  71330. + "SetPortFeature request %xh "
  71331. + "unknown or unsupported\n", wValue);
  71332. + break;
  71333. + }
  71334. + break;
  71335. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71336. + case UCR_SET_AND_TEST_PORT_FEATURE:
  71337. + if (wValue != UHF_PORT_L1) {
  71338. + goto error;
  71339. + }
  71340. + {
  71341. + int portnum, hird, devaddr, remwake;
  71342. + glpmcfg_data_t lpmcfg;
  71343. + uint32_t time_usecs;
  71344. + gintsts_data_t gintsts;
  71345. + gintmsk_data_t gintmsk;
  71346. +
  71347. + if (!dwc_otg_get_param_lpm_enable(core_if)) {
  71348. + goto error;
  71349. + }
  71350. + if (wValue != UHF_PORT_L1 || wLength != 1) {
  71351. + goto error;
  71352. + }
  71353. + /* Check if the port currently is in SLEEP state */
  71354. + lpmcfg.d32 =
  71355. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  71356. + if (lpmcfg.b.prt_sleep_sts) {
  71357. + DWC_INFO("Port is already in sleep mode\n");
  71358. + buf[0] = 0; /* Return success */
  71359. + break;
  71360. + }
  71361. +
  71362. + portnum = wIndex & 0xf;
  71363. + hird = (wIndex >> 4) & 0xf;
  71364. + devaddr = (wIndex >> 8) & 0x7f;
  71365. + remwake = (wIndex >> 15);
  71366. +
  71367. + if (portnum != 1) {
  71368. + retval = -DWC_E_INVALID;
  71369. + DWC_WARN
  71370. + ("Wrong port number(%d) in SetandTestPortFeature request\n",
  71371. + portnum);
  71372. + break;
  71373. + }
  71374. +
  71375. + DWC_PRINTF
  71376. + ("SetandTestPortFeature request: portnum = %d, hird = %d, devaddr = %d, rewake = %d\n",
  71377. + portnum, hird, devaddr, remwake);
  71378. + /* Disable LPM interrupt */
  71379. + gintmsk.d32 = 0;
  71380. + gintmsk.b.lpmtranrcvd = 1;
  71381. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  71382. + gintmsk.d32, 0);
  71383. +
  71384. + if (dwc_otg_hcd_send_lpm
  71385. + (dwc_otg_hcd, devaddr, hird, remwake)) {
  71386. + retval = -DWC_E_INVALID;
  71387. + break;
  71388. + }
  71389. +
  71390. + time_usecs = 10 * (lpmcfg.b.retry_count + 1);
  71391. + /* We will consider timeout if time_usecs microseconds pass,
  71392. + * and we don't receive LPM transaction status.
  71393. + * After receiving non-error responce(ACK/NYET/STALL) from device,
  71394. + * core will set lpmtranrcvd bit.
  71395. + */
  71396. + do {
  71397. + gintsts.d32 =
  71398. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  71399. + if (gintsts.b.lpmtranrcvd) {
  71400. + break;
  71401. + }
  71402. + dwc_udelay(1);
  71403. + } while (--time_usecs);
  71404. + /* lpm_int bit will be cleared in LPM interrupt handler */
  71405. +
  71406. + /* Now fill status
  71407. + * 0x00 - Success
  71408. + * 0x10 - NYET
  71409. + * 0x11 - Timeout
  71410. + */
  71411. + if (!gintsts.b.lpmtranrcvd) {
  71412. + buf[0] = 0x3; /* Completion code is Timeout */
  71413. + dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd);
  71414. + } else {
  71415. + lpmcfg.d32 =
  71416. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  71417. + if (lpmcfg.b.lpm_resp == 0x3) {
  71418. + /* ACK responce from the device */
  71419. + buf[0] = 0x00; /* Success */
  71420. + } else if (lpmcfg.b.lpm_resp == 0x2) {
  71421. + /* NYET responce from the device */
  71422. + buf[0] = 0x2;
  71423. + } else {
  71424. + /* Otherwise responce with Timeout */
  71425. + buf[0] = 0x3;
  71426. + }
  71427. + }
  71428. + DWC_PRINTF("Device responce to LPM trans is %x\n",
  71429. + lpmcfg.b.lpm_resp);
  71430. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0,
  71431. + gintmsk.d32);
  71432. +
  71433. + break;
  71434. + }
  71435. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  71436. + default:
  71437. +error:
  71438. + retval = -DWC_E_INVALID;
  71439. + DWC_WARN("DWC OTG HCD - "
  71440. + "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
  71441. + typeReq, wIndex, wValue);
  71442. + break;
  71443. + }
  71444. +
  71445. + return retval;
  71446. +}
  71447. +
  71448. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71449. +/** Returns index of host channel to perform LPM transaction. */
  71450. +int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd, uint8_t devaddr)
  71451. +{
  71452. + dwc_otg_core_if_t *core_if = hcd->core_if;
  71453. + dwc_hc_t *hc;
  71454. + hcchar_data_t hcchar;
  71455. + gintmsk_data_t gintmsk = {.d32 = 0 };
  71456. +
  71457. + if (DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  71458. + DWC_PRINTF("No free channel to select for LPM transaction\n");
  71459. + return -1;
  71460. + }
  71461. +
  71462. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  71463. +
  71464. + /* Mask host channel interrupts. */
  71465. + gintmsk.b.hcintr = 1;
  71466. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  71467. +
  71468. + /* Fill fields that core needs for LPM transaction */
  71469. + hcchar.b.devaddr = devaddr;
  71470. + hcchar.b.epnum = 0;
  71471. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  71472. + hcchar.b.mps = 64;
  71473. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  71474. + hcchar.b.epdir = 0; /* OUT */
  71475. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[hc->hc_num]->hcchar,
  71476. + hcchar.d32);
  71477. +
  71478. + /* Remove the host channel from the free list. */
  71479. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  71480. +
  71481. + DWC_PRINTF("hcnum = %d devaddr = %d\n", hc->hc_num, devaddr);
  71482. +
  71483. + return hc->hc_num;
  71484. +}
  71485. +
  71486. +/** Release hc after performing LPM transaction */
  71487. +void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd)
  71488. +{
  71489. + dwc_hc_t *hc;
  71490. + glpmcfg_data_t lpmcfg;
  71491. + uint8_t hc_num;
  71492. +
  71493. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  71494. + hc_num = lpmcfg.b.lpm_chan_index;
  71495. +
  71496. + hc = hcd->hc_ptr_array[hc_num];
  71497. +
  71498. + DWC_PRINTF("Freeing channel %d after LPM\n", hc_num);
  71499. + /* Return host channel to free list */
  71500. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  71501. +}
  71502. +
  71503. +int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr, uint8_t hird,
  71504. + uint8_t bRemoteWake)
  71505. +{
  71506. + glpmcfg_data_t lpmcfg;
  71507. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  71508. + int channel;
  71509. +
  71510. + channel = dwc_otg_hcd_get_hc_for_lpm_tran(hcd, devaddr);
  71511. + if (channel < 0) {
  71512. + return channel;
  71513. + }
  71514. +
  71515. + pcgcctl.b.enbl_sleep_gating = 1;
  71516. + DWC_MODIFY_REG32(hcd->core_if->pcgcctl, 0, pcgcctl.d32);
  71517. +
  71518. + /* Read LPM config register */
  71519. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  71520. +
  71521. + /* Program LPM transaction fields */
  71522. + lpmcfg.b.rem_wkup_en = bRemoteWake;
  71523. + lpmcfg.b.hird = hird;
  71524. + lpmcfg.b.hird_thres = 0x1c;
  71525. + lpmcfg.b.lpm_chan_index = channel;
  71526. + lpmcfg.b.en_utmi_sleep = 1;
  71527. + /* Program LPM config register */
  71528. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  71529. +
  71530. + /* Send LPM transaction */
  71531. + lpmcfg.b.send_lpm = 1;
  71532. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  71533. +
  71534. + return 0;
  71535. +}
  71536. +
  71537. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  71538. +
  71539. +int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port)
  71540. +{
  71541. + int retval;
  71542. +
  71543. + if (port != 1) {
  71544. + return -DWC_E_INVALID;
  71545. + }
  71546. +
  71547. + retval = (hcd->flags.b.port_connect_status_change ||
  71548. + hcd->flags.b.port_reset_change ||
  71549. + hcd->flags.b.port_enable_change ||
  71550. + hcd->flags.b.port_suspend_change ||
  71551. + hcd->flags.b.port_over_current_change);
  71552. +#ifdef DEBUG
  71553. + if (retval) {
  71554. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB STATUS DATA:"
  71555. + " Root port status changed\n");
  71556. + DWC_DEBUGPL(DBG_HCDV, " port_connect_status_change: %d\n",
  71557. + hcd->flags.b.port_connect_status_change);
  71558. + DWC_DEBUGPL(DBG_HCDV, " port_reset_change: %d\n",
  71559. + hcd->flags.b.port_reset_change);
  71560. + DWC_DEBUGPL(DBG_HCDV, " port_enable_change: %d\n",
  71561. + hcd->flags.b.port_enable_change);
  71562. + DWC_DEBUGPL(DBG_HCDV, " port_suspend_change: %d\n",
  71563. + hcd->flags.b.port_suspend_change);
  71564. + DWC_DEBUGPL(DBG_HCDV, " port_over_current_change: %d\n",
  71565. + hcd->flags.b.port_over_current_change);
  71566. + }
  71567. +#endif
  71568. + return retval;
  71569. +}
  71570. +
  71571. +int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * dwc_otg_hcd)
  71572. +{
  71573. + hfnum_data_t hfnum;
  71574. + hfnum.d32 =
  71575. + DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->
  71576. + hfnum);
  71577. +
  71578. +#ifdef DEBUG_SOF
  71579. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD GET FRAME NUMBER %d\n",
  71580. + hfnum.b.frnum);
  71581. +#endif
  71582. + return hfnum.b.frnum;
  71583. +}
  71584. +
  71585. +int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  71586. + struct dwc_otg_hcd_function_ops *fops)
  71587. +{
  71588. + int retval = 0;
  71589. +
  71590. + hcd->fops = fops;
  71591. + if (!dwc_otg_is_device_mode(hcd->core_if) &&
  71592. + (!hcd->core_if->adp_enable || hcd->core_if->adp.adp_started)) {
  71593. + dwc_otg_hcd_reinit(hcd);
  71594. + } else {
  71595. + retval = -DWC_E_NO_DEVICE;
  71596. + }
  71597. +
  71598. + return retval;
  71599. +}
  71600. +
  71601. +void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd)
  71602. +{
  71603. + return hcd->priv;
  71604. +}
  71605. +
  71606. +void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data)
  71607. +{
  71608. + hcd->priv = priv_data;
  71609. +}
  71610. +
  71611. +uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd)
  71612. +{
  71613. + return hcd->otg_port;
  71614. +}
  71615. +
  71616. +uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd)
  71617. +{
  71618. + uint32_t is_b_host;
  71619. + if (hcd->core_if->op_state == B_HOST) {
  71620. + is_b_host = 1;
  71621. + } else {
  71622. + is_b_host = 0;
  71623. + }
  71624. +
  71625. + return is_b_host;
  71626. +}
  71627. +
  71628. +dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  71629. + int iso_desc_count, int atomic_alloc)
  71630. +{
  71631. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  71632. + uint32_t size;
  71633. +
  71634. + size =
  71635. + sizeof(*dwc_otg_urb) +
  71636. + iso_desc_count * sizeof(struct dwc_otg_hcd_iso_packet_desc);
  71637. + if (atomic_alloc)
  71638. + dwc_otg_urb = DWC_ALLOC_ATOMIC(size);
  71639. + else
  71640. + dwc_otg_urb = DWC_ALLOC(size);
  71641. +
  71642. + if (dwc_otg_urb)
  71643. + dwc_otg_urb->packet_count = iso_desc_count;
  71644. + else {
  71645. + DWC_ERROR("**** DWC OTG HCD URB alloc - "
  71646. + "%salloc of %db failed\n",
  71647. + atomic_alloc?"atomic ":"", size);
  71648. + }
  71649. + return dwc_otg_urb;
  71650. +}
  71651. +
  71652. +void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * dwc_otg_urb,
  71653. + uint8_t dev_addr, uint8_t ep_num,
  71654. + uint8_t ep_type, uint8_t ep_dir, uint16_t mps)
  71655. +{
  71656. + dwc_otg_hcd_fill_pipe(&dwc_otg_urb->pipe_info, dev_addr, ep_num,
  71657. + ep_type, ep_dir, mps);
  71658. +#if 0
  71659. + DWC_PRINTF
  71660. + ("addr = %d, ep_num = %d, ep_dir = 0x%x, ep_type = 0x%x, mps = %d\n",
  71661. + dev_addr, ep_num, ep_dir, ep_type, mps);
  71662. +#endif
  71663. +}
  71664. +
  71665. +void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  71666. + void *urb_handle, void *buf, dwc_dma_t dma,
  71667. + uint32_t buflen, void *setup_packet,
  71668. + dwc_dma_t setup_dma, uint32_t flags,
  71669. + uint16_t interval)
  71670. +{
  71671. + dwc_otg_urb->priv = urb_handle;
  71672. + dwc_otg_urb->buf = buf;
  71673. + dwc_otg_urb->dma = dma;
  71674. + dwc_otg_urb->length = buflen;
  71675. + dwc_otg_urb->setup_packet = setup_packet;
  71676. + dwc_otg_urb->setup_dma = setup_dma;
  71677. + dwc_otg_urb->flags = flags;
  71678. + dwc_otg_urb->interval = interval;
  71679. + dwc_otg_urb->status = -DWC_E_IN_PROGRESS;
  71680. +}
  71681. +
  71682. +uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb)
  71683. +{
  71684. + return dwc_otg_urb->status;
  71685. +}
  71686. +
  71687. +uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t * dwc_otg_urb)
  71688. +{
  71689. + return dwc_otg_urb->actual_length;
  71690. +}
  71691. +
  71692. +uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t * dwc_otg_urb)
  71693. +{
  71694. + return dwc_otg_urb->error_count;
  71695. +}
  71696. +
  71697. +void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  71698. + int desc_num, uint32_t offset,
  71699. + uint32_t length)
  71700. +{
  71701. + dwc_otg_urb->iso_descs[desc_num].offset = offset;
  71702. + dwc_otg_urb->iso_descs[desc_num].length = length;
  71703. +}
  71704. +
  71705. +uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t * dwc_otg_urb,
  71706. + int desc_num)
  71707. +{
  71708. + return dwc_otg_urb->iso_descs[desc_num].status;
  71709. +}
  71710. +
  71711. +uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  71712. + dwc_otg_urb, int desc_num)
  71713. +{
  71714. + return dwc_otg_urb->iso_descs[desc_num].actual_length;
  71715. +}
  71716. +
  71717. +int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd, void *ep_handle)
  71718. +{
  71719. + int allocated = 0;
  71720. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  71721. +
  71722. + if (qh) {
  71723. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  71724. + allocated = 1;
  71725. + }
  71726. + }
  71727. + return allocated;
  71728. +}
  71729. +
  71730. +int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle)
  71731. +{
  71732. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  71733. + int freed = 0;
  71734. + DWC_ASSERT(qh, "qh is not allocated\n");
  71735. +
  71736. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  71737. + freed = 1;
  71738. + }
  71739. +
  71740. + return freed;
  71741. +}
  71742. +
  71743. +uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd, void *ep_handle)
  71744. +{
  71745. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  71746. + DWC_ASSERT(qh, "qh is not allocated\n");
  71747. + return qh->usecs;
  71748. +}
  71749. +
  71750. +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd)
  71751. +{
  71752. +#ifdef DEBUG
  71753. + int num_channels;
  71754. + int i;
  71755. + gnptxsts_data_t np_tx_status;
  71756. + hptxsts_data_t p_tx_status;
  71757. +
  71758. + num_channels = hcd->core_if->core_params->host_channels;
  71759. + DWC_PRINTF("\n");
  71760. + DWC_PRINTF
  71761. + ("************************************************************\n");
  71762. + DWC_PRINTF("HCD State:\n");
  71763. + DWC_PRINTF(" Num channels: %d\n", num_channels);
  71764. + for (i = 0; i < num_channels; i++) {
  71765. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  71766. + DWC_PRINTF(" Channel %d:\n", i);
  71767. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  71768. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  71769. + DWC_PRINTF(" speed: %d\n", hc->speed);
  71770. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  71771. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  71772. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  71773. + DWC_PRINTF(" multi_count: %d\n", hc->multi_count);
  71774. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  71775. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  71776. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  71777. + DWC_PRINTF(" xfer_count: %d\n", hc->xfer_count);
  71778. + DWC_PRINTF(" halt_on_queue: %d\n", hc->halt_on_queue);
  71779. + DWC_PRINTF(" halt_pending: %d\n", hc->halt_pending);
  71780. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  71781. + DWC_PRINTF(" do_split: %d\n", hc->do_split);
  71782. + DWC_PRINTF(" complete_split: %d\n", hc->complete_split);
  71783. + DWC_PRINTF(" hub_addr: %d\n", hc->hub_addr);
  71784. + DWC_PRINTF(" port_addr: %d\n", hc->port_addr);
  71785. + DWC_PRINTF(" xact_pos: %d\n", hc->xact_pos);
  71786. + DWC_PRINTF(" requests: %d\n", hc->requests);
  71787. + DWC_PRINTF(" qh: %p\n", hc->qh);
  71788. + if (hc->xfer_started) {
  71789. + hfnum_data_t hfnum;
  71790. + hcchar_data_t hcchar;
  71791. + hctsiz_data_t hctsiz;
  71792. + hcint_data_t hcint;
  71793. + hcintmsk_data_t hcintmsk;
  71794. + hfnum.d32 =
  71795. + DWC_READ_REG32(&hcd->core_if->
  71796. + host_if->host_global_regs->hfnum);
  71797. + hcchar.d32 =
  71798. + DWC_READ_REG32(&hcd->core_if->host_if->
  71799. + hc_regs[i]->hcchar);
  71800. + hctsiz.d32 =
  71801. + DWC_READ_REG32(&hcd->core_if->host_if->
  71802. + hc_regs[i]->hctsiz);
  71803. + hcint.d32 =
  71804. + DWC_READ_REG32(&hcd->core_if->host_if->
  71805. + hc_regs[i]->hcint);
  71806. + hcintmsk.d32 =
  71807. + DWC_READ_REG32(&hcd->core_if->host_if->
  71808. + hc_regs[i]->hcintmsk);
  71809. + DWC_PRINTF(" hfnum: 0x%08x\n", hfnum.d32);
  71810. + DWC_PRINTF(" hcchar: 0x%08x\n", hcchar.d32);
  71811. + DWC_PRINTF(" hctsiz: 0x%08x\n", hctsiz.d32);
  71812. + DWC_PRINTF(" hcint: 0x%08x\n", hcint.d32);
  71813. + DWC_PRINTF(" hcintmsk: 0x%08x\n", hcintmsk.d32);
  71814. + }
  71815. + if (hc->xfer_started && hc->qh) {
  71816. + dwc_otg_qtd_t *qtd;
  71817. + dwc_otg_hcd_urb_t *urb;
  71818. +
  71819. + DWC_CIRCLEQ_FOREACH(qtd, &hc->qh->qtd_list, qtd_list_entry) {
  71820. + if (!qtd->in_process)
  71821. + break;
  71822. +
  71823. + urb = qtd->urb;
  71824. + DWC_PRINTF(" URB Info:\n");
  71825. + DWC_PRINTF(" qtd: %p, urb: %p\n", qtd, urb);
  71826. + if (urb) {
  71827. + DWC_PRINTF(" Dev: %d, EP: %d %s\n",
  71828. + dwc_otg_hcd_get_dev_addr(&urb->
  71829. + pipe_info),
  71830. + dwc_otg_hcd_get_ep_num(&urb->
  71831. + pipe_info),
  71832. + dwc_otg_hcd_is_pipe_in(&urb->
  71833. + pipe_info) ?
  71834. + "IN" : "OUT");
  71835. + DWC_PRINTF(" Max packet size: %d\n",
  71836. + dwc_otg_hcd_get_mps(&urb->
  71837. + pipe_info));
  71838. + DWC_PRINTF(" transfer_buffer: %p\n",
  71839. + urb->buf);
  71840. + DWC_PRINTF(" transfer_dma: %p\n",
  71841. + (void *)urb->dma);
  71842. + DWC_PRINTF(" transfer_buffer_length: %d\n",
  71843. + urb->length);
  71844. + DWC_PRINTF(" actual_length: %d\n",
  71845. + urb->actual_length);
  71846. + }
  71847. + }
  71848. + }
  71849. + }
  71850. + DWC_PRINTF(" non_periodic_channels: %d\n", hcd->non_periodic_channels);
  71851. + DWC_PRINTF(" periodic_channels: %d\n", hcd->periodic_channels);
  71852. + DWC_PRINTF(" periodic_usecs: %d\n", hcd->periodic_usecs);
  71853. + np_tx_status.d32 =
  71854. + DWC_READ_REG32(&hcd->core_if->core_global_regs->gnptxsts);
  71855. + DWC_PRINTF(" NP Tx Req Queue Space Avail: %d\n",
  71856. + np_tx_status.b.nptxqspcavail);
  71857. + DWC_PRINTF(" NP Tx FIFO Space Avail: %d\n",
  71858. + np_tx_status.b.nptxfspcavail);
  71859. + p_tx_status.d32 =
  71860. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hptxsts);
  71861. + DWC_PRINTF(" P Tx Req Queue Space Avail: %d\n",
  71862. + p_tx_status.b.ptxqspcavail);
  71863. + DWC_PRINTF(" P Tx FIFO Space Avail: %d\n", p_tx_status.b.ptxfspcavail);
  71864. + dwc_otg_hcd_dump_frrem(hcd);
  71865. + dwc_otg_dump_global_registers(hcd->core_if);
  71866. + dwc_otg_dump_host_registers(hcd->core_if);
  71867. + DWC_PRINTF
  71868. + ("************************************************************\n");
  71869. + DWC_PRINTF("\n");
  71870. +#endif
  71871. +}
  71872. +
  71873. +#ifdef DEBUG
  71874. +void dwc_print_setup_data(uint8_t * setup)
  71875. +{
  71876. + int i;
  71877. + if (CHK_DEBUG_LEVEL(DBG_HCD)) {
  71878. + DWC_PRINTF("Setup Data = MSB ");
  71879. + for (i = 7; i >= 0; i--)
  71880. + DWC_PRINTF("%02x ", setup[i]);
  71881. + DWC_PRINTF("\n");
  71882. + DWC_PRINTF(" bmRequestType Tranfer = %s\n",
  71883. + (setup[0] & 0x80) ? "Device-to-Host" :
  71884. + "Host-to-Device");
  71885. + DWC_PRINTF(" bmRequestType Type = ");
  71886. + switch ((setup[0] & 0x60) >> 5) {
  71887. + case 0:
  71888. + DWC_PRINTF("Standard\n");
  71889. + break;
  71890. + case 1:
  71891. + DWC_PRINTF("Class\n");
  71892. + break;
  71893. + case 2:
  71894. + DWC_PRINTF("Vendor\n");
  71895. + break;
  71896. + case 3:
  71897. + DWC_PRINTF("Reserved\n");
  71898. + break;
  71899. + }
  71900. + DWC_PRINTF(" bmRequestType Recipient = ");
  71901. + switch (setup[0] & 0x1f) {
  71902. + case 0:
  71903. + DWC_PRINTF("Device\n");
  71904. + break;
  71905. + case 1:
  71906. + DWC_PRINTF("Interface\n");
  71907. + break;
  71908. + case 2:
  71909. + DWC_PRINTF("Endpoint\n");
  71910. + break;
  71911. + case 3:
  71912. + DWC_PRINTF("Other\n");
  71913. + break;
  71914. + default:
  71915. + DWC_PRINTF("Reserved\n");
  71916. + break;
  71917. + }
  71918. + DWC_PRINTF(" bRequest = 0x%0x\n", setup[1]);
  71919. + DWC_PRINTF(" wValue = 0x%0x\n", *((uint16_t *) & setup[2]));
  71920. + DWC_PRINTF(" wIndex = 0x%0x\n", *((uint16_t *) & setup[4]));
  71921. + DWC_PRINTF(" wLength = 0x%0x\n\n", *((uint16_t *) & setup[6]));
  71922. + }
  71923. +}
  71924. +#endif
  71925. +
  71926. +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd)
  71927. +{
  71928. +#if 0
  71929. + DWC_PRINTF("Frame remaining at SOF:\n");
  71930. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71931. + hcd->frrem_samples, hcd->frrem_accum,
  71932. + (hcd->frrem_samples > 0) ?
  71933. + hcd->frrem_accum / hcd->frrem_samples : 0);
  71934. +
  71935. + DWC_PRINTF("\n");
  71936. + DWC_PRINTF("Frame remaining at start_transfer (uframe 7):\n");
  71937. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71938. + hcd->core_if->hfnum_7_samples,
  71939. + hcd->core_if->hfnum_7_frrem_accum,
  71940. + (hcd->core_if->hfnum_7_samples >
  71941. + 0) ? hcd->core_if->hfnum_7_frrem_accum /
  71942. + hcd->core_if->hfnum_7_samples : 0);
  71943. + DWC_PRINTF("Frame remaining at start_transfer (uframe 0):\n");
  71944. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71945. + hcd->core_if->hfnum_0_samples,
  71946. + hcd->core_if->hfnum_0_frrem_accum,
  71947. + (hcd->core_if->hfnum_0_samples >
  71948. + 0) ? hcd->core_if->hfnum_0_frrem_accum /
  71949. + hcd->core_if->hfnum_0_samples : 0);
  71950. + DWC_PRINTF("Frame remaining at start_transfer (uframe 1-6):\n");
  71951. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71952. + hcd->core_if->hfnum_other_samples,
  71953. + hcd->core_if->hfnum_other_frrem_accum,
  71954. + (hcd->core_if->hfnum_other_samples >
  71955. + 0) ? hcd->core_if->hfnum_other_frrem_accum /
  71956. + hcd->core_if->hfnum_other_samples : 0);
  71957. +
  71958. + DWC_PRINTF("\n");
  71959. + DWC_PRINTF("Frame remaining at sample point A (uframe 7):\n");
  71960. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71961. + hcd->hfnum_7_samples_a, hcd->hfnum_7_frrem_accum_a,
  71962. + (hcd->hfnum_7_samples_a > 0) ?
  71963. + hcd->hfnum_7_frrem_accum_a / hcd->hfnum_7_samples_a : 0);
  71964. + DWC_PRINTF("Frame remaining at sample point A (uframe 0):\n");
  71965. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71966. + hcd->hfnum_0_samples_a, hcd->hfnum_0_frrem_accum_a,
  71967. + (hcd->hfnum_0_samples_a > 0) ?
  71968. + hcd->hfnum_0_frrem_accum_a / hcd->hfnum_0_samples_a : 0);
  71969. + DWC_PRINTF("Frame remaining at sample point A (uframe 1-6):\n");
  71970. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71971. + hcd->hfnum_other_samples_a, hcd->hfnum_other_frrem_accum_a,
  71972. + (hcd->hfnum_other_samples_a > 0) ?
  71973. + hcd->hfnum_other_frrem_accum_a /
  71974. + hcd->hfnum_other_samples_a : 0);
  71975. +
  71976. + DWC_PRINTF("\n");
  71977. + DWC_PRINTF("Frame remaining at sample point B (uframe 7):\n");
  71978. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71979. + hcd->hfnum_7_samples_b, hcd->hfnum_7_frrem_accum_b,
  71980. + (hcd->hfnum_7_samples_b > 0) ?
  71981. + hcd->hfnum_7_frrem_accum_b / hcd->hfnum_7_samples_b : 0);
  71982. + DWC_PRINTF("Frame remaining at sample point B (uframe 0):\n");
  71983. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71984. + hcd->hfnum_0_samples_b, hcd->hfnum_0_frrem_accum_b,
  71985. + (hcd->hfnum_0_samples_b > 0) ?
  71986. + hcd->hfnum_0_frrem_accum_b / hcd->hfnum_0_samples_b : 0);
  71987. + DWC_PRINTF("Frame remaining at sample point B (uframe 1-6):\n");
  71988. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71989. + hcd->hfnum_other_samples_b, hcd->hfnum_other_frrem_accum_b,
  71990. + (hcd->hfnum_other_samples_b > 0) ?
  71991. + hcd->hfnum_other_frrem_accum_b /
  71992. + hcd->hfnum_other_samples_b : 0);
  71993. +#endif
  71994. +}
  71995. +
  71996. +#endif /* DWC_DEVICE_ONLY */
  71997. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c
  71998. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 1970-01-01 01:00:00.000000000 +0100
  71999. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 2014-02-18 11:52:14.000000000 +0100
  72000. @@ -0,0 +1,1132 @@
  72001. +/*==========================================================================
  72002. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_ddma.c $
  72003. + * $Revision: #10 $
  72004. + * $Date: 2011/10/20 $
  72005. + * $Change: 1869464 $
  72006. + *
  72007. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  72008. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  72009. + * otherwise expressly agreed to in writing between Synopsys and you.
  72010. + *
  72011. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  72012. + * any End User Software License Agreement or Agreement for Licensed Product
  72013. + * with Synopsys or any supplement thereto. You are permitted to use and
  72014. + * redistribute this Software in source and binary forms, with or without
  72015. + * modification, provided that redistributions of source code must retain this
  72016. + * notice. You may not view, use, disclose, copy or distribute this file or
  72017. + * any information contained herein except pursuant to this license grant from
  72018. + * Synopsys. If you do not agree with this notice, including the disclaimer
  72019. + * below, then you are not authorized to use the Software.
  72020. + *
  72021. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  72022. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  72023. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  72024. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  72025. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  72026. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  72027. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  72028. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  72029. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  72030. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  72031. + * DAMAGE.
  72032. + * ========================================================================== */
  72033. +#ifndef DWC_DEVICE_ONLY
  72034. +
  72035. +/** @file
  72036. + * This file contains Descriptor DMA support implementation for host mode.
  72037. + */
  72038. +
  72039. +#include "dwc_otg_hcd.h"
  72040. +#include "dwc_otg_regs.h"
  72041. +
  72042. +extern bool microframe_schedule;
  72043. +
  72044. +static inline uint8_t frame_list_idx(uint16_t frame)
  72045. +{
  72046. + return (frame & (MAX_FRLIST_EN_NUM - 1));
  72047. +}
  72048. +
  72049. +static inline uint16_t desclist_idx_inc(uint16_t idx, uint16_t inc, uint8_t speed)
  72050. +{
  72051. + return (idx + inc) &
  72052. + (((speed ==
  72053. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  72054. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  72055. +}
  72056. +
  72057. +static inline uint16_t desclist_idx_dec(uint16_t idx, uint16_t inc, uint8_t speed)
  72058. +{
  72059. + return (idx - inc) &
  72060. + (((speed ==
  72061. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  72062. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  72063. +}
  72064. +
  72065. +static inline uint16_t max_desc_num(dwc_otg_qh_t * qh)
  72066. +{
  72067. + return (((qh->ep_type == UE_ISOCHRONOUS)
  72068. + && (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH))
  72069. + ? MAX_DMA_DESC_NUM_HS_ISOC : MAX_DMA_DESC_NUM_GENERIC);
  72070. +}
  72071. +static inline uint16_t frame_incr_val(dwc_otg_qh_t * qh)
  72072. +{
  72073. + return ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH)
  72074. + ? ((qh->interval + 8 - 1) / 8)
  72075. + : qh->interval);
  72076. +}
  72077. +
  72078. +static int desc_list_alloc(dwc_otg_qh_t * qh)
  72079. +{
  72080. + int retval = 0;
  72081. +
  72082. + qh->desc_list = (dwc_otg_host_dma_desc_t *)
  72083. + DWC_DMA_ALLOC(sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh),
  72084. + &qh->desc_list_dma);
  72085. +
  72086. + if (!qh->desc_list) {
  72087. + retval = -DWC_E_NO_MEMORY;
  72088. + DWC_ERROR("%s: DMA descriptor list allocation failed\n", __func__);
  72089. +
  72090. + }
  72091. +
  72092. + dwc_memset(qh->desc_list, 0x00,
  72093. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  72094. +
  72095. + qh->n_bytes =
  72096. + (uint32_t *) DWC_ALLOC(sizeof(uint32_t) * max_desc_num(qh));
  72097. +
  72098. + if (!qh->n_bytes) {
  72099. + retval = -DWC_E_NO_MEMORY;
  72100. + DWC_ERROR
  72101. + ("%s: Failed to allocate array for descriptors' size actual values\n",
  72102. + __func__);
  72103. +
  72104. + }
  72105. + return retval;
  72106. +
  72107. +}
  72108. +
  72109. +static void desc_list_free(dwc_otg_qh_t * qh)
  72110. +{
  72111. + if (qh->desc_list) {
  72112. + DWC_DMA_FREE(max_desc_num(qh), qh->desc_list,
  72113. + qh->desc_list_dma);
  72114. + qh->desc_list = NULL;
  72115. + }
  72116. +
  72117. + if (qh->n_bytes) {
  72118. + DWC_FREE(qh->n_bytes);
  72119. + qh->n_bytes = NULL;
  72120. + }
  72121. +}
  72122. +
  72123. +static int frame_list_alloc(dwc_otg_hcd_t * hcd)
  72124. +{
  72125. + int retval = 0;
  72126. + if (hcd->frame_list)
  72127. + return 0;
  72128. +
  72129. + hcd->frame_list = DWC_DMA_ALLOC(4 * MAX_FRLIST_EN_NUM,
  72130. + &hcd->frame_list_dma);
  72131. + if (!hcd->frame_list) {
  72132. + retval = -DWC_E_NO_MEMORY;
  72133. + DWC_ERROR("%s: Frame List allocation failed\n", __func__);
  72134. + }
  72135. +
  72136. + dwc_memset(hcd->frame_list, 0x00, 4 * MAX_FRLIST_EN_NUM);
  72137. +
  72138. + return retval;
  72139. +}
  72140. +
  72141. +static void frame_list_free(dwc_otg_hcd_t * hcd)
  72142. +{
  72143. + if (!hcd->frame_list)
  72144. + return;
  72145. +
  72146. + DWC_DMA_FREE(4 * MAX_FRLIST_EN_NUM, hcd->frame_list, hcd->frame_list_dma);
  72147. + hcd->frame_list = NULL;
  72148. +}
  72149. +
  72150. +static void per_sched_enable(dwc_otg_hcd_t * hcd, uint16_t fr_list_en)
  72151. +{
  72152. +
  72153. + hcfg_data_t hcfg;
  72154. +
  72155. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  72156. +
  72157. + if (hcfg.b.perschedena) {
  72158. + /* already enabled */
  72159. + return;
  72160. + }
  72161. +
  72162. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hflbaddr,
  72163. + hcd->frame_list_dma);
  72164. +
  72165. + switch (fr_list_en) {
  72166. + case 64:
  72167. + hcfg.b.frlisten = 3;
  72168. + break;
  72169. + case 32:
  72170. + hcfg.b.frlisten = 2;
  72171. + break;
  72172. + case 16:
  72173. + hcfg.b.frlisten = 1;
  72174. + break;
  72175. + case 8:
  72176. + hcfg.b.frlisten = 0;
  72177. + break;
  72178. + default:
  72179. + break;
  72180. + }
  72181. +
  72182. + hcfg.b.perschedena = 1;
  72183. +
  72184. + DWC_DEBUGPL(DBG_HCD, "Enabling Periodic schedule\n");
  72185. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  72186. +
  72187. +}
  72188. +
  72189. +static void per_sched_disable(dwc_otg_hcd_t * hcd)
  72190. +{
  72191. + hcfg_data_t hcfg;
  72192. +
  72193. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  72194. +
  72195. + if (!hcfg.b.perschedena) {
  72196. + /* already disabled */
  72197. + return;
  72198. + }
  72199. + hcfg.b.perschedena = 0;
  72200. +
  72201. + DWC_DEBUGPL(DBG_HCD, "Disabling Periodic schedule\n");
  72202. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  72203. +}
  72204. +
  72205. +/*
  72206. + * Activates/Deactivates FrameList entries for the channel
  72207. + * based on endpoint servicing period.
  72208. + */
  72209. +void update_frame_list(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, uint8_t enable)
  72210. +{
  72211. + uint16_t i, j, inc;
  72212. + dwc_hc_t *hc = NULL;
  72213. +
  72214. + if (!qh->channel) {
  72215. + DWC_ERROR("qh->channel = %p", qh->channel);
  72216. + return;
  72217. + }
  72218. +
  72219. + if (!hcd) {
  72220. + DWC_ERROR("------hcd = %p", hcd);
  72221. + return;
  72222. + }
  72223. +
  72224. + if (!hcd->frame_list) {
  72225. + DWC_ERROR("-------hcd->frame_list = %p", hcd->frame_list);
  72226. + return;
  72227. + }
  72228. +
  72229. + hc = qh->channel;
  72230. + inc = frame_incr_val(qh);
  72231. + if (qh->ep_type == UE_ISOCHRONOUS)
  72232. + i = frame_list_idx(qh->sched_frame);
  72233. + else
  72234. + i = 0;
  72235. +
  72236. + j = i;
  72237. + do {
  72238. + if (enable)
  72239. + hcd->frame_list[j] |= (1 << hc->hc_num);
  72240. + else
  72241. + hcd->frame_list[j] &= ~(1 << hc->hc_num);
  72242. + j = (j + inc) & (MAX_FRLIST_EN_NUM - 1);
  72243. + }
  72244. + while (j != i);
  72245. + if (!enable)
  72246. + return;
  72247. + hc->schinfo = 0;
  72248. + if (qh->channel->speed == DWC_OTG_EP_SPEED_HIGH) {
  72249. + j = 1;
  72250. + /* TODO - check this */
  72251. + inc = (8 + qh->interval - 1) / qh->interval;
  72252. + for (i = 0; i < inc; i++) {
  72253. + hc->schinfo |= j;
  72254. + j = j << qh->interval;
  72255. + }
  72256. + } else {
  72257. + hc->schinfo = 0xff;
  72258. + }
  72259. +}
  72260. +
  72261. +#if 1
  72262. +void dump_frame_list(dwc_otg_hcd_t * hcd)
  72263. +{
  72264. + int i = 0;
  72265. + DWC_PRINTF("--FRAME LIST (hex) --\n");
  72266. + for (i = 0; i < MAX_FRLIST_EN_NUM; i++) {
  72267. + DWC_PRINTF("%x\t", hcd->frame_list[i]);
  72268. + if (!(i % 8) && i)
  72269. + DWC_PRINTF("\n");
  72270. + }
  72271. + DWC_PRINTF("\n----\n");
  72272. +
  72273. +}
  72274. +#endif
  72275. +
  72276. +static void release_channel_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  72277. +{
  72278. + dwc_irqflags_t flags;
  72279. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  72280. +
  72281. + dwc_hc_t *hc = qh->channel;
  72282. + if (dwc_qh_is_non_per(qh)) {
  72283. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  72284. + if (!microframe_schedule)
  72285. + hcd->non_periodic_channels--;
  72286. + else
  72287. + hcd->available_host_channels++;
  72288. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  72289. + } else
  72290. + update_frame_list(hcd, qh, 0);
  72291. +
  72292. + /*
  72293. + * The condition is added to prevent double cleanup try in case of device
  72294. + * disconnect. See channel cleanup in dwc_otg_hcd_disconnect_cb().
  72295. + */
  72296. + if (hc->qh) {
  72297. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  72298. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  72299. + hc->qh = NULL;
  72300. + }
  72301. +
  72302. + qh->channel = NULL;
  72303. + qh->ntd = 0;
  72304. +
  72305. + if (qh->desc_list) {
  72306. + dwc_memset(qh->desc_list, 0x00,
  72307. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  72308. + }
  72309. +}
  72310. +
  72311. +/**
  72312. + * Initializes a QH structure's Descriptor DMA related members.
  72313. + * Allocates memory for descriptor list.
  72314. + * On first periodic QH, allocates memory for FrameList
  72315. + * and enables periodic scheduling.
  72316. + *
  72317. + * @param hcd The HCD state structure for the DWC OTG controller.
  72318. + * @param qh The QH to init.
  72319. + *
  72320. + * @return 0 if successful, negative error code otherwise.
  72321. + */
  72322. +int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  72323. +{
  72324. + int retval = 0;
  72325. +
  72326. + if (qh->do_split) {
  72327. + DWC_ERROR("SPLIT Transfers are not supported in Descriptor DMA.\n");
  72328. + return -1;
  72329. + }
  72330. +
  72331. + retval = desc_list_alloc(qh);
  72332. +
  72333. + if ((retval == 0)
  72334. + && (qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)) {
  72335. + if (!hcd->frame_list) {
  72336. + retval = frame_list_alloc(hcd);
  72337. + /* Enable periodic schedule on first periodic QH */
  72338. + if (retval == 0)
  72339. + per_sched_enable(hcd, MAX_FRLIST_EN_NUM);
  72340. + }
  72341. + }
  72342. +
  72343. + qh->ntd = 0;
  72344. +
  72345. + return retval;
  72346. +}
  72347. +
  72348. +/**
  72349. + * Frees descriptor list memory associated with the QH.
  72350. + * If QH is periodic and the last, frees FrameList memory
  72351. + * and disables periodic scheduling.
  72352. + *
  72353. + * @param hcd The HCD state structure for the DWC OTG controller.
  72354. + * @param qh The QH to init.
  72355. + */
  72356. +void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  72357. +{
  72358. + desc_list_free(qh);
  72359. +
  72360. + /*
  72361. + * Channel still assigned due to some reasons.
  72362. + * Seen on Isoc URB dequeue. Channel halted but no subsequent
  72363. + * ChHalted interrupt to release the channel. Afterwards
  72364. + * when it comes here from endpoint disable routine
  72365. + * channel remains assigned.
  72366. + */
  72367. + if (qh->channel)
  72368. + release_channel_ddma(hcd, qh);
  72369. +
  72370. + if ((qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)
  72371. + && (microframe_schedule || !hcd->periodic_channels) && hcd->frame_list) {
  72372. +
  72373. + per_sched_disable(hcd);
  72374. + frame_list_free(hcd);
  72375. + }
  72376. +}
  72377. +
  72378. +static uint8_t frame_to_desc_idx(dwc_otg_qh_t * qh, uint16_t frame_idx)
  72379. +{
  72380. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  72381. + /*
  72382. + * Descriptor set(8 descriptors) index
  72383. + * which is 8-aligned.
  72384. + */
  72385. + return (frame_idx & ((MAX_DMA_DESC_NUM_HS_ISOC / 8) - 1)) * 8;
  72386. + } else {
  72387. + return (frame_idx & (MAX_DMA_DESC_NUM_GENERIC - 1));
  72388. + }
  72389. +}
  72390. +
  72391. +/*
  72392. + * Determine starting frame for Isochronous transfer.
  72393. + * Few frames skipped to prevent race condition with HC.
  72394. + */
  72395. +static uint8_t calc_starting_frame(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  72396. + uint8_t * skip_frames)
  72397. +{
  72398. + uint16_t frame = 0;
  72399. + hcd->frame_number = dwc_otg_hcd_get_frame_number(hcd);
  72400. +
  72401. + /* sched_frame is always frame number(not uFrame) both in FS and HS !! */
  72402. +
  72403. + /*
  72404. + * skip_frames is used to limit activated descriptors number
  72405. + * to avoid the situation when HC services the last activated
  72406. + * descriptor firstly.
  72407. + * Example for FS:
  72408. + * Current frame is 1, scheduled frame is 3. Since HC always fetches the descriptor
  72409. + * corresponding to curr_frame+1, the descriptor corresponding to frame 2
  72410. + * will be fetched. If the number of descriptors is max=64 (or greather) the
  72411. + * list will be fully programmed with Active descriptors and it is possible
  72412. + * case(rare) that the latest descriptor(considering rollback) corresponding
  72413. + * to frame 2 will be serviced first. HS case is more probable because, in fact,
  72414. + * up to 11 uframes(16 in the code) may be skipped.
  72415. + */
  72416. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  72417. + /*
  72418. + * Consider uframe counter also, to start xfer asap.
  72419. + * If half of the frame elapsed skip 2 frames otherwise
  72420. + * just 1 frame.
  72421. + * Starting descriptor index must be 8-aligned, so
  72422. + * if the current frame is near to complete the next one
  72423. + * is skipped as well.
  72424. + */
  72425. +
  72426. + if (dwc_micro_frame_num(hcd->frame_number) >= 5) {
  72427. + *skip_frames = 2 * 8;
  72428. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  72429. + } else {
  72430. + *skip_frames = 1 * 8;
  72431. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  72432. + }
  72433. +
  72434. + frame = dwc_full_frame_num(frame);
  72435. + } else {
  72436. + /*
  72437. + * Two frames are skipped for FS - the current and the next.
  72438. + * But for descriptor programming, 1 frame(descriptor) is enough,
  72439. + * see example above.
  72440. + */
  72441. + *skip_frames = 1;
  72442. + frame = dwc_frame_num_inc(hcd->frame_number, 2);
  72443. + }
  72444. +
  72445. + return frame;
  72446. +}
  72447. +
  72448. +/*
  72449. + * Calculate initial descriptor index for isochronous transfer
  72450. + * based on scheduled frame.
  72451. + */
  72452. +static uint8_t recalc_initial_desc_idx(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  72453. +{
  72454. + uint16_t frame = 0, fr_idx, fr_idx_tmp;
  72455. + uint8_t skip_frames = 0;
  72456. + /*
  72457. + * With current ISOC processing algorithm the channel is being
  72458. + * released when no more QTDs in the list(qh->ntd == 0).
  72459. + * Thus this function is called only when qh->ntd == 0 and qh->channel == 0.
  72460. + *
  72461. + * So qh->channel != NULL branch is not used and just not removed from the
  72462. + * source file. It is required for another possible approach which is,
  72463. + * do not disable and release the channel when ISOC session completed,
  72464. + * just move QH to inactive schedule until new QTD arrives.
  72465. + * On new QTD, the QH moved back to 'ready' schedule,
  72466. + * starting frame and therefore starting desc_index are recalculated.
  72467. + * In this case channel is released only on ep_disable.
  72468. + */
  72469. +
  72470. + /* Calculate starting descriptor index. For INTERRUPT endpoint it is always 0. */
  72471. + if (qh->channel) {
  72472. + frame = calc_starting_frame(hcd, qh, &skip_frames);
  72473. + /*
  72474. + * Calculate initial descriptor index based on FrameList current bitmap
  72475. + * and servicing period.
  72476. + */
  72477. + fr_idx_tmp = frame_list_idx(frame);
  72478. + fr_idx =
  72479. + (MAX_FRLIST_EN_NUM + frame_list_idx(qh->sched_frame) -
  72480. + fr_idx_tmp)
  72481. + % frame_incr_val(qh);
  72482. + fr_idx = (fr_idx + fr_idx_tmp) % MAX_FRLIST_EN_NUM;
  72483. + } else {
  72484. + qh->sched_frame = calc_starting_frame(hcd, qh, &skip_frames);
  72485. + fr_idx = frame_list_idx(qh->sched_frame);
  72486. + }
  72487. +
  72488. + qh->td_first = qh->td_last = frame_to_desc_idx(qh, fr_idx);
  72489. +
  72490. + return skip_frames;
  72491. +}
  72492. +
  72493. +#define ISOC_URB_GIVEBACK_ASAP
  72494. +
  72495. +#define MAX_ISOC_XFER_SIZE_FS 1023
  72496. +#define MAX_ISOC_XFER_SIZE_HS 3072
  72497. +#define DESCNUM_THRESHOLD 4
  72498. +
  72499. +static void init_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  72500. + uint8_t skip_frames)
  72501. +{
  72502. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  72503. + dwc_otg_qtd_t *qtd;
  72504. + dwc_otg_host_dma_desc_t *dma_desc;
  72505. + uint16_t idx, inc, n_desc, ntd_max, max_xfer_size;
  72506. +
  72507. + idx = qh->td_last;
  72508. + inc = qh->interval;
  72509. + n_desc = 0;
  72510. +
  72511. + ntd_max = (max_desc_num(qh) + qh->interval - 1) / qh->interval;
  72512. + if (skip_frames && !qh->channel)
  72513. + ntd_max = ntd_max - skip_frames / qh->interval;
  72514. +
  72515. + max_xfer_size =
  72516. + (qh->dev_speed ==
  72517. + DWC_OTG_EP_SPEED_HIGH) ? MAX_ISOC_XFER_SIZE_HS :
  72518. + MAX_ISOC_XFER_SIZE_FS;
  72519. +
  72520. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  72521. + while ((qh->ntd < ntd_max)
  72522. + && (qtd->isoc_frame_index_last <
  72523. + qtd->urb->packet_count)) {
  72524. +
  72525. + dma_desc = &qh->desc_list[idx];
  72526. + dwc_memset(dma_desc, 0x00, sizeof(dwc_otg_host_dma_desc_t));
  72527. +
  72528. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last];
  72529. +
  72530. + if (frame_desc->length > max_xfer_size)
  72531. + qh->n_bytes[idx] = max_xfer_size;
  72532. + else
  72533. + qh->n_bytes[idx] = frame_desc->length;
  72534. + dma_desc->status.b_isoc.n_bytes = qh->n_bytes[idx];
  72535. + dma_desc->status.b_isoc.a = 1;
  72536. + dma_desc->status.b_isoc.sts = 0;
  72537. +
  72538. + dma_desc->buf = qtd->urb->dma + frame_desc->offset;
  72539. +
  72540. + qh->ntd++;
  72541. +
  72542. + qtd->isoc_frame_index_last++;
  72543. +
  72544. +#ifdef ISOC_URB_GIVEBACK_ASAP
  72545. + /*
  72546. + * Set IOC for each descriptor corresponding to the
  72547. + * last frame of the URB.
  72548. + */
  72549. + if (qtd->isoc_frame_index_last ==
  72550. + qtd->urb->packet_count)
  72551. + dma_desc->status.b_isoc.ioc = 1;
  72552. +
  72553. +#endif
  72554. + idx = desclist_idx_inc(idx, inc, qh->dev_speed);
  72555. + n_desc++;
  72556. +
  72557. + }
  72558. + qtd->in_process = 1;
  72559. + }
  72560. +
  72561. + qh->td_last = idx;
  72562. +
  72563. +#ifdef ISOC_URB_GIVEBACK_ASAP
  72564. + /* Set IOC for the last descriptor if descriptor list is full */
  72565. + if (qh->ntd == ntd_max) {
  72566. + idx = desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  72567. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  72568. + }
  72569. +#else
  72570. + /*
  72571. + * Set IOC bit only for one descriptor.
  72572. + * Always try to be ahead of HW processing,
  72573. + * i.e. on IOC generation driver activates next descriptors but
  72574. + * core continues to process descriptors followed the one with IOC set.
  72575. + */
  72576. +
  72577. + if (n_desc > DESCNUM_THRESHOLD) {
  72578. + /*
  72579. + * Move IOC "up". Required even if there is only one QTD
  72580. + * in the list, cause QTDs migth continue to be queued,
  72581. + * but during the activation it was only one queued.
  72582. + * Actually more than one QTD might be in the list if this function called
  72583. + * from XferCompletion - QTDs was queued during HW processing of the previous
  72584. + * descriptor chunk.
  72585. + */
  72586. + idx = dwc_desclist_idx_dec(idx, inc * ((qh->ntd + 1) / 2), qh->dev_speed);
  72587. + } else {
  72588. + /*
  72589. + * Set the IOC for the latest descriptor
  72590. + * if either number of descriptor is not greather than threshold
  72591. + * or no more new descriptors activated.
  72592. + */
  72593. + idx = dwc_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  72594. + }
  72595. +
  72596. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  72597. +#endif
  72598. +}
  72599. +
  72600. +static void init_non_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  72601. +{
  72602. +
  72603. + dwc_hc_t *hc;
  72604. + dwc_otg_host_dma_desc_t *dma_desc;
  72605. + dwc_otg_qtd_t *qtd;
  72606. + int num_packets, len, n_desc = 0;
  72607. +
  72608. + hc = qh->channel;
  72609. +
  72610. + /*
  72611. + * Start with hc->xfer_buff initialized in
  72612. + * assign_and_init_hc(), then if SG transfer consists of multiple URBs,
  72613. + * this pointer re-assigned to the buffer of the currently processed QTD.
  72614. + * For non-SG request there is always one QTD active.
  72615. + */
  72616. +
  72617. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  72618. +
  72619. + if (n_desc) {
  72620. + /* SG request - more than 1 QTDs */
  72621. + hc->xfer_buff = (uint8_t *)qtd->urb->dma + qtd->urb->actual_length;
  72622. + hc->xfer_len = qtd->urb->length - qtd->urb->actual_length;
  72623. + }
  72624. +
  72625. + qtd->n_desc = 0;
  72626. +
  72627. + do {
  72628. + dma_desc = &qh->desc_list[n_desc];
  72629. + len = hc->xfer_len;
  72630. +
  72631. + if (len > MAX_DMA_DESC_SIZE)
  72632. + len = MAX_DMA_DESC_SIZE - hc->max_packet + 1;
  72633. +
  72634. + if (hc->ep_is_in) {
  72635. + if (len > 0) {
  72636. + num_packets = (len + hc->max_packet - 1) / hc->max_packet;
  72637. + } else {
  72638. + /* Need 1 packet for transfer length of 0. */
  72639. + num_packets = 1;
  72640. + }
  72641. + /* Always program an integral # of max packets for IN transfers. */
  72642. + len = num_packets * hc->max_packet;
  72643. + }
  72644. +
  72645. + dma_desc->status.b.n_bytes = len;
  72646. +
  72647. + qh->n_bytes[n_desc] = len;
  72648. +
  72649. + if ((qh->ep_type == UE_CONTROL)
  72650. + && (qtd->control_phase == DWC_OTG_CONTROL_SETUP))
  72651. + dma_desc->status.b.sup = 1; /* Setup Packet */
  72652. +
  72653. + dma_desc->status.b.a = 1; /* Active descriptor */
  72654. + dma_desc->status.b.sts = 0;
  72655. +
  72656. + dma_desc->buf =
  72657. + ((unsigned long)hc->xfer_buff & 0xffffffff);
  72658. +
  72659. + /*
  72660. + * Last descriptor(or single) of IN transfer
  72661. + * with actual size less than MaxPacket.
  72662. + */
  72663. + if (len > hc->xfer_len) {
  72664. + hc->xfer_len = 0;
  72665. + } else {
  72666. + hc->xfer_buff += len;
  72667. + hc->xfer_len -= len;
  72668. + }
  72669. +
  72670. + qtd->n_desc++;
  72671. + n_desc++;
  72672. + }
  72673. + while ((hc->xfer_len > 0) && (n_desc != MAX_DMA_DESC_NUM_GENERIC));
  72674. +
  72675. +
  72676. + qtd->in_process = 1;
  72677. +
  72678. + if (qh->ep_type == UE_CONTROL)
  72679. + break;
  72680. +
  72681. + if (n_desc == MAX_DMA_DESC_NUM_GENERIC)
  72682. + break;
  72683. + }
  72684. +
  72685. + if (n_desc) {
  72686. + /* Request Transfer Complete interrupt for the last descriptor */
  72687. + qh->desc_list[n_desc - 1].status.b.ioc = 1;
  72688. + /* End of List indicator */
  72689. + qh->desc_list[n_desc - 1].status.b.eol = 1;
  72690. +
  72691. + hc->ntd = n_desc;
  72692. + }
  72693. +}
  72694. +
  72695. +/**
  72696. + * For Control and Bulk endpoints initializes descriptor list
  72697. + * and starts the transfer.
  72698. + *
  72699. + * For Interrupt and Isochronous endpoints initializes descriptor list
  72700. + * then updates FrameList, marking appropriate entries as active.
  72701. + * In case of Isochronous, the starting descriptor index is calculated based
  72702. + * on the scheduled frame, but only on the first transfer descriptor within a session.
  72703. + * Then starts the transfer via enabling the channel.
  72704. + * For Isochronous endpoint the channel is not halted on XferComplete
  72705. + * interrupt so remains assigned to the endpoint(QH) until session is done.
  72706. + *
  72707. + * @param hcd The HCD state structure for the DWC OTG controller.
  72708. + * @param qh The QH to init.
  72709. + *
  72710. + * @return 0 if successful, negative error code otherwise.
  72711. + */
  72712. +void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  72713. +{
  72714. + /* Channel is already assigned */
  72715. + dwc_hc_t *hc = qh->channel;
  72716. + uint8_t skip_frames = 0;
  72717. +
  72718. + switch (hc->ep_type) {
  72719. + case DWC_OTG_EP_TYPE_CONTROL:
  72720. + case DWC_OTG_EP_TYPE_BULK:
  72721. + init_non_isoc_dma_desc(hcd, qh);
  72722. +
  72723. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  72724. + break;
  72725. + case DWC_OTG_EP_TYPE_INTR:
  72726. + init_non_isoc_dma_desc(hcd, qh);
  72727. +
  72728. + update_frame_list(hcd, qh, 1);
  72729. +
  72730. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  72731. + break;
  72732. + case DWC_OTG_EP_TYPE_ISOC:
  72733. +
  72734. + if (!qh->ntd)
  72735. + skip_frames = recalc_initial_desc_idx(hcd, qh);
  72736. +
  72737. + init_isoc_dma_desc(hcd, qh, skip_frames);
  72738. +
  72739. + if (!hc->xfer_started) {
  72740. +
  72741. + update_frame_list(hcd, qh, 1);
  72742. +
  72743. + /*
  72744. + * Always set to max, instead of actual size.
  72745. + * Otherwise ntd will be changed with
  72746. + * channel being enabled. Not recommended.
  72747. + *
  72748. + */
  72749. + hc->ntd = max_desc_num(qh);
  72750. + /* Enable channel only once for ISOC */
  72751. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  72752. + }
  72753. +
  72754. + break;
  72755. + default:
  72756. +
  72757. + break;
  72758. + }
  72759. +}
  72760. +
  72761. +static void complete_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  72762. + dwc_hc_t * hc,
  72763. + dwc_otg_hc_regs_t * hc_regs,
  72764. + dwc_otg_halt_status_e halt_status)
  72765. +{
  72766. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  72767. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  72768. + dwc_otg_qh_t *qh;
  72769. + dwc_otg_host_dma_desc_t *dma_desc;
  72770. + uint16_t idx, remain;
  72771. + uint8_t urb_compl;
  72772. +
  72773. + qh = hc->qh;
  72774. + idx = qh->td_first;
  72775. +
  72776. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  72777. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry)
  72778. + qtd->in_process = 0;
  72779. + return;
  72780. + } else if ((halt_status == DWC_OTG_HC_XFER_AHB_ERR) ||
  72781. + (halt_status == DWC_OTG_HC_XFER_BABBLE_ERR)) {
  72782. + /*
  72783. + * Channel is halted in these error cases.
  72784. + * Considered as serious issues.
  72785. + * Complete all URBs marking all frames as failed,
  72786. + * irrespective whether some of the descriptors(frames) succeeded or no.
  72787. + * Pass error code to completion routine as well, to
  72788. + * update urb->status, some of class drivers might use it to stop
  72789. + * queing transfer requests.
  72790. + */
  72791. + int err = (halt_status == DWC_OTG_HC_XFER_AHB_ERR)
  72792. + ? (-DWC_E_IO)
  72793. + : (-DWC_E_OVERFLOW);
  72794. +
  72795. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  72796. + for (idx = 0; idx < qtd->urb->packet_count; idx++) {
  72797. + frame_desc = &qtd->urb->iso_descs[idx];
  72798. + frame_desc->status = err;
  72799. + }
  72800. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, err);
  72801. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  72802. + }
  72803. + return;
  72804. + }
  72805. +
  72806. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  72807. +
  72808. + if (!qtd->in_process)
  72809. + break;
  72810. +
  72811. + urb_compl = 0;
  72812. +
  72813. + do {
  72814. +
  72815. + dma_desc = &qh->desc_list[idx];
  72816. +
  72817. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  72818. + remain = hc->ep_is_in ? dma_desc->status.b_isoc.n_bytes : 0;
  72819. +
  72820. + if (dma_desc->status.b_isoc.sts == DMA_DESC_STS_PKTERR) {
  72821. + /*
  72822. + * XactError or, unable to complete all the transactions
  72823. + * in the scheduled micro-frame/frame,
  72824. + * both indicated by DMA_DESC_STS_PKTERR.
  72825. + */
  72826. + qtd->urb->error_count++;
  72827. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  72828. + frame_desc->status = -DWC_E_PROTOCOL;
  72829. + } else {
  72830. + /* Success */
  72831. +
  72832. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  72833. + frame_desc->status = 0;
  72834. + }
  72835. +
  72836. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  72837. + /*
  72838. + * urb->status is not used for isoc transfers here.
  72839. + * The individual frame_desc status are used instead.
  72840. + */
  72841. +
  72842. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  72843. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  72844. +
  72845. + /*
  72846. + * This check is necessary because urb_dequeue can be called
  72847. + * from urb complete callback(sound driver example).
  72848. + * All pending URBs are dequeued there, so no need for
  72849. + * further processing.
  72850. + */
  72851. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  72852. + return;
  72853. + }
  72854. +
  72855. + urb_compl = 1;
  72856. +
  72857. + }
  72858. +
  72859. + qh->ntd--;
  72860. +
  72861. + /* Stop if IOC requested descriptor reached */
  72862. + if (dma_desc->status.b_isoc.ioc) {
  72863. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  72864. + goto stop_scan;
  72865. + }
  72866. +
  72867. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  72868. +
  72869. + if (urb_compl)
  72870. + break;
  72871. + }
  72872. + while (idx != qh->td_first);
  72873. + }
  72874. +stop_scan:
  72875. + qh->td_first = idx;
  72876. +}
  72877. +
  72878. +uint8_t update_non_isoc_urb_state_ddma(dwc_otg_hcd_t * hcd,
  72879. + dwc_hc_t * hc,
  72880. + dwc_otg_qtd_t * qtd,
  72881. + dwc_otg_host_dma_desc_t * dma_desc,
  72882. + dwc_otg_halt_status_e halt_status,
  72883. + uint32_t n_bytes, uint8_t * xfer_done)
  72884. +{
  72885. +
  72886. + uint16_t remain = hc->ep_is_in ? dma_desc->status.b.n_bytes : 0;
  72887. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  72888. +
  72889. + if (halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  72890. + urb->status = -DWC_E_IO;
  72891. + return 1;
  72892. + }
  72893. + if (dma_desc->status.b.sts == DMA_DESC_STS_PKTERR) {
  72894. + switch (halt_status) {
  72895. + case DWC_OTG_HC_XFER_STALL:
  72896. + urb->status = -DWC_E_PIPE;
  72897. + break;
  72898. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  72899. + urb->status = -DWC_E_OVERFLOW;
  72900. + break;
  72901. + case DWC_OTG_HC_XFER_XACT_ERR:
  72902. + urb->status = -DWC_E_PROTOCOL;
  72903. + break;
  72904. + default:
  72905. + DWC_ERROR("%s: Unhandled descriptor error status (%d)\n", __func__,
  72906. + halt_status);
  72907. + break;
  72908. + }
  72909. + return 1;
  72910. + }
  72911. +
  72912. + if (dma_desc->status.b.a == 1) {
  72913. + DWC_DEBUGPL(DBG_HCDV,
  72914. + "Active descriptor encountered on channel %d\n",
  72915. + hc->hc_num);
  72916. + return 0;
  72917. + }
  72918. +
  72919. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL) {
  72920. + if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  72921. + urb->actual_length += n_bytes - remain;
  72922. + if (remain || urb->actual_length == urb->length) {
  72923. + /*
  72924. + * For Control Data stage do not set urb->status=0 to prevent
  72925. + * URB callback. Set it when Status phase done. See below.
  72926. + */
  72927. + *xfer_done = 1;
  72928. + }
  72929. +
  72930. + } else if (qtd->control_phase == DWC_OTG_CONTROL_STATUS) {
  72931. + urb->status = 0;
  72932. + *xfer_done = 1;
  72933. + }
  72934. + /* No handling for SETUP stage */
  72935. + } else {
  72936. + /* BULK and INTR */
  72937. + urb->actual_length += n_bytes - remain;
  72938. + if (remain || urb->actual_length == urb->length) {
  72939. + urb->status = 0;
  72940. + *xfer_done = 1;
  72941. + }
  72942. + }
  72943. +
  72944. + return 0;
  72945. +}
  72946. +
  72947. +static void complete_non_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  72948. + dwc_hc_t * hc,
  72949. + dwc_otg_hc_regs_t * hc_regs,
  72950. + dwc_otg_halt_status_e halt_status)
  72951. +{
  72952. + dwc_otg_hcd_urb_t *urb = NULL;
  72953. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  72954. + dwc_otg_qh_t *qh;
  72955. + dwc_otg_host_dma_desc_t *dma_desc;
  72956. + uint32_t n_bytes, n_desc, i;
  72957. + uint8_t failed = 0, xfer_done;
  72958. +
  72959. + n_desc = 0;
  72960. +
  72961. + qh = hc->qh;
  72962. +
  72963. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  72964. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  72965. + qtd->in_process = 0;
  72966. + }
  72967. + return;
  72968. + }
  72969. +
  72970. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  72971. +
  72972. + urb = qtd->urb;
  72973. +
  72974. + n_bytes = 0;
  72975. + xfer_done = 0;
  72976. +
  72977. + for (i = 0; i < qtd->n_desc; i++) {
  72978. + dma_desc = &qh->desc_list[n_desc];
  72979. +
  72980. + n_bytes = qh->n_bytes[n_desc];
  72981. +
  72982. + failed =
  72983. + update_non_isoc_urb_state_ddma(hcd, hc, qtd,
  72984. + dma_desc,
  72985. + halt_status, n_bytes,
  72986. + &xfer_done);
  72987. +
  72988. + if (failed
  72989. + || (xfer_done
  72990. + && (urb->status != -DWC_E_IN_PROGRESS))) {
  72991. +
  72992. + hcd->fops->complete(hcd, urb->priv, urb,
  72993. + urb->status);
  72994. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  72995. +
  72996. + if (failed)
  72997. + goto stop_scan;
  72998. + } else if (qh->ep_type == UE_CONTROL) {
  72999. + if (qtd->control_phase == DWC_OTG_CONTROL_SETUP) {
  73000. + if (urb->length > 0) {
  73001. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  73002. + } else {
  73003. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  73004. + }
  73005. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction done\n");
  73006. + } else if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  73007. + if (xfer_done) {
  73008. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  73009. + DWC_DEBUGPL(DBG_HCDV, " Control data transfer done\n");
  73010. + } else if (i + 1 == qtd->n_desc) {
  73011. + /*
  73012. + * Last descriptor for Control data stage which is
  73013. + * not completed yet.
  73014. + */
  73015. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  73016. + }
  73017. + }
  73018. + }
  73019. +
  73020. + n_desc++;
  73021. + }
  73022. +
  73023. + }
  73024. +
  73025. +stop_scan:
  73026. +
  73027. + if (qh->ep_type != UE_CONTROL) {
  73028. + /*
  73029. + * Resetting the data toggle for bulk
  73030. + * and interrupt endpoints in case of stall. See handle_hc_stall_intr()
  73031. + */
  73032. + if (halt_status == DWC_OTG_HC_XFER_STALL)
  73033. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  73034. + else
  73035. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  73036. + }
  73037. +
  73038. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  73039. + hcint_data_t hcint;
  73040. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  73041. + if (hcint.b.nyet) {
  73042. + /*
  73043. + * Got a NYET on the last transaction of the transfer. It
  73044. + * means that the endpoint should be in the PING state at the
  73045. + * beginning of the next transfer.
  73046. + */
  73047. + qh->ping_state = 1;
  73048. + clear_hc_int(hc_regs, nyet);
  73049. + }
  73050. +
  73051. + }
  73052. +
  73053. +}
  73054. +
  73055. +/**
  73056. + * This function is called from interrupt handlers.
  73057. + * Scans the descriptor list, updates URB's status and
  73058. + * calls completion routine for the URB if it's done.
  73059. + * Releases the channel to be used by other transfers.
  73060. + * In case of Isochronous endpoint the channel is not halted until
  73061. + * the end of the session, i.e. QTD list is empty.
  73062. + * If periodic channel released the FrameList is updated accordingly.
  73063. + *
  73064. + * Calls transaction selection routines to activate pending transfers.
  73065. + *
  73066. + * @param hcd The HCD state structure for the DWC OTG controller.
  73067. + * @param hc Host channel, the transfer is completed on.
  73068. + * @param hc_regs Host channel registers.
  73069. + * @param halt_status Reason the channel is being halted,
  73070. + * or just XferComplete for isochronous transfer
  73071. + */
  73072. +void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  73073. + dwc_hc_t * hc,
  73074. + dwc_otg_hc_regs_t * hc_regs,
  73075. + dwc_otg_halt_status_e halt_status)
  73076. +{
  73077. + uint8_t continue_isoc_xfer = 0;
  73078. + dwc_otg_transaction_type_e tr_type;
  73079. + dwc_otg_qh_t *qh = hc->qh;
  73080. +
  73081. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  73082. +
  73083. + complete_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  73084. +
  73085. + /* Release the channel if halted or session completed */
  73086. + if (halt_status != DWC_OTG_HC_XFER_COMPLETE ||
  73087. + DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  73088. +
  73089. + /* Halt the channel if session completed */
  73090. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  73091. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  73092. + }
  73093. +
  73094. + release_channel_ddma(hcd, qh);
  73095. + dwc_otg_hcd_qh_remove(hcd, qh);
  73096. + } else {
  73097. + /* Keep in assigned schedule to continue transfer */
  73098. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  73099. + &qh->qh_list_entry);
  73100. + continue_isoc_xfer = 1;
  73101. +
  73102. + }
  73103. + /** @todo Consider the case when period exceeds FrameList size.
  73104. + * Frame Rollover interrupt should be used.
  73105. + */
  73106. + } else {
  73107. + /* Scan descriptor list to complete the URB(s), then release the channel */
  73108. + complete_non_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  73109. +
  73110. + release_channel_ddma(hcd, qh);
  73111. + dwc_otg_hcd_qh_remove(hcd, qh);
  73112. +
  73113. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  73114. + /* Add back to inactive non-periodic schedule on normal completion */
  73115. + dwc_otg_hcd_qh_add(hcd, qh);
  73116. + }
  73117. +
  73118. + }
  73119. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  73120. + if (tr_type != DWC_OTG_TRANSACTION_NONE || continue_isoc_xfer) {
  73121. + if (continue_isoc_xfer) {
  73122. + if (tr_type == DWC_OTG_TRANSACTION_NONE) {
  73123. + tr_type = DWC_OTG_TRANSACTION_PERIODIC;
  73124. + } else if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC) {
  73125. + tr_type = DWC_OTG_TRANSACTION_ALL;
  73126. + }
  73127. + }
  73128. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  73129. + }
  73130. +}
  73131. +
  73132. +#endif /* DWC_DEVICE_ONLY */
  73133. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd.h linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
  73134. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 1970-01-01 01:00:00.000000000 +0100
  73135. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 2014-02-18 11:52:14.000000000 +0100
  73136. @@ -0,0 +1,851 @@
  73137. +/* ==========================================================================
  73138. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.h $
  73139. + * $Revision: #58 $
  73140. + * $Date: 2011/09/15 $
  73141. + * $Change: 1846647 $
  73142. + *
  73143. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  73144. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  73145. + * otherwise expressly agreed to in writing between Synopsys and you.
  73146. + *
  73147. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  73148. + * any End User Software License Agreement or Agreement for Licensed Product
  73149. + * with Synopsys or any supplement thereto. You are permitted to use and
  73150. + * redistribute this Software in source and binary forms, with or without
  73151. + * modification, provided that redistributions of source code must retain this
  73152. + * notice. You may not view, use, disclose, copy or distribute this file or
  73153. + * any information contained herein except pursuant to this license grant from
  73154. + * Synopsys. If you do not agree with this notice, including the disclaimer
  73155. + * below, then you are not authorized to use the Software.
  73156. + *
  73157. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  73158. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  73159. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  73160. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  73161. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  73162. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  73163. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  73164. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  73165. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  73166. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  73167. + * DAMAGE.
  73168. + * ========================================================================== */
  73169. +#ifndef DWC_DEVICE_ONLY
  73170. +#ifndef __DWC_HCD_H__
  73171. +#define __DWC_HCD_H__
  73172. +
  73173. +#include "dwc_otg_os_dep.h"
  73174. +#include "usb.h"
  73175. +#include "dwc_otg_hcd_if.h"
  73176. +#include "dwc_otg_core_if.h"
  73177. +#include "dwc_list.h"
  73178. +#include "dwc_otg_cil.h"
  73179. +
  73180. +/**
  73181. + * @file
  73182. + *
  73183. + * This file contains the structures, constants, and interfaces for
  73184. + * the Host Contoller Driver (HCD).
  73185. + *
  73186. + * The Host Controller Driver (HCD) is responsible for translating requests
  73187. + * from the USB Driver into the appropriate actions on the DWC_otg controller.
  73188. + * It isolates the USBD from the specifics of the controller by providing an
  73189. + * API to the USBD.
  73190. + */
  73191. +
  73192. +struct dwc_otg_hcd_pipe_info {
  73193. + uint8_t dev_addr;
  73194. + uint8_t ep_num;
  73195. + uint8_t pipe_type;
  73196. + uint8_t pipe_dir;
  73197. + uint16_t mps;
  73198. +};
  73199. +
  73200. +struct dwc_otg_hcd_iso_packet_desc {
  73201. + uint32_t offset;
  73202. + uint32_t length;
  73203. + uint32_t actual_length;
  73204. + uint32_t status;
  73205. +};
  73206. +
  73207. +struct dwc_otg_qtd;
  73208. +
  73209. +struct dwc_otg_hcd_urb {
  73210. + void *priv;
  73211. + struct dwc_otg_qtd *qtd;
  73212. + void *buf;
  73213. + dwc_dma_t dma;
  73214. + void *setup_packet;
  73215. + dwc_dma_t setup_dma;
  73216. + uint32_t length;
  73217. + uint32_t actual_length;
  73218. + uint32_t status;
  73219. + uint32_t error_count;
  73220. + uint32_t packet_count;
  73221. + uint32_t flags;
  73222. + uint16_t interval;
  73223. + struct dwc_otg_hcd_pipe_info pipe_info;
  73224. + struct dwc_otg_hcd_iso_packet_desc iso_descs[0];
  73225. +};
  73226. +
  73227. +static inline uint8_t dwc_otg_hcd_get_ep_num(struct dwc_otg_hcd_pipe_info *pipe)
  73228. +{
  73229. + return pipe->ep_num;
  73230. +}
  73231. +
  73232. +static inline uint8_t dwc_otg_hcd_get_pipe_type(struct dwc_otg_hcd_pipe_info
  73233. + *pipe)
  73234. +{
  73235. + return pipe->pipe_type;
  73236. +}
  73237. +
  73238. +static inline uint16_t dwc_otg_hcd_get_mps(struct dwc_otg_hcd_pipe_info *pipe)
  73239. +{
  73240. + return pipe->mps;
  73241. +}
  73242. +
  73243. +static inline uint8_t dwc_otg_hcd_get_dev_addr(struct dwc_otg_hcd_pipe_info
  73244. + *pipe)
  73245. +{
  73246. + return pipe->dev_addr;
  73247. +}
  73248. +
  73249. +static inline uint8_t dwc_otg_hcd_is_pipe_isoc(struct dwc_otg_hcd_pipe_info
  73250. + *pipe)
  73251. +{
  73252. + return (pipe->pipe_type == UE_ISOCHRONOUS);
  73253. +}
  73254. +
  73255. +static inline uint8_t dwc_otg_hcd_is_pipe_int(struct dwc_otg_hcd_pipe_info
  73256. + *pipe)
  73257. +{
  73258. + return (pipe->pipe_type == UE_INTERRUPT);
  73259. +}
  73260. +
  73261. +static inline uint8_t dwc_otg_hcd_is_pipe_bulk(struct dwc_otg_hcd_pipe_info
  73262. + *pipe)
  73263. +{
  73264. + return (pipe->pipe_type == UE_BULK);
  73265. +}
  73266. +
  73267. +static inline uint8_t dwc_otg_hcd_is_pipe_control(struct dwc_otg_hcd_pipe_info
  73268. + *pipe)
  73269. +{
  73270. + return (pipe->pipe_type == UE_CONTROL);
  73271. +}
  73272. +
  73273. +static inline uint8_t dwc_otg_hcd_is_pipe_in(struct dwc_otg_hcd_pipe_info *pipe)
  73274. +{
  73275. + return (pipe->pipe_dir == UE_DIR_IN);
  73276. +}
  73277. +
  73278. +static inline uint8_t dwc_otg_hcd_is_pipe_out(struct dwc_otg_hcd_pipe_info
  73279. + *pipe)
  73280. +{
  73281. + return (!dwc_otg_hcd_is_pipe_in(pipe));
  73282. +}
  73283. +
  73284. +static inline void dwc_otg_hcd_fill_pipe(struct dwc_otg_hcd_pipe_info *pipe,
  73285. + uint8_t devaddr, uint8_t ep_num,
  73286. + uint8_t pipe_type, uint8_t pipe_dir,
  73287. + uint16_t mps)
  73288. +{
  73289. + pipe->dev_addr = devaddr;
  73290. + pipe->ep_num = ep_num;
  73291. + pipe->pipe_type = pipe_type;
  73292. + pipe->pipe_dir = pipe_dir;
  73293. + pipe->mps = mps;
  73294. +}
  73295. +
  73296. +/**
  73297. + * Phases for control transfers.
  73298. + */
  73299. +typedef enum dwc_otg_control_phase {
  73300. + DWC_OTG_CONTROL_SETUP,
  73301. + DWC_OTG_CONTROL_DATA,
  73302. + DWC_OTG_CONTROL_STATUS
  73303. +} dwc_otg_control_phase_e;
  73304. +
  73305. +/** Transaction types. */
  73306. +typedef enum dwc_otg_transaction_type {
  73307. + DWC_OTG_TRANSACTION_NONE = 0,
  73308. + DWC_OTG_TRANSACTION_PERIODIC = 1,
  73309. + DWC_OTG_TRANSACTION_NON_PERIODIC = 2,
  73310. + DWC_OTG_TRANSACTION_ALL = DWC_OTG_TRANSACTION_PERIODIC + DWC_OTG_TRANSACTION_NON_PERIODIC
  73311. +} dwc_otg_transaction_type_e;
  73312. +
  73313. +struct dwc_otg_qh;
  73314. +
  73315. +/**
  73316. + * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
  73317. + * interrupt, or isochronous transfer. A single QTD is created for each URB
  73318. + * (of one of these types) submitted to the HCD. The transfer associated with
  73319. + * a QTD may require one or multiple transactions.
  73320. + *
  73321. + * A QTD is linked to a Queue Head, which is entered in either the
  73322. + * non-periodic or periodic schedule for execution. When a QTD is chosen for
  73323. + * execution, some or all of its transactions may be executed. After
  73324. + * execution, the state of the QTD is updated. The QTD may be retired if all
  73325. + * its transactions are complete or if an error occurred. Otherwise, it
  73326. + * remains in the schedule so more transactions can be executed later.
  73327. + */
  73328. +typedef struct dwc_otg_qtd {
  73329. + /**
  73330. + * Determines the PID of the next data packet for the data phase of
  73331. + * control transfers. Ignored for other transfer types.<br>
  73332. + * One of the following values:
  73333. + * - DWC_OTG_HC_PID_DATA0
  73334. + * - DWC_OTG_HC_PID_DATA1
  73335. + */
  73336. + uint8_t data_toggle;
  73337. +
  73338. + /** Current phase for control transfers (Setup, Data, or Status). */
  73339. + dwc_otg_control_phase_e control_phase;
  73340. +
  73341. + /** Keep track of the current split type
  73342. + * for FS/LS endpoints on a HS Hub */
  73343. + uint8_t complete_split;
  73344. +
  73345. + /** How many bytes transferred during SSPLIT OUT */
  73346. + uint32_t ssplit_out_xfer_count;
  73347. +
  73348. + /**
  73349. + * Holds the number of bus errors that have occurred for a transaction
  73350. + * within this transfer.
  73351. + */
  73352. + uint8_t error_count;
  73353. +
  73354. + /**
  73355. + * Index of the next frame descriptor for an isochronous transfer. A
  73356. + * frame descriptor describes the buffer position and length of the
  73357. + * data to be transferred in the next scheduled (micro)frame of an
  73358. + * isochronous transfer. It also holds status for that transaction.
  73359. + * The frame index starts at 0.
  73360. + */
  73361. + uint16_t isoc_frame_index;
  73362. +
  73363. + /** Position of the ISOC split on full/low speed */
  73364. + uint8_t isoc_split_pos;
  73365. +
  73366. + /** Position of the ISOC split in the buffer for the current frame */
  73367. + uint16_t isoc_split_offset;
  73368. +
  73369. + /** URB for this transfer */
  73370. + struct dwc_otg_hcd_urb *urb;
  73371. +
  73372. + struct dwc_otg_qh *qh;
  73373. +
  73374. + /** This list of QTDs */
  73375. + DWC_CIRCLEQ_ENTRY(dwc_otg_qtd) qtd_list_entry;
  73376. +
  73377. + /** Indicates if this QTD is currently processed by HW. */
  73378. + uint8_t in_process;
  73379. +
  73380. + /** Number of DMA descriptors for this QTD */
  73381. + uint8_t n_desc;
  73382. +
  73383. + /**
  73384. + * Last activated frame(packet) index.
  73385. + * Used in Descriptor DMA mode only.
  73386. + */
  73387. + uint16_t isoc_frame_index_last;
  73388. +
  73389. +} dwc_otg_qtd_t;
  73390. +
  73391. +DWC_CIRCLEQ_HEAD(dwc_otg_qtd_list, dwc_otg_qtd);
  73392. +
  73393. +/**
  73394. + * A Queue Head (QH) holds the static characteristics of an endpoint and
  73395. + * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
  73396. + * be entered in either the non-periodic or periodic schedule.
  73397. + */
  73398. +typedef struct dwc_otg_qh {
  73399. + /**
  73400. + * Endpoint type.
  73401. + * One of the following values:
  73402. + * - UE_CONTROL
  73403. + * - UE_BULK
  73404. + * - UE_INTERRUPT
  73405. + * - UE_ISOCHRONOUS
  73406. + */
  73407. + uint8_t ep_type;
  73408. + uint8_t ep_is_in;
  73409. +
  73410. + /** wMaxPacketSize Field of Endpoint Descriptor. */
  73411. + uint16_t maxp;
  73412. +
  73413. + /**
  73414. + * Device speed.
  73415. + * One of the following values:
  73416. + * - DWC_OTG_EP_SPEED_LOW
  73417. + * - DWC_OTG_EP_SPEED_FULL
  73418. + * - DWC_OTG_EP_SPEED_HIGH
  73419. + */
  73420. + uint8_t dev_speed;
  73421. +
  73422. + /**
  73423. + * Determines the PID of the next data packet for non-control
  73424. + * transfers. Ignored for control transfers.<br>
  73425. + * One of the following values:
  73426. + * - DWC_OTG_HC_PID_DATA0
  73427. + * - DWC_OTG_HC_PID_DATA1
  73428. + */
  73429. + uint8_t data_toggle;
  73430. +
  73431. + /** Ping state if 1. */
  73432. + uint8_t ping_state;
  73433. +
  73434. + /**
  73435. + * List of QTDs for this QH.
  73436. + */
  73437. + struct dwc_otg_qtd_list qtd_list;
  73438. +
  73439. + /** Host channel currently processing transfers for this QH. */
  73440. + struct dwc_hc *channel;
  73441. +
  73442. + /** Full/low speed endpoint on high-speed hub requires split. */
  73443. + uint8_t do_split;
  73444. +
  73445. + /** @name Periodic schedule information */
  73446. + /** @{ */
  73447. +
  73448. + /** Bandwidth in microseconds per (micro)frame. */
  73449. + uint16_t usecs;
  73450. +
  73451. + /** Interval between transfers in (micro)frames. */
  73452. + uint16_t interval;
  73453. +
  73454. + /**
  73455. + * (micro)frame to initialize a periodic transfer. The transfer
  73456. + * executes in the following (micro)frame.
  73457. + */
  73458. + uint16_t sched_frame;
  73459. +
  73460. + /*
  73461. + ** Frame a NAK was received on this queue head, used to minimise NAK retransmission
  73462. + */
  73463. + uint16_t nak_frame;
  73464. +
  73465. + /** (micro)frame at which last start split was initialized. */
  73466. + uint16_t start_split_frame;
  73467. +
  73468. + /** @} */
  73469. +
  73470. + /**
  73471. + * Used instead of original buffer if
  73472. + * it(physical address) is not dword-aligned.
  73473. + */
  73474. + uint8_t *dw_align_buf;
  73475. + dwc_dma_t dw_align_buf_dma;
  73476. +
  73477. + /** Entry for QH in either the periodic or non-periodic schedule. */
  73478. + dwc_list_link_t qh_list_entry;
  73479. +
  73480. + /** @name Descriptor DMA support */
  73481. + /** @{ */
  73482. +
  73483. + /** Descriptor List. */
  73484. + dwc_otg_host_dma_desc_t *desc_list;
  73485. +
  73486. + /** Descriptor List physical address. */
  73487. + dwc_dma_t desc_list_dma;
  73488. +
  73489. + /**
  73490. + * Xfer Bytes array.
  73491. + * Each element corresponds to a descriptor and indicates
  73492. + * original XferSize size value for the descriptor.
  73493. + */
  73494. + uint32_t *n_bytes;
  73495. +
  73496. + /** Actual number of transfer descriptors in a list. */
  73497. + uint16_t ntd;
  73498. +
  73499. + /** First activated isochronous transfer descriptor index. */
  73500. + uint8_t td_first;
  73501. + /** Last activated isochronous transfer descriptor index. */
  73502. + uint8_t td_last;
  73503. +
  73504. + /** @} */
  73505. +
  73506. +
  73507. + uint16_t speed;
  73508. + uint16_t frame_usecs[8];
  73509. +
  73510. + uint32_t skip_count;
  73511. +} dwc_otg_qh_t;
  73512. +
  73513. +DWC_CIRCLEQ_HEAD(hc_list, dwc_hc);
  73514. +
  73515. +typedef struct urb_tq_entry {
  73516. + struct urb *urb;
  73517. + DWC_TAILQ_ENTRY(urb_tq_entry) urb_tq_entries;
  73518. +} urb_tq_entry_t;
  73519. +
  73520. +DWC_TAILQ_HEAD(urb_list, urb_tq_entry);
  73521. +
  73522. +/**
  73523. + * This structure holds the state of the HCD, including the non-periodic and
  73524. + * periodic schedules.
  73525. + */
  73526. +struct dwc_otg_hcd {
  73527. + /** The DWC otg device pointer */
  73528. + struct dwc_otg_device *otg_dev;
  73529. + /** DWC OTG Core Interface Layer */
  73530. + dwc_otg_core_if_t *core_if;
  73531. +
  73532. + /** Function HCD driver callbacks */
  73533. + struct dwc_otg_hcd_function_ops *fops;
  73534. +
  73535. + /** Internal DWC HCD Flags */
  73536. + volatile union dwc_otg_hcd_internal_flags {
  73537. + uint32_t d32;
  73538. + struct {
  73539. + unsigned port_connect_status_change:1;
  73540. + unsigned port_connect_status:1;
  73541. + unsigned port_reset_change:1;
  73542. + unsigned port_enable_change:1;
  73543. + unsigned port_suspend_change:1;
  73544. + unsigned port_over_current_change:1;
  73545. + unsigned port_l1_change:1;
  73546. + unsigned reserved:26;
  73547. + } b;
  73548. + } flags;
  73549. +
  73550. + /**
  73551. + * Inactive items in the non-periodic schedule. This is a list of
  73552. + * Queue Heads. Transfers associated with these Queue Heads are not
  73553. + * currently assigned to a host channel.
  73554. + */
  73555. + dwc_list_link_t non_periodic_sched_inactive;
  73556. +
  73557. + /**
  73558. + * Active items in the non-periodic schedule. This is a list of
  73559. + * Queue Heads. Transfers associated with these Queue Heads are
  73560. + * currently assigned to a host channel.
  73561. + */
  73562. + dwc_list_link_t non_periodic_sched_active;
  73563. +
  73564. + /**
  73565. + * Pointer to the next Queue Head to process in the active
  73566. + * non-periodic schedule.
  73567. + */
  73568. + dwc_list_link_t *non_periodic_qh_ptr;
  73569. +
  73570. + /**
  73571. + * Inactive items in the periodic schedule. This is a list of QHs for
  73572. + * periodic transfers that are _not_ scheduled for the next frame.
  73573. + * Each QH in the list has an interval counter that determines when it
  73574. + * needs to be scheduled for execution. This scheduling mechanism
  73575. + * allows only a simple calculation for periodic bandwidth used (i.e.
  73576. + * must assume that all periodic transfers may need to execute in the
  73577. + * same frame). However, it greatly simplifies scheduling and should
  73578. + * be sufficient for the vast majority of OTG hosts, which need to
  73579. + * connect to a small number of peripherals at one time.
  73580. + *
  73581. + * Items move from this list to periodic_sched_ready when the QH
  73582. + * interval counter is 0 at SOF.
  73583. + */
  73584. + dwc_list_link_t periodic_sched_inactive;
  73585. +
  73586. + /**
  73587. + * List of periodic QHs that are ready for execution in the next
  73588. + * frame, but have not yet been assigned to host channels.
  73589. + *
  73590. + * Items move from this list to periodic_sched_assigned as host
  73591. + * channels become available during the current frame.
  73592. + */
  73593. + dwc_list_link_t periodic_sched_ready;
  73594. +
  73595. + /**
  73596. + * List of periodic QHs to be executed in the next frame that are
  73597. + * assigned to host channels.
  73598. + *
  73599. + * Items move from this list to periodic_sched_queued as the
  73600. + * transactions for the QH are queued to the DWC_otg controller.
  73601. + */
  73602. + dwc_list_link_t periodic_sched_assigned;
  73603. +
  73604. + /**
  73605. + * List of periodic QHs that have been queued for execution.
  73606. + *
  73607. + * Items move from this list to either periodic_sched_inactive or
  73608. + * periodic_sched_ready when the channel associated with the transfer
  73609. + * is released. If the interval for the QH is 1, the item moves to
  73610. + * periodic_sched_ready because it must be rescheduled for the next
  73611. + * frame. Otherwise, the item moves to periodic_sched_inactive.
  73612. + */
  73613. + dwc_list_link_t periodic_sched_queued;
  73614. +
  73615. + /**
  73616. + * Total bandwidth claimed so far for periodic transfers. This value
  73617. + * is in microseconds per (micro)frame. The assumption is that all
  73618. + * periodic transfers may occur in the same (micro)frame.
  73619. + */
  73620. + uint16_t periodic_usecs;
  73621. +
  73622. + /**
  73623. + * Total bandwidth claimed so far for all periodic transfers
  73624. + * in a frame.
  73625. + * This will include a mixture of HS and FS transfers.
  73626. + * Units are microseconds per (micro)frame.
  73627. + * We have a budget per frame and have to schedule
  73628. + * transactions accordingly.
  73629. + * Watch out for the fact that things are actually scheduled for the
  73630. + * "next frame".
  73631. + */
  73632. + uint16_t frame_usecs[8];
  73633. +
  73634. +
  73635. + /**
  73636. + * Frame number read from the core at SOF. The value ranges from 0 to
  73637. + * DWC_HFNUM_MAX_FRNUM.
  73638. + */
  73639. + uint16_t frame_number;
  73640. +
  73641. + /**
  73642. + * Count of periodic QHs, if using several eps. For SOF enable/disable.
  73643. + */
  73644. + uint16_t periodic_qh_count;
  73645. +
  73646. + /**
  73647. + * Free host channels in the controller. This is a list of
  73648. + * dwc_hc_t items.
  73649. + */
  73650. + struct hc_list free_hc_list;
  73651. + /**
  73652. + * Number of host channels assigned to periodic transfers. Currently
  73653. + * assuming that there is a dedicated host channel for each periodic
  73654. + * transaction and at least one host channel available for
  73655. + * non-periodic transactions.
  73656. + */
  73657. + int periodic_channels; /* microframe_schedule==0 */
  73658. +
  73659. + /**
  73660. + * Number of host channels assigned to non-periodic transfers.
  73661. + */
  73662. + int non_periodic_channels; /* microframe_schedule==0 */
  73663. +
  73664. + /**
  73665. + * Number of host channels assigned to non-periodic transfers.
  73666. + */
  73667. + int available_host_channels;
  73668. +
  73669. + /**
  73670. + * Array of pointers to the host channel descriptors. Allows accessing
  73671. + * a host channel descriptor given the host channel number. This is
  73672. + * useful in interrupt handlers.
  73673. + */
  73674. + struct dwc_hc *hc_ptr_array[MAX_EPS_CHANNELS];
  73675. +
  73676. + /**
  73677. + * Buffer to use for any data received during the status phase of a
  73678. + * control transfer. Normally no data is transferred during the status
  73679. + * phase. This buffer is used as a bit bucket.
  73680. + */
  73681. + uint8_t *status_buf;
  73682. +
  73683. + /**
  73684. + * DMA address for status_buf.
  73685. + */
  73686. + dma_addr_t status_buf_dma;
  73687. +#define DWC_OTG_HCD_STATUS_BUF_SIZE 64
  73688. +
  73689. + /**
  73690. + * Connection timer. An OTG host must display a message if the device
  73691. + * does not connect. Started when the VBus power is turned on via
  73692. + * sysfs attribute "buspower".
  73693. + */
  73694. + dwc_timer_t *conn_timer;
  73695. +
  73696. + /* Tasket to do a reset */
  73697. + dwc_tasklet_t *reset_tasklet;
  73698. +
  73699. + dwc_tasklet_t *completion_tasklet;
  73700. + struct urb_list completed_urb_list;
  73701. +
  73702. + /* */
  73703. + dwc_spinlock_t *lock;
  73704. + dwc_spinlock_t *channel_lock;
  73705. + /**
  73706. + * Private data that could be used by OS wrapper.
  73707. + */
  73708. + void *priv;
  73709. +
  73710. + uint8_t otg_port;
  73711. +
  73712. + /** Frame List */
  73713. + uint32_t *frame_list;
  73714. +
  73715. + /** Hub - Port assignment */
  73716. + int hub_port[128];
  73717. +#ifdef FIQ_DEBUG
  73718. + int hub_port_alloc[2048];
  73719. +#endif
  73720. +
  73721. + /** Frame List DMA address */
  73722. + dma_addr_t frame_list_dma;
  73723. +
  73724. +#ifdef DEBUG
  73725. + uint32_t frrem_samples;
  73726. + uint64_t frrem_accum;
  73727. +
  73728. + uint32_t hfnum_7_samples_a;
  73729. + uint64_t hfnum_7_frrem_accum_a;
  73730. + uint32_t hfnum_0_samples_a;
  73731. + uint64_t hfnum_0_frrem_accum_a;
  73732. + uint32_t hfnum_other_samples_a;
  73733. + uint64_t hfnum_other_frrem_accum_a;
  73734. +
  73735. + uint32_t hfnum_7_samples_b;
  73736. + uint64_t hfnum_7_frrem_accum_b;
  73737. + uint32_t hfnum_0_samples_b;
  73738. + uint64_t hfnum_0_frrem_accum_b;
  73739. + uint32_t hfnum_other_samples_b;
  73740. + uint64_t hfnum_other_frrem_accum_b;
  73741. +#endif
  73742. +};
  73743. +
  73744. +/** @name Transaction Execution Functions */
  73745. +/** @{ */
  73746. +extern dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t
  73747. + * hcd);
  73748. +extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  73749. + dwc_otg_transaction_type_e tr_type);
  73750. +
  73751. +int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh);
  73752. +void dwc_otg_hcd_release_port(dwc_otg_hcd_t * dwc_otg_hcd, dwc_otg_qh_t *qh);
  73753. +
  73754. +
  73755. +/** @} */
  73756. +
  73757. +/** @name Interrupt Handler Functions */
  73758. +/** @{ */
  73759. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  73760. +extern int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  73761. +extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t *
  73762. + dwc_otg_hcd);
  73763. +extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t *
  73764. + dwc_otg_hcd);
  73765. +extern int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t *
  73766. + dwc_otg_hcd);
  73767. +extern int32_t dwc_otg_hcd_handle_incomplete_periodic_intr(dwc_otg_hcd_t *
  73768. + dwc_otg_hcd);
  73769. +extern int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  73770. +extern int32_t dwc_otg_hcd_handle_conn_id_status_change_intr(dwc_otg_hcd_t *
  73771. + dwc_otg_hcd);
  73772. +extern int32_t dwc_otg_hcd_handle_disconnect_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  73773. +extern int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  73774. +extern int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd,
  73775. + uint32_t num);
  73776. +extern int32_t dwc_otg_hcd_handle_session_req_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  73777. +extern int32_t dwc_otg_hcd_handle_wakeup_detected_intr(dwc_otg_hcd_t *
  73778. + dwc_otg_hcd);
  73779. +/** @} */
  73780. +
  73781. +/** @name Schedule Queue Functions */
  73782. +/** @{ */
  73783. +
  73784. +/* Implemented in dwc_otg_hcd_queue.c */
  73785. +extern dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  73786. + dwc_otg_hcd_urb_t * urb, int atomic_alloc);
  73787. +extern void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  73788. +extern int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  73789. +extern void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  73790. +extern void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  73791. + int sched_csplit);
  73792. +
  73793. +/** Remove and free a QH */
  73794. +static inline void dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd_t * hcd,
  73795. + dwc_otg_qh_t * qh)
  73796. +{
  73797. + dwc_irqflags_t flags;
  73798. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  73799. + dwc_otg_hcd_qh_remove(hcd, qh);
  73800. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  73801. + dwc_otg_hcd_qh_free(hcd, qh);
  73802. +}
  73803. +
  73804. +/** Allocates memory for a QH structure.
  73805. + * @return Returns the memory allocate or NULL on error. */
  73806. +static inline dwc_otg_qh_t *dwc_otg_hcd_qh_alloc(int atomic_alloc)
  73807. +{
  73808. + if (atomic_alloc)
  73809. + return (dwc_otg_qh_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qh_t));
  73810. + else
  73811. + return (dwc_otg_qh_t *) DWC_ALLOC(sizeof(dwc_otg_qh_t));
  73812. +}
  73813. +
  73814. +extern dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb,
  73815. + int atomic_alloc);
  73816. +extern void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb);
  73817. +extern int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd, dwc_otg_hcd_t * dwc_otg_hcd,
  73818. + dwc_otg_qh_t ** qh, int atomic_alloc);
  73819. +
  73820. +/** Allocates memory for a QTD structure.
  73821. + * @return Returns the memory allocate or NULL on error. */
  73822. +static inline dwc_otg_qtd_t *dwc_otg_hcd_qtd_alloc(int atomic_alloc)
  73823. +{
  73824. + if (atomic_alloc)
  73825. + return (dwc_otg_qtd_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qtd_t));
  73826. + else
  73827. + return (dwc_otg_qtd_t *) DWC_ALLOC(sizeof(dwc_otg_qtd_t));
  73828. +}
  73829. +
  73830. +/** Frees the memory for a QTD structure. QTD should already be removed from
  73831. + * list.
  73832. + * @param qtd QTD to free.*/
  73833. +static inline void dwc_otg_hcd_qtd_free(dwc_otg_qtd_t * qtd)
  73834. +{
  73835. + DWC_FREE(qtd);
  73836. +}
  73837. +
  73838. +/** Removes a QTD from list.
  73839. + * @param hcd HCD instance.
  73840. + * @param qtd QTD to remove from list.
  73841. + * @param qh QTD belongs to.
  73842. + */
  73843. +static inline void dwc_otg_hcd_qtd_remove(dwc_otg_hcd_t * hcd,
  73844. + dwc_otg_qtd_t * qtd,
  73845. + dwc_otg_qh_t * qh)
  73846. +{
  73847. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  73848. +}
  73849. +
  73850. +/** Remove and free a QTD
  73851. + * Need to disable IRQ and hold hcd lock while calling this function out of
  73852. + * interrupt servicing chain */
  73853. +static inline void dwc_otg_hcd_qtd_remove_and_free(dwc_otg_hcd_t * hcd,
  73854. + dwc_otg_qtd_t * qtd,
  73855. + dwc_otg_qh_t * qh)
  73856. +{
  73857. + dwc_otg_hcd_qtd_remove(hcd, qtd, qh);
  73858. + dwc_otg_hcd_qtd_free(qtd);
  73859. +}
  73860. +
  73861. +/** @} */
  73862. +
  73863. +/** @name Descriptor DMA Supporting Functions */
  73864. +/** @{ */
  73865. +
  73866. +extern void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  73867. +extern void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  73868. + dwc_hc_t * hc,
  73869. + dwc_otg_hc_regs_t * hc_regs,
  73870. + dwc_otg_halt_status_e halt_status);
  73871. +
  73872. +extern int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  73873. +extern void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  73874. +
  73875. +/** @} */
  73876. +
  73877. +/** @name Internal Functions */
  73878. +/** @{ */
  73879. +dwc_otg_qh_t *dwc_urb_to_qh(dwc_otg_hcd_urb_t * urb);
  73880. +/** @} */
  73881. +
  73882. +#ifdef CONFIG_USB_DWC_OTG_LPM
  73883. +extern int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd,
  73884. + uint8_t devaddr);
  73885. +extern void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd);
  73886. +#endif
  73887. +
  73888. +/** Gets the QH that contains the list_head */
  73889. +#define dwc_list_to_qh(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qh_t, qh_list_entry)
  73890. +
  73891. +/** Gets the QTD that contains the list_head */
  73892. +#define dwc_list_to_qtd(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qtd_t, qtd_list_entry)
  73893. +
  73894. +/** Check if QH is non-periodic */
  73895. +#define dwc_qh_is_non_per(_qh_ptr_) ((_qh_ptr_->ep_type == UE_BULK) || \
  73896. + (_qh_ptr_->ep_type == UE_CONTROL))
  73897. +
  73898. +/** High bandwidth multiplier as encoded in highspeed endpoint descriptors */
  73899. +#define dwc_hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
  73900. +
  73901. +/** Packet size for any kind of endpoint descriptor */
  73902. +#define dwc_max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
  73903. +
  73904. +/**
  73905. + * Returns true if _frame1 is less than or equal to _frame2. The comparison is
  73906. + * done modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the
  73907. + * frame number when the max frame number is reached.
  73908. + */
  73909. +static inline int dwc_frame_num_le(uint16_t frame1, uint16_t frame2)
  73910. +{
  73911. + return ((frame2 - frame1) & DWC_HFNUM_MAX_FRNUM) <=
  73912. + (DWC_HFNUM_MAX_FRNUM >> 1);
  73913. +}
  73914. +
  73915. +/**
  73916. + * Returns true if _frame1 is greater than _frame2. The comparison is done
  73917. + * modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
  73918. + * number when the max frame number is reached.
  73919. + */
  73920. +static inline int dwc_frame_num_gt(uint16_t frame1, uint16_t frame2)
  73921. +{
  73922. + return (frame1 != frame2) &&
  73923. + (((frame1 - frame2) & DWC_HFNUM_MAX_FRNUM) <
  73924. + (DWC_HFNUM_MAX_FRNUM >> 1));
  73925. +}
  73926. +
  73927. +/**
  73928. + * Increments _frame by the amount specified by _inc. The addition is done
  73929. + * modulo DWC_HFNUM_MAX_FRNUM. Returns the incremented value.
  73930. + */
  73931. +static inline uint16_t dwc_frame_num_inc(uint16_t frame, uint16_t inc)
  73932. +{
  73933. + return (frame + inc) & DWC_HFNUM_MAX_FRNUM;
  73934. +}
  73935. +
  73936. +static inline uint16_t dwc_full_frame_num(uint16_t frame)
  73937. +{
  73938. + return (frame & DWC_HFNUM_MAX_FRNUM) >> 3;
  73939. +}
  73940. +
  73941. +static inline uint16_t dwc_micro_frame_num(uint16_t frame)
  73942. +{
  73943. + return frame & 0x7;
  73944. +}
  73945. +
  73946. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  73947. + dwc_otg_hc_regs_t * hc_regs,
  73948. + dwc_otg_qtd_t * qtd);
  73949. +
  73950. +#ifdef DEBUG
  73951. +/**
  73952. + * Macro to sample the remaining PHY clocks left in the current frame. This
  73953. + * may be used during debugging to determine the average time it takes to
  73954. + * execute sections of code. There are two possible sample points, "a" and
  73955. + * "b", so the _letter argument must be one of these values.
  73956. + *
  73957. + * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
  73958. + * example, "cat /sys/devices/lm0/hcd_frrem".
  73959. + */
  73960. +#define dwc_sample_frrem(_hcd, _qh, _letter) \
  73961. +{ \
  73962. + hfnum_data_t hfnum; \
  73963. + dwc_otg_qtd_t *qtd; \
  73964. + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry); \
  73965. + if (usb_pipeint(qtd->urb->pipe) && _qh->start_split_frame != 0 && !qtd->complete_split) { \
  73966. + hfnum.d32 = DWC_READ_REG32(&_hcd->core_if->host_if->host_global_regs->hfnum); \
  73967. + switch (hfnum.b.frnum & 0x7) { \
  73968. + case 7: \
  73969. + _hcd->hfnum_7_samples_##_letter++; \
  73970. + _hcd->hfnum_7_frrem_accum_##_letter += hfnum.b.frrem; \
  73971. + break; \
  73972. + case 0: \
  73973. + _hcd->hfnum_0_samples_##_letter++; \
  73974. + _hcd->hfnum_0_frrem_accum_##_letter += hfnum.b.frrem; \
  73975. + break; \
  73976. + default: \
  73977. + _hcd->hfnum_other_samples_##_letter++; \
  73978. + _hcd->hfnum_other_frrem_accum_##_letter += hfnum.b.frrem; \
  73979. + break; \
  73980. + } \
  73981. + } \
  73982. +}
  73983. +#else
  73984. +#define dwc_sample_frrem(_hcd, _qh, _letter)
  73985. +#endif
  73986. +#endif
  73987. +#endif /* DWC_DEVICE_ONLY */
  73988. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h
  73989. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 1970-01-01 01:00:00.000000000 +0100
  73990. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 2014-02-18 11:52:14.000000000 +0100
  73991. @@ -0,0 +1,417 @@
  73992. +/* ==========================================================================
  73993. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_if.h $
  73994. + * $Revision: #12 $
  73995. + * $Date: 2011/10/26 $
  73996. + * $Change: 1873028 $
  73997. + *
  73998. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  73999. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  74000. + * otherwise expressly agreed to in writing between Synopsys and you.
  74001. + *
  74002. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  74003. + * any End User Software License Agreement or Agreement for Licensed Product
  74004. + * with Synopsys or any supplement thereto. You are permitted to use and
  74005. + * redistribute this Software in source and binary forms, with or without
  74006. + * modification, provided that redistributions of source code must retain this
  74007. + * notice. You may not view, use, disclose, copy or distribute this file or
  74008. + * any information contained herein except pursuant to this license grant from
  74009. + * Synopsys. If you do not agree with this notice, including the disclaimer
  74010. + * below, then you are not authorized to use the Software.
  74011. + *
  74012. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  74013. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  74014. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  74015. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  74016. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  74017. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  74018. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  74019. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  74020. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  74021. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  74022. + * DAMAGE.
  74023. + * ========================================================================== */
  74024. +#ifndef DWC_DEVICE_ONLY
  74025. +#ifndef __DWC_HCD_IF_H__
  74026. +#define __DWC_HCD_IF_H__
  74027. +
  74028. +#include "dwc_otg_core_if.h"
  74029. +
  74030. +/** @file
  74031. + * This file defines DWC_OTG HCD Core API.
  74032. + */
  74033. +
  74034. +struct dwc_otg_hcd;
  74035. +typedef struct dwc_otg_hcd dwc_otg_hcd_t;
  74036. +
  74037. +struct dwc_otg_hcd_urb;
  74038. +typedef struct dwc_otg_hcd_urb dwc_otg_hcd_urb_t;
  74039. +
  74040. +/** @name HCD Function Driver Callbacks */
  74041. +/** @{ */
  74042. +
  74043. +/** This function is called whenever core switches to host mode. */
  74044. +typedef int (*dwc_otg_hcd_start_cb_t) (dwc_otg_hcd_t * hcd);
  74045. +
  74046. +/** This function is called when device has been disconnected */
  74047. +typedef int (*dwc_otg_hcd_disconnect_cb_t) (dwc_otg_hcd_t * hcd);
  74048. +
  74049. +/** Wrapper provides this function to HCD to core, so it can get hub information to which device is connected */
  74050. +typedef int (*dwc_otg_hcd_hub_info_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  74051. + void *urb_handle,
  74052. + uint32_t * hub_addr,
  74053. + uint32_t * port_addr);
  74054. +/** Via this function HCD core gets device speed */
  74055. +typedef int (*dwc_otg_hcd_speed_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  74056. + void *urb_handle);
  74057. +
  74058. +/** This function is called when urb is completed */
  74059. +typedef int (*dwc_otg_hcd_complete_urb_cb_t) (dwc_otg_hcd_t * hcd,
  74060. + void *urb_handle,
  74061. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  74062. + int32_t status);
  74063. +
  74064. +/** Via this function HCD core gets b_hnp_enable parameter */
  74065. +typedef int (*dwc_otg_hcd_get_b_hnp_enable) (dwc_otg_hcd_t * hcd);
  74066. +
  74067. +struct dwc_otg_hcd_function_ops {
  74068. + dwc_otg_hcd_start_cb_t start;
  74069. + dwc_otg_hcd_disconnect_cb_t disconnect;
  74070. + dwc_otg_hcd_hub_info_from_urb_cb_t hub_info;
  74071. + dwc_otg_hcd_speed_from_urb_cb_t speed;
  74072. + dwc_otg_hcd_complete_urb_cb_t complete;
  74073. + dwc_otg_hcd_get_b_hnp_enable get_b_hnp_enable;
  74074. +};
  74075. +/** @} */
  74076. +
  74077. +/** @name HCD Core API */
  74078. +/** @{ */
  74079. +/** This function allocates dwc_otg_hcd structure and returns pointer on it. */
  74080. +extern dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void);
  74081. +
  74082. +/** This function should be called to initiate HCD Core.
  74083. + *
  74084. + * @param hcd The HCD
  74085. + * @param core_if The DWC_OTG Core
  74086. + *
  74087. + * Returns -DWC_E_NO_MEMORY if no enough memory.
  74088. + * Returns 0 on success
  74089. + */
  74090. +extern int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if);
  74091. +
  74092. +/** Frees HCD
  74093. + *
  74094. + * @param hcd The HCD
  74095. + */
  74096. +extern void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd);
  74097. +
  74098. +/** This function should be called on every hardware interrupt.
  74099. + *
  74100. + * @param dwc_otg_hcd The HCD
  74101. + *
  74102. + * Returns non zero if interrupt is handled
  74103. + * Return 0 if interrupt is not handled
  74104. + */
  74105. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  74106. +
  74107. +/** This function is used to handle the fast interrupt
  74108. + *
  74109. + */
  74110. +extern void __attribute__ ((naked)) dwc_otg_hcd_handle_fiq(void);
  74111. +
  74112. +/**
  74113. + * Returns private data set by
  74114. + * dwc_otg_hcd_set_priv_data function.
  74115. + *
  74116. + * @param hcd The HCD
  74117. + */
  74118. +extern void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd);
  74119. +
  74120. +/**
  74121. + * Set private data.
  74122. + *
  74123. + * @param hcd The HCD
  74124. + * @param priv_data pointer to be stored in private data
  74125. + */
  74126. +extern void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data);
  74127. +
  74128. +/**
  74129. + * This function initializes the HCD Core.
  74130. + *
  74131. + * @param hcd The HCD
  74132. + * @param fops The Function Driver Operations data structure containing pointers to all callbacks.
  74133. + *
  74134. + * Returns -DWC_E_NO_DEVICE if Core is currently is in device mode.
  74135. + * Returns 0 on success
  74136. + */
  74137. +extern int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  74138. + struct dwc_otg_hcd_function_ops *fops);
  74139. +
  74140. +/**
  74141. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  74142. + * stopped.
  74143. + *
  74144. + * @param hcd The HCD
  74145. + */
  74146. +extern void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd);
  74147. +
  74148. +/**
  74149. + * Handles hub class-specific requests.
  74150. + *
  74151. + * @param dwc_otg_hcd The HCD
  74152. + * @param typeReq Request Type
  74153. + * @param wValue wValue from control request
  74154. + * @param wIndex wIndex from control request
  74155. + * @param buf data buffer
  74156. + * @param wLength data buffer length
  74157. + *
  74158. + * Returns -DWC_E_INVALID if invalid argument is passed
  74159. + * Returns 0 on success
  74160. + */
  74161. +extern int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  74162. + uint16_t typeReq, uint16_t wValue,
  74163. + uint16_t wIndex, uint8_t * buf,
  74164. + uint16_t wLength);
  74165. +
  74166. +/**
  74167. + * Returns otg port number.
  74168. + *
  74169. + * @param hcd The HCD
  74170. + */
  74171. +extern uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd);
  74172. +
  74173. +/**
  74174. + * Returns OTG version - either 1.3 or 2.0.
  74175. + *
  74176. + * @param core_if The core_if structure pointer
  74177. + */
  74178. +extern uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if);
  74179. +
  74180. +/**
  74181. + * Returns 1 if currently core is acting as B host, and 0 otherwise.
  74182. + *
  74183. + * @param hcd The HCD
  74184. + */
  74185. +extern uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd);
  74186. +
  74187. +/**
  74188. + * Returns current frame number.
  74189. + *
  74190. + * @param hcd The HCD
  74191. + */
  74192. +extern int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * hcd);
  74193. +
  74194. +/**
  74195. + * Dumps hcd state.
  74196. + *
  74197. + * @param hcd The HCD
  74198. + */
  74199. +extern void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd);
  74200. +
  74201. +/**
  74202. + * Dump the average frame remaining at SOF. This can be used to
  74203. + * determine average interrupt latency. Frame remaining is also shown for
  74204. + * start transfer and two additional sample points.
  74205. + * Currently this function is not implemented.
  74206. + *
  74207. + * @param hcd The HCD
  74208. + */
  74209. +extern void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd);
  74210. +
  74211. +/**
  74212. + * Sends LPM transaction to the local device.
  74213. + *
  74214. + * @param hcd The HCD
  74215. + * @param devaddr Device Address
  74216. + * @param hird Host initiated resume duration
  74217. + * @param bRemoteWake Value of bRemoteWake field in LPM transaction
  74218. + *
  74219. + * Returns negative value if sending LPM transaction was not succeeded.
  74220. + * Returns 0 on success.
  74221. + */
  74222. +extern int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr,
  74223. + uint8_t hird, uint8_t bRemoteWake);
  74224. +
  74225. +/* URB interface */
  74226. +
  74227. +/**
  74228. + * Allocates memory for dwc_otg_hcd_urb structure.
  74229. + * Allocated memory should be freed by call of DWC_FREE.
  74230. + *
  74231. + * @param hcd The HCD
  74232. + * @param iso_desc_count Count of ISOC descriptors
  74233. + * @param atomic_alloc Specefies whether to perform atomic allocation.
  74234. + */
  74235. +extern dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  74236. + int iso_desc_count,
  74237. + int atomic_alloc);
  74238. +
  74239. +/**
  74240. + * Set pipe information in URB.
  74241. + *
  74242. + * @param hcd_urb DWC_OTG URB
  74243. + * @param devaddr Device Address
  74244. + * @param ep_num Endpoint Number
  74245. + * @param ep_type Endpoint Type
  74246. + * @param ep_dir Endpoint Direction
  74247. + * @param mps Max Packet Size
  74248. + */
  74249. +extern void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * hcd_urb,
  74250. + uint8_t devaddr, uint8_t ep_num,
  74251. + uint8_t ep_type, uint8_t ep_dir,
  74252. + uint16_t mps);
  74253. +
  74254. +/* Transfer flags */
  74255. +#define URB_GIVEBACK_ASAP 0x1
  74256. +#define URB_SEND_ZERO_PACKET 0x2
  74257. +
  74258. +/**
  74259. + * Sets dwc_otg_hcd_urb parameters.
  74260. + *
  74261. + * @param urb DWC_OTG URB allocated by dwc_otg_hcd_urb_alloc function.
  74262. + * @param urb_handle Unique handle for request, this will be passed back
  74263. + * to function driver in completion callback.
  74264. + * @param buf The buffer for the data
  74265. + * @param dma The DMA buffer for the data
  74266. + * @param buflen Transfer length
  74267. + * @param sp Buffer for setup data
  74268. + * @param sp_dma DMA address of setup data buffer
  74269. + * @param flags Transfer flags
  74270. + * @param interval Polling interval for interrupt or isochronous transfers.
  74271. + */
  74272. +extern void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * urb,
  74273. + void *urb_handle, void *buf,
  74274. + dwc_dma_t dma, uint32_t buflen, void *sp,
  74275. + dwc_dma_t sp_dma, uint32_t flags,
  74276. + uint16_t interval);
  74277. +
  74278. +/** Gets status from dwc_otg_hcd_urb
  74279. + *
  74280. + * @param dwc_otg_urb DWC_OTG URB
  74281. + */
  74282. +extern uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb);
  74283. +
  74284. +/** Gets actual length from dwc_otg_hcd_urb
  74285. + *
  74286. + * @param dwc_otg_urb DWC_OTG URB
  74287. + */
  74288. +extern uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t *
  74289. + dwc_otg_urb);
  74290. +
  74291. +/** Gets error count from dwc_otg_hcd_urb. Only for ISOC URBs
  74292. + *
  74293. + * @param dwc_otg_urb DWC_OTG URB
  74294. + */
  74295. +extern uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t *
  74296. + dwc_otg_urb);
  74297. +
  74298. +/** Set ISOC descriptor offset and length
  74299. + *
  74300. + * @param dwc_otg_urb DWC_OTG URB
  74301. + * @param desc_num ISOC descriptor number
  74302. + * @param offset Offset from beginig of buffer.
  74303. + * @param length Transaction length
  74304. + */
  74305. +extern void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  74306. + int desc_num, uint32_t offset,
  74307. + uint32_t length);
  74308. +
  74309. +/** Get status of ISOC descriptor, specified by desc_num
  74310. + *
  74311. + * @param dwc_otg_urb DWC_OTG URB
  74312. + * @param desc_num ISOC descriptor number
  74313. + */
  74314. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t *
  74315. + dwc_otg_urb, int desc_num);
  74316. +
  74317. +/** Get actual length of ISOC descriptor, specified by desc_num
  74318. + *
  74319. + * @param dwc_otg_urb DWC_OTG URB
  74320. + * @param desc_num ISOC descriptor number
  74321. + */
  74322. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  74323. + dwc_otg_urb,
  74324. + int desc_num);
  74325. +
  74326. +/** Queue URB. After transfer is completes, the complete callback will be called with the URB status
  74327. + *
  74328. + * @param dwc_otg_hcd The HCD
  74329. + * @param dwc_otg_urb DWC_OTG URB
  74330. + * @param ep_handle Out parameter for returning endpoint handle
  74331. + * @param atomic_alloc Flag to do atomic allocation if needed
  74332. + *
  74333. + * Returns -DWC_E_NO_DEVICE if no device is connected.
  74334. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  74335. + * Returns 0 on success.
  74336. + */
  74337. +extern int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * dwc_otg_hcd,
  74338. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  74339. + void **ep_handle, int atomic_alloc);
  74340. +
  74341. +/** De-queue the specified URB
  74342. + *
  74343. + * @param dwc_otg_hcd The HCD
  74344. + * @param dwc_otg_urb DWC_OTG URB
  74345. + */
  74346. +extern int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * dwc_otg_hcd,
  74347. + dwc_otg_hcd_urb_t * dwc_otg_urb);
  74348. +
  74349. +/** Frees resources in the DWC_otg controller related to a given endpoint.
  74350. + * Any URBs for the endpoint must already be dequeued.
  74351. + *
  74352. + * @param hcd The HCD
  74353. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  74354. + * @param retry Number of retries if there are queued transfers.
  74355. + *
  74356. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  74357. + * Returns 0 on success
  74358. + */
  74359. +extern int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  74360. + int retry);
  74361. +
  74362. +/* Resets the data toggle in qh structure. This function can be called from
  74363. + * usb_clear_halt routine.
  74364. + *
  74365. + * @param hcd The HCD
  74366. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  74367. + *
  74368. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  74369. + * Returns 0 on success
  74370. + */
  74371. +extern int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle);
  74372. +
  74373. +/** Returns 1 if status of specified port is changed and 0 otherwise.
  74374. + *
  74375. + * @param hcd The HCD
  74376. + * @param port Port number
  74377. + */
  74378. +extern int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port);
  74379. +
  74380. +/** Call this function to check if bandwidth was allocated for specified endpoint.
  74381. + * Only for ISOC and INTERRUPT endpoints.
  74382. + *
  74383. + * @param hcd The HCD
  74384. + * @param ep_handle Endpoint handle
  74385. + */
  74386. +extern int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd,
  74387. + void *ep_handle);
  74388. +
  74389. +/** Call this function to check if bandwidth was freed for specified endpoint.
  74390. + *
  74391. + * @param hcd The HCD
  74392. + * @param ep_handle Endpoint handle
  74393. + */
  74394. +extern int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle);
  74395. +
  74396. +/** Returns bandwidth allocated for specified endpoint in microseconds.
  74397. + * Only for ISOC and INTERRUPT endpoints.
  74398. + *
  74399. + * @param hcd The HCD
  74400. + * @param ep_handle Endpoint handle
  74401. + */
  74402. +extern uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd,
  74403. + void *ep_handle);
  74404. +
  74405. +/** @} */
  74406. +
  74407. +#endif /* __DWC_HCD_IF_H__ */
  74408. +#endif /* DWC_DEVICE_ONLY */
  74409. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
  74410. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  74411. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 2014-02-18 11:52:14.000000000 +0100
  74412. @@ -0,0 +1,2741 @@
  74413. +/* ==========================================================================
  74414. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_intr.c $
  74415. + * $Revision: #89 $
  74416. + * $Date: 2011/10/20 $
  74417. + * $Change: 1869487 $
  74418. + *
  74419. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  74420. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  74421. + * otherwise expressly agreed to in writing between Synopsys and you.
  74422. + *
  74423. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  74424. + * any End User Software License Agreement or Agreement for Licensed Product
  74425. + * with Synopsys or any supplement thereto. You are permitted to use and
  74426. + * redistribute this Software in source and binary forms, with or without
  74427. + * modification, provided that redistributions of source code must retain this
  74428. + * notice. You may not view, use, disclose, copy or distribute this file or
  74429. + * any information contained herein except pursuant to this license grant from
  74430. + * Synopsys. If you do not agree with this notice, including the disclaimer
  74431. + * below, then you are not authorized to use the Software.
  74432. + *
  74433. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  74434. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  74435. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  74436. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  74437. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  74438. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  74439. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  74440. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  74441. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  74442. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  74443. + * DAMAGE.
  74444. + * ========================================================================== */
  74445. +#ifndef DWC_DEVICE_ONLY
  74446. +
  74447. +#include "dwc_otg_hcd.h"
  74448. +#include "dwc_otg_regs.h"
  74449. +#include "dwc_otg_mphi_fix.h"
  74450. +
  74451. +#include <linux/jiffies.h>
  74452. +#include <mach/hardware.h>
  74453. +#include <asm/fiq.h>
  74454. +
  74455. +
  74456. +extern bool microframe_schedule;
  74457. +
  74458. +/** @file
  74459. + * This file contains the implementation of the HCD Interrupt handlers.
  74460. + */
  74461. +
  74462. +/*
  74463. + * Some globals to communicate between the FIQ and INTERRUPT
  74464. + */
  74465. +
  74466. +void * dummy_send;
  74467. +mphi_regs_t c_mphi_regs;
  74468. +volatile void *dwc_regs_base;
  74469. +int fiq_done, int_done;
  74470. +
  74471. +gintsts_data_t gintsts_saved = {.d32 = 0};
  74472. +hcint_data_t hcint_saved[MAX_EPS_CHANNELS];
  74473. +hcintmsk_data_t hcintmsk_saved[MAX_EPS_CHANNELS];
  74474. +int split_out_xfersize[MAX_EPS_CHANNELS];
  74475. +haint_data_t haint_saved;
  74476. +
  74477. +int g_next_sched_frame, g_np_count, g_np_sent;
  74478. +static int mphi_int_count = 0 ;
  74479. +
  74480. +hcchar_data_t nak_hcchar;
  74481. +hctsiz_data_t nak_hctsiz;
  74482. +hcsplt_data_t nak_hcsplt;
  74483. +int nak_count;
  74484. +
  74485. +int complete_sched[MAX_EPS_CHANNELS] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
  74486. +int split_start_frame[MAX_EPS_CHANNELS];
  74487. +int queued_port[MAX_EPS_CHANNELS];
  74488. +
  74489. +#ifdef FIQ_DEBUG
  74490. +char buffer[1000*16];
  74491. +int wptr;
  74492. +void notrace _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...)
  74493. +{
  74494. + FIQDBG_T dbg_lvl_req = FIQDBG_PORTHUB;
  74495. + va_list args;
  74496. + char text[17];
  74497. + hfnum_data_t hfnum = { .d32 = FIQ_READ(dwc_regs_base + 0x408) };
  74498. + unsigned long flags;
  74499. +
  74500. + local_irq_save(flags);
  74501. + local_fiq_disable();
  74502. + if(dbg_lvl & dbg_lvl_req || dbg_lvl == FIQDBG_ERR)
  74503. + {
  74504. + snprintf(text, 9, "%4d%d:%d ", hfnum.b.frnum/8, hfnum.b.frnum%8, 8 - hfnum.b.frrem/937);
  74505. + va_start(args, fmt);
  74506. + vsnprintf(text+8, 9, fmt, args);
  74507. + va_end(args);
  74508. +
  74509. + memcpy(buffer + wptr, text, 16);
  74510. + wptr = (wptr + 16) % sizeof(buffer);
  74511. + }
  74512. + local_irq_restore(flags);
  74513. +}
  74514. +#endif
  74515. +
  74516. +void notrace fiq_queue_request(int channel, int odd_frame)
  74517. +{
  74518. + hcchar_data_t hcchar = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x0) };
  74519. + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x4) };
  74520. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x10) };
  74521. +
  74522. + if(hcsplt.b.spltena == 0)
  74523. + {
  74524. + fiq_print(FIQDBG_ERR, "SPLTENA ");
  74525. + BUG();
  74526. + }
  74527. +
  74528. + if(hcchar.b.epdir == 1)
  74529. + {
  74530. + fiq_print(FIQDBG_SCHED, "IN Ch %d", channel);
  74531. + }
  74532. + else
  74533. + {
  74534. + hctsiz.b.xfersize = 0;
  74535. + fiq_print(FIQDBG_SCHED, "OUT Ch %d", channel);
  74536. + }
  74537. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x10), hctsiz.d32);
  74538. +
  74539. + hcsplt.b.compsplt = 1;
  74540. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x4), hcsplt.d32);
  74541. +
  74542. + // Send the Split complete
  74543. + hcchar.b.chen = 1;
  74544. + hcchar.b.oddfrm = odd_frame ? 1 : 0;
  74545. +
  74546. + // Post this for transmit on the next frame for periodic or this frame for non-periodic
  74547. + fiq_print(FIQDBG_SCHED, "SND_%s", odd_frame ? "ODD " : "EVEN");
  74548. +
  74549. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x0), hcchar.d32);
  74550. +}
  74551. +
  74552. +static int last_sof = -1;
  74553. +
  74554. +/*
  74555. +** Function to handle the start of frame interrupt, choose whether we need to do anything and
  74556. +** therefore trigger the main interrupt
  74557. +**
  74558. +** returns int != 0 - interrupt has been handled
  74559. +*/
  74560. +int diff;
  74561. +
  74562. +int notrace fiq_sof_handle(hfnum_data_t hfnum)
  74563. +{
  74564. + int handled = 0;
  74565. + int i;
  74566. +
  74567. + // Just check that once we're running we don't miss a SOF
  74568. + /*if(last_sof != -1 && (hfnum.b.frnum != ((last_sof + 1) & 0x3fff)))
  74569. + {
  74570. + fiq_print(FIQDBG_ERR, "LASTSOF ");
  74571. + fiq_print(FIQDBG_ERR, "%4d%d ", last_sof / 8, last_sof & 7);
  74572. + fiq_print(FIQDBG_ERR, "%4d%d ", hfnum.b.frnum / 8, hfnum.b.frnum & 7);
  74573. + BUG();
  74574. + }*/
  74575. +
  74576. + // Only start remembering the last sof when the interrupt has been
  74577. + // enabled (we don't check the mask to come in here...)
  74578. + if(last_sof != -1 || FIQ_READ(dwc_regs_base + 0x18) & (1<<3))
  74579. + last_sof = hfnum.b.frnum;
  74580. +
  74581. + for(i = 0; i < MAX_EPS_CHANNELS; i++)
  74582. + {
  74583. + if(complete_sched[i] != -1)
  74584. + {
  74585. + if(complete_sched[i] <= hfnum.b.frnum || (complete_sched[i] > 0x3f00 && hfnum.b.frnum < 0xf0))
  74586. + {
  74587. + fiq_queue_request(i, hfnum.b.frnum & 1);
  74588. + complete_sched[i] = -1;
  74589. + }
  74590. + }
  74591. +
  74592. + if(complete_sched[i] != -1)
  74593. + {
  74594. + // This is because we've seen a split complete occur with no start...
  74595. + // most likely because missed the complete 0x3fff frames ago!
  74596. +
  74597. + diff = (hfnum.b.frnum + 0x3fff - complete_sched[i]) & 0x3fff ;
  74598. + if(diff > 32 && diff < 0x3f00)
  74599. + {
  74600. + fiq_print(FIQDBG_ERR, "SPLTMISS");
  74601. + BUG();
  74602. + }
  74603. + }
  74604. + }
  74605. +
  74606. + if(g_np_count == g_np_sent && dwc_frame_num_gt(g_next_sched_frame, hfnum.b.frnum))
  74607. + {
  74608. + /*
  74609. + * If np_count != np_sent that means we need to queue non-periodic (bulk) packets this packet
  74610. + * g_next_sched_frame is the next frame we have periodic packets for
  74611. + *
  74612. + * if neither of these are required for this frame then just clear the interrupt
  74613. + */
  74614. + handled = 1;
  74615. +
  74616. + }
  74617. +
  74618. + return handled;
  74619. +}
  74620. +
  74621. +int notrace port_id(hcsplt_data_t hcsplt)
  74622. +{
  74623. + return hcsplt.b.prtaddr + (hcsplt.b.hubaddr << 8);
  74624. +}
  74625. +
  74626. +int notrace fiq_hcintr_handle(int channel, hfnum_data_t hfnum)
  74627. +{
  74628. + hcchar_data_t hcchar = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x0) };
  74629. + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x4) };
  74630. + hcint_data_t hcint = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x8) };
  74631. + hcintmsk_data_t hcintmsk = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0xc) };
  74632. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x10)};
  74633. +
  74634. + hcint_saved[channel].d32 |= hcint.d32;
  74635. + hcintmsk_saved[channel].d32 = hcintmsk.d32;
  74636. +
  74637. + if(hcsplt.b.spltena)
  74638. + {
  74639. + fiq_print(FIQDBG_PORTHUB, "ph: %4x", port_id(hcsplt));
  74640. + if(hcint.b.chhltd)
  74641. + {
  74642. + fiq_print(FIQDBG_SCHED, "CH HLT %d", channel);
  74643. + fiq_print(FIQDBG_SCHED, "%08x", hcint_saved[channel]);
  74644. + }
  74645. + if(hcint.b.stall || hcint.b.xacterr || hcint.b.bblerr || hcint.b.frmovrun || hcint.b.datatglerr)
  74646. + {
  74647. + queued_port[channel] = 0;
  74648. + fiq_print(FIQDBG_ERR, "CHAN ERR");
  74649. + }
  74650. + if(hcint.b.xfercomp)
  74651. + {
  74652. + // Clear the port allocation and transmit anything also on this port
  74653. + queued_port[channel] = 0;
  74654. + fiq_print(FIQDBG_SCHED, "XFERCOMP");
  74655. + }
  74656. + if(hcint.b.nak)
  74657. + {
  74658. + queued_port[channel] = 0;
  74659. + fiq_print(FIQDBG_SCHED, "NAK");
  74660. + }
  74661. + if(hcint.b.ack && !hcsplt.b.compsplt)
  74662. + {
  74663. + int i;
  74664. +
  74665. + // Do not complete isochronous out transactions
  74666. + if(hcchar.b.eptype == 1 && hcchar.b.epdir == 0)
  74667. + {
  74668. + queued_port[channel] = 0;
  74669. + fiq_print(FIQDBG_SCHED, "ISOC_OUT");
  74670. + }
  74671. + else
  74672. + {
  74673. + // Make sure we check the port / hub combination that we sent this split on.
  74674. + // Do not queue a second request to the same port
  74675. + for(i = 0; i < MAX_EPS_CHANNELS; i++)
  74676. + {
  74677. + if(port_id(hcsplt) == queued_port[i])
  74678. + {
  74679. + fiq_print(FIQDBG_ERR, "PORTERR ");
  74680. + //BUG();
  74681. + }
  74682. + }
  74683. +
  74684. + split_start_frame[channel] = (hfnum.b.frnum + 1) & ~7;
  74685. +
  74686. + // Note, the size of an OUT is in the start split phase, not
  74687. + // the complete split
  74688. + split_out_xfersize[channel] = hctsiz.b.xfersize;
  74689. +
  74690. + hcint_saved[channel].b.chhltd = 0;
  74691. + hcint_saved[channel].b.ack = 0;
  74692. +
  74693. + queued_port[channel] = port_id(hcsplt);
  74694. +
  74695. + if(hcchar.b.eptype & 1)
  74696. + {
  74697. + // Send the periodic complete in the same oddness frame as the ACK went...
  74698. + fiq_queue_request(channel, !(hfnum.b.frnum & 1));
  74699. + // complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 1);
  74700. + }
  74701. + else
  74702. + {
  74703. + // Schedule the split complete to occur later
  74704. + complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 2);
  74705. + fiq_print(FIQDBG_SCHED, "ACK%04d%d", complete_sched[channel]/8, complete_sched[channel]%8);
  74706. + }
  74707. + }
  74708. + }
  74709. + if(hcint.b.nyet)
  74710. + {
  74711. + fiq_print(FIQDBG_ERR, "NYETERR1");
  74712. + //BUG();
  74713. + // Can transmit a split complete up to uframe .0 of the next frame
  74714. + if(hfnum.b.frnum <= dwc_frame_num_inc(split_start_frame[channel], 8))
  74715. + {
  74716. + // Send it next frame
  74717. + if(hcchar.b.eptype & 1) // type 1 & 3 are interrupt & isoc
  74718. + {
  74719. + fiq_print(FIQDBG_SCHED, "NYT:SEND");
  74720. + fiq_queue_request(channel, !(hfnum.b.frnum & 1));
  74721. + }
  74722. + else
  74723. + {
  74724. + // Schedule non-periodic access for next frame (the odd-even bit doesn't effect NP)
  74725. + complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 1);
  74726. + fiq_print(FIQDBG_SCHED, "NYT%04d%d", complete_sched[channel]/8, complete_sched[channel]%8);
  74727. + }
  74728. + hcint_saved[channel].b.chhltd = 0;
  74729. + hcint_saved[channel].b.nyet = 0;
  74730. + }
  74731. + else
  74732. + {
  74733. + queued_port[channel] = 0;
  74734. + fiq_print(FIQDBG_ERR, "NYETERR2");
  74735. + //BUG();
  74736. + }
  74737. + }
  74738. + }
  74739. + else
  74740. + {
  74741. + /*
  74742. + * If we have any of NAK, ACK, Datatlgerr active on a
  74743. + * non-split channel, the sole reason is to reset error
  74744. + * counts for a previously broken transaction. The FIQ
  74745. + * will thrash on NAK IN and ACK OUT in particular so
  74746. + * handle it "once" and allow the IRQ to do the rest.
  74747. + */
  74748. + hcint.d32 &= hcintmsk.d32;
  74749. + if(hcint.b.nak)
  74750. + {
  74751. + hcintmsk.b.nak = 0;
  74752. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0xc), hcintmsk.d32);
  74753. + }
  74754. + if (hcint.b.ack)
  74755. + {
  74756. + hcintmsk.b.ack = 0;
  74757. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0xc), hcintmsk.d32);
  74758. + }
  74759. + }
  74760. +
  74761. + // Clear the interrupt, this will also clear the HAINT bit
  74762. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x8), hcint.d32);
  74763. + return hcint_saved[channel].d32 == 0;
  74764. +}
  74765. +
  74766. +gintsts_data_t gintsts;
  74767. +gintmsk_data_t gintmsk;
  74768. +// triggered: The set of interrupts that were triggered
  74769. +// handled: The set of interrupts that have been handled (no IRQ is
  74770. +// required)
  74771. +// keep: The set of interrupts we want to keep unmasked even though we
  74772. +// want to trigger an IRQ to handle it (SOF and HCINTR)
  74773. +gintsts_data_t triggered, handled, keep;
  74774. +hfnum_data_t hfnum;
  74775. +
  74776. +void __attribute__ ((naked)) notrace dwc_otg_hcd_handle_fiq(void)
  74777. +{
  74778. +
  74779. + /* entry takes care to store registers we will be treading on here */
  74780. + asm __volatile__ (
  74781. + "mov ip, sp ;"
  74782. + /* stash FIQ and normal regs */
  74783. + "stmdb sp!, {r0-r12, lr};"
  74784. + /* !! THIS SETS THE FRAME, adjust to > sizeof locals */
  74785. + "sub fp, ip, #512 ;"
  74786. + );
  74787. +
  74788. + // Cannot put local variables at the beginning of the function
  74789. + // because otherwise 'C' will play with the stack pointer. any locals
  74790. + // need to be inside the following block
  74791. + do
  74792. + {
  74793. + fiq_done++;
  74794. + gintsts.d32 = FIQ_READ(dwc_regs_base + 0x14);
  74795. + gintmsk.d32 = FIQ_READ(dwc_regs_base + 0x18);
  74796. + hfnum.d32 = FIQ_READ(dwc_regs_base + 0x408);
  74797. + triggered.d32 = gintsts.d32 & gintmsk.d32;
  74798. + handled.d32 = 0;
  74799. + keep.d32 = 0;
  74800. + fiq_print(FIQDBG_INT, "FIQ ");
  74801. + fiq_print(FIQDBG_INT, "%08x", gintsts.d32);
  74802. + fiq_print(FIQDBG_INT, "%08x", gintmsk.d32);
  74803. + if(gintsts.d32)
  74804. + {
  74805. + // If port enabled
  74806. + if((FIQ_READ(dwc_regs_base + 0x440) & 0xf) == 0x5)
  74807. + {
  74808. + if(gintsts.b.sofintr)
  74809. + {
  74810. + if(fiq_sof_handle(hfnum))
  74811. + {
  74812. + handled.b.sofintr = 1; /* Handled in FIQ */
  74813. + }
  74814. + else
  74815. + {
  74816. + /* Keer interrupt unmasked */
  74817. + keep.b.sofintr = 1;
  74818. + }
  74819. + {
  74820. + // Need to make sure the read and clearing of the SOF interrupt is as close as possible to avoid the possibility of missing
  74821. + // a start of frame interrupt
  74822. + gintsts_data_t gintsts = { .b.sofintr = 1 };
  74823. + FIQ_WRITE((dwc_regs_base + 0x14), gintsts.d32);
  74824. + }
  74825. + }
  74826. +
  74827. + if(fiq_split_enable && gintsts.b.hcintr)
  74828. + {
  74829. + int i;
  74830. + haint_data_t haint;
  74831. + haintmsk_data_t haintmsk;
  74832. +
  74833. + haint.d32 = FIQ_READ(dwc_regs_base + 0x414);
  74834. + haintmsk.d32 = FIQ_READ(dwc_regs_base + 0x418);
  74835. + haint.d32 &= haintmsk.d32;
  74836. + haint_saved.d32 |= haint.d32;
  74837. +
  74838. + fiq_print(FIQDBG_INT, "hcintr");
  74839. + fiq_print(FIQDBG_INT, "%08x", FIQ_READ(dwc_regs_base + 0x414));
  74840. +
  74841. + // Go through each channel that has an enabled interrupt
  74842. + for(i = 0; i < 16; i++)
  74843. + if((haint.d32 >> i) & 1)
  74844. + if(fiq_hcintr_handle(i, hfnum))
  74845. + haint_saved.d32 &= ~(1 << i); /* this was handled */
  74846. +
  74847. + /* If we've handled all host channel interrupts then don't trigger the interrupt */
  74848. + if(haint_saved.d32 == 0)
  74849. + {
  74850. + handled.b.hcintr = 1;
  74851. + }
  74852. + else
  74853. + {
  74854. + /* Make sure we keep the channel interrupt unmasked when triggering the IRQ */
  74855. + keep.b.hcintr = 1;
  74856. + }
  74857. +
  74858. + {
  74859. + gintsts_data_t gintsts = { .b.hcintr = 1 };
  74860. +
  74861. + // Always clear the channel interrupt
  74862. + FIQ_WRITE((dwc_regs_base + 0x14), gintsts.d32);
  74863. + }
  74864. + }
  74865. + }
  74866. + else
  74867. + {
  74868. + last_sof = -1;
  74869. + }
  74870. + }
  74871. +
  74872. + // Mask out the interrupts triggered - those handled - don't mask out the ones we want to keep
  74873. + gintmsk.d32 = keep.d32 | (gintmsk.d32 & ~(triggered.d32 & ~handled.d32));
  74874. + // Save those that were triggered but not handled
  74875. + gintsts_saved.d32 |= triggered.d32 & ~handled.d32;
  74876. + FIQ_WRITE(dwc_regs_base + 0x18, gintmsk.d32);
  74877. +
  74878. + // Clear and save any unhandled interrupts and trigger the interrupt
  74879. + if(gintsts_saved.d32)
  74880. + {
  74881. + /* To enable the MPHI interrupt (INT 32)
  74882. + */
  74883. + FIQ_WRITE( c_mphi_regs.outdda, (int) dummy_send);
  74884. + FIQ_WRITE( c_mphi_regs.outddb, (1 << 29));
  74885. +
  74886. + mphi_int_count++;
  74887. + }
  74888. + }
  74889. + while(0);
  74890. +
  74891. + mb();
  74892. +
  74893. + /* exit back to normal mode restoring everything */
  74894. + asm __volatile__ (
  74895. + /* return FIQ regs back to pristine state
  74896. + * and get normal regs back
  74897. + */
  74898. + "ldmia sp!, {r0-r12, lr};"
  74899. +
  74900. + /* return */
  74901. + "subs pc, lr, #4;"
  74902. + );
  74903. +}
  74904. +
  74905. +/** This function handles interrupts for the HCD. */
  74906. +int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  74907. +{
  74908. + int retval = 0;
  74909. + static int last_time;
  74910. +
  74911. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  74912. + gintsts_data_t gintsts;
  74913. + gintmsk_data_t gintmsk;
  74914. + hfnum_data_t hfnum;
  74915. +
  74916. +#ifdef DEBUG
  74917. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  74918. +
  74919. +#endif
  74920. +
  74921. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  74922. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  74923. +
  74924. + /* Exit from ISR if core is hibernated */
  74925. + if (core_if->hibernation_suspend == 1) {
  74926. + goto exit_handler_routine;
  74927. + }
  74928. + DWC_SPINLOCK(dwc_otg_hcd->lock);
  74929. + /* Check if HOST Mode */
  74930. + if (dwc_otg_is_host_mode(core_if)) {
  74931. + local_fiq_disable();
  74932. + gintmsk.d32 |= gintsts_saved.d32;
  74933. + gintsts.d32 |= gintsts_saved.d32;
  74934. + gintsts_saved.d32 = 0;
  74935. + local_fiq_enable();
  74936. + if (!gintsts.d32) {
  74937. + goto exit_handler_routine;
  74938. + }
  74939. + gintsts.d32 &= gintmsk.d32;
  74940. +
  74941. +#ifdef DEBUG
  74942. + // We should be OK doing this because the common interrupts should already have been serviced
  74943. + /* Don't print debug message in the interrupt handler on SOF */
  74944. +#ifndef DEBUG_SOF
  74945. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  74946. +#endif
  74947. + DWC_DEBUGPL(DBG_HCDI, "\n");
  74948. +#endif
  74949. +
  74950. +#ifdef DEBUG
  74951. +#ifndef DEBUG_SOF
  74952. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  74953. +#endif
  74954. + DWC_DEBUGPL(DBG_HCDI,
  74955. + "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x core_if=%p\n",
  74956. + gintsts.d32, core_if);
  74957. +#endif
  74958. + hfnum.d32 = DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->hfnum);
  74959. + if (gintsts.b.sofintr && g_np_count == g_np_sent && dwc_frame_num_gt(g_next_sched_frame, hfnum.b.frnum))
  74960. + {
  74961. + /* Note, we should never get here if the FIQ is doing it's job properly*/
  74962. + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
  74963. + }
  74964. + else if (gintsts.b.sofintr) {
  74965. + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
  74966. + }
  74967. +
  74968. + if (gintsts.b.rxstsqlvl) {
  74969. + retval |=
  74970. + dwc_otg_hcd_handle_rx_status_q_level_intr
  74971. + (dwc_otg_hcd);
  74972. + }
  74973. + if (gintsts.b.nptxfempty) {
  74974. + retval |=
  74975. + dwc_otg_hcd_handle_np_tx_fifo_empty_intr
  74976. + (dwc_otg_hcd);
  74977. + }
  74978. + if (gintsts.b.i2cintr) {
  74979. + /** @todo Implement i2cintr handler. */
  74980. + }
  74981. + if (gintsts.b.portintr) {
  74982. +
  74983. + gintmsk_data_t gintmsk = { .b.portintr = 1};
  74984. + retval |= dwc_otg_hcd_handle_port_intr(dwc_otg_hcd);
  74985. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  74986. + }
  74987. + if (gintsts.b.hcintr) {
  74988. + retval |= dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd);
  74989. + }
  74990. + if (gintsts.b.ptxfempty) {
  74991. + retval |=
  74992. + dwc_otg_hcd_handle_perio_tx_fifo_empty_intr
  74993. + (dwc_otg_hcd);
  74994. + }
  74995. +#ifdef DEBUG
  74996. +#ifndef DEBUG_SOF
  74997. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  74998. +#endif
  74999. + {
  75000. + DWC_DEBUGPL(DBG_HCDI,
  75001. + "DWC OTG HCD Finished Servicing Interrupts\n");
  75002. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintsts=0x%08x\n",
  75003. + DWC_READ_REG32(&global_regs->gintsts));
  75004. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintmsk=0x%08x\n",
  75005. + DWC_READ_REG32(&global_regs->gintmsk));
  75006. + }
  75007. +#endif
  75008. +
  75009. +#ifdef DEBUG
  75010. +#ifndef DEBUG_SOF
  75011. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  75012. +#endif
  75013. + DWC_DEBUGPL(DBG_HCDI, "\n");
  75014. +#endif
  75015. +
  75016. + }
  75017. +
  75018. +exit_handler_routine:
  75019. +
  75020. + if (fiq_fix_enable)
  75021. + {
  75022. + local_fiq_disable();
  75023. + // Make sure that we don't clear the interrupt if we've still got pending work to do
  75024. + if(gintsts_saved.d32 == 0)
  75025. + {
  75026. + /* Clear the MPHI interrupt */
  75027. + DWC_WRITE_REG32(c_mphi_regs.intstat, (1<<16));
  75028. + if (mphi_int_count >= 60)
  75029. + {
  75030. + DWC_WRITE_REG32(c_mphi_regs.ctrl, ((1<<31) + (1<<16)));
  75031. + while(!(DWC_READ_REG32(c_mphi_regs.ctrl) & (1 << 17)))
  75032. + ;
  75033. + DWC_WRITE_REG32(c_mphi_regs.ctrl, (1<<31));
  75034. + mphi_int_count = 0;
  75035. + }
  75036. + int_done++;
  75037. + }
  75038. +
  75039. + // Unmask handled interrupts
  75040. + FIQ_WRITE(dwc_regs_base + 0x18, gintmsk.d32);
  75041. + //DWC_MODIFY_REG32((uint32_t *)IO_ADDRESS(USB_BASE + 0x8), 0 , 1);
  75042. +
  75043. + local_fiq_enable();
  75044. +
  75045. + if((jiffies / HZ) > last_time)
  75046. + {
  75047. + /* Once a second output the fiq and irq numbers, useful for debug */
  75048. + last_time = jiffies / HZ;
  75049. + DWC_DEBUGPL(DBG_USER, "int_done = %d fiq_done = %d\n", int_done, fiq_done);
  75050. + }
  75051. + }
  75052. +
  75053. + DWC_SPINUNLOCK(dwc_otg_hcd->lock);
  75054. + return retval;
  75055. +}
  75056. +
  75057. +#ifdef DWC_TRACK_MISSED_SOFS
  75058. +
  75059. +#warning Compiling code to track missed SOFs
  75060. +#define FRAME_NUM_ARRAY_SIZE 1000
  75061. +/**
  75062. + * This function is for debug only.
  75063. + */
  75064. +static inline void track_missed_sofs(uint16_t curr_frame_number)
  75065. +{
  75066. + static uint16_t frame_num_array[FRAME_NUM_ARRAY_SIZE];
  75067. + static uint16_t last_frame_num_array[FRAME_NUM_ARRAY_SIZE];
  75068. + static int frame_num_idx = 0;
  75069. + static uint16_t last_frame_num = DWC_HFNUM_MAX_FRNUM;
  75070. + static int dumped_frame_num_array = 0;
  75071. +
  75072. + if (frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
  75073. + if (((last_frame_num + 1) & DWC_HFNUM_MAX_FRNUM) !=
  75074. + curr_frame_number) {
  75075. + frame_num_array[frame_num_idx] = curr_frame_number;
  75076. + last_frame_num_array[frame_num_idx++] = last_frame_num;
  75077. + }
  75078. + } else if (!dumped_frame_num_array) {
  75079. + int i;
  75080. + DWC_PRINTF("Frame Last Frame\n");
  75081. + DWC_PRINTF("----- ----------\n");
  75082. + for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
  75083. + DWC_PRINTF("0x%04x 0x%04x\n",
  75084. + frame_num_array[i], last_frame_num_array[i]);
  75085. + }
  75086. + dumped_frame_num_array = 1;
  75087. + }
  75088. + last_frame_num = curr_frame_number;
  75089. +}
  75090. +#endif
  75091. +
  75092. +/**
  75093. + * Handles the start-of-frame interrupt in host mode. Non-periodic
  75094. + * transactions may be queued to the DWC_otg controller for the current
  75095. + * (micro)frame. Periodic transactions may be queued to the controller for the
  75096. + * next (micro)frame.
  75097. + */
  75098. +int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * hcd)
  75099. +{
  75100. + hfnum_data_t hfnum;
  75101. + dwc_list_link_t *qh_entry;
  75102. + dwc_otg_qh_t *qh;
  75103. + dwc_otg_transaction_type_e tr_type;
  75104. + int did_something = 0;
  75105. + int32_t next_sched_frame = -1;
  75106. +
  75107. + hfnum.d32 =
  75108. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  75109. +
  75110. +#ifdef DEBUG_SOF
  75111. + DWC_DEBUGPL(DBG_HCD, "--Start of Frame Interrupt--\n");
  75112. +#endif
  75113. + hcd->frame_number = hfnum.b.frnum;
  75114. +
  75115. +#ifdef DEBUG
  75116. + hcd->frrem_accum += hfnum.b.frrem;
  75117. + hcd->frrem_samples++;
  75118. +#endif
  75119. +
  75120. +#ifdef DWC_TRACK_MISSED_SOFS
  75121. + track_missed_sofs(hcd->frame_number);
  75122. +#endif
  75123. + /* Determine whether any periodic QHs should be executed. */
  75124. + qh_entry = DWC_LIST_FIRST(&hcd->periodic_sched_inactive);
  75125. + while (qh_entry != &hcd->periodic_sched_inactive) {
  75126. + qh = DWC_LIST_ENTRY(qh_entry, dwc_otg_qh_t, qh_list_entry);
  75127. + qh_entry = qh_entry->next;
  75128. + if (dwc_frame_num_le(qh->sched_frame, hcd->frame_number)) {
  75129. +
  75130. + /*
  75131. + * Move QH to the ready list to be executed next
  75132. + * (micro)frame.
  75133. + */
  75134. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  75135. + &qh->qh_list_entry);
  75136. +
  75137. + did_something = 1;
  75138. + }
  75139. + else
  75140. + {
  75141. + if(next_sched_frame < 0 || dwc_frame_num_le(qh->sched_frame, next_sched_frame))
  75142. + {
  75143. + next_sched_frame = qh->sched_frame;
  75144. + }
  75145. + }
  75146. + }
  75147. +
  75148. + g_next_sched_frame = next_sched_frame;
  75149. +
  75150. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  75151. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  75152. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  75153. + did_something = 1;
  75154. + }
  75155. +
  75156. + /* Clear interrupt */
  75157. + gintsts.b.sofintr = 1;
  75158. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
  75159. +
  75160. + return 1;
  75161. +}
  75162. +
  75163. +/** Handles the Rx Status Queue Level Interrupt, which indicates that there is at
  75164. + * least one packet in the Rx FIFO. The packets are moved from the FIFO to
  75165. + * memory if the DWC_otg controller is operating in Slave mode. */
  75166. +int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  75167. +{
  75168. + host_grxsts_data_t grxsts;
  75169. + dwc_hc_t *hc = NULL;
  75170. +
  75171. + DWC_DEBUGPL(DBG_HCD, "--RxStsQ Level Interrupt--\n");
  75172. +
  75173. + grxsts.d32 =
  75174. + DWC_READ_REG32(&dwc_otg_hcd->core_if->core_global_regs->grxstsp);
  75175. +
  75176. + hc = dwc_otg_hcd->hc_ptr_array[grxsts.b.chnum];
  75177. + if (!hc) {
  75178. + DWC_ERROR("Unable to get corresponding channel\n");
  75179. + return 0;
  75180. + }
  75181. +
  75182. + /* Packet Status */
  75183. + DWC_DEBUGPL(DBG_HCDV, " Ch num = %d\n", grxsts.b.chnum);
  75184. + DWC_DEBUGPL(DBG_HCDV, " Count = %d\n", grxsts.b.bcnt);
  75185. + DWC_DEBUGPL(DBG_HCDV, " DPID = %d, hc.dpid = %d\n", grxsts.b.dpid,
  75186. + hc->data_pid_start);
  75187. + DWC_DEBUGPL(DBG_HCDV, " PStatus = %d\n", grxsts.b.pktsts);
  75188. +
  75189. + switch (grxsts.b.pktsts) {
  75190. + case DWC_GRXSTS_PKTSTS_IN:
  75191. + /* Read the data into the host buffer. */
  75192. + if (grxsts.b.bcnt > 0) {
  75193. + dwc_otg_read_packet(dwc_otg_hcd->core_if,
  75194. + hc->xfer_buff, grxsts.b.bcnt);
  75195. +
  75196. + /* Update the HC fields for the next packet received. */
  75197. + hc->xfer_count += grxsts.b.bcnt;
  75198. + hc->xfer_buff += grxsts.b.bcnt;
  75199. + }
  75200. +
  75201. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  75202. + case DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
  75203. + case DWC_GRXSTS_PKTSTS_CH_HALTED:
  75204. + /* Handled in interrupt, just ignore data */
  75205. + break;
  75206. + default:
  75207. + DWC_ERROR("RX_STS_Q Interrupt: Unknown status %d\n",
  75208. + grxsts.b.pktsts);
  75209. + break;
  75210. + }
  75211. +
  75212. + return 1;
  75213. +}
  75214. +
  75215. +/** This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
  75216. + * data packets may be written to the FIFO for OUT transfers. More requests
  75217. + * may be written to the non-periodic request queue for IN transfers. This
  75218. + * interrupt is enabled only in Slave mode. */
  75219. +int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  75220. +{
  75221. + DWC_DEBUGPL(DBG_HCD, "--Non-Periodic TxFIFO Empty Interrupt--\n");
  75222. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  75223. + DWC_OTG_TRANSACTION_NON_PERIODIC);
  75224. + return 1;
  75225. +}
  75226. +
  75227. +/** This interrupt occurs when the periodic Tx FIFO is half-empty. More data
  75228. + * packets may be written to the FIFO for OUT transfers. More requests may be
  75229. + * written to the periodic request queue for IN transfers. This interrupt is
  75230. + * enabled only in Slave mode. */
  75231. +int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  75232. +{
  75233. + DWC_DEBUGPL(DBG_HCD, "--Periodic TxFIFO Empty Interrupt--\n");
  75234. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  75235. + DWC_OTG_TRANSACTION_PERIODIC);
  75236. + return 1;
  75237. +}
  75238. +
  75239. +/** There are multiple conditions that can cause a port interrupt. This function
  75240. + * determines which interrupt conditions have occurred and handles them
  75241. + * appropriately. */
  75242. +int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  75243. +{
  75244. + int retval = 0;
  75245. + hprt0_data_t hprt0;
  75246. + hprt0_data_t hprt0_modify;
  75247. +
  75248. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  75249. + hprt0_modify.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  75250. +
  75251. + /* Clear appropriate bits in HPRT0 to clear the interrupt bit in
  75252. + * GINTSTS */
  75253. +
  75254. + hprt0_modify.b.prtena = 0;
  75255. + hprt0_modify.b.prtconndet = 0;
  75256. + hprt0_modify.b.prtenchng = 0;
  75257. + hprt0_modify.b.prtovrcurrchng = 0;
  75258. +
  75259. + /* Port Connect Detected
  75260. + * Set flag and clear if detected */
  75261. + if (dwc_otg_hcd->core_if->hibernation_suspend == 1) {
  75262. + // Dont modify port status if we are in hibernation state
  75263. + hprt0_modify.b.prtconndet = 1;
  75264. + hprt0_modify.b.prtenchng = 1;
  75265. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  75266. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  75267. + return retval;
  75268. + }
  75269. +
  75270. + if (hprt0.b.prtconndet) {
  75271. + /** @todo - check if steps performed in 'else' block should be perfromed regardles adp */
  75272. + if (dwc_otg_hcd->core_if->adp_enable &&
  75273. + dwc_otg_hcd->core_if->adp.vbuson_timer_started == 1) {
  75274. + DWC_PRINTF("PORT CONNECT DETECTED ----------------\n");
  75275. + DWC_TIMER_CANCEL(dwc_otg_hcd->core_if->adp.vbuson_timer);
  75276. + dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  75277. + /* TODO - check if this is required, as
  75278. + * host initialization was already performed
  75279. + * after initial ADP probing
  75280. + */
  75281. + /*dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  75282. + dwc_otg_core_init(dwc_otg_hcd->core_if);
  75283. + dwc_otg_enable_global_interrupts(dwc_otg_hcd->core_if);
  75284. + cil_hcd_start(dwc_otg_hcd->core_if);*/
  75285. + } else {
  75286. +
  75287. + DWC_DEBUGPL(DBG_HCD, "--Port Interrupt HPRT0=0x%08x "
  75288. + "Port Connect Detected--\n", hprt0.d32);
  75289. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  75290. + dwc_otg_hcd->flags.b.port_connect_status = 1;
  75291. + hprt0_modify.b.prtconndet = 1;
  75292. +
  75293. + /* B-Device has connected, Delete the connection timer. */
  75294. + DWC_TIMER_CANCEL(dwc_otg_hcd->conn_timer);
  75295. + }
  75296. + /* The Hub driver asserts a reset when it sees port connect
  75297. + * status change flag */
  75298. + retval |= 1;
  75299. + }
  75300. +
  75301. + /* Port Enable Changed
  75302. + * Clear if detected - Set internal flag if disabled */
  75303. + if (hprt0.b.prtenchng) {
  75304. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  75305. + "Port Enable Changed--\n", hprt0.d32);
  75306. + hprt0_modify.b.prtenchng = 1;
  75307. + if (hprt0.b.prtena == 1) {
  75308. + hfir_data_t hfir;
  75309. + int do_reset = 0;
  75310. + dwc_otg_core_params_t *params =
  75311. + dwc_otg_hcd->core_if->core_params;
  75312. + dwc_otg_core_global_regs_t *global_regs =
  75313. + dwc_otg_hcd->core_if->core_global_regs;
  75314. + dwc_otg_host_if_t *host_if =
  75315. + dwc_otg_hcd->core_if->host_if;
  75316. +
  75317. + /* Every time when port enables calculate
  75318. + * HFIR.FrInterval
  75319. + */
  75320. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  75321. + hfir.b.frint = calc_frame_interval(dwc_otg_hcd->core_if);
  75322. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  75323. +
  75324. + /* Check if we need to adjust the PHY clock speed for
  75325. + * low power and adjust it */
  75326. + if (params->host_support_fs_ls_low_power) {
  75327. + gusbcfg_data_t usbcfg;
  75328. +
  75329. + usbcfg.d32 =
  75330. + DWC_READ_REG32(&global_regs->gusbcfg);
  75331. +
  75332. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED
  75333. + || hprt0.b.prtspd ==
  75334. + DWC_HPRT0_PRTSPD_FULL_SPEED) {
  75335. + /*
  75336. + * Low power
  75337. + */
  75338. + hcfg_data_t hcfg;
  75339. + if (usbcfg.b.phylpwrclksel == 0) {
  75340. + /* Set PHY low power clock select for FS/LS devices */
  75341. + usbcfg.b.phylpwrclksel = 1;
  75342. + DWC_WRITE_REG32
  75343. + (&global_regs->gusbcfg,
  75344. + usbcfg.d32);
  75345. + do_reset = 1;
  75346. + }
  75347. +
  75348. + hcfg.d32 =
  75349. + DWC_READ_REG32
  75350. + (&host_if->host_global_regs->hcfg);
  75351. +
  75352. + if (hprt0.b.prtspd ==
  75353. + DWC_HPRT0_PRTSPD_LOW_SPEED
  75354. + && params->host_ls_low_power_phy_clk
  75355. + ==
  75356. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)
  75357. + {
  75358. + /* 6 MHZ */
  75359. + DWC_DEBUGPL(DBG_CIL,
  75360. + "FS_PHY programming HCFG to 6 MHz (Low Power)\n");
  75361. + if (hcfg.b.fslspclksel !=
  75362. + DWC_HCFG_6_MHZ) {
  75363. + hcfg.b.fslspclksel =
  75364. + DWC_HCFG_6_MHZ;
  75365. + DWC_WRITE_REG32
  75366. + (&host_if->host_global_regs->hcfg,
  75367. + hcfg.d32);
  75368. + do_reset = 1;
  75369. + }
  75370. + } else {
  75371. + /* 48 MHZ */
  75372. + DWC_DEBUGPL(DBG_CIL,
  75373. + "FS_PHY programming HCFG to 48 MHz ()\n");
  75374. + if (hcfg.b.fslspclksel !=
  75375. + DWC_HCFG_48_MHZ) {
  75376. + hcfg.b.fslspclksel =
  75377. + DWC_HCFG_48_MHZ;
  75378. + DWC_WRITE_REG32
  75379. + (&host_if->host_global_regs->hcfg,
  75380. + hcfg.d32);
  75381. + do_reset = 1;
  75382. + }
  75383. + }
  75384. + } else {
  75385. + /*
  75386. + * Not low power
  75387. + */
  75388. + if (usbcfg.b.phylpwrclksel == 1) {
  75389. + usbcfg.b.phylpwrclksel = 0;
  75390. + DWC_WRITE_REG32
  75391. + (&global_regs->gusbcfg,
  75392. + usbcfg.d32);
  75393. + do_reset = 1;
  75394. + }
  75395. + }
  75396. +
  75397. + if (do_reset) {
  75398. + DWC_TASK_SCHEDULE(dwc_otg_hcd->reset_tasklet);
  75399. + }
  75400. + }
  75401. +
  75402. + if (!do_reset) {
  75403. + /* Port has been enabled set the reset change flag */
  75404. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  75405. + }
  75406. + } else {
  75407. + dwc_otg_hcd->flags.b.port_enable_change = 1;
  75408. + }
  75409. + retval |= 1;
  75410. + }
  75411. +
  75412. + /** Overcurrent Change Interrupt */
  75413. + if (hprt0.b.prtovrcurrchng) {
  75414. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  75415. + "Port Overcurrent Changed--\n", hprt0.d32);
  75416. + dwc_otg_hcd->flags.b.port_over_current_change = 1;
  75417. + hprt0_modify.b.prtovrcurrchng = 1;
  75418. + retval |= 1;
  75419. + }
  75420. +
  75421. + /* Clear Port Interrupts */
  75422. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  75423. +
  75424. + return retval;
  75425. +}
  75426. +
  75427. +/** This interrupt indicates that one or more host channels has a pending
  75428. + * interrupt. There are multiple conditions that can cause each host channel
  75429. + * interrupt. This function determines which conditions have occurred for each
  75430. + * host channel interrupt and handles them appropriately. */
  75431. +int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  75432. +{
  75433. + int i;
  75434. + int retval = 0;
  75435. + haint_data_t haint;
  75436. +
  75437. + /* Clear appropriate bits in HCINTn to clear the interrupt bit in
  75438. + * GINTSTS */
  75439. +
  75440. + haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
  75441. +
  75442. + // Overwrite with saved interrupts from fiq handler
  75443. + if(fiq_split_enable)
  75444. + {
  75445. + local_fiq_disable();
  75446. + haint.d32 = haint_saved.d32;
  75447. + haint_saved.d32 = 0;
  75448. + local_fiq_enable();
  75449. + }
  75450. +
  75451. + for (i = 0; i < dwc_otg_hcd->core_if->core_params->host_channels; i++) {
  75452. + if (haint.b2.chint & (1 << i)) {
  75453. + retval |= dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd, i);
  75454. + }
  75455. + }
  75456. +
  75457. + return retval;
  75458. +}
  75459. +
  75460. +/**
  75461. + * Gets the actual length of a transfer after the transfer halts. _halt_status
  75462. + * holds the reason for the halt.
  75463. + *
  75464. + * For IN transfers where halt_status is DWC_OTG_HC_XFER_COMPLETE,
  75465. + * *short_read is set to 1 upon return if less than the requested
  75466. + * number of bytes were transferred. Otherwise, *short_read is set to 0 upon
  75467. + * return. short_read may also be NULL on entry, in which case it remains
  75468. + * unchanged.
  75469. + */
  75470. +static uint32_t get_actual_xfer_length(dwc_hc_t * hc,
  75471. + dwc_otg_hc_regs_t * hc_regs,
  75472. + dwc_otg_qtd_t * qtd,
  75473. + dwc_otg_halt_status_e halt_status,
  75474. + int *short_read)
  75475. +{
  75476. + hctsiz_data_t hctsiz;
  75477. + uint32_t length;
  75478. +
  75479. + if (short_read != NULL) {
  75480. + *short_read = 0;
  75481. + }
  75482. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  75483. +
  75484. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  75485. + if (hc->ep_is_in) {
  75486. + length = hc->xfer_len - hctsiz.b.xfersize;
  75487. + if (short_read != NULL) {
  75488. + *short_read = (hctsiz.b.xfersize != 0);
  75489. + }
  75490. + } else if (hc->qh->do_split) {
  75491. + if(fiq_split_enable)
  75492. + length = split_out_xfersize[hc->hc_num];
  75493. + else
  75494. + length = qtd->ssplit_out_xfer_count;
  75495. + } else {
  75496. + length = hc->xfer_len;
  75497. + }
  75498. + } else {
  75499. + /*
  75500. + * Must use the hctsiz.pktcnt field to determine how much data
  75501. + * has been transferred. This field reflects the number of
  75502. + * packets that have been transferred via the USB. This is
  75503. + * always an integral number of packets if the transfer was
  75504. + * halted before its normal completion. (Can't use the
  75505. + * hctsiz.xfersize field because that reflects the number of
  75506. + * bytes transferred via the AHB, not the USB).
  75507. + */
  75508. + length =
  75509. + (hc->start_pkt_count - hctsiz.b.pktcnt) * hc->max_packet;
  75510. + }
  75511. +
  75512. + return length;
  75513. +}
  75514. +
  75515. +/**
  75516. + * Updates the state of the URB after a Transfer Complete interrupt on the
  75517. + * host channel. Updates the actual_length field of the URB based on the
  75518. + * number of bytes transferred via the host channel. Sets the URB status
  75519. + * if the data transfer is finished.
  75520. + *
  75521. + * @return 1 if the data transfer specified by the URB is completely finished,
  75522. + * 0 otherwise.
  75523. + */
  75524. +static int update_urb_state_xfer_comp(dwc_hc_t * hc,
  75525. + dwc_otg_hc_regs_t * hc_regs,
  75526. + dwc_otg_hcd_urb_t * urb,
  75527. + dwc_otg_qtd_t * qtd)
  75528. +{
  75529. + int xfer_done = 0;
  75530. + int short_read = 0;
  75531. +
  75532. + int xfer_length;
  75533. +
  75534. + xfer_length = get_actual_xfer_length(hc, hc_regs, qtd,
  75535. + DWC_OTG_HC_XFER_COMPLETE,
  75536. + &short_read);
  75537. +
  75538. + /* non DWORD-aligned buffer case handling. */
  75539. + if (hc->align_buff && xfer_length && hc->ep_is_in) {
  75540. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  75541. + xfer_length);
  75542. + }
  75543. +
  75544. + urb->actual_length += xfer_length;
  75545. +
  75546. + if (xfer_length && (hc->ep_type == DWC_OTG_EP_TYPE_BULK) &&
  75547. + (urb->flags & URB_SEND_ZERO_PACKET)
  75548. + && (urb->actual_length == urb->length)
  75549. + && !(urb->length % hc->max_packet)) {
  75550. + xfer_done = 0;
  75551. + } else if (short_read || urb->actual_length >= urb->length) {
  75552. + xfer_done = 1;
  75553. + urb->status = 0;
  75554. + }
  75555. +
  75556. +#ifdef DEBUG
  75557. + {
  75558. + hctsiz_data_t hctsiz;
  75559. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  75560. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  75561. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  75562. + hc->hc_num);
  75563. + DWC_DEBUGPL(DBG_HCDV, " hc->xfer_len %d\n", hc->xfer_len);
  75564. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.xfersize %d\n",
  75565. + hctsiz.b.xfersize);
  75566. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  75567. + urb->length);
  75568. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  75569. + urb->actual_length);
  75570. + DWC_DEBUGPL(DBG_HCDV, " short_read %d, xfer_done %d\n",
  75571. + short_read, xfer_done);
  75572. + }
  75573. +#endif
  75574. +
  75575. + return xfer_done;
  75576. +}
  75577. +
  75578. +/*
  75579. + * Save the starting data toggle for the next transfer. The data toggle is
  75580. + * saved in the QH for non-control transfers and it's saved in the QTD for
  75581. + * control transfers.
  75582. + */
  75583. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  75584. + dwc_otg_hc_regs_t * hc_regs, dwc_otg_qtd_t * qtd)
  75585. +{
  75586. + hctsiz_data_t hctsiz;
  75587. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  75588. +
  75589. + if (hc->ep_type != DWC_OTG_EP_TYPE_CONTROL) {
  75590. + dwc_otg_qh_t *qh = hc->qh;
  75591. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  75592. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  75593. + } else {
  75594. + qh->data_toggle = DWC_OTG_HC_PID_DATA1;
  75595. + }
  75596. + } else {
  75597. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  75598. + qtd->data_toggle = DWC_OTG_HC_PID_DATA0;
  75599. + } else {
  75600. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  75601. + }
  75602. + }
  75603. +}
  75604. +
  75605. +/**
  75606. + * Updates the state of an Isochronous URB when the transfer is stopped for
  75607. + * any reason. The fields of the current entry in the frame descriptor array
  75608. + * are set based on the transfer state and the input _halt_status. Completes
  75609. + * the Isochronous URB if all the URB frames have been completed.
  75610. + *
  75611. + * @return DWC_OTG_HC_XFER_COMPLETE if there are more frames remaining to be
  75612. + * transferred in the URB. Otherwise return DWC_OTG_HC_XFER_URB_COMPLETE.
  75613. + */
  75614. +static dwc_otg_halt_status_e
  75615. +update_isoc_urb_state(dwc_otg_hcd_t * hcd,
  75616. + dwc_hc_t * hc,
  75617. + dwc_otg_hc_regs_t * hc_regs,
  75618. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  75619. +{
  75620. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  75621. + dwc_otg_halt_status_e ret_val = halt_status;
  75622. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  75623. +
  75624. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  75625. + switch (halt_status) {
  75626. + case DWC_OTG_HC_XFER_COMPLETE:
  75627. + frame_desc->status = 0;
  75628. + frame_desc->actual_length =
  75629. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  75630. +
  75631. + /* non DWORD-aligned buffer case handling. */
  75632. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  75633. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  75634. + hc->qh->dw_align_buf, frame_desc->actual_length);
  75635. + }
  75636. +
  75637. + break;
  75638. + case DWC_OTG_HC_XFER_FRAME_OVERRUN:
  75639. + urb->error_count++;
  75640. + if (hc->ep_is_in) {
  75641. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  75642. + } else {
  75643. + frame_desc->status = -DWC_E_COMMUNICATION;
  75644. + }
  75645. + frame_desc->actual_length = 0;
  75646. + break;
  75647. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  75648. + urb->error_count++;
  75649. + frame_desc->status = -DWC_E_OVERFLOW;
  75650. + /* Don't need to update actual_length in this case. */
  75651. + break;
  75652. + case DWC_OTG_HC_XFER_XACT_ERR:
  75653. + urb->error_count++;
  75654. + frame_desc->status = -DWC_E_PROTOCOL;
  75655. + frame_desc->actual_length =
  75656. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  75657. +
  75658. + /* non DWORD-aligned buffer case handling. */
  75659. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  75660. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  75661. + hc->qh->dw_align_buf, frame_desc->actual_length);
  75662. + }
  75663. + /* Skip whole frame */
  75664. + if (hc->qh->do_split && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) &&
  75665. + hc->ep_is_in && hcd->core_if->dma_enable) {
  75666. + qtd->complete_split = 0;
  75667. + qtd->isoc_split_offset = 0;
  75668. + }
  75669. +
  75670. + break;
  75671. + default:
  75672. + DWC_ASSERT(1, "Unhandled _halt_status (%d)\n", halt_status);
  75673. + break;
  75674. + }
  75675. + if (++qtd->isoc_frame_index == urb->packet_count) {
  75676. + /*
  75677. + * urb->status is not used for isoc transfers.
  75678. + * The individual frame_desc statuses are used instead.
  75679. + */
  75680. + hcd->fops->complete(hcd, urb->priv, urb, 0);
  75681. + ret_val = DWC_OTG_HC_XFER_URB_COMPLETE;
  75682. + } else {
  75683. + ret_val = DWC_OTG_HC_XFER_COMPLETE;
  75684. + }
  75685. + return ret_val;
  75686. +}
  75687. +
  75688. +/**
  75689. + * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
  75690. + * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
  75691. + * still linked to the QH, the QH is added to the end of the inactive
  75692. + * non-periodic schedule. For periodic QHs, removes the QH from the periodic
  75693. + * schedule if no more QTDs are linked to the QH.
  75694. + */
  75695. +static void deactivate_qh(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, int free_qtd)
  75696. +{
  75697. + int continue_split = 0;
  75698. + dwc_otg_qtd_t *qtd;
  75699. +
  75700. + DWC_DEBUGPL(DBG_HCDV, " %s(%p,%p,%d)\n", __func__, hcd, qh, free_qtd);
  75701. +
  75702. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  75703. +
  75704. + if (qtd->complete_split) {
  75705. + continue_split = 1;
  75706. + } else if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
  75707. + qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END) {
  75708. + continue_split = 1;
  75709. + }
  75710. +
  75711. + if (free_qtd) {
  75712. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  75713. + continue_split = 0;
  75714. + }
  75715. +
  75716. + qh->channel = NULL;
  75717. + dwc_otg_hcd_qh_deactivate(hcd, qh, continue_split);
  75718. +}
  75719. +
  75720. +/**
  75721. + * Releases a host channel for use by other transfers. Attempts to select and
  75722. + * queue more transactions since at least one host channel is available.
  75723. + *
  75724. + * @param hcd The HCD state structure.
  75725. + * @param hc The host channel to release.
  75726. + * @param qtd The QTD associated with the host channel. This QTD may be freed
  75727. + * if the transfer is complete or an error has occurred.
  75728. + * @param halt_status Reason the channel is being released. This status
  75729. + * determines the actions taken by this function.
  75730. + */
  75731. +static void release_channel(dwc_otg_hcd_t * hcd,
  75732. + dwc_hc_t * hc,
  75733. + dwc_otg_qtd_t * qtd,
  75734. + dwc_otg_halt_status_e halt_status)
  75735. +{
  75736. + dwc_otg_transaction_type_e tr_type;
  75737. + int free_qtd;
  75738. + dwc_irqflags_t flags;
  75739. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  75740. +#ifdef FIQ_DEBUG
  75741. + int endp = qtd->urb ? qtd->urb->pipe_info.ep_num : 0;
  75742. +#endif
  75743. + int hog_port = 0;
  75744. +
  75745. + DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d, xfer_len %d\n",
  75746. + __func__, hc->hc_num, halt_status, hc->xfer_len);
  75747. +
  75748. + if(fiq_split_enable && hc->do_split) {
  75749. + if(!hc->ep_is_in && hc->ep_type == UE_ISOCHRONOUS) {
  75750. + if(hc->xact_pos == DWC_HCSPLIT_XACTPOS_MID ||
  75751. + hc->xact_pos == DWC_HCSPLIT_XACTPOS_BEGIN) {
  75752. + hog_port = 1;
  75753. + }
  75754. + }
  75755. + }
  75756. +
  75757. + switch (halt_status) {
  75758. + case DWC_OTG_HC_XFER_URB_COMPLETE:
  75759. + free_qtd = 1;
  75760. + break;
  75761. + case DWC_OTG_HC_XFER_AHB_ERR:
  75762. + case DWC_OTG_HC_XFER_STALL:
  75763. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  75764. + free_qtd = 1;
  75765. + break;
  75766. + case DWC_OTG_HC_XFER_XACT_ERR:
  75767. + if (qtd->error_count >= 3) {
  75768. + DWC_DEBUGPL(DBG_HCDV,
  75769. + " Complete URB with transaction error\n");
  75770. + free_qtd = 1;
  75771. + qtd->urb->status = -DWC_E_PROTOCOL;
  75772. + hcd->fops->complete(hcd, qtd->urb->priv,
  75773. + qtd->urb, -DWC_E_PROTOCOL);
  75774. + } else {
  75775. + free_qtd = 0;
  75776. + }
  75777. + break;
  75778. + case DWC_OTG_HC_XFER_URB_DEQUEUE:
  75779. + /*
  75780. + * The QTD has already been removed and the QH has been
  75781. + * deactivated. Don't want to do anything except release the
  75782. + * host channel and try to queue more transfers.
  75783. + */
  75784. + goto cleanup;
  75785. + case DWC_OTG_HC_XFER_NO_HALT_STATUS:
  75786. + free_qtd = 0;
  75787. + break;
  75788. + case DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE:
  75789. + DWC_DEBUGPL(DBG_HCDV,
  75790. + " Complete URB with I/O error\n");
  75791. + free_qtd = 1;
  75792. + qtd->urb->status = -DWC_E_IO;
  75793. + hcd->fops->complete(hcd, qtd->urb->priv,
  75794. + qtd->urb, -DWC_E_IO);
  75795. + break;
  75796. + default:
  75797. + free_qtd = 0;
  75798. + break;
  75799. + }
  75800. +
  75801. + deactivate_qh(hcd, hc->qh, free_qtd);
  75802. +
  75803. +cleanup:
  75804. + /*
  75805. + * Release the host channel for use by other transfers. The cleanup
  75806. + * function clears the channel interrupt enables and conditions, so
  75807. + * there's no need to clear the Channel Halted interrupt separately.
  75808. + */
  75809. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  75810. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  75811. +
  75812. + if (!microframe_schedule) {
  75813. + switch (hc->ep_type) {
  75814. + case DWC_OTG_EP_TYPE_CONTROL:
  75815. + case DWC_OTG_EP_TYPE_BULK:
  75816. + hcd->non_periodic_channels--;
  75817. + break;
  75818. +
  75819. + default:
  75820. + /*
  75821. + * Don't release reservations for periodic channels here.
  75822. + * That's done when a periodic transfer is descheduled (i.e.
  75823. + * when the QH is removed from the periodic schedule).
  75824. + */
  75825. + break;
  75826. + }
  75827. + } else {
  75828. +
  75829. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  75830. + hcd->available_host_channels++;
  75831. + fiq_print(FIQDBG_PORTHUB, "AHC = %d ", hcd->available_host_channels);
  75832. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  75833. + }
  75834. +
  75835. + if(fiq_split_enable && hc->do_split)
  75836. + {
  75837. + if(!(hcd->hub_port[hc->hub_addr] & (1 << hc->port_addr)))
  75838. + {
  75839. + fiq_print(FIQDBG_ERR, "PRTNOTAL");
  75840. + //BUG();
  75841. + }
  75842. + if(!hog_port && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC ||
  75843. + hc->ep_type == DWC_OTG_EP_TYPE_INTR)) {
  75844. + hcd->hub_port[hc->hub_addr] &= ~(1 << hc->port_addr);
  75845. +#ifdef FIQ_DEBUG
  75846. + hcd->hub_port_alloc[hc->hub_addr * 16 + hc->port_addr] = -1;
  75847. +#endif
  75848. + fiq_print(FIQDBG_PORTHUB, "H%dP%d:RR%d", hc->hub_addr, hc->port_addr, endp);
  75849. + }
  75850. + }
  75851. +
  75852. + /* Try to queue more transfers now that there's a free channel. */
  75853. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  75854. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  75855. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  75856. + }
  75857. +}
  75858. +
  75859. +/**
  75860. + * Halts a host channel. If the channel cannot be halted immediately because
  75861. + * the request queue is full, this function ensures that the FIFO empty
  75862. + * interrupt for the appropriate queue is enabled so that the halt request can
  75863. + * be queued when there is space in the request queue.
  75864. + *
  75865. + * This function may also be called in DMA mode. In that case, the channel is
  75866. + * simply released since the core always halts the channel automatically in
  75867. + * DMA mode.
  75868. + */
  75869. +static void halt_channel(dwc_otg_hcd_t * hcd,
  75870. + dwc_hc_t * hc,
  75871. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  75872. +{
  75873. + if (hcd->core_if->dma_enable) {
  75874. + release_channel(hcd, hc, qtd, halt_status);
  75875. + return;
  75876. + }
  75877. +
  75878. + /* Slave mode processing... */
  75879. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  75880. +
  75881. + if (hc->halt_on_queue) {
  75882. + gintmsk_data_t gintmsk = {.d32 = 0 };
  75883. + dwc_otg_core_global_regs_t *global_regs;
  75884. + global_regs = hcd->core_if->core_global_regs;
  75885. +
  75886. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  75887. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  75888. + /*
  75889. + * Make sure the Non-periodic Tx FIFO empty interrupt
  75890. + * is enabled so that the non-periodic schedule will
  75891. + * be processed.
  75892. + */
  75893. + gintmsk.b.nptxfempty = 1;
  75894. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  75895. + } else {
  75896. + /*
  75897. + * Move the QH from the periodic queued schedule to
  75898. + * the periodic assigned schedule. This allows the
  75899. + * halt to be queued when the periodic schedule is
  75900. + * processed.
  75901. + */
  75902. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  75903. + &hc->qh->qh_list_entry);
  75904. +
  75905. + /*
  75906. + * Make sure the Periodic Tx FIFO Empty interrupt is
  75907. + * enabled so that the periodic schedule will be
  75908. + * processed.
  75909. + */
  75910. + gintmsk.b.ptxfempty = 1;
  75911. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  75912. + }
  75913. + }
  75914. +}
  75915. +
  75916. +/**
  75917. + * Performs common cleanup for non-periodic transfers after a Transfer
  75918. + * Complete interrupt. This function should be called after any endpoint type
  75919. + * specific handling is finished to release the host channel.
  75920. + */
  75921. +static void complete_non_periodic_xfer(dwc_otg_hcd_t * hcd,
  75922. + dwc_hc_t * hc,
  75923. + dwc_otg_hc_regs_t * hc_regs,
  75924. + dwc_otg_qtd_t * qtd,
  75925. + dwc_otg_halt_status_e halt_status)
  75926. +{
  75927. + hcint_data_t hcint;
  75928. +
  75929. + qtd->error_count = 0;
  75930. +
  75931. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  75932. + if (hcint.b.nyet) {
  75933. + /*
  75934. + * Got a NYET on the last transaction of the transfer. This
  75935. + * means that the endpoint should be in the PING state at the
  75936. + * beginning of the next transfer.
  75937. + */
  75938. + hc->qh->ping_state = 1;
  75939. + clear_hc_int(hc_regs, nyet);
  75940. + }
  75941. +
  75942. + /*
  75943. + * Always halt and release the host channel to make it available for
  75944. + * more transfers. There may still be more phases for a control
  75945. + * transfer or more data packets for a bulk transfer at this point,
  75946. + * but the host channel is still halted. A channel will be reassigned
  75947. + * to the transfer when the non-periodic schedule is processed after
  75948. + * the channel is released. This allows transactions to be queued
  75949. + * properly via dwc_otg_hcd_queue_transactions, which also enables the
  75950. + * Tx FIFO Empty interrupt if necessary.
  75951. + */
  75952. + if (hc->ep_is_in) {
  75953. + /*
  75954. + * IN transfers in Slave mode require an explicit disable to
  75955. + * halt the channel. (In DMA mode, this call simply releases
  75956. + * the channel.)
  75957. + */
  75958. + halt_channel(hcd, hc, qtd, halt_status);
  75959. + } else {
  75960. + /*
  75961. + * The channel is automatically disabled by the core for OUT
  75962. + * transfers in Slave mode.
  75963. + */
  75964. + release_channel(hcd, hc, qtd, halt_status);
  75965. + }
  75966. +}
  75967. +
  75968. +/**
  75969. + * Performs common cleanup for periodic transfers after a Transfer Complete
  75970. + * interrupt. This function should be called after any endpoint type specific
  75971. + * handling is finished to release the host channel.
  75972. + */
  75973. +static void complete_periodic_xfer(dwc_otg_hcd_t * hcd,
  75974. + dwc_hc_t * hc,
  75975. + dwc_otg_hc_regs_t * hc_regs,
  75976. + dwc_otg_qtd_t * qtd,
  75977. + dwc_otg_halt_status_e halt_status)
  75978. +{
  75979. + hctsiz_data_t hctsiz;
  75980. + qtd->error_count = 0;
  75981. +
  75982. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  75983. + if (!hc->ep_is_in || hctsiz.b.pktcnt == 0) {
  75984. + /* Core halts channel in these cases. */
  75985. + release_channel(hcd, hc, qtd, halt_status);
  75986. + } else {
  75987. + /* Flush any outstanding requests from the Tx queue. */
  75988. + halt_channel(hcd, hc, qtd, halt_status);
  75989. + }
  75990. +}
  75991. +
  75992. +static int32_t handle_xfercomp_isoc_split_in(dwc_otg_hcd_t * hcd,
  75993. + dwc_hc_t * hc,
  75994. + dwc_otg_hc_regs_t * hc_regs,
  75995. + dwc_otg_qtd_t * qtd)
  75996. +{
  75997. + uint32_t len;
  75998. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  75999. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  76000. +
  76001. + len = get_actual_xfer_length(hc, hc_regs, qtd,
  76002. + DWC_OTG_HC_XFER_COMPLETE, NULL);
  76003. +
  76004. + if (!len) {
  76005. + qtd->complete_split = 0;
  76006. + qtd->isoc_split_offset = 0;
  76007. + return 0;
  76008. + }
  76009. + frame_desc->actual_length += len;
  76010. +
  76011. + if (hc->align_buff && len)
  76012. + dwc_memcpy(qtd->urb->buf + frame_desc->offset +
  76013. + qtd->isoc_split_offset, hc->qh->dw_align_buf, len);
  76014. + qtd->isoc_split_offset += len;
  76015. +
  76016. + if (frame_desc->length == frame_desc->actual_length) {
  76017. + frame_desc->status = 0;
  76018. + qtd->isoc_frame_index++;
  76019. + qtd->complete_split = 0;
  76020. + qtd->isoc_split_offset = 0;
  76021. + }
  76022. +
  76023. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  76024. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  76025. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  76026. + } else {
  76027. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  76028. + }
  76029. +
  76030. + return 1; /* Indicates that channel released */
  76031. +}
  76032. +
  76033. +/**
  76034. + * Handles a host channel Transfer Complete interrupt. This handler may be
  76035. + * called in either DMA mode or Slave mode.
  76036. + */
  76037. +static int32_t handle_hc_xfercomp_intr(dwc_otg_hcd_t * hcd,
  76038. + dwc_hc_t * hc,
  76039. + dwc_otg_hc_regs_t * hc_regs,
  76040. + dwc_otg_qtd_t * qtd)
  76041. +{
  76042. + int urb_xfer_done;
  76043. + dwc_otg_halt_status_e halt_status = DWC_OTG_HC_XFER_COMPLETE;
  76044. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  76045. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  76046. +
  76047. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76048. + "Transfer Complete--\n", hc->hc_num);
  76049. +
  76050. + if (hcd->core_if->dma_desc_enable) {
  76051. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, halt_status);
  76052. + if (pipe_type == UE_ISOCHRONOUS) {
  76053. + /* Do not disable the interrupt, just clear it */
  76054. + clear_hc_int(hc_regs, xfercomp);
  76055. + return 1;
  76056. + }
  76057. + goto handle_xfercomp_done;
  76058. + }
  76059. +
  76060. + /*
  76061. + * Handle xfer complete on CSPLIT.
  76062. + */
  76063. +
  76064. + if (hc->qh->do_split) {
  76065. + if ((hc->ep_type == DWC_OTG_EP_TYPE_ISOC) && hc->ep_is_in
  76066. + && hcd->core_if->dma_enable) {
  76067. + if (qtd->complete_split
  76068. + && handle_xfercomp_isoc_split_in(hcd, hc, hc_regs,
  76069. + qtd))
  76070. + goto handle_xfercomp_done;
  76071. + } else {
  76072. + qtd->complete_split = 0;
  76073. + }
  76074. + }
  76075. +
  76076. + /* Update the QTD and URB states. */
  76077. + switch (pipe_type) {
  76078. + case UE_CONTROL:
  76079. + switch (qtd->control_phase) {
  76080. + case DWC_OTG_CONTROL_SETUP:
  76081. + if (urb->length > 0) {
  76082. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  76083. + } else {
  76084. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  76085. + }
  76086. + DWC_DEBUGPL(DBG_HCDV,
  76087. + " Control setup transaction done\n");
  76088. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  76089. + break;
  76090. + case DWC_OTG_CONTROL_DATA:{
  76091. + urb_xfer_done =
  76092. + update_urb_state_xfer_comp(hc, hc_regs, urb,
  76093. + qtd);
  76094. + if (urb_xfer_done) {
  76095. + qtd->control_phase =
  76096. + DWC_OTG_CONTROL_STATUS;
  76097. + DWC_DEBUGPL(DBG_HCDV,
  76098. + " Control data transfer done\n");
  76099. + } else {
  76100. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  76101. + }
  76102. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  76103. + break;
  76104. + }
  76105. + case DWC_OTG_CONTROL_STATUS:
  76106. + DWC_DEBUGPL(DBG_HCDV, " Control transfer complete\n");
  76107. + if (urb->status == -DWC_E_IN_PROGRESS) {
  76108. + urb->status = 0;
  76109. + }
  76110. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  76111. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  76112. + break;
  76113. + }
  76114. +
  76115. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  76116. + break;
  76117. + case UE_BULK:
  76118. + DWC_DEBUGPL(DBG_HCDV, " Bulk transfer complete\n");
  76119. + urb_xfer_done =
  76120. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  76121. + if (urb_xfer_done) {
  76122. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  76123. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  76124. + } else {
  76125. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  76126. + }
  76127. +
  76128. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  76129. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  76130. + break;
  76131. + case UE_INTERRUPT:
  76132. + DWC_DEBUGPL(DBG_HCDV, " Interrupt transfer complete\n");
  76133. + urb_xfer_done =
  76134. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  76135. +
  76136. + /*
  76137. + * Interrupt URB is done on the first transfer complete
  76138. + * interrupt.
  76139. + */
  76140. + if (urb_xfer_done) {
  76141. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  76142. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  76143. + } else {
  76144. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  76145. + }
  76146. +
  76147. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  76148. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  76149. + break;
  76150. + case UE_ISOCHRONOUS:
  76151. + DWC_DEBUGPL(DBG_HCDV, " Isochronous transfer complete\n");
  76152. + if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  76153. + halt_status =
  76154. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  76155. + DWC_OTG_HC_XFER_COMPLETE);
  76156. + }
  76157. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  76158. + break;
  76159. + }
  76160. +
  76161. +handle_xfercomp_done:
  76162. + disable_hc_int(hc_regs, xfercompl);
  76163. +
  76164. + return 1;
  76165. +}
  76166. +
  76167. +/**
  76168. + * Handles a host channel STALL interrupt. This handler may be called in
  76169. + * either DMA mode or Slave mode.
  76170. + */
  76171. +static int32_t handle_hc_stall_intr(dwc_otg_hcd_t * hcd,
  76172. + dwc_hc_t * hc,
  76173. + dwc_otg_hc_regs_t * hc_regs,
  76174. + dwc_otg_qtd_t * qtd)
  76175. +{
  76176. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  76177. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  76178. +
  76179. + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
  76180. + "STALL Received--\n", hc->hc_num);
  76181. +
  76182. + if (hcd->core_if->dma_desc_enable) {
  76183. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, DWC_OTG_HC_XFER_STALL);
  76184. + goto handle_stall_done;
  76185. + }
  76186. +
  76187. + if (pipe_type == UE_CONTROL) {
  76188. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  76189. + }
  76190. +
  76191. + if (pipe_type == UE_BULK || pipe_type == UE_INTERRUPT) {
  76192. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  76193. + /*
  76194. + * USB protocol requires resetting the data toggle for bulk
  76195. + * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
  76196. + * setup command is issued to the endpoint. Anticipate the
  76197. + * CLEAR_FEATURE command since a STALL has occurred and reset
  76198. + * the data toggle now.
  76199. + */
  76200. + hc->qh->data_toggle = 0;
  76201. + }
  76202. +
  76203. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_STALL);
  76204. +
  76205. +handle_stall_done:
  76206. + disable_hc_int(hc_regs, stall);
  76207. +
  76208. + return 1;
  76209. +}
  76210. +
  76211. +/*
  76212. + * Updates the state of the URB when a transfer has been stopped due to an
  76213. + * abnormal condition before the transfer completes. Modifies the
  76214. + * actual_length field of the URB to reflect the number of bytes that have
  76215. + * actually been transferred via the host channel.
  76216. + */
  76217. +static void update_urb_state_xfer_intr(dwc_hc_t * hc,
  76218. + dwc_otg_hc_regs_t * hc_regs,
  76219. + dwc_otg_hcd_urb_t * urb,
  76220. + dwc_otg_qtd_t * qtd,
  76221. + dwc_otg_halt_status_e halt_status)
  76222. +{
  76223. + uint32_t bytes_transferred = get_actual_xfer_length(hc, hc_regs, qtd,
  76224. + halt_status, NULL);
  76225. + /* non DWORD-aligned buffer case handling. */
  76226. + if (hc->align_buff && bytes_transferred && hc->ep_is_in) {
  76227. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  76228. + bytes_transferred);
  76229. + }
  76230. +
  76231. + urb->actual_length += bytes_transferred;
  76232. +
  76233. +#ifdef DEBUG
  76234. + {
  76235. + hctsiz_data_t hctsiz;
  76236. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  76237. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  76238. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  76239. + hc->hc_num);
  76240. + DWC_DEBUGPL(DBG_HCDV, " hc->start_pkt_count %d\n",
  76241. + hc->start_pkt_count);
  76242. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.pktcnt %d\n", hctsiz.b.pktcnt);
  76243. + DWC_DEBUGPL(DBG_HCDV, " hc->max_packet %d\n", hc->max_packet);
  76244. + DWC_DEBUGPL(DBG_HCDV, " bytes_transferred %d\n",
  76245. + bytes_transferred);
  76246. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  76247. + urb->actual_length);
  76248. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  76249. + urb->length);
  76250. + }
  76251. +#endif
  76252. +}
  76253. +
  76254. +/**
  76255. + * Handles a host channel NAK interrupt. This handler may be called in either
  76256. + * DMA mode or Slave mode.
  76257. + */
  76258. +static int32_t handle_hc_nak_intr(dwc_otg_hcd_t * hcd,
  76259. + dwc_hc_t * hc,
  76260. + dwc_otg_hc_regs_t * hc_regs,
  76261. + dwc_otg_qtd_t * qtd)
  76262. +{
  76263. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76264. + "NAK Received--\n", hc->hc_num);
  76265. +
  76266. + /*
  76267. + * When we get bulk NAKs then remember this so we holdoff on this qh until
  76268. + * the beginning of the next frame
  76269. + */
  76270. + switch(dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  76271. + case UE_BULK:
  76272. + case UE_CONTROL:
  76273. + if (nak_holdoff_enable)
  76274. + hc->qh->nak_frame = dwc_otg_hcd_get_frame_number(hcd);
  76275. + }
  76276. +
  76277. + /*
  76278. + * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
  76279. + * interrupt. Re-start the SSPLIT transfer.
  76280. + */
  76281. + if (hc->do_split) {
  76282. + if (hc->complete_split) {
  76283. + qtd->error_count = 0;
  76284. + }
  76285. + qtd->complete_split = 0;
  76286. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  76287. + goto handle_nak_done;
  76288. + }
  76289. +
  76290. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  76291. + case UE_CONTROL:
  76292. + case UE_BULK:
  76293. + if (hcd->core_if->dma_enable && hc->ep_is_in) {
  76294. + /*
  76295. + * NAK interrupts are enabled on bulk/control IN
  76296. + * transfers in DMA mode for the sole purpose of
  76297. + * resetting the error count after a transaction error
  76298. + * occurs. The core will continue transferring data.
  76299. + * Disable other interrupts unmasked for the same
  76300. + * reason.
  76301. + */
  76302. + disable_hc_int(hc_regs, datatglerr);
  76303. + disable_hc_int(hc_regs, ack);
  76304. + qtd->error_count = 0;
  76305. + goto handle_nak_done;
  76306. + }
  76307. +
  76308. + /*
  76309. + * NAK interrupts normally occur during OUT transfers in DMA
  76310. + * or Slave mode. For IN transfers, more requests will be
  76311. + * queued as request queue space is available.
  76312. + */
  76313. + qtd->error_count = 0;
  76314. +
  76315. + if (!hc->qh->ping_state) {
  76316. + update_urb_state_xfer_intr(hc, hc_regs,
  76317. + qtd->urb, qtd,
  76318. + DWC_OTG_HC_XFER_NAK);
  76319. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  76320. +
  76321. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH)
  76322. + hc->qh->ping_state = 1;
  76323. + }
  76324. +
  76325. + /*
  76326. + * Halt the channel so the transfer can be re-started from
  76327. + * the appropriate point or the PING protocol will
  76328. + * start/continue.
  76329. + */
  76330. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  76331. + break;
  76332. + case UE_INTERRUPT:
  76333. + qtd->error_count = 0;
  76334. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  76335. + break;
  76336. + case UE_ISOCHRONOUS:
  76337. + /* Should never get called for isochronous transfers. */
  76338. + DWC_ASSERT(1, "NACK interrupt for ISOC transfer\n");
  76339. + break;
  76340. + }
  76341. +
  76342. +handle_nak_done:
  76343. + disable_hc_int(hc_regs, nak);
  76344. +
  76345. + return 1;
  76346. +}
  76347. +
  76348. +/**
  76349. + * Handles a host channel ACK interrupt. This interrupt is enabled when
  76350. + * performing the PING protocol in Slave mode, when errors occur during
  76351. + * either Slave mode or DMA mode, and during Start Split transactions.
  76352. + */
  76353. +static int32_t handle_hc_ack_intr(dwc_otg_hcd_t * hcd,
  76354. + dwc_hc_t * hc,
  76355. + dwc_otg_hc_regs_t * hc_regs,
  76356. + dwc_otg_qtd_t * qtd)
  76357. +{
  76358. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76359. + "ACK Received--\n", hc->hc_num);
  76360. +
  76361. + if (hc->do_split) {
  76362. + /*
  76363. + * Handle ACK on SSPLIT.
  76364. + * ACK should not occur in CSPLIT.
  76365. + */
  76366. + if (!hc->ep_is_in && hc->data_pid_start != DWC_OTG_HC_PID_SETUP) {
  76367. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  76368. + }
  76369. + if (!(hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in)) {
  76370. + /* Don't need complete for isochronous out transfers. */
  76371. + qtd->complete_split = 1;
  76372. + }
  76373. +
  76374. + /* ISOC OUT */
  76375. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  76376. + switch (hc->xact_pos) {
  76377. + case DWC_HCSPLIT_XACTPOS_ALL:
  76378. + break;
  76379. + case DWC_HCSPLIT_XACTPOS_END:
  76380. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  76381. + qtd->isoc_split_offset = 0;
  76382. + break;
  76383. + case DWC_HCSPLIT_XACTPOS_BEGIN:
  76384. + case DWC_HCSPLIT_XACTPOS_MID:
  76385. + /*
  76386. + * For BEGIN or MID, calculate the length for
  76387. + * the next microframe to determine the correct
  76388. + * SSPLIT token, either MID or END.
  76389. + */
  76390. + {
  76391. + struct dwc_otg_hcd_iso_packet_desc
  76392. + *frame_desc;
  76393. +
  76394. + frame_desc =
  76395. + &qtd->urb->
  76396. + iso_descs[qtd->isoc_frame_index];
  76397. + qtd->isoc_split_offset += 188;
  76398. +
  76399. + if ((frame_desc->length -
  76400. + qtd->isoc_split_offset) <= 188) {
  76401. + qtd->isoc_split_pos =
  76402. + DWC_HCSPLIT_XACTPOS_END;
  76403. + } else {
  76404. + qtd->isoc_split_pos =
  76405. + DWC_HCSPLIT_XACTPOS_MID;
  76406. + }
  76407. +
  76408. + }
  76409. + break;
  76410. + }
  76411. + } else {
  76412. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  76413. + }
  76414. + } else {
  76415. + /*
  76416. + * An unmasked ACK on a non-split DMA transaction is
  76417. + * for the sole purpose of resetting error counts. Disable other
  76418. + * interrupts unmasked for the same reason.
  76419. + */
  76420. + if(hcd->core_if->dma_enable) {
  76421. + disable_hc_int(hc_regs, datatglerr);
  76422. + disable_hc_int(hc_regs, nak);
  76423. + }
  76424. + qtd->error_count = 0;
  76425. +
  76426. + if (hc->qh->ping_state) {
  76427. + hc->qh->ping_state = 0;
  76428. + /*
  76429. + * Halt the channel so the transfer can be re-started
  76430. + * from the appropriate point. This only happens in
  76431. + * Slave mode. In DMA mode, the ping_state is cleared
  76432. + * when the transfer is started because the core
  76433. + * automatically executes the PING, then the transfer.
  76434. + */
  76435. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  76436. + }
  76437. + }
  76438. +
  76439. + /*
  76440. + * If the ACK occurred when _not_ in the PING state, let the channel
  76441. + * continue transferring data after clearing the error count.
  76442. + */
  76443. +
  76444. + disable_hc_int(hc_regs, ack);
  76445. +
  76446. + return 1;
  76447. +}
  76448. +
  76449. +/**
  76450. + * Handles a host channel NYET interrupt. This interrupt should only occur on
  76451. + * Bulk and Control OUT endpoints and for complete split transactions. If a
  76452. + * NYET occurs at the same time as a Transfer Complete interrupt, it is
  76453. + * handled in the xfercomp interrupt handler, not here. This handler may be
  76454. + * called in either DMA mode or Slave mode.
  76455. + */
  76456. +static int32_t handle_hc_nyet_intr(dwc_otg_hcd_t * hcd,
  76457. + dwc_hc_t * hc,
  76458. + dwc_otg_hc_regs_t * hc_regs,
  76459. + dwc_otg_qtd_t * qtd)
  76460. +{
  76461. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76462. + "NYET Received--\n", hc->hc_num);
  76463. +
  76464. + /*
  76465. + * NYET on CSPLIT
  76466. + * re-do the CSPLIT immediately on non-periodic
  76467. + */
  76468. + if (hc->do_split && hc->complete_split) {
  76469. + if (hc->ep_is_in && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  76470. + && hcd->core_if->dma_enable) {
  76471. + qtd->complete_split = 0;
  76472. + qtd->isoc_split_offset = 0;
  76473. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  76474. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  76475. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  76476. + }
  76477. + else
  76478. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  76479. + goto handle_nyet_done;
  76480. + }
  76481. +
  76482. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  76483. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  76484. + int frnum = dwc_otg_hcd_get_frame_number(hcd);
  76485. +
  76486. + // With the FIQ running we only ever see the failed NYET
  76487. + if (dwc_full_frame_num(frnum) !=
  76488. + dwc_full_frame_num(hc->qh->sched_frame) ||
  76489. + fiq_split_enable) {
  76490. + /*
  76491. + * No longer in the same full speed frame.
  76492. + * Treat this as a transaction error.
  76493. + */
  76494. +#if 0
  76495. + /** @todo Fix system performance so this can
  76496. + * be treated as an error. Right now complete
  76497. + * splits cannot be scheduled precisely enough
  76498. + * due to other system activity, so this error
  76499. + * occurs regularly in Slave mode.
  76500. + */
  76501. + qtd->error_count++;
  76502. +#endif
  76503. + qtd->complete_split = 0;
  76504. + halt_channel(hcd, hc, qtd,
  76505. + DWC_OTG_HC_XFER_XACT_ERR);
  76506. + /** @todo add support for isoc release */
  76507. + goto handle_nyet_done;
  76508. + }
  76509. + }
  76510. +
  76511. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  76512. + goto handle_nyet_done;
  76513. + }
  76514. +
  76515. + hc->qh->ping_state = 1;
  76516. + qtd->error_count = 0;
  76517. +
  76518. + update_urb_state_xfer_intr(hc, hc_regs, qtd->urb, qtd,
  76519. + DWC_OTG_HC_XFER_NYET);
  76520. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  76521. +
  76522. + /*
  76523. + * Halt the channel and re-start the transfer so the PING
  76524. + * protocol will start.
  76525. + */
  76526. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  76527. +
  76528. +handle_nyet_done:
  76529. + disable_hc_int(hc_regs, nyet);
  76530. + return 1;
  76531. +}
  76532. +
  76533. +/**
  76534. + * Handles a host channel babble interrupt. This handler may be called in
  76535. + * either DMA mode or Slave mode.
  76536. + */
  76537. +static int32_t handle_hc_babble_intr(dwc_otg_hcd_t * hcd,
  76538. + dwc_hc_t * hc,
  76539. + dwc_otg_hc_regs_t * hc_regs,
  76540. + dwc_otg_qtd_t * qtd)
  76541. +{
  76542. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76543. + "Babble Error--\n", hc->hc_num);
  76544. +
  76545. + if (hcd->core_if->dma_desc_enable) {
  76546. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  76547. + DWC_OTG_HC_XFER_BABBLE_ERR);
  76548. + goto handle_babble_done;
  76549. + }
  76550. +
  76551. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  76552. + hcd->fops->complete(hcd, qtd->urb->priv,
  76553. + qtd->urb, -DWC_E_OVERFLOW);
  76554. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_BABBLE_ERR);
  76555. + } else {
  76556. + dwc_otg_halt_status_e halt_status;
  76557. + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  76558. + DWC_OTG_HC_XFER_BABBLE_ERR);
  76559. + halt_channel(hcd, hc, qtd, halt_status);
  76560. + }
  76561. +
  76562. +handle_babble_done:
  76563. + disable_hc_int(hc_regs, bblerr);
  76564. + return 1;
  76565. +}
  76566. +
  76567. +/**
  76568. + * Handles a host channel AHB error interrupt. This handler is only called in
  76569. + * DMA mode.
  76570. + */
  76571. +static int32_t handle_hc_ahberr_intr(dwc_otg_hcd_t * hcd,
  76572. + dwc_hc_t * hc,
  76573. + dwc_otg_hc_regs_t * hc_regs,
  76574. + dwc_otg_qtd_t * qtd)
  76575. +{
  76576. + hcchar_data_t hcchar;
  76577. + hcsplt_data_t hcsplt;
  76578. + hctsiz_data_t hctsiz;
  76579. + uint32_t hcdma;
  76580. + char *pipetype, *speed;
  76581. +
  76582. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  76583. +
  76584. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76585. + "AHB Error--\n", hc->hc_num);
  76586. +
  76587. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  76588. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  76589. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  76590. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  76591. +
  76592. + DWC_ERROR("AHB ERROR, Channel %d\n", hc->hc_num);
  76593. + DWC_ERROR(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
  76594. + DWC_ERROR(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
  76595. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Enqueue\n");
  76596. + DWC_ERROR(" Device address: %d\n",
  76597. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  76598. + DWC_ERROR(" Endpoint: %d, %s\n",
  76599. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  76600. + (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT"));
  76601. +
  76602. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  76603. + case UE_CONTROL:
  76604. + pipetype = "CONTROL";
  76605. + break;
  76606. + case UE_BULK:
  76607. + pipetype = "BULK";
  76608. + break;
  76609. + case UE_INTERRUPT:
  76610. + pipetype = "INTERRUPT";
  76611. + break;
  76612. + case UE_ISOCHRONOUS:
  76613. + pipetype = "ISOCHRONOUS";
  76614. + break;
  76615. + default:
  76616. + pipetype = "UNKNOWN";
  76617. + break;
  76618. + }
  76619. +
  76620. + DWC_ERROR(" Endpoint type: %s\n", pipetype);
  76621. +
  76622. + switch (hc->speed) {
  76623. + case DWC_OTG_EP_SPEED_HIGH:
  76624. + speed = "HIGH";
  76625. + break;
  76626. + case DWC_OTG_EP_SPEED_FULL:
  76627. + speed = "FULL";
  76628. + break;
  76629. + case DWC_OTG_EP_SPEED_LOW:
  76630. + speed = "LOW";
  76631. + break;
  76632. + default:
  76633. + speed = "UNKNOWN";
  76634. + break;
  76635. + };
  76636. +
  76637. + DWC_ERROR(" Speed: %s\n", speed);
  76638. +
  76639. + DWC_ERROR(" Max packet size: %d\n",
  76640. + dwc_otg_hcd_get_mps(&urb->pipe_info));
  76641. + DWC_ERROR(" Data buffer length: %d\n", urb->length);
  76642. + DWC_ERROR(" Transfer buffer: %p, Transfer DMA: %p\n",
  76643. + urb->buf, (void *)urb->dma);
  76644. + DWC_ERROR(" Setup buffer: %p, Setup DMA: %p\n",
  76645. + urb->setup_packet, (void *)urb->setup_dma);
  76646. + DWC_ERROR(" Interval: %d\n", urb->interval);
  76647. +
  76648. + /* Core haltes the channel for Descriptor DMA mode */
  76649. + if (hcd->core_if->dma_desc_enable) {
  76650. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  76651. + DWC_OTG_HC_XFER_AHB_ERR);
  76652. + goto handle_ahberr_done;
  76653. + }
  76654. +
  76655. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_IO);
  76656. +
  76657. + /*
  76658. + * Force a channel halt. Don't call halt_channel because that won't
  76659. + * write to the HCCHARn register in DMA mode to force the halt.
  76660. + */
  76661. + dwc_otg_hc_halt(hcd->core_if, hc, DWC_OTG_HC_XFER_AHB_ERR);
  76662. +handle_ahberr_done:
  76663. + disable_hc_int(hc_regs, ahberr);
  76664. + return 1;
  76665. +}
  76666. +
  76667. +/**
  76668. + * Handles a host channel transaction error interrupt. This handler may be
  76669. + * called in either DMA mode or Slave mode.
  76670. + */
  76671. +static int32_t handle_hc_xacterr_intr(dwc_otg_hcd_t * hcd,
  76672. + dwc_hc_t * hc,
  76673. + dwc_otg_hc_regs_t * hc_regs,
  76674. + dwc_otg_qtd_t * qtd)
  76675. +{
  76676. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76677. + "Transaction Error--\n", hc->hc_num);
  76678. +
  76679. + if (hcd->core_if->dma_desc_enable) {
  76680. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  76681. + DWC_OTG_HC_XFER_XACT_ERR);
  76682. + goto handle_xacterr_done;
  76683. + }
  76684. +
  76685. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  76686. + case UE_CONTROL:
  76687. + case UE_BULK:
  76688. + qtd->error_count++;
  76689. + if (!hc->qh->ping_state) {
  76690. +
  76691. + update_urb_state_xfer_intr(hc, hc_regs,
  76692. + qtd->urb, qtd,
  76693. + DWC_OTG_HC_XFER_XACT_ERR);
  76694. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  76695. + if (!hc->ep_is_in && hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  76696. + hc->qh->ping_state = 1;
  76697. + }
  76698. + }
  76699. +
  76700. + /*
  76701. + * Halt the channel so the transfer can be re-started from
  76702. + * the appropriate point or the PING protocol will start.
  76703. + */
  76704. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  76705. + break;
  76706. + case UE_INTERRUPT:
  76707. + qtd->error_count++;
  76708. + if (hc->do_split && hc->complete_split) {
  76709. + qtd->complete_split = 0;
  76710. + }
  76711. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  76712. + break;
  76713. + case UE_ISOCHRONOUS:
  76714. + {
  76715. + dwc_otg_halt_status_e halt_status;
  76716. + halt_status =
  76717. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  76718. + DWC_OTG_HC_XFER_XACT_ERR);
  76719. +
  76720. + halt_channel(hcd, hc, qtd, halt_status);
  76721. + }
  76722. + break;
  76723. + }
  76724. +handle_xacterr_done:
  76725. + disable_hc_int(hc_regs, xacterr);
  76726. +
  76727. + return 1;
  76728. +}
  76729. +
  76730. +/**
  76731. + * Handles a host channel frame overrun interrupt. This handler may be called
  76732. + * in either DMA mode or Slave mode.
  76733. + */
  76734. +static int32_t handle_hc_frmovrun_intr(dwc_otg_hcd_t * hcd,
  76735. + dwc_hc_t * hc,
  76736. + dwc_otg_hc_regs_t * hc_regs,
  76737. + dwc_otg_qtd_t * qtd)
  76738. +{
  76739. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76740. + "Frame Overrun--\n", hc->hc_num);
  76741. +
  76742. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  76743. + case UE_CONTROL:
  76744. + case UE_BULK:
  76745. + break;
  76746. + case UE_INTERRUPT:
  76747. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_FRAME_OVERRUN);
  76748. + break;
  76749. + case UE_ISOCHRONOUS:
  76750. + {
  76751. + dwc_otg_halt_status_e halt_status;
  76752. + halt_status =
  76753. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  76754. + DWC_OTG_HC_XFER_FRAME_OVERRUN);
  76755. +
  76756. + halt_channel(hcd, hc, qtd, halt_status);
  76757. + }
  76758. + break;
  76759. + }
  76760. +
  76761. + disable_hc_int(hc_regs, frmovrun);
  76762. +
  76763. + return 1;
  76764. +}
  76765. +
  76766. +/**
  76767. + * Handles a host channel data toggle error interrupt. This handler may be
  76768. + * called in either DMA mode or Slave mode.
  76769. + */
  76770. +static int32_t handle_hc_datatglerr_intr(dwc_otg_hcd_t * hcd,
  76771. + dwc_hc_t * hc,
  76772. + dwc_otg_hc_regs_t * hc_regs,
  76773. + dwc_otg_qtd_t * qtd)
  76774. +{
  76775. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76776. + "Data Toggle Error on %s transfer--\n",
  76777. + hc->hc_num, (hc->ep_is_in ? "IN" : "OUT"));
  76778. +
  76779. + /* Data toggles on split transactions cause the hc to halt.
  76780. + * restart transfer */
  76781. + if(hc->qh->do_split)
  76782. + {
  76783. + qtd->error_count++;
  76784. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  76785. + update_urb_state_xfer_intr(hc, hc_regs,
  76786. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  76787. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  76788. + } else if (hc->ep_is_in) {
  76789. + /* An unmasked data toggle error on a non-split DMA transaction is
  76790. + * for the sole purpose of resetting error counts. Disable other
  76791. + * interrupts unmasked for the same reason.
  76792. + */
  76793. + if(hcd->core_if->dma_enable) {
  76794. + disable_hc_int(hc_regs, ack);
  76795. + disable_hc_int(hc_regs, nak);
  76796. + }
  76797. + qtd->error_count = 0;
  76798. + }
  76799. +
  76800. + disable_hc_int(hc_regs, datatglerr);
  76801. +
  76802. + return 1;
  76803. +}
  76804. +
  76805. +#ifdef DEBUG
  76806. +/**
  76807. + * This function is for debug only. It checks that a valid halt status is set
  76808. + * and that HCCHARn.chdis is clear. If there's a problem, corrective action is
  76809. + * taken and a warning is issued.
  76810. + * @return 1 if halt status is ok, 0 otherwise.
  76811. + */
  76812. +static inline int halt_status_ok(dwc_otg_hcd_t * hcd,
  76813. + dwc_hc_t * hc,
  76814. + dwc_otg_hc_regs_t * hc_regs,
  76815. + dwc_otg_qtd_t * qtd)
  76816. +{
  76817. + hcchar_data_t hcchar;
  76818. + hctsiz_data_t hctsiz;
  76819. + hcint_data_t hcint;
  76820. + hcintmsk_data_t hcintmsk;
  76821. + hcsplt_data_t hcsplt;
  76822. +
  76823. + if (hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS) {
  76824. + /*
  76825. + * This code is here only as a check. This condition should
  76826. + * never happen. Ignore the halt if it does occur.
  76827. + */
  76828. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  76829. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  76830. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  76831. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  76832. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  76833. + DWC_WARN
  76834. + ("%s: hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS, "
  76835. + "channel %d, hcchar 0x%08x, hctsiz 0x%08x, "
  76836. + "hcint 0x%08x, hcintmsk 0x%08x, "
  76837. + "hcsplt 0x%08x, qtd->complete_split %d\n", __func__,
  76838. + hc->hc_num, hcchar.d32, hctsiz.d32, hcint.d32,
  76839. + hcintmsk.d32, hcsplt.d32, qtd->complete_split);
  76840. +
  76841. + DWC_WARN("%s: no halt status, channel %d, ignoring interrupt\n",
  76842. + __func__, hc->hc_num);
  76843. + DWC_WARN("\n");
  76844. + clear_hc_int(hc_regs, chhltd);
  76845. + return 0;
  76846. + }
  76847. +
  76848. + /*
  76849. + * This code is here only as a check. hcchar.chdis should
  76850. + * never be set when the halt interrupt occurs. Halt the
  76851. + * channel again if it does occur.
  76852. + */
  76853. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  76854. + if (hcchar.b.chdis) {
  76855. + DWC_WARN("%s: hcchar.chdis set unexpectedly, "
  76856. + "hcchar 0x%08x, trying to halt again\n",
  76857. + __func__, hcchar.d32);
  76858. + clear_hc_int(hc_regs, chhltd);
  76859. + hc->halt_pending = 0;
  76860. + halt_channel(hcd, hc, qtd, hc->halt_status);
  76861. + return 0;
  76862. + }
  76863. +
  76864. + return 1;
  76865. +}
  76866. +#endif
  76867. +
  76868. +/**
  76869. + * Handles a host Channel Halted interrupt in DMA mode. This handler
  76870. + * determines the reason the channel halted and proceeds accordingly.
  76871. + */
  76872. +static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t * hcd,
  76873. + dwc_hc_t * hc,
  76874. + dwc_otg_hc_regs_t * hc_regs,
  76875. + dwc_otg_qtd_t * qtd,
  76876. + hcint_data_t hcint,
  76877. + hcintmsk_data_t hcintmsk)
  76878. +{
  76879. + int out_nak_enh = 0;
  76880. +
  76881. + /* For core with OUT NAK enhancement, the flow for high-
  76882. + * speed CONTROL/BULK OUT is handled a little differently.
  76883. + */
  76884. + if (hcd->core_if->snpsid >= OTG_CORE_REV_2_71a) {
  76885. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH && !hc->ep_is_in &&
  76886. + (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  76887. + hc->ep_type == DWC_OTG_EP_TYPE_BULK)) {
  76888. + out_nak_enh = 1;
  76889. + }
  76890. + }
  76891. +
  76892. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  76893. + (hc->halt_status == DWC_OTG_HC_XFER_AHB_ERR
  76894. + && !hcd->core_if->dma_desc_enable)) {
  76895. + /*
  76896. + * Just release the channel. A dequeue can happen on a
  76897. + * transfer timeout. In the case of an AHB Error, the channel
  76898. + * was forced to halt because there's no way to gracefully
  76899. + * recover.
  76900. + */
  76901. + if (hcd->core_if->dma_desc_enable)
  76902. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  76903. + hc->halt_status);
  76904. + else
  76905. + release_channel(hcd, hc, qtd, hc->halt_status);
  76906. + return;
  76907. + }
  76908. +
  76909. + /* Read the HCINTn register to determine the cause for the halt. */
  76910. + if(!fiq_split_enable)
  76911. + {
  76912. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  76913. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  76914. + }
  76915. +
  76916. + if (hcint.b.xfercomp) {
  76917. + /** @todo This is here because of a possible hardware bug. Spec
  76918. + * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
  76919. + * interrupt w/ACK bit set should occur, but I only see the
  76920. + * XFERCOMP bit, even with it masked out. This is a workaround
  76921. + * for that behavior. Should fix this when hardware is fixed.
  76922. + */
  76923. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  76924. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  76925. + }
  76926. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  76927. + } else if (hcint.b.stall) {
  76928. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  76929. + } else if (hcint.b.xacterr && !hcd->core_if->dma_desc_enable) {
  76930. + if (out_nak_enh) {
  76931. + if (hcint.b.nyet || hcint.b.nak || hcint.b.ack) {
  76932. + DWC_DEBUGPL(DBG_HCD, "XactErr with NYET/NAK/ACK\n");
  76933. + qtd->error_count = 0;
  76934. + } else {
  76935. + DWC_DEBUGPL(DBG_HCD, "XactErr without NYET/NAK/ACK\n");
  76936. + }
  76937. + }
  76938. +
  76939. + /*
  76940. + * Must handle xacterr before nak or ack. Could get a xacterr
  76941. + * at the same time as either of these on a BULK/CONTROL OUT
  76942. + * that started with a PING. The xacterr takes precedence.
  76943. + */
  76944. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  76945. + } else if (hcint.b.xcs_xact && hcd->core_if->dma_desc_enable) {
  76946. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  76947. + } else if (hcint.b.ahberr && hcd->core_if->dma_desc_enable) {
  76948. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  76949. + } else if (hcint.b.bblerr) {
  76950. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  76951. + } else if (hcint.b.frmovrun) {
  76952. + handle_hc_frmovrun_intr(hcd, hc, hc_regs, qtd);
  76953. + } else if (hcint.b.datatglerr) {
  76954. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  76955. + } else if (!out_nak_enh) {
  76956. + if (hcint.b.nyet) {
  76957. + /*
  76958. + * Must handle nyet before nak or ack. Could get a nyet at the
  76959. + * same time as either of those on a BULK/CONTROL OUT that
  76960. + * started with a PING. The nyet takes precedence.
  76961. + */
  76962. + handle_hc_nyet_intr(hcd, hc, hc_regs, qtd);
  76963. + } else if (hcint.b.nak && !hcintmsk.b.nak) {
  76964. + /*
  76965. + * If nak is not masked, it's because a non-split IN transfer
  76966. + * is in an error state. In that case, the nak is handled by
  76967. + * the nak interrupt handler, not here. Handle nak here for
  76968. + * BULK/CONTROL OUT transfers, which halt on a NAK to allow
  76969. + * rewinding the buffer pointer.
  76970. + */
  76971. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  76972. + } else if (hcint.b.ack && !hcintmsk.b.ack) {
  76973. + /*
  76974. + * If ack is not masked, it's because a non-split IN transfer
  76975. + * is in an error state. In that case, the ack is handled by
  76976. + * the ack interrupt handler, not here. Handle ack here for
  76977. + * split transfers. Start splits halt on ACK.
  76978. + */
  76979. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  76980. + } else {
  76981. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  76982. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  76983. + /*
  76984. + * A periodic transfer halted with no other channel
  76985. + * interrupts set. Assume it was halted by the core
  76986. + * because it could not be completed in its scheduled
  76987. + * (micro)frame.
  76988. + */
  76989. +#ifdef DEBUG
  76990. + DWC_PRINTF
  76991. + ("%s: Halt channel %d (assume incomplete periodic transfer)\n",
  76992. + __func__, hc->hc_num);
  76993. +#endif
  76994. + halt_channel(hcd, hc, qtd,
  76995. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE);
  76996. + } else {
  76997. + DWC_ERROR
  76998. + ("%s: Channel %d, DMA Mode -- ChHltd set, but reason "
  76999. + "for halting is unknown, hcint 0x%08x, intsts 0x%08x\n",
  77000. + __func__, hc->hc_num, hcint.d32,
  77001. + DWC_READ_REG32(&hcd->
  77002. + core_if->core_global_regs->
  77003. + gintsts));
  77004. + /* Failthrough: use 3-strikes rule */
  77005. + qtd->error_count++;
  77006. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  77007. + update_urb_state_xfer_intr(hc, hc_regs,
  77008. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  77009. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  77010. + }
  77011. +
  77012. + }
  77013. + } else {
  77014. + DWC_PRINTF("NYET/NAK/ACK/other in non-error case, 0x%08x\n",
  77015. + hcint.d32);
  77016. + /* Failthrough: use 3-strikes rule */
  77017. + qtd->error_count++;
  77018. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  77019. + update_urb_state_xfer_intr(hc, hc_regs,
  77020. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  77021. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  77022. + }
  77023. +}
  77024. +
  77025. +/**
  77026. + * Handles a host channel Channel Halted interrupt.
  77027. + *
  77028. + * In slave mode, this handler is called only when the driver specifically
  77029. + * requests a halt. This occurs during handling other host channel interrupts
  77030. + * (e.g. nak, xacterr, stall, nyet, etc.).
  77031. + *
  77032. + * In DMA mode, this is the interrupt that occurs when the core has finished
  77033. + * processing a transfer on a channel. Other host channel interrupts (except
  77034. + * ahberr) are disabled in DMA mode.
  77035. + */
  77036. +static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t * hcd,
  77037. + dwc_hc_t * hc,
  77038. + dwc_otg_hc_regs_t * hc_regs,
  77039. + dwc_otg_qtd_t * qtd,
  77040. + hcint_data_t hcint,
  77041. + hcintmsk_data_t hcintmsk)
  77042. +{
  77043. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  77044. + "Channel Halted--\n", hc->hc_num);
  77045. +
  77046. + if (hcd->core_if->dma_enable) {
  77047. + handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd, hcint, hcintmsk);
  77048. + } else {
  77049. +#ifdef DEBUG
  77050. + if (!halt_status_ok(hcd, hc, hc_regs, qtd)) {
  77051. + return 1;
  77052. + }
  77053. +#endif
  77054. + release_channel(hcd, hc, qtd, hc->halt_status);
  77055. + }
  77056. +
  77057. + return 1;
  77058. +}
  77059. +
  77060. +/** Handles interrupt for a specific Host Channel */
  77061. +int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd, uint32_t num)
  77062. +{
  77063. + int retval = 0;
  77064. + hcint_data_t hcint, hcint_orig;
  77065. + hcintmsk_data_t hcintmsk;
  77066. + dwc_hc_t *hc;
  77067. + dwc_otg_hc_regs_t *hc_regs;
  77068. + dwc_otg_qtd_t *qtd;
  77069. +
  77070. + DWC_DEBUGPL(DBG_HCDV, "--Host Channel Interrupt--, Channel %d\n", num);
  77071. +
  77072. + hc = dwc_otg_hcd->hc_ptr_array[num];
  77073. + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[num];
  77074. + if(hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  77075. + /* We are responding to a channel disable. Driver
  77076. + * state is cleared - our qtd has gone away.
  77077. + */
  77078. + release_channel(dwc_otg_hcd, hc, NULL, hc->halt_status);
  77079. + return 1;
  77080. + }
  77081. + qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  77082. +
  77083. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  77084. + hcint_orig = hcint;
  77085. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  77086. + DWC_DEBUGPL(DBG_HCDV,
  77087. + " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
  77088. + hcint.d32, hcintmsk.d32, (hcint.d32 & hcintmsk.d32));
  77089. + hcint.d32 = hcint.d32 & hcintmsk.d32;
  77090. +
  77091. + if(fiq_split_enable)
  77092. + {
  77093. + // replace with the saved interrupts from the fiq handler
  77094. + local_fiq_disable();
  77095. + hcint_orig.d32 = hcint_saved[num].d32;
  77096. + hcint.d32 = hcint_orig.d32 & hcintmsk_saved[num].d32;
  77097. + hcint_saved[num].d32 = 0;
  77098. + local_fiq_enable();
  77099. + }
  77100. +
  77101. + if (!dwc_otg_hcd->core_if->dma_enable) {
  77102. + if (hcint.b.chhltd && hcint.d32 != 0x2) {
  77103. + hcint.b.chhltd = 0;
  77104. + }
  77105. + }
  77106. +
  77107. + if (hcint.b.xfercomp) {
  77108. + retval |=
  77109. + handle_hc_xfercomp_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77110. + /*
  77111. + * If NYET occurred at same time as Xfer Complete, the NYET is
  77112. + * handled by the Xfer Complete interrupt handler. Don't want
  77113. + * to call the NYET interrupt handler in this case.
  77114. + */
  77115. + hcint.b.nyet = 0;
  77116. + }
  77117. + if (hcint.b.chhltd) {
  77118. + retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd, hcint_orig, hcintmsk_saved[num]);
  77119. + }
  77120. + if (hcint.b.ahberr) {
  77121. + retval |= handle_hc_ahberr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77122. + }
  77123. + if (hcint.b.stall) {
  77124. + retval |= handle_hc_stall_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77125. + }
  77126. + if (hcint.b.nak) {
  77127. + retval |= handle_hc_nak_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77128. + }
  77129. + if (hcint.b.ack) {
  77130. + if(!hcint.b.chhltd)
  77131. + retval |= handle_hc_ack_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77132. + }
  77133. + if (hcint.b.nyet) {
  77134. + retval |= handle_hc_nyet_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77135. + }
  77136. + if (hcint.b.xacterr) {
  77137. + retval |= handle_hc_xacterr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77138. + }
  77139. + if (hcint.b.bblerr) {
  77140. + retval |= handle_hc_babble_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77141. + }
  77142. + if (hcint.b.frmovrun) {
  77143. + retval |=
  77144. + handle_hc_frmovrun_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77145. + }
  77146. + if (hcint.b.datatglerr) {
  77147. + retval |=
  77148. + handle_hc_datatglerr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  77149. + }
  77150. +
  77151. + return retval;
  77152. +}
  77153. +#endif /* DWC_DEVICE_ONLY */
  77154. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
  77155. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  77156. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 2014-02-18 11:52:14.000000000 +0100
  77157. @@ -0,0 +1,972 @@
  77158. +
  77159. +/* ==========================================================================
  77160. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_linux.c $
  77161. + * $Revision: #20 $
  77162. + * $Date: 2011/10/26 $
  77163. + * $Change: 1872981 $
  77164. + *
  77165. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  77166. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  77167. + * otherwise expressly agreed to in writing between Synopsys and you.
  77168. + *
  77169. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  77170. + * any End User Software License Agreement or Agreement for Licensed Product
  77171. + * with Synopsys or any supplement thereto. You are permitted to use and
  77172. + * redistribute this Software in source and binary forms, with or without
  77173. + * modification, provided that redistributions of source code must retain this
  77174. + * notice. You may not view, use, disclose, copy or distribute this file or
  77175. + * any information contained herein except pursuant to this license grant from
  77176. + * Synopsys. If you do not agree with this notice, including the disclaimer
  77177. + * below, then you are not authorized to use the Software.
  77178. + *
  77179. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  77180. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  77181. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  77182. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  77183. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  77184. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  77185. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  77186. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  77187. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  77188. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  77189. + * DAMAGE.
  77190. + * ========================================================================== */
  77191. +#ifndef DWC_DEVICE_ONLY
  77192. +
  77193. +/**
  77194. + * @file
  77195. + *
  77196. + * This file contains the implementation of the HCD. In Linux, the HCD
  77197. + * implements the hc_driver API.
  77198. + */
  77199. +#include <linux/kernel.h>
  77200. +#include <linux/module.h>
  77201. +#include <linux/moduleparam.h>
  77202. +#include <linux/init.h>
  77203. +#include <linux/device.h>
  77204. +#include <linux/errno.h>
  77205. +#include <linux/list.h>
  77206. +#include <linux/interrupt.h>
  77207. +#include <linux/string.h>
  77208. +#include <linux/dma-mapping.h>
  77209. +#include <linux/version.h>
  77210. +#include <asm/io.h>
  77211. +#include <asm/fiq.h>
  77212. +#include <linux/usb.h>
  77213. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
  77214. +#include <../drivers/usb/core/hcd.h>
  77215. +#else
  77216. +#include <linux/usb/hcd.h>
  77217. +#endif
  77218. +
  77219. +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  77220. +#define USB_URB_EP_LINKING 1
  77221. +#else
  77222. +#define USB_URB_EP_LINKING 0
  77223. +#endif
  77224. +
  77225. +#include "dwc_otg_hcd_if.h"
  77226. +#include "dwc_otg_dbg.h"
  77227. +#include "dwc_otg_driver.h"
  77228. +#include "dwc_otg_hcd.h"
  77229. +#include "dwc_otg_mphi_fix.h"
  77230. +
  77231. +/**
  77232. + * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
  77233. + * qualified with its direction (possible 32 endpoints per device).
  77234. + */
  77235. +#define dwc_ep_addr_to_endpoint(_bEndpointAddress_) ((_bEndpointAddress_ & USB_ENDPOINT_NUMBER_MASK) | \
  77236. + ((_bEndpointAddress_ & USB_DIR_IN) != 0) << 4)
  77237. +
  77238. +static const char dwc_otg_hcd_name[] = "dwc_otg_hcd";
  77239. +
  77240. +extern bool fiq_fix_enable;
  77241. +
  77242. +/** @name Linux HC Driver API Functions */
  77243. +/** @{ */
  77244. +/* manage i/o requests, device state */
  77245. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  77246. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  77247. + struct usb_host_endpoint *ep,
  77248. +#endif
  77249. + struct urb *urb, gfp_t mem_flags);
  77250. +
  77251. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  77252. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  77253. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb);
  77254. +#endif
  77255. +#else /* kernels at or post 2.6.30 */
  77256. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd,
  77257. + struct urb *urb, int status);
  77258. +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) */
  77259. +
  77260. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  77261. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  77262. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  77263. +#endif
  77264. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd);
  77265. +extern int hcd_start(struct usb_hcd *hcd);
  77266. +extern void hcd_stop(struct usb_hcd *hcd);
  77267. +static int get_frame_number(struct usb_hcd *hcd);
  77268. +extern int hub_status_data(struct usb_hcd *hcd, char *buf);
  77269. +extern int hub_control(struct usb_hcd *hcd,
  77270. + u16 typeReq,
  77271. + u16 wValue, u16 wIndex, char *buf, u16 wLength);
  77272. +
  77273. +struct wrapper_priv_data {
  77274. + dwc_otg_hcd_t *dwc_otg_hcd;
  77275. +};
  77276. +
  77277. +/** @} */
  77278. +
  77279. +static struct hc_driver dwc_otg_hc_driver = {
  77280. +
  77281. + .description = dwc_otg_hcd_name,
  77282. + .product_desc = "DWC OTG Controller",
  77283. + .hcd_priv_size = sizeof(struct wrapper_priv_data),
  77284. +
  77285. + .irq = dwc_otg_hcd_irq,
  77286. +
  77287. + .flags = HCD_MEMORY | HCD_USB2,
  77288. +
  77289. + //.reset =
  77290. + .start = hcd_start,
  77291. + //.suspend =
  77292. + //.resume =
  77293. + .stop = hcd_stop,
  77294. +
  77295. + .urb_enqueue = dwc_otg_urb_enqueue,
  77296. + .urb_dequeue = dwc_otg_urb_dequeue,
  77297. + .endpoint_disable = endpoint_disable,
  77298. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  77299. + .endpoint_reset = endpoint_reset,
  77300. +#endif
  77301. + .get_frame_number = get_frame_number,
  77302. +
  77303. + .hub_status_data = hub_status_data,
  77304. + .hub_control = hub_control,
  77305. + //.bus_suspend =
  77306. + //.bus_resume =
  77307. +};
  77308. +
  77309. +/** Gets the dwc_otg_hcd from a struct usb_hcd */
  77310. +static inline dwc_otg_hcd_t *hcd_to_dwc_otg_hcd(struct usb_hcd *hcd)
  77311. +{
  77312. + struct wrapper_priv_data *p;
  77313. + p = (struct wrapper_priv_data *)(hcd->hcd_priv);
  77314. + return p->dwc_otg_hcd;
  77315. +}
  77316. +
  77317. +/** Gets the struct usb_hcd that contains a dwc_otg_hcd_t. */
  77318. +static inline struct usb_hcd *dwc_otg_hcd_to_hcd(dwc_otg_hcd_t * dwc_otg_hcd)
  77319. +{
  77320. + return dwc_otg_hcd_get_priv_data(dwc_otg_hcd);
  77321. +}
  77322. +
  77323. +/** Gets the usb_host_endpoint associated with an URB. */
  77324. +inline struct usb_host_endpoint *dwc_urb_to_endpoint(struct urb *urb)
  77325. +{
  77326. + struct usb_device *dev = urb->dev;
  77327. + int ep_num = usb_pipeendpoint(urb->pipe);
  77328. +
  77329. + if (usb_pipein(urb->pipe))
  77330. + return dev->ep_in[ep_num];
  77331. + else
  77332. + return dev->ep_out[ep_num];
  77333. +}
  77334. +
  77335. +static int _disconnect(dwc_otg_hcd_t * hcd)
  77336. +{
  77337. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  77338. +
  77339. + usb_hcd->self.is_b_host = 0;
  77340. + return 0;
  77341. +}
  77342. +
  77343. +static int _start(dwc_otg_hcd_t * hcd)
  77344. +{
  77345. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  77346. +
  77347. + usb_hcd->self.is_b_host = dwc_otg_hcd_is_b_host(hcd);
  77348. + hcd_start(usb_hcd);
  77349. +
  77350. + return 0;
  77351. +}
  77352. +
  77353. +static int _hub_info(dwc_otg_hcd_t * hcd, void *urb_handle, uint32_t * hub_addr,
  77354. + uint32_t * port_addr)
  77355. +{
  77356. + struct urb *urb = (struct urb *)urb_handle;
  77357. + struct usb_bus *bus;
  77358. +#if 1 //GRAYG - temporary
  77359. + if (NULL == urb_handle)
  77360. + DWC_ERROR("**** %s - NULL URB handle\n", __func__);//GRAYG
  77361. + if (NULL == urb->dev)
  77362. + DWC_ERROR("**** %s - URB has no device\n", __func__);//GRAYG
  77363. + if (NULL == port_addr)
  77364. + DWC_ERROR("**** %s - NULL port_address\n", __func__);//GRAYG
  77365. +#endif
  77366. + if (urb->dev->tt) {
  77367. + if (NULL == urb->dev->tt->hub) {
  77368. + DWC_ERROR("**** %s - (URB's transactor has no TT - giving no hub)\n",
  77369. + __func__); //GRAYG
  77370. + //*hub_addr = (u8)usb_pipedevice(urb->pipe); //GRAYG
  77371. + *hub_addr = 0; //GRAYG
  77372. + // we probably shouldn't have a transaction translator if
  77373. + // there's no associated hub?
  77374. + } else {
  77375. + bus = hcd_to_bus(dwc_otg_hcd_to_hcd(hcd));
  77376. + if (urb->dev->tt->hub == bus->root_hub)
  77377. + *hub_addr = 0;
  77378. + else
  77379. + *hub_addr = urb->dev->tt->hub->devnum;
  77380. + }
  77381. + *port_addr = urb->dev->tt->multi ? urb->dev->ttport : 1;
  77382. + } else {
  77383. + *hub_addr = 0;
  77384. + *port_addr = urb->dev->ttport;
  77385. + }
  77386. + return 0;
  77387. +}
  77388. +
  77389. +static int _speed(dwc_otg_hcd_t * hcd, void *urb_handle)
  77390. +{
  77391. + struct urb *urb = (struct urb *)urb_handle;
  77392. + return urb->dev->speed;
  77393. +}
  77394. +
  77395. +static int _get_b_hnp_enable(dwc_otg_hcd_t * hcd)
  77396. +{
  77397. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  77398. + return usb_hcd->self.b_hnp_enable;
  77399. +}
  77400. +
  77401. +static void allocate_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  77402. + struct urb *urb)
  77403. +{
  77404. + hcd_to_bus(hcd)->bandwidth_allocated += bw / urb->interval;
  77405. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  77406. + hcd_to_bus(hcd)->bandwidth_isoc_reqs++;
  77407. + } else {
  77408. + hcd_to_bus(hcd)->bandwidth_int_reqs++;
  77409. + }
  77410. +}
  77411. +
  77412. +static void free_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  77413. + struct urb *urb)
  77414. +{
  77415. + hcd_to_bus(hcd)->bandwidth_allocated -= bw / urb->interval;
  77416. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  77417. + hcd_to_bus(hcd)->bandwidth_isoc_reqs--;
  77418. + } else {
  77419. + hcd_to_bus(hcd)->bandwidth_int_reqs--;
  77420. + }
  77421. +}
  77422. +
  77423. +/**
  77424. + * Sets the final status of an URB and returns it to the device driver. Any
  77425. + * required cleanup of the URB is performed. The HCD lock should be held on
  77426. + * entry.
  77427. + */
  77428. +static int _complete(dwc_otg_hcd_t * hcd, void *urb_handle,
  77429. + dwc_otg_hcd_urb_t * dwc_otg_urb, int32_t status)
  77430. +{
  77431. + struct urb *urb = (struct urb *)urb_handle;
  77432. + urb_tq_entry_t *new_entry;
  77433. + int rc = 0;
  77434. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  77435. + DWC_PRINTF("%s: urb %p, device %d, ep %d %s, status=%d\n",
  77436. + __func__, urb, usb_pipedevice(urb->pipe),
  77437. + usb_pipeendpoint(urb->pipe),
  77438. + usb_pipein(urb->pipe) ? "IN" : "OUT", status);
  77439. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  77440. + int i;
  77441. + for (i = 0; i < urb->number_of_packets; i++) {
  77442. + DWC_PRINTF(" ISO Desc %d status: %d\n",
  77443. + i, urb->iso_frame_desc[i].status);
  77444. + }
  77445. + }
  77446. + }
  77447. + new_entry = DWC_ALLOC_ATOMIC(sizeof(urb_tq_entry_t));
  77448. + urb->actual_length = dwc_otg_hcd_urb_get_actual_length(dwc_otg_urb);
  77449. + /* Convert status value. */
  77450. + switch (status) {
  77451. + case -DWC_E_PROTOCOL:
  77452. + status = -EPROTO;
  77453. + break;
  77454. + case -DWC_E_IN_PROGRESS:
  77455. + status = -EINPROGRESS;
  77456. + break;
  77457. + case -DWC_E_PIPE:
  77458. + status = -EPIPE;
  77459. + break;
  77460. + case -DWC_E_IO:
  77461. + status = -EIO;
  77462. + break;
  77463. + case -DWC_E_TIMEOUT:
  77464. + status = -ETIMEDOUT;
  77465. + break;
  77466. + case -DWC_E_OVERFLOW:
  77467. + status = -EOVERFLOW;
  77468. + break;
  77469. + case -DWC_E_SHUTDOWN:
  77470. + status = -ESHUTDOWN;
  77471. + break;
  77472. + default:
  77473. + if (status) {
  77474. + DWC_PRINTF("Uknown urb status %d\n", status);
  77475. +
  77476. + }
  77477. + }
  77478. +
  77479. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  77480. + int i;
  77481. +
  77482. + urb->error_count = dwc_otg_hcd_urb_get_error_count(dwc_otg_urb);
  77483. + for (i = 0; i < urb->number_of_packets; ++i) {
  77484. + urb->iso_frame_desc[i].actual_length =
  77485. + dwc_otg_hcd_urb_get_iso_desc_actual_length
  77486. + (dwc_otg_urb, i);
  77487. + urb->iso_frame_desc[i].status =
  77488. + dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_urb, i);
  77489. + }
  77490. + }
  77491. +
  77492. + urb->status = status;
  77493. + urb->hcpriv = NULL;
  77494. + if (!status) {
  77495. + if ((urb->transfer_flags & URB_SHORT_NOT_OK) &&
  77496. + (urb->actual_length < urb->transfer_buffer_length)) {
  77497. + urb->status = -EREMOTEIO;
  77498. + }
  77499. + }
  77500. +
  77501. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) ||
  77502. + (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  77503. + struct usb_host_endpoint *ep = dwc_urb_to_endpoint(urb);
  77504. + if (ep) {
  77505. + free_bus_bandwidth(dwc_otg_hcd_to_hcd(hcd),
  77506. + dwc_otg_hcd_get_ep_bandwidth(hcd,
  77507. + ep->hcpriv),
  77508. + urb);
  77509. + }
  77510. + }
  77511. +
  77512. + DWC_FREE(dwc_otg_urb);
  77513. + if (!new_entry) {
  77514. + DWC_ERROR("dwc_otg_hcd: complete: cannot allocate URB TQ entry\n");
  77515. + urb->status = -EPROTO;
  77516. + /* don't schedule the tasklet -
  77517. + * directly return the packet here with error. */
  77518. +#if USB_URB_EP_LINKING
  77519. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  77520. +#endif
  77521. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  77522. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb);
  77523. +#else
  77524. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  77525. +#endif
  77526. + } else {
  77527. + new_entry->urb = urb;
  77528. +#if USB_URB_EP_LINKING
  77529. + rc = usb_hcd_check_unlink_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  77530. + if(0 == rc) {
  77531. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  77532. + }
  77533. +#endif
  77534. + if(0 == rc) {
  77535. + DWC_TAILQ_INSERT_TAIL(&hcd->completed_urb_list, new_entry,
  77536. + urb_tq_entries);
  77537. + DWC_TASK_HI_SCHEDULE(hcd->completion_tasklet);
  77538. + }
  77539. + }
  77540. + return 0;
  77541. +}
  77542. +
  77543. +static struct dwc_otg_hcd_function_ops hcd_fops = {
  77544. + .start = _start,
  77545. + .disconnect = _disconnect,
  77546. + .hub_info = _hub_info,
  77547. + .speed = _speed,
  77548. + .complete = _complete,
  77549. + .get_b_hnp_enable = _get_b_hnp_enable,
  77550. +};
  77551. +
  77552. +static struct fiq_handler fh = {
  77553. + .name = "usb_fiq",
  77554. +};
  77555. +struct fiq_stack_s {
  77556. + int magic1;
  77557. + uint8_t stack[2048];
  77558. + int magic2;
  77559. +} fiq_stack;
  77560. +
  77561. +extern mphi_regs_t c_mphi_regs;
  77562. +/**
  77563. + * Initializes the HCD. This function allocates memory for and initializes the
  77564. + * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
  77565. + * USB bus with the core and calls the hc_driver->start() function. It returns
  77566. + * a negative error on failure.
  77567. + */
  77568. +int hcd_init(dwc_bus_dev_t *_dev)
  77569. +{
  77570. + struct usb_hcd *hcd = NULL;
  77571. + dwc_otg_hcd_t *dwc_otg_hcd = NULL;
  77572. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  77573. + int retval = 0;
  77574. + u64 dmamask;
  77575. + struct pt_regs regs;
  77576. +
  77577. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT otg_dev=%p\n", otg_dev);
  77578. +
  77579. + /* Set device flags indicating whether the HCD supports DMA. */
  77580. + if (dwc_otg_is_dma_enable(otg_dev->core_if))
  77581. + dmamask = DMA_BIT_MASK(32);
  77582. + else
  77583. + dmamask = 0;
  77584. +
  77585. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  77586. + dma_set_mask(&_dev->dev, dmamask);
  77587. + dma_set_coherent_mask(&_dev->dev, dmamask);
  77588. +#elif defined(PCI_INTERFACE)
  77589. + pci_set_dma_mask(_dev, dmamask);
  77590. + pci_set_consistent_dma_mask(_dev, dmamask);
  77591. +#endif
  77592. +
  77593. + if (fiq_fix_enable)
  77594. + {
  77595. + // Set up fiq
  77596. + claim_fiq(&fh);
  77597. + set_fiq_handler(__FIQ_Branch, 4);
  77598. + memset(&regs,0,sizeof(regs));
  77599. + regs.ARM_r8 = (long)dwc_otg_hcd_handle_fiq;
  77600. + regs.ARM_r9 = (long)0;
  77601. + regs.ARM_sp = (long)fiq_stack.stack + sizeof(fiq_stack.stack) - 4;
  77602. + set_fiq_regs(&regs);
  77603. + fiq_stack.magic1 = 0xdeadbeef;
  77604. + fiq_stack.magic2 = 0xaa995566;
  77605. + }
  77606. +
  77607. + /*
  77608. + * Allocate memory for the base HCD plus the DWC OTG HCD.
  77609. + * Initialize the base HCD.
  77610. + */
  77611. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  77612. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, _dev->dev.bus_id);
  77613. +#else
  77614. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, dev_name(&_dev->dev));
  77615. + hcd->has_tt = 1;
  77616. +// hcd->uses_new_polling = 1;
  77617. +// hcd->poll_rh = 0;
  77618. +#endif
  77619. + if (!hcd) {
  77620. + retval = -ENOMEM;
  77621. + goto error1;
  77622. + }
  77623. +
  77624. + hcd->regs = otg_dev->os_dep.base;
  77625. +
  77626. + if (fiq_fix_enable)
  77627. + {
  77628. + volatile extern void *dwc_regs_base;
  77629. +
  77630. + //Set the mphi periph to the required registers
  77631. + c_mphi_regs.base = otg_dev->os_dep.mphi_base;
  77632. + c_mphi_regs.ctrl = otg_dev->os_dep.mphi_base + 0x4c;
  77633. + c_mphi_regs.outdda = otg_dev->os_dep.mphi_base + 0x28;
  77634. + c_mphi_regs.outddb = otg_dev->os_dep.mphi_base + 0x2c;
  77635. + c_mphi_regs.intstat = otg_dev->os_dep.mphi_base + 0x50;
  77636. +
  77637. + dwc_regs_base = otg_dev->os_dep.base;
  77638. +
  77639. + //Enable mphi peripheral
  77640. + writel((1<<31),c_mphi_regs.ctrl);
  77641. +#ifdef DEBUG
  77642. + if (readl(c_mphi_regs.ctrl) & 0x80000000)
  77643. + DWC_DEBUGPL(DBG_USER, "MPHI periph has been enabled\n");
  77644. + else
  77645. + DWC_DEBUGPL(DBG_USER, "MPHI periph has NOT been enabled\n");
  77646. +#endif
  77647. + // Enable FIQ interrupt from USB peripheral
  77648. + enable_fiq(INTERRUPT_VC_USB);
  77649. + }
  77650. + /* Initialize the DWC OTG HCD. */
  77651. + dwc_otg_hcd = dwc_otg_hcd_alloc_hcd();
  77652. + if (!dwc_otg_hcd) {
  77653. + goto error2;
  77654. + }
  77655. + ((struct wrapper_priv_data *)(hcd->hcd_priv))->dwc_otg_hcd =
  77656. + dwc_otg_hcd;
  77657. + otg_dev->hcd = dwc_otg_hcd;
  77658. +
  77659. + if (dwc_otg_hcd_init(dwc_otg_hcd, otg_dev->core_if)) {
  77660. + goto error2;
  77661. + }
  77662. +
  77663. + otg_dev->hcd->otg_dev = otg_dev;
  77664. + hcd->self.otg_port = dwc_otg_hcd_otg_port(dwc_otg_hcd);
  77665. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33) //don't support for LM(with 2.6.20.1 kernel)
  77666. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) //version field absent later
  77667. + hcd->self.otg_version = dwc_otg_get_otg_version(otg_dev->core_if);
  77668. +#endif
  77669. + /* Don't support SG list at this point */
  77670. + hcd->self.sg_tablesize = 0;
  77671. +#endif
  77672. + /*
  77673. + * Finish generic HCD initialization and start the HCD. This function
  77674. + * allocates the DMA buffer pool, registers the USB bus, requests the
  77675. + * IRQ line, and calls hcd_start method.
  77676. + */
  77677. +#ifdef PLATFORM_INTERFACE
  77678. + retval = usb_add_hcd(hcd, platform_get_irq(_dev, 0), IRQF_SHARED | IRQF_DISABLED);
  77679. +#else
  77680. + retval = usb_add_hcd(hcd, _dev->irq, IRQF_SHARED | IRQF_DISABLED);
  77681. +#endif
  77682. + if (retval < 0) {
  77683. + goto error2;
  77684. + }
  77685. +
  77686. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, hcd);
  77687. + return 0;
  77688. +
  77689. +error2:
  77690. + usb_put_hcd(hcd);
  77691. +error1:
  77692. + return retval;
  77693. +}
  77694. +
  77695. +/**
  77696. + * Removes the HCD.
  77697. + * Frees memory and resources associated with the HCD and deregisters the bus.
  77698. + */
  77699. +void hcd_remove(dwc_bus_dev_t *_dev)
  77700. +{
  77701. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  77702. + dwc_otg_hcd_t *dwc_otg_hcd;
  77703. + struct usb_hcd *hcd;
  77704. +
  77705. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD REMOVE otg_dev=%p\n", otg_dev);
  77706. +
  77707. + if (!otg_dev) {
  77708. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  77709. + return;
  77710. + }
  77711. +
  77712. + dwc_otg_hcd = otg_dev->hcd;
  77713. +
  77714. + if (!dwc_otg_hcd) {
  77715. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  77716. + return;
  77717. + }
  77718. +
  77719. + hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
  77720. +
  77721. + if (!hcd) {
  77722. + DWC_DEBUGPL(DBG_ANY,
  77723. + "%s: dwc_otg_hcd_to_hcd(dwc_otg_hcd) NULL!\n",
  77724. + __func__);
  77725. + return;
  77726. + }
  77727. + usb_remove_hcd(hcd);
  77728. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, NULL);
  77729. + dwc_otg_hcd_remove(dwc_otg_hcd);
  77730. + usb_put_hcd(hcd);
  77731. +}
  77732. +
  77733. +/* =========================================================================
  77734. + * Linux HC Driver Functions
  77735. + * ========================================================================= */
  77736. +
  77737. +/** Initializes the DWC_otg controller and its root hub and prepares it for host
  77738. + * mode operation. Activates the root port. Returns 0 on success and a negative
  77739. + * error code on failure. */
  77740. +int hcd_start(struct usb_hcd *hcd)
  77741. +{
  77742. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  77743. + struct usb_bus *bus;
  77744. +
  77745. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD START\n");
  77746. + bus = hcd_to_bus(hcd);
  77747. +
  77748. + hcd->state = HC_STATE_RUNNING;
  77749. + if (dwc_otg_hcd_start(dwc_otg_hcd, &hcd_fops)) {
  77750. + return 0;
  77751. + }
  77752. +
  77753. + /* Initialize and connect root hub if one is not already attached */
  77754. + if (bus->root_hub) {
  77755. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Has Root Hub\n");
  77756. + /* Inform the HUB driver to resume. */
  77757. + usb_hcd_resume_root_hub(hcd);
  77758. + }
  77759. +
  77760. + return 0;
  77761. +}
  77762. +
  77763. +/**
  77764. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  77765. + * stopped.
  77766. + */
  77767. +void hcd_stop(struct usb_hcd *hcd)
  77768. +{
  77769. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  77770. +
  77771. + dwc_otg_hcd_stop(dwc_otg_hcd);
  77772. +}
  77773. +
  77774. +/** Returns the current frame number. */
  77775. +static int get_frame_number(struct usb_hcd *hcd)
  77776. +{
  77777. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  77778. +
  77779. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd);
  77780. +}
  77781. +
  77782. +#ifdef DEBUG
  77783. +static void dump_urb_info(struct urb *urb, char *fn_name)
  77784. +{
  77785. + DWC_PRINTF("%s, urb %p\n", fn_name, urb);
  77786. + DWC_PRINTF(" Device address: %d\n", usb_pipedevice(urb->pipe));
  77787. + DWC_PRINTF(" Endpoint: %d, %s\n", usb_pipeendpoint(urb->pipe),
  77788. + (usb_pipein(urb->pipe) ? "IN" : "OUT"));
  77789. + DWC_PRINTF(" Endpoint type: %s\n", ( {
  77790. + char *pipetype;
  77791. + switch (usb_pipetype(urb->pipe)) {
  77792. +case PIPE_CONTROL:
  77793. +pipetype = "CONTROL"; break; case PIPE_BULK:
  77794. +pipetype = "BULK"; break; case PIPE_INTERRUPT:
  77795. +pipetype = "INTERRUPT"; break; case PIPE_ISOCHRONOUS:
  77796. +pipetype = "ISOCHRONOUS"; break; default:
  77797. + pipetype = "UNKNOWN"; break;};
  77798. + pipetype;}
  77799. + )) ;
  77800. + DWC_PRINTF(" Speed: %s\n", ( {
  77801. + char *speed; switch (urb->dev->speed) {
  77802. +case USB_SPEED_HIGH:
  77803. +speed = "HIGH"; break; case USB_SPEED_FULL:
  77804. +speed = "FULL"; break; case USB_SPEED_LOW:
  77805. +speed = "LOW"; break; default:
  77806. + speed = "UNKNOWN"; break;};
  77807. + speed;}
  77808. + )) ;
  77809. + DWC_PRINTF(" Max packet size: %d\n",
  77810. + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
  77811. + DWC_PRINTF(" Data buffer length: %d\n", urb->transfer_buffer_length);
  77812. + DWC_PRINTF(" Transfer buffer: %p, Transfer DMA: %p\n",
  77813. + urb->transfer_buffer, (void *)urb->transfer_dma);
  77814. + DWC_PRINTF(" Setup buffer: %p, Setup DMA: %p\n",
  77815. + urb->setup_packet, (void *)urb->setup_dma);
  77816. + DWC_PRINTF(" Interval: %d\n", urb->interval);
  77817. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  77818. + int i;
  77819. + for (i = 0; i < urb->number_of_packets; i++) {
  77820. + DWC_PRINTF(" ISO Desc %d:\n", i);
  77821. + DWC_PRINTF(" offset: %d, length %d\n",
  77822. + urb->iso_frame_desc[i].offset,
  77823. + urb->iso_frame_desc[i].length);
  77824. + }
  77825. + }
  77826. +}
  77827. +#endif
  77828. +
  77829. +/** Starts processing a USB transfer request specified by a USB Request Block
  77830. + * (URB). mem_flags indicates the type of memory allocation to use while
  77831. + * processing this URB. */
  77832. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  77833. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  77834. + struct usb_host_endpoint *ep,
  77835. +#endif
  77836. + struct urb *urb, gfp_t mem_flags)
  77837. +{
  77838. + int retval = 0;
  77839. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
  77840. + struct usb_host_endpoint *ep = urb->ep;
  77841. +#endif
  77842. + dwc_irqflags_t irqflags;
  77843. + void **ref_ep_hcpriv = &ep->hcpriv;
  77844. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  77845. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  77846. + int i;
  77847. + int alloc_bandwidth = 0;
  77848. + uint8_t ep_type = 0;
  77849. + uint32_t flags = 0;
  77850. + void *buf;
  77851. +
  77852. +#ifdef DEBUG
  77853. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  77854. + dump_urb_info(urb, "dwc_otg_urb_enqueue");
  77855. + }
  77856. +#endif
  77857. +
  77858. + if (!urb->transfer_buffer && urb->transfer_buffer_length)
  77859. + return -EINVAL;
  77860. +
  77861. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
  77862. + || (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  77863. + if (!dwc_otg_hcd_is_bandwidth_allocated
  77864. + (dwc_otg_hcd, ref_ep_hcpriv)) {
  77865. + alloc_bandwidth = 1;
  77866. + }
  77867. + }
  77868. +
  77869. + switch (usb_pipetype(urb->pipe)) {
  77870. + case PIPE_CONTROL:
  77871. + ep_type = USB_ENDPOINT_XFER_CONTROL;
  77872. + break;
  77873. + case PIPE_ISOCHRONOUS:
  77874. + ep_type = USB_ENDPOINT_XFER_ISOC;
  77875. + break;
  77876. + case PIPE_BULK:
  77877. + ep_type = USB_ENDPOINT_XFER_BULK;
  77878. + break;
  77879. + case PIPE_INTERRUPT:
  77880. + ep_type = USB_ENDPOINT_XFER_INT;
  77881. + break;
  77882. + default:
  77883. + DWC_WARN("Wrong EP type - %d\n", usb_pipetype(urb->pipe));
  77884. + }
  77885. +
  77886. + /* # of packets is often 0 - do we really need to call this then? */
  77887. + dwc_otg_urb = dwc_otg_hcd_urb_alloc(dwc_otg_hcd,
  77888. + urb->number_of_packets,
  77889. + mem_flags == GFP_ATOMIC ? 1 : 0);
  77890. +
  77891. + if(dwc_otg_urb == NULL)
  77892. + return -ENOMEM;
  77893. +
  77894. + if (!dwc_otg_urb && urb->number_of_packets)
  77895. + return -ENOMEM;
  77896. +
  77897. + dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_urb, usb_pipedevice(urb->pipe),
  77898. + usb_pipeendpoint(urb->pipe), ep_type,
  77899. + usb_pipein(urb->pipe),
  77900. + usb_maxpacket(urb->dev, urb->pipe,
  77901. + !(usb_pipein(urb->pipe))));
  77902. +
  77903. + buf = urb->transfer_buffer;
  77904. + if (hcd->self.uses_dma) {
  77905. + /*
  77906. + * Calculate virtual address from physical address,
  77907. + * because some class driver may not fill transfer_buffer.
  77908. + * In Buffer DMA mode virual address is used,
  77909. + * when handling non DWORD aligned buffers.
  77910. + */
  77911. + //buf = phys_to_virt(urb->transfer_dma);
  77912. + // DMA addresses are bus addresses not physical addresses!
  77913. + buf = dma_to_virt(&urb->dev->dev, urb->transfer_dma);
  77914. + }
  77915. +
  77916. + if (!(urb->transfer_flags & URB_NO_INTERRUPT))
  77917. + flags |= URB_GIVEBACK_ASAP;
  77918. + if (urb->transfer_flags & URB_ZERO_PACKET)
  77919. + flags |= URB_SEND_ZERO_PACKET;
  77920. +
  77921. + dwc_otg_hcd_urb_set_params(dwc_otg_urb, urb, buf,
  77922. + urb->transfer_dma,
  77923. + urb->transfer_buffer_length,
  77924. + urb->setup_packet,
  77925. + urb->setup_dma, flags, urb->interval);
  77926. +
  77927. + for (i = 0; i < urb->number_of_packets; ++i) {
  77928. + dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_urb, i,
  77929. + urb->
  77930. + iso_frame_desc[i].offset,
  77931. + urb->
  77932. + iso_frame_desc[i].length);
  77933. + }
  77934. +
  77935. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &irqflags);
  77936. + urb->hcpriv = dwc_otg_urb;
  77937. +#if USB_URB_EP_LINKING
  77938. + retval = usb_hcd_link_urb_to_ep(hcd, urb);
  77939. + if (0 == retval)
  77940. +#endif
  77941. + {
  77942. + retval = dwc_otg_hcd_urb_enqueue(dwc_otg_hcd, dwc_otg_urb,
  77943. + /*(dwc_otg_qh_t **)*/
  77944. + ref_ep_hcpriv, 1);
  77945. + if (0 == retval) {
  77946. + if (alloc_bandwidth) {
  77947. + allocate_bus_bandwidth(hcd,
  77948. + dwc_otg_hcd_get_ep_bandwidth(
  77949. + dwc_otg_hcd, *ref_ep_hcpriv),
  77950. + urb);
  77951. + }
  77952. + } else {
  77953. + DWC_DEBUGPL(DBG_HCD, "DWC OTG dwc_otg_hcd_urb_enqueue failed rc %d\n", retval);
  77954. +#if USB_URB_EP_LINKING
  77955. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  77956. +#endif
  77957. + DWC_FREE(dwc_otg_urb);
  77958. + urb->hcpriv = NULL;
  77959. + if (retval == -DWC_E_NO_DEVICE)
  77960. + retval = -ENODEV;
  77961. + }
  77962. + }
  77963. +#if USB_URB_EP_LINKING
  77964. + else
  77965. + {
  77966. + DWC_FREE(dwc_otg_urb);
  77967. + urb->hcpriv = NULL;
  77968. + }
  77969. +#endif
  77970. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, irqflags);
  77971. + return retval;
  77972. +}
  77973. +
  77974. +/** Aborts/cancels a USB transfer request. Always returns 0 to indicate
  77975. + * success. */
  77976. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  77977. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
  77978. +#else
  77979. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  77980. +#endif
  77981. +{
  77982. + dwc_irqflags_t flags;
  77983. + dwc_otg_hcd_t *dwc_otg_hcd;
  77984. + int rc;
  77985. +
  77986. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue\n");
  77987. +
  77988. + dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  77989. +
  77990. +#ifdef DEBUG
  77991. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  77992. + dump_urb_info(urb, "dwc_otg_urb_dequeue");
  77993. + }
  77994. +#endif
  77995. +
  77996. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  77997. + rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  77998. + if (0 == rc) {
  77999. + if(urb->hcpriv != NULL) {
  78000. + dwc_otg_hcd_urb_dequeue(dwc_otg_hcd,
  78001. + (dwc_otg_hcd_urb_t *)urb->hcpriv);
  78002. +
  78003. + DWC_FREE(urb->hcpriv);
  78004. + urb->hcpriv = NULL;
  78005. + }
  78006. + }
  78007. +
  78008. + if (0 == rc) {
  78009. + /* Higher layer software sets URB status. */
  78010. +#if USB_URB_EP_LINKING
  78011. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  78012. +#endif
  78013. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  78014. +
  78015. +
  78016. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  78017. + usb_hcd_giveback_urb(hcd, urb);
  78018. +#else
  78019. + usb_hcd_giveback_urb(hcd, urb, status);
  78020. +#endif
  78021. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  78022. + DWC_PRINTF("Called usb_hcd_giveback_urb() \n");
  78023. + DWC_PRINTF(" 1urb->status = %d\n", urb->status);
  78024. + }
  78025. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue OK\n");
  78026. + } else {
  78027. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  78028. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue failed - rc %d\n",
  78029. + rc);
  78030. + }
  78031. +
  78032. + return rc;
  78033. +}
  78034. +
  78035. +/* Frees resources in the DWC_otg controller related to a given endpoint. Also
  78036. + * clears state in the HCD related to the endpoint. Any URBs for the endpoint
  78037. + * must already be dequeued. */
  78038. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  78039. +{
  78040. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  78041. +
  78042. + DWC_DEBUGPL(DBG_HCD,
  78043. + "DWC OTG HCD EP DISABLE: _bEndpointAddress=0x%02x, "
  78044. + "endpoint=%d\n", ep->desc.bEndpointAddress,
  78045. + dwc_ep_addr_to_endpoint(ep->desc.bEndpointAddress));
  78046. + dwc_otg_hcd_endpoint_disable(dwc_otg_hcd, ep->hcpriv, 250);
  78047. + ep->hcpriv = NULL;
  78048. +}
  78049. +
  78050. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  78051. +/* Resets endpoint specific parameter values, in current version used to reset
  78052. + * the data toggle(as a WA). This function can be called from usb_clear_halt routine */
  78053. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  78054. +{
  78055. + dwc_irqflags_t flags;
  78056. + struct usb_device *udev = NULL;
  78057. + int epnum = usb_endpoint_num(&ep->desc);
  78058. + int is_out = usb_endpoint_dir_out(&ep->desc);
  78059. + int is_control = usb_endpoint_xfer_control(&ep->desc);
  78060. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  78061. + struct device *dev = DWC_OTG_OS_GETDEV(dwc_otg_hcd->otg_dev->os_dep);
  78062. +
  78063. + if (dev)
  78064. + udev = to_usb_device(dev);
  78065. + else
  78066. + return;
  78067. +
  78068. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD EP RESET: Endpoint Num=0x%02d\n", epnum);
  78069. +
  78070. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  78071. + usb_settoggle(udev, epnum, is_out, 0);
  78072. + if (is_control)
  78073. + usb_settoggle(udev, epnum, !is_out, 0);
  78074. +
  78075. + if (ep->hcpriv) {
  78076. + dwc_otg_hcd_endpoint_reset(dwc_otg_hcd, ep->hcpriv);
  78077. + }
  78078. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  78079. +}
  78080. +#endif
  78081. +
  78082. +/** Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
  78083. + * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
  78084. + * interrupt.
  78085. + *
  78086. + * This function is called by the USB core when an interrupt occurs */
  78087. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd)
  78088. +{
  78089. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  78090. + int32_t retval = dwc_otg_hcd_handle_intr(dwc_otg_hcd);
  78091. + if (retval != 0) {
  78092. + S3C2410X_CLEAR_EINTPEND();
  78093. + }
  78094. + return IRQ_RETVAL(retval);
  78095. +}
  78096. +
  78097. +/** Creates Status Change bitmap for the root hub and root port. The bitmap is
  78098. + * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
  78099. + * is the status change indicator for the single root port. Returns 1 if either
  78100. + * change indicator is 1, otherwise returns 0. */
  78101. +int hub_status_data(struct usb_hcd *hcd, char *buf)
  78102. +{
  78103. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  78104. +
  78105. + buf[0] = 0;
  78106. + buf[0] |= (dwc_otg_hcd_is_status_changed(dwc_otg_hcd, 1)) << 1;
  78107. +
  78108. + return (buf[0] != 0);
  78109. +}
  78110. +
  78111. +/** Handles hub class-specific requests. */
  78112. +int hub_control(struct usb_hcd *hcd,
  78113. + u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength)
  78114. +{
  78115. + int retval;
  78116. +
  78117. + retval = dwc_otg_hcd_hub_control(hcd_to_dwc_otg_hcd(hcd),
  78118. + typeReq, wValue, wIndex, buf, wLength);
  78119. +
  78120. + switch (retval) {
  78121. + case -DWC_E_INVALID:
  78122. + retval = -EINVAL;
  78123. + break;
  78124. + }
  78125. +
  78126. + return retval;
  78127. +}
  78128. +
  78129. +#endif /* DWC_DEVICE_ONLY */
  78130. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
  78131. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 1970-01-01 01:00:00.000000000 +0100
  78132. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 2014-02-18 11:52:14.000000000 +0100
  78133. @@ -0,0 +1,959 @@
  78134. +/* ==========================================================================
  78135. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_queue.c $
  78136. + * $Revision: #44 $
  78137. + * $Date: 2011/10/26 $
  78138. + * $Change: 1873028 $
  78139. + *
  78140. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  78141. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  78142. + * otherwise expressly agreed to in writing between Synopsys and you.
  78143. + *
  78144. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  78145. + * any End User Software License Agreement or Agreement for Licensed Product
  78146. + * with Synopsys or any supplement thereto. You are permitted to use and
  78147. + * redistribute this Software in source and binary forms, with or without
  78148. + * modification, provided that redistributions of source code must retain this
  78149. + * notice. You may not view, use, disclose, copy or distribute this file or
  78150. + * any information contained herein except pursuant to this license grant from
  78151. + * Synopsys. If you do not agree with this notice, including the disclaimer
  78152. + * below, then you are not authorized to use the Software.
  78153. + *
  78154. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  78155. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  78156. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  78157. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  78158. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  78159. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  78160. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  78161. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  78162. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  78163. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  78164. + * DAMAGE.
  78165. + * ========================================================================== */
  78166. +#ifndef DWC_DEVICE_ONLY
  78167. +
  78168. +/**
  78169. + * @file
  78170. + *
  78171. + * This file contains the functions to manage Queue Heads and Queue
  78172. + * Transfer Descriptors.
  78173. + */
  78174. +
  78175. +#include "dwc_otg_hcd.h"
  78176. +#include "dwc_otg_regs.h"
  78177. +#include "dwc_otg_mphi_fix.h"
  78178. +
  78179. +extern bool microframe_schedule;
  78180. +
  78181. +/**
  78182. + * Free each QTD in the QH's QTD-list then free the QH. QH should already be
  78183. + * removed from a list. QTD list should already be empty if called from URB
  78184. + * Dequeue.
  78185. + *
  78186. + * @param hcd HCD instance.
  78187. + * @param qh The QH to free.
  78188. + */
  78189. +void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  78190. +{
  78191. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  78192. +
  78193. + /* Free each QTD in the QTD list */
  78194. + DWC_SPINLOCK(hcd->lock);
  78195. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  78196. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  78197. + dwc_otg_hcd_qtd_free(qtd);
  78198. + }
  78199. +
  78200. + if (hcd->core_if->dma_desc_enable) {
  78201. + dwc_otg_hcd_qh_free_ddma(hcd, qh);
  78202. + } else if (qh->dw_align_buf) {
  78203. + uint32_t buf_size;
  78204. + if (qh->ep_type == UE_ISOCHRONOUS) {
  78205. + buf_size = 4096;
  78206. + } else {
  78207. + buf_size = hcd->core_if->core_params->max_transfer_size;
  78208. + }
  78209. + DWC_DMA_FREE(buf_size, qh->dw_align_buf, qh->dw_align_buf_dma);
  78210. + }
  78211. +
  78212. + DWC_FREE(qh);
  78213. + DWC_SPINUNLOCK(hcd->lock);
  78214. + return;
  78215. +}
  78216. +
  78217. +#define BitStuffTime(bytecount) ((8 * 7* bytecount) / 6)
  78218. +#define HS_HOST_DELAY 5 /* nanoseconds */
  78219. +#define FS_LS_HOST_DELAY 1000 /* nanoseconds */
  78220. +#define HUB_LS_SETUP 333 /* nanoseconds */
  78221. +#define NS_TO_US(ns) ((ns + 500) / 1000)
  78222. + /* convert & round nanoseconds to microseconds */
  78223. +
  78224. +static uint32_t calc_bus_time(int speed, int is_in, int is_isoc, int bytecount)
  78225. +{
  78226. + unsigned long retval;
  78227. +
  78228. + switch (speed) {
  78229. + case USB_SPEED_HIGH:
  78230. + if (is_isoc) {
  78231. + retval =
  78232. + ((38 * 8 * 2083) +
  78233. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  78234. + HS_HOST_DELAY;
  78235. + } else {
  78236. + retval =
  78237. + ((55 * 8 * 2083) +
  78238. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  78239. + HS_HOST_DELAY;
  78240. + }
  78241. + break;
  78242. + case USB_SPEED_FULL:
  78243. + if (is_isoc) {
  78244. + retval =
  78245. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  78246. + if (is_in) {
  78247. + retval = 7268 + FS_LS_HOST_DELAY + retval;
  78248. + } else {
  78249. + retval = 6265 + FS_LS_HOST_DELAY + retval;
  78250. + }
  78251. + } else {
  78252. + retval =
  78253. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  78254. + retval = 9107 + FS_LS_HOST_DELAY + retval;
  78255. + }
  78256. + break;
  78257. + case USB_SPEED_LOW:
  78258. + if (is_in) {
  78259. + retval =
  78260. + (67667 * (31 + 10 * BitStuffTime(bytecount))) /
  78261. + 1000;
  78262. + retval =
  78263. + 64060 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  78264. + retval;
  78265. + } else {
  78266. + retval =
  78267. + (66700 * (31 + 10 * BitStuffTime(bytecount))) /
  78268. + 1000;
  78269. + retval =
  78270. + 64107 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  78271. + retval;
  78272. + }
  78273. + break;
  78274. + default:
  78275. + DWC_WARN("Unknown device speed\n");
  78276. + retval = -1;
  78277. + }
  78278. +
  78279. + return NS_TO_US(retval);
  78280. +}
  78281. +
  78282. +/**
  78283. + * Initializes a QH structure.
  78284. + *
  78285. + * @param hcd The HCD state structure for the DWC OTG controller.
  78286. + * @param qh The QH to init.
  78287. + * @param urb Holds the information about the device/endpoint that we need
  78288. + * to initialize the QH.
  78289. + */
  78290. +#define SCHEDULE_SLOP 10
  78291. +void qh_init(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, dwc_otg_hcd_urb_t * urb)
  78292. +{
  78293. + char *speed, *type;
  78294. + int dev_speed;
  78295. + uint32_t hub_addr, hub_port;
  78296. +
  78297. + dwc_memset(qh, 0, sizeof(dwc_otg_qh_t));
  78298. +
  78299. + /* Initialize QH */
  78300. + qh->ep_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  78301. + qh->ep_is_in = dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? 1 : 0;
  78302. +
  78303. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  78304. + qh->maxp = dwc_otg_hcd_get_mps(&urb->pipe_info);
  78305. + DWC_CIRCLEQ_INIT(&qh->qtd_list);
  78306. + DWC_LIST_INIT(&qh->qh_list_entry);
  78307. + qh->channel = NULL;
  78308. +
  78309. + /* FS/LS Enpoint on HS Hub
  78310. + * NOT virtual root hub */
  78311. + dev_speed = hcd->fops->speed(hcd, urb->priv);
  78312. +
  78313. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &hub_port);
  78314. + qh->do_split = 0;
  78315. + if (microframe_schedule)
  78316. + qh->speed = dev_speed;
  78317. +
  78318. + qh->nak_frame = 0xffff;
  78319. +
  78320. + if (((dev_speed == USB_SPEED_LOW) ||
  78321. + (dev_speed == USB_SPEED_FULL)) &&
  78322. + (hub_addr != 0 && hub_addr != 1)) {
  78323. + DWC_DEBUGPL(DBG_HCD,
  78324. + "QH init: EP %d: TT found at hub addr %d, for port %d\n",
  78325. + dwc_otg_hcd_get_ep_num(&urb->pipe_info), hub_addr,
  78326. + hub_port);
  78327. + qh->do_split = 1;
  78328. + qh->skip_count = 0;
  78329. + }
  78330. +
  78331. + if (qh->ep_type == UE_INTERRUPT || qh->ep_type == UE_ISOCHRONOUS) {
  78332. + /* Compute scheduling parameters once and save them. */
  78333. + hprt0_data_t hprt;
  78334. +
  78335. + /** @todo Account for split transfers in the bus time. */
  78336. + int bytecount =
  78337. + dwc_hb_mult(qh->maxp) * dwc_max_packet(qh->maxp);
  78338. +
  78339. + qh->usecs =
  78340. + calc_bus_time((qh->do_split ? USB_SPEED_HIGH : dev_speed),
  78341. + qh->ep_is_in, (qh->ep_type == UE_ISOCHRONOUS),
  78342. + bytecount);
  78343. + /* Start in a slightly future (micro)frame. */
  78344. + qh->sched_frame = dwc_frame_num_inc(hcd->frame_number,
  78345. + SCHEDULE_SLOP);
  78346. + qh->interval = urb->interval;
  78347. +
  78348. +#if 0
  78349. + /* Increase interrupt polling rate for debugging. */
  78350. + if (qh->ep_type == UE_INTERRUPT) {
  78351. + qh->interval = 8;
  78352. + }
  78353. +#endif
  78354. + hprt.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  78355. + if ((hprt.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED) &&
  78356. + ((dev_speed == USB_SPEED_LOW) ||
  78357. + (dev_speed == USB_SPEED_FULL))) {
  78358. + qh->interval *= 8;
  78359. + qh->sched_frame |= 0x7;
  78360. + qh->start_split_frame = qh->sched_frame;
  78361. + }
  78362. +
  78363. + }
  78364. +
  78365. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD QH Initialized\n");
  78366. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - qh = %p\n", qh);
  78367. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Device Address = %d\n",
  78368. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  78369. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Endpoint %d, %s\n",
  78370. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  78371. + dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
  78372. + switch (dev_speed) {
  78373. + case USB_SPEED_LOW:
  78374. + qh->dev_speed = DWC_OTG_EP_SPEED_LOW;
  78375. + speed = "low";
  78376. + break;
  78377. + case USB_SPEED_FULL:
  78378. + qh->dev_speed = DWC_OTG_EP_SPEED_FULL;
  78379. + speed = "full";
  78380. + break;
  78381. + case USB_SPEED_HIGH:
  78382. + qh->dev_speed = DWC_OTG_EP_SPEED_HIGH;
  78383. + speed = "high";
  78384. + break;
  78385. + default:
  78386. + speed = "?";
  78387. + break;
  78388. + }
  78389. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Speed = %s\n", speed);
  78390. +
  78391. + switch (qh->ep_type) {
  78392. + case UE_ISOCHRONOUS:
  78393. + type = "isochronous";
  78394. + break;
  78395. + case UE_INTERRUPT:
  78396. + type = "interrupt";
  78397. + break;
  78398. + case UE_CONTROL:
  78399. + type = "control";
  78400. + break;
  78401. + case UE_BULK:
  78402. + type = "bulk";
  78403. + break;
  78404. + default:
  78405. + type = "?";
  78406. + break;
  78407. + }
  78408. +
  78409. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Type = %s\n", type);
  78410. +
  78411. +#ifdef DEBUG
  78412. + if (qh->ep_type == UE_INTERRUPT) {
  78413. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - usecs = %d\n",
  78414. + qh->usecs);
  78415. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - interval = %d\n",
  78416. + qh->interval);
  78417. + }
  78418. +#endif
  78419. +
  78420. +}
  78421. +
  78422. +/**
  78423. + * This function allocates and initializes a QH.
  78424. + *
  78425. + * @param hcd The HCD state structure for the DWC OTG controller.
  78426. + * @param urb Holds the information about the device/endpoint that we need
  78427. + * to initialize the QH.
  78428. + * @param atomic_alloc Flag to do atomic allocation if needed
  78429. + *
  78430. + * @return Returns pointer to the newly allocated QH, or NULL on error. */
  78431. +dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  78432. + dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  78433. +{
  78434. + dwc_otg_qh_t *qh;
  78435. +
  78436. + /* Allocate memory */
  78437. + /** @todo add memflags argument */
  78438. + qh = dwc_otg_hcd_qh_alloc(atomic_alloc);
  78439. + if (qh == NULL) {
  78440. + DWC_ERROR("qh allocation failed");
  78441. + return NULL;
  78442. + }
  78443. +
  78444. + qh_init(hcd, qh, urb);
  78445. +
  78446. + if (hcd->core_if->dma_desc_enable
  78447. + && (dwc_otg_hcd_qh_init_ddma(hcd, qh) < 0)) {
  78448. + dwc_otg_hcd_qh_free(hcd, qh);
  78449. + return NULL;
  78450. + }
  78451. +
  78452. + return qh;
  78453. +}
  78454. +
  78455. +/* microframe_schedule=0 start */
  78456. +
  78457. +/**
  78458. + * Checks that a channel is available for a periodic transfer.
  78459. + *
  78460. + * @return 0 if successful, negative error code otherise.
  78461. + */
  78462. +static int periodic_channel_available(dwc_otg_hcd_t * hcd)
  78463. +{
  78464. + /*
  78465. + * Currently assuming that there is a dedicated host channnel for each
  78466. + * periodic transaction plus at least one host channel for
  78467. + * non-periodic transactions.
  78468. + */
  78469. + int status;
  78470. + int num_channels;
  78471. +
  78472. + num_channels = hcd->core_if->core_params->host_channels;
  78473. + if ((hcd->periodic_channels + hcd->non_periodic_channels < num_channels)
  78474. + && (hcd->periodic_channels < num_channels - 1)) {
  78475. + status = 0;
  78476. + } else {
  78477. + DWC_INFO("%s: Total channels: %d, Periodic: %d, Non-periodic: %d\n",
  78478. + __func__, num_channels, hcd->periodic_channels, hcd->non_periodic_channels); //NOTICE
  78479. + status = -DWC_E_NO_SPACE;
  78480. + }
  78481. +
  78482. + return status;
  78483. +}
  78484. +
  78485. +/**
  78486. + * Checks that there is sufficient bandwidth for the specified QH in the
  78487. + * periodic schedule. For simplicity, this calculation assumes that all the
  78488. + * transfers in the periodic schedule may occur in the same (micro)frame.
  78489. + *
  78490. + * @param hcd The HCD state structure for the DWC OTG controller.
  78491. + * @param qh QH containing periodic bandwidth required.
  78492. + *
  78493. + * @return 0 if successful, negative error code otherwise.
  78494. + */
  78495. +static int check_periodic_bandwidth(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  78496. +{
  78497. + int status;
  78498. + int16_t max_claimed_usecs;
  78499. +
  78500. + status = 0;
  78501. +
  78502. + if ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) || qh->do_split) {
  78503. + /*
  78504. + * High speed mode.
  78505. + * Max periodic usecs is 80% x 125 usec = 100 usec.
  78506. + */
  78507. +
  78508. + max_claimed_usecs = 100 - qh->usecs;
  78509. + } else {
  78510. + /*
  78511. + * Full speed mode.
  78512. + * Max periodic usecs is 90% x 1000 usec = 900 usec.
  78513. + */
  78514. + max_claimed_usecs = 900 - qh->usecs;
  78515. + }
  78516. +
  78517. + if (hcd->periodic_usecs > max_claimed_usecs) {
  78518. + DWC_INFO("%s: already claimed usecs %d, required usecs %d\n", __func__, hcd->periodic_usecs, qh->usecs); //NOTICE
  78519. + status = -DWC_E_NO_SPACE;
  78520. + }
  78521. +
  78522. + return status;
  78523. +}
  78524. +
  78525. +/* microframe_schedule=0 end */
  78526. +
  78527. +/**
  78528. + * Microframe scheduler
  78529. + * track the total use in hcd->frame_usecs
  78530. + * keep each qh use in qh->frame_usecs
  78531. + * when surrendering the qh then donate the time back
  78532. + */
  78533. +const unsigned short max_uframe_usecs[]={ 100, 100, 100, 100, 100, 100, 30, 0 };
  78534. +
  78535. +/*
  78536. + * called from dwc_otg_hcd.c:dwc_otg_hcd_init
  78537. + */
  78538. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd)
  78539. +{
  78540. + int i;
  78541. + for (i=0; i<8; i++) {
  78542. + _hcd->frame_usecs[i] = max_uframe_usecs[i];
  78543. + }
  78544. + return 0;
  78545. +}
  78546. +
  78547. +static int find_single_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  78548. +{
  78549. + int i;
  78550. + unsigned short utime;
  78551. + int t_left;
  78552. + int ret;
  78553. + int done;
  78554. +
  78555. + ret = -1;
  78556. + utime = _qh->usecs;
  78557. + t_left = utime;
  78558. + i = 0;
  78559. + done = 0;
  78560. + while (done == 0) {
  78561. + /* At the start _hcd->frame_usecs[i] = max_uframe_usecs[i]; */
  78562. + if (utime <= _hcd->frame_usecs[i]) {
  78563. + _hcd->frame_usecs[i] -= utime;
  78564. + _qh->frame_usecs[i] += utime;
  78565. + t_left -= utime;
  78566. + ret = i;
  78567. + done = 1;
  78568. + return ret;
  78569. + } else {
  78570. + i++;
  78571. + if (i == 8) {
  78572. + done = 1;
  78573. + ret = -1;
  78574. + }
  78575. + }
  78576. + }
  78577. + return ret;
  78578. + }
  78579. +
  78580. +/*
  78581. + * use this for FS apps that can span multiple uframes
  78582. + */
  78583. +static int find_multi_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  78584. +{
  78585. + int i;
  78586. + int j;
  78587. + unsigned short utime;
  78588. + int t_left;
  78589. + int ret;
  78590. + int done;
  78591. + unsigned short xtime;
  78592. +
  78593. + ret = -1;
  78594. + utime = _qh->usecs;
  78595. + t_left = utime;
  78596. + i = 0;
  78597. + done = 0;
  78598. +loop:
  78599. + while (done == 0) {
  78600. + if(_hcd->frame_usecs[i] <= 0) {
  78601. + i++;
  78602. + if (i == 8) {
  78603. + done = 1;
  78604. + ret = -1;
  78605. + }
  78606. + goto loop;
  78607. + }
  78608. +
  78609. + /*
  78610. + * we need n consecutive slots
  78611. + * so use j as a start slot j plus j+1 must be enough time (for now)
  78612. + */
  78613. + xtime= _hcd->frame_usecs[i];
  78614. + for (j = i+1 ; j < 8 ; j++ ) {
  78615. + /*
  78616. + * if we add this frame remaining time to xtime we may
  78617. + * be OK, if not we need to test j for a complete frame
  78618. + */
  78619. + if ((xtime+_hcd->frame_usecs[j]) < utime) {
  78620. + if (_hcd->frame_usecs[j] < max_uframe_usecs[j]) {
  78621. + j = 8;
  78622. + ret = -1;
  78623. + continue;
  78624. + }
  78625. + }
  78626. + if (xtime >= utime) {
  78627. + ret = i;
  78628. + j = 8; /* stop loop with a good value ret */
  78629. + continue;
  78630. + }
  78631. + /* add the frame time to x time */
  78632. + xtime += _hcd->frame_usecs[j];
  78633. + /* we must have a fully available next frame or break */
  78634. + if ((xtime < utime)
  78635. + && (_hcd->frame_usecs[j] == max_uframe_usecs[j])) {
  78636. + ret = -1;
  78637. + j = 8; /* stop loop with a bad value ret */
  78638. + continue;
  78639. + }
  78640. + }
  78641. + if (ret >= 0) {
  78642. + t_left = utime;
  78643. + for (j = i; (t_left>0) && (j < 8); j++ ) {
  78644. + t_left -= _hcd->frame_usecs[j];
  78645. + if ( t_left <= 0 ) {
  78646. + _qh->frame_usecs[j] += _hcd->frame_usecs[j] + t_left;
  78647. + _hcd->frame_usecs[j]= -t_left;
  78648. + ret = i;
  78649. + done = 1;
  78650. + } else {
  78651. + _qh->frame_usecs[j] += _hcd->frame_usecs[j];
  78652. + _hcd->frame_usecs[j] = 0;
  78653. + }
  78654. + }
  78655. + } else {
  78656. + i++;
  78657. + if (i == 8) {
  78658. + done = 1;
  78659. + ret = -1;
  78660. + }
  78661. + }
  78662. + }
  78663. + return ret;
  78664. +}
  78665. +
  78666. +static int find_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  78667. +{
  78668. + int ret;
  78669. + ret = -1;
  78670. +
  78671. + if (_qh->speed == USB_SPEED_HIGH) {
  78672. + /* if this is a hs transaction we need a full frame */
  78673. + ret = find_single_uframe(_hcd, _qh);
  78674. + } else {
  78675. + /* if this is a fs transaction we may need a sequence of frames */
  78676. + ret = find_multi_uframe(_hcd, _qh);
  78677. + }
  78678. + return ret;
  78679. +}
  78680. +
  78681. +/**
  78682. + * Checks that the max transfer size allowed in a host channel is large enough
  78683. + * to handle the maximum data transfer in a single (micro)frame for a periodic
  78684. + * transfer.
  78685. + *
  78686. + * @param hcd The HCD state structure for the DWC OTG controller.
  78687. + * @param qh QH for a periodic endpoint.
  78688. + *
  78689. + * @return 0 if successful, negative error code otherwise.
  78690. + */
  78691. +static int check_max_xfer_size(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  78692. +{
  78693. + int status;
  78694. + uint32_t max_xfer_size;
  78695. + uint32_t max_channel_xfer_size;
  78696. +
  78697. + status = 0;
  78698. +
  78699. + max_xfer_size = dwc_max_packet(qh->maxp) * dwc_hb_mult(qh->maxp);
  78700. + max_channel_xfer_size = hcd->core_if->core_params->max_transfer_size;
  78701. +
  78702. + if (max_xfer_size > max_channel_xfer_size) {
  78703. + DWC_INFO("%s: Periodic xfer length %d > " "max xfer length for channel %d\n",
  78704. + __func__, max_xfer_size, max_channel_xfer_size); //NOTICE
  78705. + status = -DWC_E_NO_SPACE;
  78706. + }
  78707. +
  78708. + return status;
  78709. +}
  78710. +
  78711. +
  78712. +extern int g_next_sched_frame, g_np_count, g_np_sent;
  78713. +
  78714. +/**
  78715. + * Schedules an interrupt or isochronous transfer in the periodic schedule.
  78716. + *
  78717. + * @param hcd The HCD state structure for the DWC OTG controller.
  78718. + * @param qh QH for the periodic transfer. The QH should already contain the
  78719. + * scheduling information.
  78720. + *
  78721. + * @return 0 if successful, negative error code otherwise.
  78722. + */
  78723. +static int schedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  78724. +{
  78725. + int status = 0;
  78726. +
  78727. + if (microframe_schedule) {
  78728. + int frame;
  78729. + status = find_uframe(hcd, qh);
  78730. + frame = -1;
  78731. + if (status == 0) {
  78732. + frame = 7;
  78733. + } else {
  78734. + if (status > 0 )
  78735. + frame = status-1;
  78736. + }
  78737. +
  78738. + /* Set the new frame up */
  78739. + if (frame > -1) {
  78740. + qh->sched_frame &= ~0x7;
  78741. + qh->sched_frame |= (frame & 7);
  78742. + }
  78743. +
  78744. + if (status != -1)
  78745. + status = 0;
  78746. + } else {
  78747. + status = periodic_channel_available(hcd);
  78748. + if (status) {
  78749. + DWC_INFO("%s: No host channel available for periodic " "transfer.\n", __func__); //NOTICE
  78750. + return status;
  78751. + }
  78752. +
  78753. + status = check_periodic_bandwidth(hcd, qh);
  78754. + }
  78755. + if (status) {
  78756. + DWC_INFO("%s: Insufficient periodic bandwidth for "
  78757. + "periodic transfer.\n", __func__);
  78758. + return status;
  78759. + }
  78760. + status = check_max_xfer_size(hcd, qh);
  78761. + if (status) {
  78762. + DWC_INFO("%s: Channel max transfer size too small "
  78763. + "for periodic transfer.\n", __func__);
  78764. + return status;
  78765. + }
  78766. +
  78767. + if (hcd->core_if->dma_desc_enable) {
  78768. + /* Don't rely on SOF and start in ready schedule */
  78769. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_ready, &qh->qh_list_entry);
  78770. + }
  78771. + else {
  78772. + if(DWC_LIST_EMPTY(&hcd->periodic_sched_inactive) || dwc_frame_num_le(qh->sched_frame, g_next_sched_frame))
  78773. + {
  78774. + g_next_sched_frame = qh->sched_frame;
  78775. +
  78776. + }
  78777. + /* Always start in the inactive schedule. */
  78778. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_inactive, &qh->qh_list_entry);
  78779. + }
  78780. +
  78781. + if (!microframe_schedule) {
  78782. + /* Reserve the periodic channel. */
  78783. + hcd->periodic_channels++;
  78784. + }
  78785. +
  78786. + /* Update claimed usecs per (micro)frame. */
  78787. + hcd->periodic_usecs += qh->usecs;
  78788. +
  78789. + return status;
  78790. +}
  78791. +
  78792. +
  78793. +/**
  78794. + * This function adds a QH to either the non periodic or periodic schedule if
  78795. + * it is not already in the schedule. If the QH is already in the schedule, no
  78796. + * action is taken.
  78797. + *
  78798. + * @return 0 if successful, negative error code otherwise.
  78799. + */
  78800. +int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  78801. +{
  78802. + int status = 0;
  78803. + gintmsk_data_t intr_mask = {.d32 = 0 };
  78804. +
  78805. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  78806. + /* QH already in a schedule. */
  78807. + return status;
  78808. + }
  78809. +
  78810. + /* Add the new QH to the appropriate schedule */
  78811. + if (dwc_qh_is_non_per(qh)) {
  78812. + /* Always start in the inactive schedule. */
  78813. + DWC_LIST_INSERT_TAIL(&hcd->non_periodic_sched_inactive,
  78814. + &qh->qh_list_entry);
  78815. + g_np_count++;
  78816. + } else {
  78817. + status = schedule_periodic(hcd, qh);
  78818. + if ( !hcd->periodic_qh_count ) {
  78819. + intr_mask.b.sofintr = 1;
  78820. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  78821. + intr_mask.d32, intr_mask.d32);
  78822. + }
  78823. + hcd->periodic_qh_count++;
  78824. + }
  78825. +
  78826. + return status;
  78827. +}
  78828. +
  78829. +/**
  78830. + * Removes an interrupt or isochronous transfer from the periodic schedule.
  78831. + *
  78832. + * @param hcd The HCD state structure for the DWC OTG controller.
  78833. + * @param qh QH for the periodic transfer.
  78834. + */
  78835. +static void deschedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  78836. +{
  78837. + int i;
  78838. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  78839. +
  78840. + /* Update claimed usecs per (micro)frame. */
  78841. + hcd->periodic_usecs -= qh->usecs;
  78842. +
  78843. + if (!microframe_schedule) {
  78844. + /* Release the periodic channel reservation. */
  78845. + hcd->periodic_channels--;
  78846. + } else {
  78847. + for (i = 0; i < 8; i++) {
  78848. + hcd->frame_usecs[i] += qh->frame_usecs[i];
  78849. + qh->frame_usecs[i] = 0;
  78850. + }
  78851. + }
  78852. +}
  78853. +
  78854. +/**
  78855. + * Removes a QH from either the non-periodic or periodic schedule. Memory is
  78856. + * not freed.
  78857. + *
  78858. + * @param hcd The HCD state structure.
  78859. + * @param qh QH to remove from schedule. */
  78860. +void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  78861. +{
  78862. + gintmsk_data_t intr_mask = {.d32 = 0 };
  78863. +
  78864. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  78865. + /* QH is not in a schedule. */
  78866. + return;
  78867. + }
  78868. +
  78869. + if (dwc_qh_is_non_per(qh)) {
  78870. + if (hcd->non_periodic_qh_ptr == &qh->qh_list_entry) {
  78871. + hcd->non_periodic_qh_ptr =
  78872. + hcd->non_periodic_qh_ptr->next;
  78873. + }
  78874. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  78875. +
  78876. + // If we've removed the last non-periodic entry then there are none left!
  78877. + g_np_count = g_np_sent;
  78878. + } else {
  78879. + deschedule_periodic(hcd, qh);
  78880. + hcd->periodic_qh_count--;
  78881. + if( !hcd->periodic_qh_count ) {
  78882. + intr_mask.b.sofintr = 1;
  78883. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  78884. + intr_mask.d32, 0);
  78885. + }
  78886. + }
  78887. +}
  78888. +
  78889. +/**
  78890. + * Deactivates a QH. For non-periodic QHs, removes the QH from the active
  78891. + * non-periodic schedule. The QH is added to the inactive non-periodic
  78892. + * schedule if any QTDs are still attached to the QH.
  78893. + *
  78894. + * For periodic QHs, the QH is removed from the periodic queued schedule. If
  78895. + * there are any QTDs still attached to the QH, the QH is added to either the
  78896. + * periodic inactive schedule or the periodic ready schedule and its next
  78897. + * scheduled frame is calculated. The QH is placed in the ready schedule if
  78898. + * the scheduled frame has been reached already. Otherwise it's placed in the
  78899. + * inactive schedule. If there are no QTDs attached to the QH, the QH is
  78900. + * completely removed from the periodic schedule.
  78901. + */
  78902. +void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  78903. + int sched_next_periodic_split)
  78904. +{
  78905. + if (dwc_qh_is_non_per(qh)) {
  78906. +
  78907. + dwc_otg_qh_t *qh_tmp;
  78908. + dwc_list_link_t *qh_list;
  78909. + DWC_LIST_FOREACH(qh_list, &hcd->non_periodic_sched_inactive)
  78910. + {
  78911. + qh_tmp = DWC_LIST_ENTRY(qh_list, struct dwc_otg_qh, qh_list_entry);
  78912. + if(qh_tmp == qh)
  78913. + {
  78914. + /*
  78915. + * FIQ is being disabled because this one nevers gets a np_count increment
  78916. + * This is still not absolutely correct, but it should fix itself with
  78917. + * just an unnecessary extra interrupt
  78918. + */
  78919. + g_np_sent = g_np_count;
  78920. + }
  78921. + }
  78922. +
  78923. +
  78924. + dwc_otg_hcd_qh_remove(hcd, qh);
  78925. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  78926. + /* Add back to inactive non-periodic schedule. */
  78927. + dwc_otg_hcd_qh_add(hcd, qh);
  78928. + }
  78929. + } else {
  78930. + uint16_t frame_number = dwc_otg_hcd_get_frame_number(hcd);
  78931. +
  78932. + if (qh->do_split) {
  78933. + /* Schedule the next continuing periodic split transfer */
  78934. + if (sched_next_periodic_split) {
  78935. +
  78936. + qh->sched_frame = frame_number;
  78937. +
  78938. + if (dwc_frame_num_le(frame_number,
  78939. + dwc_frame_num_inc
  78940. + (qh->start_split_frame,
  78941. + 1))) {
  78942. + /*
  78943. + * Allow one frame to elapse after start
  78944. + * split microframe before scheduling
  78945. + * complete split, but DONT if we are
  78946. + * doing the next start split in the
  78947. + * same frame for an ISOC out.
  78948. + */
  78949. + if ((qh->ep_type != UE_ISOCHRONOUS) ||
  78950. + (qh->ep_is_in != 0)) {
  78951. + qh->sched_frame =
  78952. + dwc_frame_num_inc(qh->sched_frame, 1);
  78953. + }
  78954. + }
  78955. + } else {
  78956. + qh->sched_frame =
  78957. + dwc_frame_num_inc(qh->start_split_frame,
  78958. + qh->interval);
  78959. + if (dwc_frame_num_le
  78960. + (qh->sched_frame, frame_number)) {
  78961. + qh->sched_frame = frame_number;
  78962. + }
  78963. + qh->sched_frame |= 0x7;
  78964. + qh->start_split_frame = qh->sched_frame;
  78965. + }
  78966. + } else {
  78967. + qh->sched_frame =
  78968. + dwc_frame_num_inc(qh->sched_frame, qh->interval);
  78969. + if (dwc_frame_num_le(qh->sched_frame, frame_number)) {
  78970. + qh->sched_frame = frame_number;
  78971. + }
  78972. + }
  78973. +
  78974. + if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  78975. + dwc_otg_hcd_qh_remove(hcd, qh);
  78976. + } else {
  78977. + /*
  78978. + * Remove from periodic_sched_queued and move to
  78979. + * appropriate queue.
  78980. + */
  78981. + if ((microframe_schedule && dwc_frame_num_le(qh->sched_frame, frame_number)) ||
  78982. + (!microframe_schedule && qh->sched_frame == frame_number)) {
  78983. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  78984. + &qh->qh_list_entry);
  78985. + } else {
  78986. + if(!dwc_frame_num_le(g_next_sched_frame, qh->sched_frame))
  78987. + {
  78988. + g_next_sched_frame = qh->sched_frame;
  78989. + }
  78990. +
  78991. + DWC_LIST_MOVE_HEAD
  78992. + (&hcd->periodic_sched_inactive,
  78993. + &qh->qh_list_entry);
  78994. + }
  78995. + }
  78996. + }
  78997. +}
  78998. +
  78999. +/**
  79000. + * This function allocates and initializes a QTD.
  79001. + *
  79002. + * @param urb The URB to create a QTD from. Each URB-QTD pair will end up
  79003. + * pointing to each other so each pair should have a unique correlation.
  79004. + * @param atomic_alloc Flag to do atomic alloc if needed
  79005. + *
  79006. + * @return Returns pointer to the newly allocated QTD, or NULL on error. */
  79007. +dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  79008. +{
  79009. + dwc_otg_qtd_t *qtd;
  79010. +
  79011. + qtd = dwc_otg_hcd_qtd_alloc(atomic_alloc);
  79012. + if (qtd == NULL) {
  79013. + return NULL;
  79014. + }
  79015. +
  79016. + dwc_otg_hcd_qtd_init(qtd, urb);
  79017. + return qtd;
  79018. +}
  79019. +
  79020. +/**
  79021. + * Initializes a QTD structure.
  79022. + *
  79023. + * @param qtd The QTD to initialize.
  79024. + * @param urb The URB to use for initialization. */
  79025. +void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb)
  79026. +{
  79027. + dwc_memset(qtd, 0, sizeof(dwc_otg_qtd_t));
  79028. + qtd->urb = urb;
  79029. + if (dwc_otg_hcd_get_pipe_type(&urb->pipe_info) == UE_CONTROL) {
  79030. + /*
  79031. + * The only time the QTD data toggle is used is on the data
  79032. + * phase of control transfers. This phase always starts with
  79033. + * DATA1.
  79034. + */
  79035. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  79036. + qtd->control_phase = DWC_OTG_CONTROL_SETUP;
  79037. + }
  79038. +
  79039. + /* start split */
  79040. + qtd->complete_split = 0;
  79041. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  79042. + qtd->isoc_split_offset = 0;
  79043. + qtd->in_process = 0;
  79044. +
  79045. + /* Store the qtd ptr in the urb to reference what QTD. */
  79046. + urb->qtd = qtd;
  79047. + return;
  79048. +}
  79049. +
  79050. +/**
  79051. + * This function adds a QTD to the QTD-list of a QH. It will find the correct
  79052. + * QH to place the QTD into. If it does not find a QH, then it will create a
  79053. + * new QH. If the QH to which the QTD is added is not currently scheduled, it
  79054. + * is placed into the proper schedule based on its EP type.
  79055. + * HCD lock must be held and interrupts must be disabled on entry
  79056. + *
  79057. + * @param[in] qtd The QTD to add
  79058. + * @param[in] hcd The DWC HCD structure
  79059. + * @param[out] qh out parameter to return queue head
  79060. + * @param atomic_alloc Flag to do atomic alloc if needed
  79061. + *
  79062. + * @return 0 if successful, negative error code otherwise.
  79063. + */
  79064. +int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd,
  79065. + dwc_otg_hcd_t * hcd, dwc_otg_qh_t ** qh, int atomic_alloc)
  79066. +{
  79067. + int retval = 0;
  79068. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  79069. +
  79070. + /*
  79071. + * Get the QH which holds the QTD-list to insert to. Create QH if it
  79072. + * doesn't exist.
  79073. + */
  79074. + if (*qh == NULL) {
  79075. + *qh = dwc_otg_hcd_qh_create(hcd, urb, atomic_alloc);
  79076. + if (*qh == NULL) {
  79077. + retval = -DWC_E_NO_MEMORY;
  79078. + goto done;
  79079. + }
  79080. + }
  79081. + retval = dwc_otg_hcd_qh_add(hcd, *qh);
  79082. + if (retval == 0) {
  79083. + DWC_CIRCLEQ_INSERT_TAIL(&((*qh)->qtd_list), qtd,
  79084. + qtd_list_entry);
  79085. + qtd->qh = *qh;
  79086. + }
  79087. +done:
  79088. +
  79089. + return retval;
  79090. +}
  79091. +
  79092. +#endif /* DWC_DEVICE_ONLY */
  79093. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c
  79094. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c 1970-01-01 01:00:00.000000000 +0100
  79095. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c 2014-02-18 11:52:14.000000000 +0100
  79096. @@ -0,0 +1,113 @@
  79097. +#include "dwc_otg_regs.h"
  79098. +#include "dwc_otg_dbg.h"
  79099. +
  79100. +void dwc_debug_print_core_int_reg(gintsts_data_t gintsts, const char* function_name)
  79101. +{
  79102. + DWC_DEBUGPL(DBG_USER, "*** Debugging from within the %s function: ***\n"
  79103. + "curmode: %1i Modemismatch: %1i otgintr: %1i sofintr: %1i\n"
  79104. + "rxstsqlvl: %1i nptxfempty : %1i ginnakeff: %1i goutnakeff: %1i\n"
  79105. + "ulpickint: %1i i2cintr: %1i erlysuspend:%1i usbsuspend: %1i\n"
  79106. + "usbreset: %1i enumdone: %1i isooutdrop: %1i eopframe: %1i\n"
  79107. + "restoredone: %1i epmismatch: %1i inepint: %1i outepintr: %1i\n"
  79108. + "incomplisoin:%1i incomplisoout:%1i fetsusp: %1i resetdet: %1i\n"
  79109. + "portintr: %1i hcintr: %1i ptxfempty: %1i lpmtranrcvd:%1i\n"
  79110. + "conidstschng:%1i disconnect: %1i sessreqintr:%1i wkupintr: %1i\n",
  79111. + function_name,
  79112. + gintsts.b.curmode,
  79113. + gintsts.b.modemismatch,
  79114. + gintsts.b.otgintr,
  79115. + gintsts.b.sofintr,
  79116. + gintsts.b.rxstsqlvl,
  79117. + gintsts.b.nptxfempty,
  79118. + gintsts.b.ginnakeff,
  79119. + gintsts.b.goutnakeff,
  79120. + gintsts.b.ulpickint,
  79121. + gintsts.b.i2cintr,
  79122. + gintsts.b.erlysuspend,
  79123. + gintsts.b.usbsuspend,
  79124. + gintsts.b.usbreset,
  79125. + gintsts.b.enumdone,
  79126. + gintsts.b.isooutdrop,
  79127. + gintsts.b.eopframe,
  79128. + gintsts.b.restoredone,
  79129. + gintsts.b.epmismatch,
  79130. + gintsts.b.inepint,
  79131. + gintsts.b.outepintr,
  79132. + gintsts.b.incomplisoin,
  79133. + gintsts.b.incomplisoout,
  79134. + gintsts.b.fetsusp,
  79135. + gintsts.b.resetdet,
  79136. + gintsts.b.portintr,
  79137. + gintsts.b.hcintr,
  79138. + gintsts.b.ptxfempty,
  79139. + gintsts.b.lpmtranrcvd,
  79140. + gintsts.b.conidstschng,
  79141. + gintsts.b.disconnect,
  79142. + gintsts.b.sessreqintr,
  79143. + gintsts.b.wkupintr);
  79144. + return;
  79145. +}
  79146. +
  79147. +void dwc_debug_core_int_mask(gintmsk_data_t gintmsk, const char* function_name)
  79148. +{
  79149. + DWC_DEBUGPL(DBG_USER, "Interrupt Mask status (called from %s) :\n"
  79150. + "modemismatch: %1i otgintr: %1i sofintr: %1i rxstsqlvl: %1i\n"
  79151. + "nptxfempty: %1i ginnakeff: %1i goutnakeff: %1i ulpickint: %1i\n"
  79152. + "i2cintr: %1i erlysuspend:%1i usbsuspend: %1i usbreset: %1i\n"
  79153. + "enumdone: %1i isooutdrop: %1i eopframe: %1i restoredone: %1i\n"
  79154. + "epmismatch: %1i inepintr: %1i outepintr: %1i incomplisoin:%1i\n"
  79155. + "incomplisoout:%1i fetsusp: %1i resetdet: %1i portintr: %1i\n"
  79156. + "hcintr: %1i ptxfempty: %1i lpmtranrcvd:%1i conidstschng:%1i\n"
  79157. + "disconnect: %1i sessreqintr:%1i wkupintr: %1i\n",
  79158. + function_name,
  79159. + gintmsk.b.modemismatch,
  79160. + gintmsk.b.otgintr,
  79161. + gintmsk.b.sofintr,
  79162. + gintmsk.b.rxstsqlvl,
  79163. + gintmsk.b.nptxfempty,
  79164. + gintmsk.b.ginnakeff,
  79165. + gintmsk.b.goutnakeff,
  79166. + gintmsk.b.ulpickint,
  79167. + gintmsk.b.i2cintr,
  79168. + gintmsk.b.erlysuspend,
  79169. + gintmsk.b.usbsuspend,
  79170. + gintmsk.b.usbreset,
  79171. + gintmsk.b.enumdone,
  79172. + gintmsk.b.isooutdrop,
  79173. + gintmsk.b.eopframe,
  79174. + gintmsk.b.restoredone,
  79175. + gintmsk.b.epmismatch,
  79176. + gintmsk.b.inepintr,
  79177. + gintmsk.b.outepintr,
  79178. + gintmsk.b.incomplisoin,
  79179. + gintmsk.b.incomplisoout,
  79180. + gintmsk.b.fetsusp,
  79181. + gintmsk.b.resetdet,
  79182. + gintmsk.b.portintr,
  79183. + gintmsk.b.hcintr,
  79184. + gintmsk.b.ptxfempty,
  79185. + gintmsk.b.lpmtranrcvd,
  79186. + gintmsk.b.conidstschng,
  79187. + gintmsk.b.disconnect,
  79188. + gintmsk.b.sessreqintr,
  79189. + gintmsk.b.wkupintr);
  79190. + return;
  79191. +}
  79192. +
  79193. +void dwc_debug_otg_int(gotgint_data_t gotgint, const char* function_name)
  79194. +{
  79195. + DWC_DEBUGPL(DBG_USER, "otg int register (from %s function):\n"
  79196. + "sesenddet:%1i sesreqsucstschung:%2i hstnegsucstschng:%1i\n"
  79197. + "hstnegdet:%1i adevtoutchng: %2i debdone: %1i\n"
  79198. + "mvic: %1i\n",
  79199. + function_name,
  79200. + gotgint.b.sesenddet,
  79201. + gotgint.b.sesreqsucstschng,
  79202. + gotgint.b.hstnegsucstschng,
  79203. + gotgint.b.hstnegdet,
  79204. + gotgint.b.adevtoutchng,
  79205. + gotgint.b.debdone,
  79206. + gotgint.b.mvic);
  79207. +
  79208. + return;
  79209. +}
  79210. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h
  79211. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h 1970-01-01 01:00:00.000000000 +0100
  79212. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h 2014-02-18 11:52:14.000000000 +0100
  79213. @@ -0,0 +1,48 @@
  79214. +#ifndef __DWC_OTG_MPHI_FIX_H__
  79215. +#define __DWC_OTG_MPHI_FIX_H__
  79216. +#define FIQ_WRITE(_addr_,_data_) (*(volatile uint32_t *) (_addr_) = (_data_))
  79217. +#define FIQ_READ(_addr_) (*(volatile uint32_t *) (_addr_))
  79218. +
  79219. +typedef struct {
  79220. + volatile void* base;
  79221. + volatile void* ctrl;
  79222. + volatile void* outdda;
  79223. + volatile void* outddb;
  79224. + volatile void* intstat;
  79225. +} mphi_regs_t;
  79226. +
  79227. +void dwc_debug_print_core_int_reg(gintsts_data_t gintsts, const char* function_name);
  79228. +void dwc_debug_core_int_mask(gintsts_data_t gintmsk, const char* function_name);
  79229. +void dwc_debug_otg_int(gotgint_data_t gotgint, const char* function_name);
  79230. +
  79231. +extern gintsts_data_t gintsts_saved;
  79232. +
  79233. +#ifdef DEBUG
  79234. +#define DWC_DBG_PRINT_CORE_INT(_arg_) dwc_debug_print_core_int_reg(_arg_,__func__)
  79235. +#define DWC_DBG_PRINT_CORE_INT_MASK(_arg_) dwc_debug_core_int_mask(_arg_,__func__)
  79236. +#define DWC_DBG_PRINT_OTG_INT(_arg_) dwc_debug_otg_int(_arg_,__func__)
  79237. +
  79238. +#else
  79239. +#define DWC_DBG_PRINT_CORE_INT(_arg_)
  79240. +#define DWC_DBG_PRINT_CORE_INT_MASK(_arg_)
  79241. +#define DWC_DBG_PRINT_OTG_INT(_arg_)
  79242. +
  79243. +#endif
  79244. +
  79245. +typedef enum {
  79246. + FIQDBG_SCHED = (1 << 0),
  79247. + FIQDBG_INT = (1 << 1),
  79248. + FIQDBG_ERR = (1 << 2),
  79249. + FIQDBG_PORTHUB = (1 << 3),
  79250. +} FIQDBG_T;
  79251. +
  79252. +void _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...);
  79253. +#ifdef FIQ_DEBUG
  79254. +#define fiq_print _fiq_print
  79255. +#else
  79256. +#define fiq_print(x, y, ...)
  79257. +#endif
  79258. +
  79259. +extern bool fiq_fix_enable, nak_holdoff_enable, fiq_split_enable;
  79260. +
  79261. +#endif
  79262. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h
  79263. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 1970-01-01 01:00:00.000000000 +0100
  79264. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 2014-02-18 11:52:14.000000000 +0100
  79265. @@ -0,0 +1,188 @@
  79266. +#ifndef _DWC_OS_DEP_H_
  79267. +#define _DWC_OS_DEP_H_
  79268. +
  79269. +/**
  79270. + * @file
  79271. + *
  79272. + * This file contains OS dependent structures.
  79273. + *
  79274. + */
  79275. +
  79276. +#include <linux/kernel.h>
  79277. +#include <linux/module.h>
  79278. +#include <linux/moduleparam.h>
  79279. +#include <linux/init.h>
  79280. +#include <linux/device.h>
  79281. +#include <linux/errno.h>
  79282. +#include <linux/types.h>
  79283. +#include <linux/slab.h>
  79284. +#include <linux/list.h>
  79285. +#include <linux/interrupt.h>
  79286. +#include <linux/ctype.h>
  79287. +#include <linux/string.h>
  79288. +#include <linux/dma-mapping.h>
  79289. +#include <linux/jiffies.h>
  79290. +#include <linux/delay.h>
  79291. +#include <linux/timer.h>
  79292. +#include <linux/workqueue.h>
  79293. +#include <linux/stat.h>
  79294. +#include <linux/pci.h>
  79295. +
  79296. +#include <linux/version.h>
  79297. +
  79298. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
  79299. +# include <linux/irq.h>
  79300. +#endif
  79301. +
  79302. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  79303. +# include <linux/usb/ch9.h>
  79304. +#else
  79305. +# include <linux/usb_ch9.h>
  79306. +#endif
  79307. +
  79308. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  79309. +# include <linux/usb/gadget.h>
  79310. +#else
  79311. +# include <linux/usb_gadget.h>
  79312. +#endif
  79313. +
  79314. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
  79315. +# include <asm/irq.h>
  79316. +#endif
  79317. +
  79318. +#ifdef PCI_INTERFACE
  79319. +# include <asm/io.h>
  79320. +#endif
  79321. +
  79322. +#ifdef LM_INTERFACE
  79323. +# include <asm/unaligned.h>
  79324. +# include <asm/sizes.h>
  79325. +# include <asm/param.h>
  79326. +# include <asm/io.h>
  79327. +# if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  79328. +# include <asm/arch/hardware.h>
  79329. +# include <asm/arch/lm.h>
  79330. +# include <asm/arch/irqs.h>
  79331. +# include <asm/arch/regs-irq.h>
  79332. +# else
  79333. +/* in 2.6.31, at least, we seem to have lost the generic LM infrastructure -
  79334. + here we assume that the machine architecture provides definitions
  79335. + in its own header
  79336. +*/
  79337. +# include <mach/lm.h>
  79338. +# include <mach/hardware.h>
  79339. +# endif
  79340. +#endif
  79341. +
  79342. +#ifdef PLATFORM_INTERFACE
  79343. +#include <linux/platform_device.h>
  79344. +#include <asm/mach/map.h>
  79345. +#endif
  79346. +
  79347. +/** The OS page size */
  79348. +#define DWC_OS_PAGE_SIZE PAGE_SIZE
  79349. +
  79350. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
  79351. +typedef int gfp_t;
  79352. +#endif
  79353. +
  79354. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
  79355. +# define IRQF_SHARED SA_SHIRQ
  79356. +#endif
  79357. +
  79358. +typedef struct os_dependent {
  79359. + /** Base address returned from ioremap() */
  79360. + void *base;
  79361. +
  79362. + /** Register offset for Diagnostic API */
  79363. + uint32_t reg_offset;
  79364. +
  79365. + /** Base address for MPHI peripheral */
  79366. + void *mphi_base;
  79367. +
  79368. +#ifdef LM_INTERFACE
  79369. + struct lm_device *lmdev;
  79370. +#elif defined(PCI_INTERFACE)
  79371. + struct pci_dev *pcidev;
  79372. +
  79373. + /** Start address of a PCI region */
  79374. + resource_size_t rsrc_start;
  79375. +
  79376. + /** Length address of a PCI region */
  79377. + resource_size_t rsrc_len;
  79378. +#elif defined(PLATFORM_INTERFACE)
  79379. + struct platform_device *platformdev;
  79380. +#endif
  79381. +
  79382. +} os_dependent_t;
  79383. +
  79384. +#ifdef __cplusplus
  79385. +}
  79386. +#endif
  79387. +
  79388. +
  79389. +
  79390. +/* Type for the our device on the chosen bus */
  79391. +#if defined(LM_INTERFACE)
  79392. +typedef struct lm_device dwc_bus_dev_t;
  79393. +#elif defined(PCI_INTERFACE)
  79394. +typedef struct pci_dev dwc_bus_dev_t;
  79395. +#elif defined(PLATFORM_INTERFACE)
  79396. +typedef struct platform_device dwc_bus_dev_t;
  79397. +#endif
  79398. +
  79399. +/* Helper macro to retrieve drvdata from the device on the chosen bus */
  79400. +#if defined(LM_INTERFACE)
  79401. +#define DWC_OTG_BUSDRVDATA(_dev) lm_get_drvdata(_dev)
  79402. +#elif defined(PCI_INTERFACE)
  79403. +#define DWC_OTG_BUSDRVDATA(_dev) pci_get_drvdata(_dev)
  79404. +#elif defined(PLATFORM_INTERFACE)
  79405. +#define DWC_OTG_BUSDRVDATA(_dev) platform_get_drvdata(_dev)
  79406. +#endif
  79407. +
  79408. +/**
  79409. + * Helper macro returning the otg_device structure of a given struct device
  79410. + *
  79411. + * c.f. static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  79412. + */
  79413. +#ifdef LM_INTERFACE
  79414. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  79415. + struct lm_device *lm_dev = \
  79416. + container_of(_dev, struct lm_device, dev); \
  79417. + _var = lm_get_drvdata(lm_dev); \
  79418. + } while (0)
  79419. +
  79420. +#elif defined(PCI_INTERFACE)
  79421. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  79422. + _var = dev_get_drvdata(_dev); \
  79423. + } while (0)
  79424. +
  79425. +#elif defined(PLATFORM_INTERFACE)
  79426. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  79427. + struct platform_device *platform_dev = \
  79428. + container_of(_dev, struct platform_device, dev); \
  79429. + _var = platform_get_drvdata(platform_dev); \
  79430. + } while (0)
  79431. +#endif
  79432. +
  79433. +
  79434. +/**
  79435. + * Helper macro returning the struct dev of the given struct os_dependent
  79436. + *
  79437. + * c.f. static struct device *dwc_otg_getdev(struct os_dependent *osdep)
  79438. + */
  79439. +#ifdef LM_INTERFACE
  79440. +#define DWC_OTG_OS_GETDEV(_osdep) \
  79441. + ((_osdep).lmdev == NULL? NULL: &(_osdep).lmdev->dev)
  79442. +#elif defined(PCI_INTERFACE)
  79443. +#define DWC_OTG_OS_GETDEV(_osdep) \
  79444. + ((_osdep).pci_dev == NULL? NULL: &(_osdep).pci_dev->dev)
  79445. +#elif defined(PLATFORM_INTERFACE)
  79446. +#define DWC_OTG_OS_GETDEV(_osdep) \
  79447. + ((_osdep).platformdev == NULL? NULL: &(_osdep).platformdev->dev)
  79448. +#endif
  79449. +
  79450. +
  79451. +
  79452. +
  79453. +#endif /* _DWC_OS_DEP_H_ */
  79454. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd.c linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_pcd.c
  79455. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 1970-01-01 01:00:00.000000000 +0100
  79456. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 2014-02-18 11:52:14.000000000 +0100
  79457. @@ -0,0 +1,2708 @@
  79458. +/* ==========================================================================
  79459. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.c $
  79460. + * $Revision: #101 $
  79461. + * $Date: 2012/08/10 $
  79462. + * $Change: 2047372 $
  79463. + *
  79464. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  79465. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  79466. + * otherwise expressly agreed to in writing between Synopsys and you.
  79467. + *
  79468. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  79469. + * any End User Software License Agreement or Agreement for Licensed Product
  79470. + * with Synopsys or any supplement thereto. You are permitted to use and
  79471. + * redistribute this Software in source and binary forms, with or without
  79472. + * modification, provided that redistributions of source code must retain this
  79473. + * notice. You may not view, use, disclose, copy or distribute this file or
  79474. + * any information contained herein except pursuant to this license grant from
  79475. + * Synopsys. If you do not agree with this notice, including the disclaimer
  79476. + * below, then you are not authorized to use the Software.
  79477. + *
  79478. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  79479. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  79480. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  79481. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  79482. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  79483. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  79484. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  79485. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  79486. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  79487. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  79488. + * DAMAGE.
  79489. + * ========================================================================== */
  79490. +#ifndef DWC_HOST_ONLY
  79491. +
  79492. +/** @file
  79493. + * This file implements PCD Core. All code in this file is portable and doesn't
  79494. + * use any OS specific functions.
  79495. + * PCD Core provides Interface, defined in <code><dwc_otg_pcd_if.h></code>
  79496. + * header file, which can be used to implement OS specific PCD interface.
  79497. + *
  79498. + * An important function of the PCD is managing interrupts generated
  79499. + * by the DWC_otg controller. The implementation of the DWC_otg device
  79500. + * mode interrupt service routines is in dwc_otg_pcd_intr.c.
  79501. + *
  79502. + * @todo Add Device Mode test modes (Test J mode, Test K mode, etc).
  79503. + * @todo Does it work when the request size is greater than DEPTSIZ
  79504. + * transfer size
  79505. + *
  79506. + */
  79507. +
  79508. +#include "dwc_otg_pcd.h"
  79509. +
  79510. +#ifdef DWC_UTE_CFI
  79511. +#include "dwc_otg_cfi.h"
  79512. +
  79513. +extern int init_cfi(cfiobject_t * cfiobj);
  79514. +#endif
  79515. +
  79516. +/**
  79517. + * Choose endpoint from ep arrays using usb_ep structure.
  79518. + */
  79519. +static dwc_otg_pcd_ep_t *get_ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  79520. +{
  79521. + int i;
  79522. + if (pcd->ep0.priv == handle) {
  79523. + return &pcd->ep0;
  79524. + }
  79525. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  79526. + if (pcd->in_ep[i].priv == handle)
  79527. + return &pcd->in_ep[i];
  79528. + if (pcd->out_ep[i].priv == handle)
  79529. + return &pcd->out_ep[i];
  79530. + }
  79531. +
  79532. + return NULL;
  79533. +}
  79534. +
  79535. +/**
  79536. + * This function completes a request. It call's the request call back.
  79537. + */
  79538. +void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req,
  79539. + int32_t status)
  79540. +{
  79541. + unsigned stopped = ep->stopped;
  79542. +
  79543. + DWC_DEBUGPL(DBG_PCDV, "%s(ep %p req %p)\n", __func__, ep, req);
  79544. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  79545. +
  79546. + /* don't modify queue heads during completion callback */
  79547. + ep->stopped = 1;
  79548. + /* spin_unlock/spin_lock now done in fops->complete() */
  79549. + ep->pcd->fops->complete(ep->pcd, ep->priv, req->priv, status,
  79550. + req->actual);
  79551. +
  79552. + if (ep->pcd->request_pending > 0) {
  79553. + --ep->pcd->request_pending;
  79554. + }
  79555. +
  79556. + ep->stopped = stopped;
  79557. + DWC_FREE(req);
  79558. +}
  79559. +
  79560. +/**
  79561. + * This function terminates all the requsts in the EP request queue.
  79562. + */
  79563. +void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep)
  79564. +{
  79565. + dwc_otg_pcd_request_t *req;
  79566. +
  79567. + ep->stopped = 1;
  79568. +
  79569. + /* called with irqs blocked?? */
  79570. + while (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  79571. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  79572. + dwc_otg_request_done(ep, req, -DWC_E_SHUTDOWN);
  79573. + }
  79574. +}
  79575. +
  79576. +void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  79577. + const struct dwc_otg_pcd_function_ops *fops)
  79578. +{
  79579. + pcd->fops = fops;
  79580. +}
  79581. +
  79582. +/**
  79583. + * PCD Callback function for initializing the PCD when switching to
  79584. + * device mode.
  79585. + *
  79586. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  79587. + */
  79588. +static int32_t dwc_otg_pcd_start_cb(void *p)
  79589. +{
  79590. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  79591. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  79592. +
  79593. + /*
  79594. + * Initialized the Core for Device mode.
  79595. + */
  79596. + if (dwc_otg_is_device_mode(core_if)) {
  79597. + dwc_otg_core_dev_init(core_if);
  79598. + /* Set core_if's lock pointer to the pcd->lock */
  79599. + core_if->lock = pcd->lock;
  79600. + }
  79601. + return 1;
  79602. +}
  79603. +
  79604. +/** CFI-specific buffer allocation function for EP */
  79605. +#ifdef DWC_UTE_CFI
  79606. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  79607. + size_t buflen, int flags)
  79608. +{
  79609. + dwc_otg_pcd_ep_t *ep;
  79610. + ep = get_ep_from_handle(pcd, pep);
  79611. + if (!ep) {
  79612. + DWC_WARN("bad ep\n");
  79613. + return -DWC_E_INVALID;
  79614. + }
  79615. +
  79616. + return pcd->cfi->ops.ep_alloc_buf(pcd->cfi, pcd, ep, addr, buflen,
  79617. + flags);
  79618. +}
  79619. +#else
  79620. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  79621. + size_t buflen, int flags);
  79622. +#endif
  79623. +
  79624. +/**
  79625. + * PCD Callback function for notifying the PCD when resuming from
  79626. + * suspend.
  79627. + *
  79628. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  79629. + */
  79630. +static int32_t dwc_otg_pcd_resume_cb(void *p)
  79631. +{
  79632. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  79633. +
  79634. + if (pcd->fops->resume) {
  79635. + pcd->fops->resume(pcd);
  79636. + }
  79637. +
  79638. + /* Stop the SRP timeout timer. */
  79639. + if ((GET_CORE_IF(pcd)->core_params->phy_type != DWC_PHY_TYPE_PARAM_FS)
  79640. + || (!GET_CORE_IF(pcd)->core_params->i2c_enable)) {
  79641. + if (GET_CORE_IF(pcd)->srp_timer_started) {
  79642. + GET_CORE_IF(pcd)->srp_timer_started = 0;
  79643. + DWC_TIMER_CANCEL(GET_CORE_IF(pcd)->srp_timer);
  79644. + }
  79645. + }
  79646. + return 1;
  79647. +}
  79648. +
  79649. +/**
  79650. + * PCD Callback function for notifying the PCD device is suspended.
  79651. + *
  79652. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  79653. + */
  79654. +static int32_t dwc_otg_pcd_suspend_cb(void *p)
  79655. +{
  79656. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  79657. +
  79658. + if (pcd->fops->suspend) {
  79659. + DWC_SPINUNLOCK(pcd->lock);
  79660. + pcd->fops->suspend(pcd);
  79661. + DWC_SPINLOCK(pcd->lock);
  79662. + }
  79663. +
  79664. + return 1;
  79665. +}
  79666. +
  79667. +/**
  79668. + * PCD Callback function for stopping the PCD when switching to Host
  79669. + * mode.
  79670. + *
  79671. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  79672. + */
  79673. +static int32_t dwc_otg_pcd_stop_cb(void *p)
  79674. +{
  79675. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  79676. + extern void dwc_otg_pcd_stop(dwc_otg_pcd_t * _pcd);
  79677. +
  79678. + dwc_otg_pcd_stop(pcd);
  79679. + return 1;
  79680. +}
  79681. +
  79682. +/**
  79683. + * PCD Callback structure for handling mode switching.
  79684. + */
  79685. +static dwc_otg_cil_callbacks_t pcd_callbacks = {
  79686. + .start = dwc_otg_pcd_start_cb,
  79687. + .stop = dwc_otg_pcd_stop_cb,
  79688. + .suspend = dwc_otg_pcd_suspend_cb,
  79689. + .resume_wakeup = dwc_otg_pcd_resume_cb,
  79690. + .p = 0, /* Set at registration */
  79691. +};
  79692. +
  79693. +/**
  79694. + * This function allocates a DMA Descriptor chain for the Endpoint
  79695. + * buffer to be used for a transfer to/from the specified endpoint.
  79696. + */
  79697. +dwc_otg_dev_dma_desc_t *dwc_otg_ep_alloc_desc_chain(dwc_dma_t * dma_desc_addr,
  79698. + uint32_t count)
  79699. +{
  79700. + return DWC_DMA_ALLOC_ATOMIC(count * sizeof(dwc_otg_dev_dma_desc_t),
  79701. + dma_desc_addr);
  79702. +}
  79703. +
  79704. +/**
  79705. + * This function frees a DMA Descriptor chain that was allocated by ep_alloc_desc.
  79706. + */
  79707. +void dwc_otg_ep_free_desc_chain(dwc_otg_dev_dma_desc_t * desc_addr,
  79708. + uint32_t dma_desc_addr, uint32_t count)
  79709. +{
  79710. + DWC_DMA_FREE(count * sizeof(dwc_otg_dev_dma_desc_t), desc_addr,
  79711. + dma_desc_addr);
  79712. +}
  79713. +
  79714. +#ifdef DWC_EN_ISOC
  79715. +
  79716. +/**
  79717. + * This function initializes a descriptor chain for Isochronous transfer
  79718. + *
  79719. + * @param core_if Programming view of DWC_otg controller.
  79720. + * @param dwc_ep The EP to start the transfer on.
  79721. + *
  79722. + */
  79723. +void dwc_otg_iso_ep_start_ddma_transfer(dwc_otg_core_if_t * core_if,
  79724. + dwc_ep_t * dwc_ep)
  79725. +{
  79726. +
  79727. + dsts_data_t dsts = {.d32 = 0 };
  79728. + depctl_data_t depctl = {.d32 = 0 };
  79729. + volatile uint32_t *addr;
  79730. + int i, j;
  79731. + uint32_t len;
  79732. +
  79733. + if (dwc_ep->is_in)
  79734. + dwc_ep->desc_cnt = dwc_ep->buf_proc_intrvl / dwc_ep->bInterval;
  79735. + else
  79736. + dwc_ep->desc_cnt =
  79737. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  79738. + dwc_ep->bInterval;
  79739. +
  79740. + /** Allocate descriptors for double buffering */
  79741. + dwc_ep->iso_desc_addr =
  79742. + dwc_otg_ep_alloc_desc_chain(&dwc_ep->iso_dma_desc_addr,
  79743. + dwc_ep->desc_cnt * 2);
  79744. + if (dwc_ep->desc_addr) {
  79745. + DWC_WARN("%s, can't allocate DMA descriptor chain\n", __func__);
  79746. + return;
  79747. + }
  79748. +
  79749. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  79750. +
  79751. + /** ISO OUT EP */
  79752. + if (dwc_ep->is_in == 0) {
  79753. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  79754. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  79755. + dma_addr_t dma_ad;
  79756. + uint32_t data_per_desc;
  79757. + dwc_otg_dev_out_ep_regs_t *out_regs =
  79758. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  79759. + int offset;
  79760. +
  79761. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  79762. + dma_ad = (dma_addr_t) DWC_READ_REG32(&(out_regs->doepdma));
  79763. +
  79764. + /** Buffer 0 descriptors setup */
  79765. + dma_ad = dwc_ep->dma_addr0;
  79766. +
  79767. + sts.b_iso_out.bs = BS_HOST_READY;
  79768. + sts.b_iso_out.rxsts = 0;
  79769. + sts.b_iso_out.l = 0;
  79770. + sts.b_iso_out.sp = 0;
  79771. + sts.b_iso_out.ioc = 0;
  79772. + sts.b_iso_out.pid = 0;
  79773. + sts.b_iso_out.framenum = 0;
  79774. +
  79775. + offset = 0;
  79776. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  79777. + i += dwc_ep->pkt_per_frm) {
  79778. +
  79779. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  79780. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  79781. + if (len > dwc_ep->data_per_frame)
  79782. + data_per_desc =
  79783. + dwc_ep->data_per_frame -
  79784. + j * dwc_ep->maxpacket;
  79785. + else
  79786. + data_per_desc = dwc_ep->maxpacket;
  79787. + len = data_per_desc % 4;
  79788. + if (len)
  79789. + data_per_desc += 4 - len;
  79790. +
  79791. + sts.b_iso_out.rxbytes = data_per_desc;
  79792. + dma_desc->buf = dma_ad;
  79793. + dma_desc->status.d32 = sts.d32;
  79794. +
  79795. + offset += data_per_desc;
  79796. + dma_desc++;
  79797. + dma_ad += data_per_desc;
  79798. + }
  79799. + }
  79800. +
  79801. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  79802. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  79803. + if (len > dwc_ep->data_per_frame)
  79804. + data_per_desc =
  79805. + dwc_ep->data_per_frame -
  79806. + j * dwc_ep->maxpacket;
  79807. + else
  79808. + data_per_desc = dwc_ep->maxpacket;
  79809. + len = data_per_desc % 4;
  79810. + if (len)
  79811. + data_per_desc += 4 - len;
  79812. + sts.b_iso_out.rxbytes = data_per_desc;
  79813. + dma_desc->buf = dma_ad;
  79814. + dma_desc->status.d32 = sts.d32;
  79815. +
  79816. + offset += data_per_desc;
  79817. + dma_desc++;
  79818. + dma_ad += data_per_desc;
  79819. + }
  79820. +
  79821. + sts.b_iso_out.ioc = 1;
  79822. + len = (j + 1) * dwc_ep->maxpacket;
  79823. + if (len > dwc_ep->data_per_frame)
  79824. + data_per_desc =
  79825. + dwc_ep->data_per_frame - j * dwc_ep->maxpacket;
  79826. + else
  79827. + data_per_desc = dwc_ep->maxpacket;
  79828. + len = data_per_desc % 4;
  79829. + if (len)
  79830. + data_per_desc += 4 - len;
  79831. + sts.b_iso_out.rxbytes = data_per_desc;
  79832. +
  79833. + dma_desc->buf = dma_ad;
  79834. + dma_desc->status.d32 = sts.d32;
  79835. + dma_desc++;
  79836. +
  79837. + /** Buffer 1 descriptors setup */
  79838. + sts.b_iso_out.ioc = 0;
  79839. + dma_ad = dwc_ep->dma_addr1;
  79840. +
  79841. + offset = 0;
  79842. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  79843. + i += dwc_ep->pkt_per_frm) {
  79844. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  79845. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  79846. + if (len > dwc_ep->data_per_frame)
  79847. + data_per_desc =
  79848. + dwc_ep->data_per_frame -
  79849. + j * dwc_ep->maxpacket;
  79850. + else
  79851. + data_per_desc = dwc_ep->maxpacket;
  79852. + len = data_per_desc % 4;
  79853. + if (len)
  79854. + data_per_desc += 4 - len;
  79855. +
  79856. + data_per_desc =
  79857. + sts.b_iso_out.rxbytes = data_per_desc;
  79858. + dma_desc->buf = dma_ad;
  79859. + dma_desc->status.d32 = sts.d32;
  79860. +
  79861. + offset += data_per_desc;
  79862. + dma_desc++;
  79863. + dma_ad += data_per_desc;
  79864. + }
  79865. + }
  79866. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  79867. + data_per_desc =
  79868. + ((j + 1) * dwc_ep->maxpacket >
  79869. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  79870. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  79871. + data_per_desc +=
  79872. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  79873. + sts.b_iso_out.rxbytes = data_per_desc;
  79874. + dma_desc->buf = dma_ad;
  79875. + dma_desc->status.d32 = sts.d32;
  79876. +
  79877. + offset += data_per_desc;
  79878. + dma_desc++;
  79879. + dma_ad += data_per_desc;
  79880. + }
  79881. +
  79882. + sts.b_iso_out.ioc = 1;
  79883. + sts.b_iso_out.l = 1;
  79884. + data_per_desc =
  79885. + ((j + 1) * dwc_ep->maxpacket >
  79886. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  79887. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  79888. + data_per_desc +=
  79889. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  79890. + sts.b_iso_out.rxbytes = data_per_desc;
  79891. +
  79892. + dma_desc->buf = dma_ad;
  79893. + dma_desc->status.d32 = sts.d32;
  79894. +
  79895. + dwc_ep->next_frame = 0;
  79896. +
  79897. + /** Write dma_ad into DOEPDMA register */
  79898. + DWC_WRITE_REG32(&(out_regs->doepdma),
  79899. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  79900. +
  79901. + }
  79902. + /** ISO IN EP */
  79903. + else {
  79904. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  79905. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  79906. + dma_addr_t dma_ad;
  79907. + dwc_otg_dev_in_ep_regs_t *in_regs =
  79908. + core_if->dev_if->in_ep_regs[dwc_ep->num];
  79909. + unsigned int frmnumber;
  79910. + fifosize_data_t txfifosize, rxfifosize;
  79911. +
  79912. + txfifosize.d32 =
  79913. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[dwc_ep->num]->
  79914. + dtxfsts);
  79915. + rxfifosize.d32 =
  79916. + DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  79917. +
  79918. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  79919. +
  79920. + dma_ad = dwc_ep->dma_addr0;
  79921. +
  79922. + dsts.d32 =
  79923. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  79924. +
  79925. + sts.b_iso_in.bs = BS_HOST_READY;
  79926. + sts.b_iso_in.txsts = 0;
  79927. + sts.b_iso_in.sp =
  79928. + (dwc_ep->data_per_frame % dwc_ep->maxpacket) ? 1 : 0;
  79929. + sts.b_iso_in.ioc = 0;
  79930. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  79931. +
  79932. + frmnumber = dwc_ep->next_frame;
  79933. +
  79934. + sts.b_iso_in.framenum = frmnumber;
  79935. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  79936. + sts.b_iso_in.l = 0;
  79937. +
  79938. + /** Buffer 0 descriptors setup */
  79939. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  79940. + dma_desc->buf = dma_ad;
  79941. + dma_desc->status.d32 = sts.d32;
  79942. + dma_desc++;
  79943. +
  79944. + dma_ad += dwc_ep->data_per_frame;
  79945. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  79946. + }
  79947. +
  79948. + sts.b_iso_in.ioc = 1;
  79949. + dma_desc->buf = dma_ad;
  79950. + dma_desc->status.d32 = sts.d32;
  79951. + ++dma_desc;
  79952. +
  79953. + /** Buffer 1 descriptors setup */
  79954. + sts.b_iso_in.ioc = 0;
  79955. + dma_ad = dwc_ep->dma_addr1;
  79956. +
  79957. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  79958. + i += dwc_ep->pkt_per_frm) {
  79959. + dma_desc->buf = dma_ad;
  79960. + dma_desc->status.d32 = sts.d32;
  79961. + dma_desc++;
  79962. +
  79963. + dma_ad += dwc_ep->data_per_frame;
  79964. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  79965. +
  79966. + sts.b_iso_in.ioc = 0;
  79967. + }
  79968. + sts.b_iso_in.ioc = 1;
  79969. + sts.b_iso_in.l = 1;
  79970. +
  79971. + dma_desc->buf = dma_ad;
  79972. + dma_desc->status.d32 = sts.d32;
  79973. +
  79974. + dwc_ep->next_frame = sts.b_iso_in.framenum + dwc_ep->bInterval;
  79975. +
  79976. + /** Write dma_ad into diepdma register */
  79977. + DWC_WRITE_REG32(&(in_regs->diepdma),
  79978. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  79979. + }
  79980. + /** Enable endpoint, clear nak */
  79981. + depctl.d32 = 0;
  79982. + depctl.b.epena = 1;
  79983. + depctl.b.usbactep = 1;
  79984. + depctl.b.cnak = 1;
  79985. +
  79986. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  79987. + depctl.d32 = DWC_READ_REG32(addr);
  79988. +}
  79989. +
  79990. +/**
  79991. + * This function initializes a descriptor chain for Isochronous transfer
  79992. + *
  79993. + * @param core_if Programming view of DWC_otg controller.
  79994. + * @param ep The EP to start the transfer on.
  79995. + *
  79996. + */
  79997. +void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  79998. + dwc_ep_t * ep)
  79999. +{
  80000. + depctl_data_t depctl = {.d32 = 0 };
  80001. + volatile uint32_t *addr;
  80002. +
  80003. + if (ep->is_in) {
  80004. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  80005. + } else {
  80006. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  80007. + }
  80008. +
  80009. + if (core_if->dma_enable == 0 || core_if->dma_desc_enable != 0) {
  80010. + return;
  80011. + } else {
  80012. + deptsiz_data_t deptsiz = {.d32 = 0 };
  80013. +
  80014. + ep->xfer_len =
  80015. + ep->data_per_frame * ep->buf_proc_intrvl / ep->bInterval;
  80016. + ep->pkt_cnt =
  80017. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  80018. + ep->xfer_count = 0;
  80019. + ep->xfer_buff =
  80020. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  80021. + ep->dma_addr =
  80022. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  80023. +
  80024. + if (ep->is_in) {
  80025. + /* Program the transfer size and packet count
  80026. + * as follows: xfersize = N * maxpacket +
  80027. + * short_packet pktcnt = N + (short_packet
  80028. + * exist ? 1 : 0)
  80029. + */
  80030. + deptsiz.b.mc = ep->pkt_per_frm;
  80031. + deptsiz.b.xfersize = ep->xfer_len;
  80032. + deptsiz.b.pktcnt =
  80033. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  80034. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  80035. + dieptsiz, deptsiz.d32);
  80036. +
  80037. + /* Write the DMA register */
  80038. + DWC_WRITE_REG32(&
  80039. + (core_if->dev_if->in_ep_regs[ep->num]->
  80040. + diepdma), (uint32_t) ep->dma_addr);
  80041. +
  80042. + } else {
  80043. + deptsiz.b.pktcnt =
  80044. + (ep->xfer_len + (ep->maxpacket - 1)) /
  80045. + ep->maxpacket;
  80046. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  80047. +
  80048. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  80049. + doeptsiz, deptsiz.d32);
  80050. +
  80051. + /* Write the DMA register */
  80052. + DWC_WRITE_REG32(&
  80053. + (core_if->dev_if->out_ep_regs[ep->num]->
  80054. + doepdma), (uint32_t) ep->dma_addr);
  80055. +
  80056. + }
  80057. + /** Enable endpoint, clear nak */
  80058. + depctl.d32 = 0;
  80059. + depctl.b.epena = 1;
  80060. + depctl.b.cnak = 1;
  80061. +
  80062. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  80063. + }
  80064. +}
  80065. +
  80066. +/**
  80067. + * This function does the setup for a data transfer for an EP and
  80068. + * starts the transfer. For an IN transfer, the packets will be
  80069. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  80070. + * the packets are unloaded from the Rx FIFO in the ISR.
  80071. + *
  80072. + * @param core_if Programming view of DWC_otg controller.
  80073. + * @param ep The EP to start the transfer on.
  80074. + */
  80075. +
  80076. +static void dwc_otg_iso_ep_start_transfer(dwc_otg_core_if_t * core_if,
  80077. + dwc_ep_t * ep)
  80078. +{
  80079. + if (core_if->dma_enable) {
  80080. + if (core_if->dma_desc_enable) {
  80081. + if (ep->is_in) {
  80082. + ep->desc_cnt = ep->pkt_cnt / ep->pkt_per_frm;
  80083. + } else {
  80084. + ep->desc_cnt = ep->pkt_cnt;
  80085. + }
  80086. + dwc_otg_iso_ep_start_ddma_transfer(core_if, ep);
  80087. + } else {
  80088. + if (core_if->pti_enh_enable) {
  80089. + dwc_otg_iso_ep_start_buf_transfer(core_if, ep);
  80090. + } else {
  80091. + ep->cur_pkt_addr =
  80092. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->
  80093. + xfer_buff0;
  80094. + ep->cur_pkt_dma_addr =
  80095. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->
  80096. + dma_addr0;
  80097. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  80098. + }
  80099. + }
  80100. + } else {
  80101. + ep->cur_pkt_addr =
  80102. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  80103. + ep->cur_pkt_dma_addr =
  80104. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  80105. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  80106. + }
  80107. +}
  80108. +
  80109. +/**
  80110. + * This function stops transfer for an EP and
  80111. + * resets the ep's variables.
  80112. + *
  80113. + * @param core_if Programming view of DWC_otg controller.
  80114. + * @param ep The EP to start the transfer on.
  80115. + */
  80116. +
  80117. +void dwc_otg_iso_ep_stop_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  80118. +{
  80119. + depctl_data_t depctl = {.d32 = 0 };
  80120. + volatile uint32_t *addr;
  80121. +
  80122. + if (ep->is_in == 1) {
  80123. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  80124. + } else {
  80125. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  80126. + }
  80127. +
  80128. + /* disable the ep */
  80129. + depctl.d32 = DWC_READ_REG32(addr);
  80130. +
  80131. + depctl.b.epdis = 1;
  80132. + depctl.b.snak = 1;
  80133. +
  80134. + DWC_WRITE_REG32(addr, depctl.d32);
  80135. +
  80136. + if (core_if->dma_desc_enable &&
  80137. + ep->iso_desc_addr && ep->iso_dma_desc_addr) {
  80138. + dwc_otg_ep_free_desc_chain(ep->iso_desc_addr,
  80139. + ep->iso_dma_desc_addr,
  80140. + ep->desc_cnt * 2);
  80141. + }
  80142. +
  80143. + /* reset varibales */
  80144. + ep->dma_addr0 = 0;
  80145. + ep->dma_addr1 = 0;
  80146. + ep->xfer_buff0 = 0;
  80147. + ep->xfer_buff1 = 0;
  80148. + ep->data_per_frame = 0;
  80149. + ep->data_pattern_frame = 0;
  80150. + ep->sync_frame = 0;
  80151. + ep->buf_proc_intrvl = 0;
  80152. + ep->bInterval = 0;
  80153. + ep->proc_buf_num = 0;
  80154. + ep->pkt_per_frm = 0;
  80155. + ep->pkt_per_frm = 0;
  80156. + ep->desc_cnt = 0;
  80157. + ep->iso_desc_addr = 0;
  80158. + ep->iso_dma_desc_addr = 0;
  80159. +}
  80160. +
  80161. +int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  80162. + uint8_t * buf0, uint8_t * buf1, dwc_dma_t dma0,
  80163. + dwc_dma_t dma1, int sync_frame, int dp_frame,
  80164. + int data_per_frame, int start_frame,
  80165. + int buf_proc_intrvl, void *req_handle,
  80166. + int atomic_alloc)
  80167. +{
  80168. + dwc_otg_pcd_ep_t *ep;
  80169. + dwc_irqflags_t flags = 0;
  80170. + dwc_ep_t *dwc_ep;
  80171. + int32_t frm_data;
  80172. + dsts_data_t dsts;
  80173. + dwc_otg_core_if_t *core_if;
  80174. +
  80175. + ep = get_ep_from_handle(pcd, ep_handle);
  80176. +
  80177. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  80178. + DWC_WARN("bad ep\n");
  80179. + return -DWC_E_INVALID;
  80180. + }
  80181. +
  80182. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  80183. + core_if = GET_CORE_IF(pcd);
  80184. + dwc_ep = &ep->dwc_ep;
  80185. +
  80186. + if (ep->iso_req_handle) {
  80187. + DWC_WARN("ISO request in progress\n");
  80188. + }
  80189. +
  80190. + dwc_ep->dma_addr0 = dma0;
  80191. + dwc_ep->dma_addr1 = dma1;
  80192. +
  80193. + dwc_ep->xfer_buff0 = buf0;
  80194. + dwc_ep->xfer_buff1 = buf1;
  80195. +
  80196. + dwc_ep->data_per_frame = data_per_frame;
  80197. +
  80198. + /** @todo - pattern data support is to be implemented in the future */
  80199. + dwc_ep->data_pattern_frame = dp_frame;
  80200. + dwc_ep->sync_frame = sync_frame;
  80201. +
  80202. + dwc_ep->buf_proc_intrvl = buf_proc_intrvl;
  80203. +
  80204. + dwc_ep->bInterval = 1 << (ep->desc->bInterval - 1);
  80205. +
  80206. + dwc_ep->proc_buf_num = 0;
  80207. +
  80208. + dwc_ep->pkt_per_frm = 0;
  80209. + frm_data = ep->dwc_ep.data_per_frame;
  80210. + while (frm_data > 0) {
  80211. + dwc_ep->pkt_per_frm++;
  80212. + frm_data -= ep->dwc_ep.maxpacket;
  80213. + }
  80214. +
  80215. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  80216. +
  80217. + if (start_frame == -1) {
  80218. + dwc_ep->next_frame = dsts.b.soffn + 1;
  80219. + if (dwc_ep->bInterval != 1) {
  80220. + dwc_ep->next_frame =
  80221. + dwc_ep->next_frame + (dwc_ep->bInterval - 1 -
  80222. + dwc_ep->next_frame %
  80223. + dwc_ep->bInterval);
  80224. + }
  80225. + } else {
  80226. + dwc_ep->next_frame = start_frame;
  80227. + }
  80228. +
  80229. + if (!core_if->pti_enh_enable) {
  80230. + dwc_ep->pkt_cnt =
  80231. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  80232. + dwc_ep->bInterval;
  80233. + } else {
  80234. + dwc_ep->pkt_cnt =
  80235. + (dwc_ep->data_per_frame *
  80236. + (dwc_ep->buf_proc_intrvl / dwc_ep->bInterval)
  80237. + - 1 + dwc_ep->maxpacket) / dwc_ep->maxpacket;
  80238. + }
  80239. +
  80240. + if (core_if->dma_desc_enable) {
  80241. + dwc_ep->desc_cnt =
  80242. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  80243. + dwc_ep->bInterval;
  80244. + }
  80245. +
  80246. + if (atomic_alloc) {
  80247. + dwc_ep->pkt_info =
  80248. + DWC_ALLOC_ATOMIC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  80249. + } else {
  80250. + dwc_ep->pkt_info =
  80251. + DWC_ALLOC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  80252. + }
  80253. + if (!dwc_ep->pkt_info) {
  80254. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80255. + return -DWC_E_NO_MEMORY;
  80256. + }
  80257. + if (core_if->pti_enh_enable) {
  80258. + dwc_memset(dwc_ep->pkt_info, 0,
  80259. + sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  80260. + }
  80261. +
  80262. + dwc_ep->cur_pkt = 0;
  80263. + ep->iso_req_handle = req_handle;
  80264. +
  80265. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80266. + dwc_otg_iso_ep_start_transfer(core_if, dwc_ep);
  80267. + return 0;
  80268. +}
  80269. +
  80270. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  80271. + void *req_handle)
  80272. +{
  80273. + dwc_irqflags_t flags = 0;
  80274. + dwc_otg_pcd_ep_t *ep;
  80275. + dwc_ep_t *dwc_ep;
  80276. +
  80277. + ep = get_ep_from_handle(pcd, ep_handle);
  80278. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  80279. + DWC_WARN("bad ep\n");
  80280. + return -DWC_E_INVALID;
  80281. + }
  80282. + dwc_ep = &ep->dwc_ep;
  80283. +
  80284. + dwc_otg_iso_ep_stop_transfer(GET_CORE_IF(pcd), dwc_ep);
  80285. +
  80286. + DWC_FREE(dwc_ep->pkt_info);
  80287. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  80288. + if (ep->iso_req_handle != req_handle) {
  80289. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80290. + return -DWC_E_INVALID;
  80291. + }
  80292. +
  80293. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80294. +
  80295. + ep->iso_req_handle = 0;
  80296. + return 0;
  80297. +}
  80298. +
  80299. +/**
  80300. + * This function is used for perodical data exchnage between PCD and gadget drivers.
  80301. + * for Isochronous EPs
  80302. + *
  80303. + * - Every time a sync period completes this function is called to
  80304. + * perform data exchange between PCD and gadget
  80305. + */
  80306. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  80307. + void *req_handle)
  80308. +{
  80309. + int i;
  80310. + dwc_ep_t *dwc_ep;
  80311. +
  80312. + dwc_ep = &ep->dwc_ep;
  80313. +
  80314. + DWC_SPINUNLOCK(ep->pcd->lock);
  80315. + pcd->fops->isoc_complete(pcd, ep->priv, ep->iso_req_handle,
  80316. + dwc_ep->proc_buf_num ^ 0x1);
  80317. + DWC_SPINLOCK(ep->pcd->lock);
  80318. +
  80319. + for (i = 0; i < dwc_ep->pkt_cnt; ++i) {
  80320. + dwc_ep->pkt_info[i].status = 0;
  80321. + dwc_ep->pkt_info[i].offset = 0;
  80322. + dwc_ep->pkt_info[i].length = 0;
  80323. + }
  80324. +}
  80325. +
  80326. +int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd, void *ep_handle,
  80327. + void *iso_req_handle)
  80328. +{
  80329. + dwc_otg_pcd_ep_t *ep;
  80330. + dwc_ep_t *dwc_ep;
  80331. +
  80332. + ep = get_ep_from_handle(pcd, ep_handle);
  80333. + if (!ep->desc || ep->dwc_ep.num == 0) {
  80334. + DWC_WARN("bad ep\n");
  80335. + return -DWC_E_INVALID;
  80336. + }
  80337. + dwc_ep = &ep->dwc_ep;
  80338. +
  80339. + return dwc_ep->pkt_cnt;
  80340. +}
  80341. +
  80342. +void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd, void *ep_handle,
  80343. + void *iso_req_handle, int packet,
  80344. + int *status, int *actual, int *offset)
  80345. +{
  80346. + dwc_otg_pcd_ep_t *ep;
  80347. + dwc_ep_t *dwc_ep;
  80348. +
  80349. + ep = get_ep_from_handle(pcd, ep_handle);
  80350. + if (!ep)
  80351. + DWC_WARN("bad ep\n");
  80352. +
  80353. + dwc_ep = &ep->dwc_ep;
  80354. +
  80355. + *status = dwc_ep->pkt_info[packet].status;
  80356. + *actual = dwc_ep->pkt_info[packet].length;
  80357. + *offset = dwc_ep->pkt_info[packet].offset;
  80358. +}
  80359. +
  80360. +#endif /* DWC_EN_ISOC */
  80361. +
  80362. +static void dwc_otg_pcd_init_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * pcd_ep,
  80363. + uint32_t is_in, uint32_t ep_num)
  80364. +{
  80365. + /* Init EP structure */
  80366. + pcd_ep->desc = 0;
  80367. + pcd_ep->pcd = pcd;
  80368. + pcd_ep->stopped = 1;
  80369. + pcd_ep->queue_sof = 0;
  80370. +
  80371. + /* Init DWC ep structure */
  80372. + pcd_ep->dwc_ep.is_in = is_in;
  80373. + pcd_ep->dwc_ep.num = ep_num;
  80374. + pcd_ep->dwc_ep.active = 0;
  80375. + pcd_ep->dwc_ep.tx_fifo_num = 0;
  80376. + /* Control until ep is actvated */
  80377. + pcd_ep->dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  80378. + pcd_ep->dwc_ep.maxpacket = MAX_PACKET_SIZE;
  80379. + pcd_ep->dwc_ep.dma_addr = 0;
  80380. + pcd_ep->dwc_ep.start_xfer_buff = 0;
  80381. + pcd_ep->dwc_ep.xfer_buff = 0;
  80382. + pcd_ep->dwc_ep.xfer_len = 0;
  80383. + pcd_ep->dwc_ep.xfer_count = 0;
  80384. + pcd_ep->dwc_ep.sent_zlp = 0;
  80385. + pcd_ep->dwc_ep.total_len = 0;
  80386. + pcd_ep->dwc_ep.desc_addr = 0;
  80387. + pcd_ep->dwc_ep.dma_desc_addr = 0;
  80388. + DWC_CIRCLEQ_INIT(&pcd_ep->queue);
  80389. +}
  80390. +
  80391. +/**
  80392. + * Initialize ep's
  80393. + */
  80394. +static void dwc_otg_pcd_reinit(dwc_otg_pcd_t * pcd)
  80395. +{
  80396. + int i;
  80397. + uint32_t hwcfg1;
  80398. + dwc_otg_pcd_ep_t *ep;
  80399. + int in_ep_cntr, out_ep_cntr;
  80400. + uint32_t num_in_eps = (GET_CORE_IF(pcd))->dev_if->num_in_eps;
  80401. + uint32_t num_out_eps = (GET_CORE_IF(pcd))->dev_if->num_out_eps;
  80402. +
  80403. + /**
  80404. + * Initialize the EP0 structure.
  80405. + */
  80406. + ep = &pcd->ep0;
  80407. + dwc_otg_pcd_init_ep(pcd, ep, 0, 0);
  80408. +
  80409. + in_ep_cntr = 0;
  80410. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 3;
  80411. + for (i = 1; in_ep_cntr < num_in_eps; i++) {
  80412. + if ((hwcfg1 & 0x1) == 0) {
  80413. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[in_ep_cntr];
  80414. + in_ep_cntr++;
  80415. + /**
  80416. + * @todo NGS: Add direction to EP, based on contents
  80417. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  80418. + * sprintf(";r
  80419. + */
  80420. + dwc_otg_pcd_init_ep(pcd, ep, 1 /* IN */ , i);
  80421. +
  80422. + DWC_CIRCLEQ_INIT(&ep->queue);
  80423. + }
  80424. + hwcfg1 >>= 2;
  80425. + }
  80426. +
  80427. + out_ep_cntr = 0;
  80428. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 2;
  80429. + for (i = 1; out_ep_cntr < num_out_eps; i++) {
  80430. + if ((hwcfg1 & 0x1) == 0) {
  80431. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[out_ep_cntr];
  80432. + out_ep_cntr++;
  80433. + /**
  80434. + * @todo NGS: Add direction to EP, based on contents
  80435. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  80436. + * sprintf(";r
  80437. + */
  80438. + dwc_otg_pcd_init_ep(pcd, ep, 0 /* OUT */ , i);
  80439. + DWC_CIRCLEQ_INIT(&ep->queue);
  80440. + }
  80441. + hwcfg1 >>= 2;
  80442. + }
  80443. +
  80444. + pcd->ep0state = EP0_DISCONNECT;
  80445. + pcd->ep0.dwc_ep.maxpacket = MAX_EP0_SIZE;
  80446. + pcd->ep0.dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  80447. +}
  80448. +
  80449. +/**
  80450. + * This function is called when the SRP timer expires. The SRP should
  80451. + * complete within 6 seconds.
  80452. + */
  80453. +static void srp_timeout(void *ptr)
  80454. +{
  80455. + gotgctl_data_t gotgctl;
  80456. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  80457. + volatile uint32_t *addr = &core_if->core_global_regs->gotgctl;
  80458. +
  80459. + gotgctl.d32 = DWC_READ_REG32(addr);
  80460. +
  80461. + core_if->srp_timer_started = 0;
  80462. +
  80463. + if (core_if->adp_enable) {
  80464. + if (gotgctl.b.bsesvld == 0) {
  80465. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  80466. + DWC_PRINTF("SRP Timeout BSESSVLD = 0\n");
  80467. + /* Power off the core */
  80468. + if (core_if->power_down == 2) {
  80469. + gpwrdn.b.pwrdnswtch = 1;
  80470. + DWC_MODIFY_REG32(&core_if->
  80471. + core_global_regs->gpwrdn,
  80472. + gpwrdn.d32, 0);
  80473. + }
  80474. +
  80475. + gpwrdn.d32 = 0;
  80476. + gpwrdn.b.pmuintsel = 1;
  80477. + gpwrdn.b.pmuactv = 1;
  80478. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  80479. + gpwrdn.d32);
  80480. + dwc_otg_adp_probe_start(core_if);
  80481. + } else {
  80482. + DWC_PRINTF("SRP Timeout BSESSVLD = 1\n");
  80483. + core_if->op_state = B_PERIPHERAL;
  80484. + dwc_otg_core_init(core_if);
  80485. + dwc_otg_enable_global_interrupts(core_if);
  80486. + cil_pcd_start(core_if);
  80487. + }
  80488. + }
  80489. +
  80490. + if ((core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
  80491. + (core_if->core_params->i2c_enable)) {
  80492. + DWC_PRINTF("SRP Timeout\n");
  80493. +
  80494. + if ((core_if->srp_success) && (gotgctl.b.bsesvld)) {
  80495. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  80496. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  80497. + }
  80498. +
  80499. + /* Clear Session Request */
  80500. + gotgctl.d32 = 0;
  80501. + gotgctl.b.sesreq = 1;
  80502. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl,
  80503. + gotgctl.d32, 0);
  80504. +
  80505. + core_if->srp_success = 0;
  80506. + } else {
  80507. + __DWC_ERROR("Device not connected/responding\n");
  80508. + gotgctl.b.sesreq = 0;
  80509. + DWC_WRITE_REG32(addr, gotgctl.d32);
  80510. + }
  80511. + } else if (gotgctl.b.sesreq) {
  80512. + DWC_PRINTF("SRP Timeout\n");
  80513. +
  80514. + __DWC_ERROR("Device not connected/responding\n");
  80515. + gotgctl.b.sesreq = 0;
  80516. + DWC_WRITE_REG32(addr, gotgctl.d32);
  80517. + } else {
  80518. + DWC_PRINTF(" SRP GOTGCTL=%0x\n", gotgctl.d32);
  80519. + }
  80520. +}
  80521. +
  80522. +/**
  80523. + * Tasklet
  80524. + *
  80525. + */
  80526. +extern void start_next_request(dwc_otg_pcd_ep_t * ep);
  80527. +
  80528. +static void start_xfer_tasklet_func(void *data)
  80529. +{
  80530. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  80531. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  80532. +
  80533. + int i;
  80534. + depctl_data_t diepctl;
  80535. +
  80536. + DWC_DEBUGPL(DBG_PCDV, "Start xfer tasklet\n");
  80537. +
  80538. + diepctl.d32 = DWC_READ_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl);
  80539. +
  80540. + if (pcd->ep0.queue_sof) {
  80541. + pcd->ep0.queue_sof = 0;
  80542. + start_next_request(&pcd->ep0);
  80543. + // break;
  80544. + }
  80545. +
  80546. + for (i = 0; i < core_if->dev_if->num_in_eps; i++) {
  80547. + depctl_data_t diepctl;
  80548. + diepctl.d32 =
  80549. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  80550. +
  80551. + if (pcd->in_ep[i].queue_sof) {
  80552. + pcd->in_ep[i].queue_sof = 0;
  80553. + start_next_request(&pcd->in_ep[i]);
  80554. + // break;
  80555. + }
  80556. + }
  80557. +
  80558. + return;
  80559. +}
  80560. +
  80561. +/**
  80562. + * This function initialized the PCD portion of the driver.
  80563. + *
  80564. + */
  80565. +dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if)
  80566. +{
  80567. + dwc_otg_pcd_t *pcd = NULL;
  80568. + dwc_otg_dev_if_t *dev_if;
  80569. + int i;
  80570. +
  80571. + /*
  80572. + * Allocate PCD structure
  80573. + */
  80574. + pcd = DWC_ALLOC(sizeof(dwc_otg_pcd_t));
  80575. +
  80576. + if (pcd == NULL) {
  80577. + return NULL;
  80578. + }
  80579. +
  80580. + pcd->lock = DWC_SPINLOCK_ALLOC();
  80581. + DWC_DEBUGPL(DBG_HCDV, "Init of PCD %p given core_if %p\n",
  80582. + pcd, core_if);//GRAYG
  80583. + if (!pcd->lock) {
  80584. + DWC_ERROR("Could not allocate lock for pcd");
  80585. + DWC_FREE(pcd);
  80586. + return NULL;
  80587. + }
  80588. + /* Set core_if's lock pointer to hcd->lock */
  80589. + core_if->lock = pcd->lock;
  80590. + pcd->core_if = core_if;
  80591. +
  80592. + dev_if = core_if->dev_if;
  80593. + dev_if->isoc_ep = NULL;
  80594. +
  80595. + if (core_if->hwcfg4.b.ded_fifo_en) {
  80596. + DWC_PRINTF("Dedicated Tx FIFOs mode\n");
  80597. + } else {
  80598. + DWC_PRINTF("Shared Tx FIFO mode\n");
  80599. + }
  80600. +
  80601. + /*
  80602. + * Initialized the Core for Device mode here if there is nod ADP support.
  80603. + * Otherwise it will be done later in dwc_otg_adp_start routine.
  80604. + */
  80605. + if (dwc_otg_is_device_mode(core_if) /*&& !core_if->adp_enable*/) {
  80606. + dwc_otg_core_dev_init(core_if);
  80607. + }
  80608. +
  80609. + /*
  80610. + * Register the PCD Callbacks.
  80611. + */
  80612. + dwc_otg_cil_register_pcd_callbacks(core_if, &pcd_callbacks, pcd);
  80613. +
  80614. + /*
  80615. + * Initialize the DMA buffer for SETUP packets
  80616. + */
  80617. + if (GET_CORE_IF(pcd)->dma_enable) {
  80618. + pcd->setup_pkt =
  80619. + DWC_DMA_ALLOC(sizeof(*pcd->setup_pkt) * 5,
  80620. + &pcd->setup_pkt_dma_handle);
  80621. + if (pcd->setup_pkt == NULL) {
  80622. + DWC_FREE(pcd);
  80623. + return NULL;
  80624. + }
  80625. +
  80626. + pcd->status_buf =
  80627. + DWC_DMA_ALLOC(sizeof(uint16_t),
  80628. + &pcd->status_buf_dma_handle);
  80629. + if (pcd->status_buf == NULL) {
  80630. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  80631. + pcd->setup_pkt, pcd->setup_pkt_dma_handle);
  80632. + DWC_FREE(pcd);
  80633. + return NULL;
  80634. + }
  80635. +
  80636. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  80637. + dev_if->setup_desc_addr[0] =
  80638. + dwc_otg_ep_alloc_desc_chain
  80639. + (&dev_if->dma_setup_desc_addr[0], 1);
  80640. + dev_if->setup_desc_addr[1] =
  80641. + dwc_otg_ep_alloc_desc_chain
  80642. + (&dev_if->dma_setup_desc_addr[1], 1);
  80643. + dev_if->in_desc_addr =
  80644. + dwc_otg_ep_alloc_desc_chain
  80645. + (&dev_if->dma_in_desc_addr, 1);
  80646. + dev_if->out_desc_addr =
  80647. + dwc_otg_ep_alloc_desc_chain
  80648. + (&dev_if->dma_out_desc_addr, 1);
  80649. + pcd->data_terminated = 0;
  80650. +
  80651. + if (dev_if->setup_desc_addr[0] == 0
  80652. + || dev_if->setup_desc_addr[1] == 0
  80653. + || dev_if->in_desc_addr == 0
  80654. + || dev_if->out_desc_addr == 0) {
  80655. +
  80656. + if (dev_if->out_desc_addr)
  80657. + dwc_otg_ep_free_desc_chain
  80658. + (dev_if->out_desc_addr,
  80659. + dev_if->dma_out_desc_addr, 1);
  80660. + if (dev_if->in_desc_addr)
  80661. + dwc_otg_ep_free_desc_chain
  80662. + (dev_if->in_desc_addr,
  80663. + dev_if->dma_in_desc_addr, 1);
  80664. + if (dev_if->setup_desc_addr[1])
  80665. + dwc_otg_ep_free_desc_chain
  80666. + (dev_if->setup_desc_addr[1],
  80667. + dev_if->dma_setup_desc_addr[1], 1);
  80668. + if (dev_if->setup_desc_addr[0])
  80669. + dwc_otg_ep_free_desc_chain
  80670. + (dev_if->setup_desc_addr[0],
  80671. + dev_if->dma_setup_desc_addr[0], 1);
  80672. +
  80673. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  80674. + pcd->setup_pkt,
  80675. + pcd->setup_pkt_dma_handle);
  80676. + DWC_DMA_FREE(sizeof(*pcd->status_buf),
  80677. + pcd->status_buf,
  80678. + pcd->status_buf_dma_handle);
  80679. +
  80680. + DWC_FREE(pcd);
  80681. +
  80682. + return NULL;
  80683. + }
  80684. + }
  80685. + } else {
  80686. + pcd->setup_pkt = DWC_ALLOC(sizeof(*pcd->setup_pkt) * 5);
  80687. + if (pcd->setup_pkt == NULL) {
  80688. + DWC_FREE(pcd);
  80689. + return NULL;
  80690. + }
  80691. +
  80692. + pcd->status_buf = DWC_ALLOC(sizeof(uint16_t));
  80693. + if (pcd->status_buf == NULL) {
  80694. + DWC_FREE(pcd->setup_pkt);
  80695. + DWC_FREE(pcd);
  80696. + return NULL;
  80697. + }
  80698. + }
  80699. +
  80700. + dwc_otg_pcd_reinit(pcd);
  80701. +
  80702. + /* Allocate the cfi object for the PCD */
  80703. +#ifdef DWC_UTE_CFI
  80704. + pcd->cfi = DWC_ALLOC(sizeof(cfiobject_t));
  80705. + if (NULL == pcd->cfi)
  80706. + goto fail;
  80707. + if (init_cfi(pcd->cfi)) {
  80708. + CFI_INFO("%s: Failed to init the CFI object\n", __func__);
  80709. + goto fail;
  80710. + }
  80711. +#endif
  80712. +
  80713. + /* Initialize tasklets */
  80714. + pcd->start_xfer_tasklet = DWC_TASK_ALLOC("xfer_tasklet",
  80715. + start_xfer_tasklet_func, pcd);
  80716. + pcd->test_mode_tasklet = DWC_TASK_ALLOC("test_mode_tasklet",
  80717. + do_test_mode, pcd);
  80718. +
  80719. + /* Initialize SRP timer */
  80720. + core_if->srp_timer = DWC_TIMER_ALLOC("SRP TIMER", srp_timeout, core_if);
  80721. +
  80722. + if (core_if->core_params->dev_out_nak) {
  80723. + /**
  80724. + * Initialize xfer timeout timer. Implemented for
  80725. + * 2.93a feature "Device DDMA OUT NAK Enhancement"
  80726. + */
  80727. + for(i = 0; i < MAX_EPS_CHANNELS; i++) {
  80728. + pcd->core_if->ep_xfer_timer[i] =
  80729. + DWC_TIMER_ALLOC("ep timer", ep_xfer_timeout,
  80730. + &pcd->core_if->ep_xfer_info[i]);
  80731. + }
  80732. + }
  80733. +
  80734. + return pcd;
  80735. +#ifdef DWC_UTE_CFI
  80736. +fail:
  80737. +#endif
  80738. + if (pcd->setup_pkt)
  80739. + DWC_FREE(pcd->setup_pkt);
  80740. + if (pcd->status_buf)
  80741. + DWC_FREE(pcd->status_buf);
  80742. +#ifdef DWC_UTE_CFI
  80743. + if (pcd->cfi)
  80744. + DWC_FREE(pcd->cfi);
  80745. +#endif
  80746. + if (pcd)
  80747. + DWC_FREE(pcd);
  80748. + return NULL;
  80749. +
  80750. +}
  80751. +
  80752. +/**
  80753. + * Remove PCD specific data
  80754. + */
  80755. +void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd)
  80756. +{
  80757. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  80758. + int i;
  80759. + if (pcd->core_if->core_params->dev_out_nak) {
  80760. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  80761. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[i]);
  80762. + pcd->core_if->ep_xfer_info[i].state = 0;
  80763. + }
  80764. + }
  80765. +
  80766. + if (GET_CORE_IF(pcd)->dma_enable) {
  80767. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5, pcd->setup_pkt,
  80768. + pcd->setup_pkt_dma_handle);
  80769. + DWC_DMA_FREE(sizeof(uint16_t), pcd->status_buf,
  80770. + pcd->status_buf_dma_handle);
  80771. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  80772. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[0],
  80773. + dev_if->dma_setup_desc_addr
  80774. + [0], 1);
  80775. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[1],
  80776. + dev_if->dma_setup_desc_addr
  80777. + [1], 1);
  80778. + dwc_otg_ep_free_desc_chain(dev_if->in_desc_addr,
  80779. + dev_if->dma_in_desc_addr, 1);
  80780. + dwc_otg_ep_free_desc_chain(dev_if->out_desc_addr,
  80781. + dev_if->dma_out_desc_addr,
  80782. + 1);
  80783. + }
  80784. + } else {
  80785. + DWC_FREE(pcd->setup_pkt);
  80786. + DWC_FREE(pcd->status_buf);
  80787. + }
  80788. + DWC_SPINLOCK_FREE(pcd->lock);
  80789. + /* Set core_if's lock pointer to NULL */
  80790. + pcd->core_if->lock = NULL;
  80791. +
  80792. + DWC_TASK_FREE(pcd->start_xfer_tasklet);
  80793. + DWC_TASK_FREE(pcd->test_mode_tasklet);
  80794. + if (pcd->core_if->core_params->dev_out_nak) {
  80795. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  80796. + if (pcd->core_if->ep_xfer_timer[i]) {
  80797. + DWC_TIMER_FREE(pcd->core_if->ep_xfer_timer[i]);
  80798. + }
  80799. + }
  80800. + }
  80801. +
  80802. +/* Release the CFI object's dynamic memory */
  80803. +#ifdef DWC_UTE_CFI
  80804. + if (pcd->cfi->ops.release) {
  80805. + pcd->cfi->ops.release(pcd->cfi);
  80806. + }
  80807. +#endif
  80808. +
  80809. + DWC_FREE(pcd);
  80810. +}
  80811. +
  80812. +/**
  80813. + * Returns whether registered pcd is dual speed or not
  80814. + */
  80815. +uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd)
  80816. +{
  80817. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  80818. +
  80819. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) ||
  80820. + ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  80821. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  80822. + (core_if->core_params->ulpi_fs_ls))) {
  80823. + return 0;
  80824. + }
  80825. +
  80826. + return 1;
  80827. +}
  80828. +
  80829. +/**
  80830. + * Returns whether registered pcd is OTG capable or not
  80831. + */
  80832. +uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd)
  80833. +{
  80834. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  80835. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  80836. +
  80837. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  80838. + if (!usbcfg.b.srpcap || !usbcfg.b.hnpcap) {
  80839. + return 0;
  80840. + }
  80841. +
  80842. + return 1;
  80843. +}
  80844. +
  80845. +/**
  80846. + * This function assigns periodic Tx FIFO to an periodic EP
  80847. + * in shared Tx FIFO mode
  80848. + */
  80849. +static uint32_t assign_tx_fifo(dwc_otg_core_if_t * core_if)
  80850. +{
  80851. + uint32_t TxMsk = 1;
  80852. + int i;
  80853. +
  80854. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; ++i) {
  80855. + if ((TxMsk & core_if->tx_msk) == 0) {
  80856. + core_if->tx_msk |= TxMsk;
  80857. + return i + 1;
  80858. + }
  80859. + TxMsk <<= 1;
  80860. + }
  80861. + return 0;
  80862. +}
  80863. +
  80864. +/**
  80865. + * This function assigns periodic Tx FIFO to an periodic EP
  80866. + * in shared Tx FIFO mode
  80867. + */
  80868. +static uint32_t assign_perio_tx_fifo(dwc_otg_core_if_t * core_if)
  80869. +{
  80870. + uint32_t PerTxMsk = 1;
  80871. + int i;
  80872. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; ++i) {
  80873. + if ((PerTxMsk & core_if->p_tx_msk) == 0) {
  80874. + core_if->p_tx_msk |= PerTxMsk;
  80875. + return i + 1;
  80876. + }
  80877. + PerTxMsk <<= 1;
  80878. + }
  80879. + return 0;
  80880. +}
  80881. +
  80882. +/**
  80883. + * This function releases periodic Tx FIFO
  80884. + * in shared Tx FIFO mode
  80885. + */
  80886. +static void release_perio_tx_fifo(dwc_otg_core_if_t * core_if,
  80887. + uint32_t fifo_num)
  80888. +{
  80889. + core_if->p_tx_msk =
  80890. + (core_if->p_tx_msk & (1 << (fifo_num - 1))) ^ core_if->p_tx_msk;
  80891. +}
  80892. +
  80893. +/**
  80894. + * This function releases periodic Tx FIFO
  80895. + * in shared Tx FIFO mode
  80896. + */
  80897. +static void release_tx_fifo(dwc_otg_core_if_t * core_if, uint32_t fifo_num)
  80898. +{
  80899. + core_if->tx_msk =
  80900. + (core_if->tx_msk & (1 << (fifo_num - 1))) ^ core_if->tx_msk;
  80901. +}
  80902. +
  80903. +/**
  80904. + * This function is being called from gadget
  80905. + * to enable PCD endpoint.
  80906. + */
  80907. +int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  80908. + const uint8_t * ep_desc, void *usb_ep)
  80909. +{
  80910. + int num, dir;
  80911. + dwc_otg_pcd_ep_t *ep = NULL;
  80912. + const usb_endpoint_descriptor_t *desc;
  80913. + dwc_irqflags_t flags;
  80914. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  80915. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  80916. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  80917. + int retval = 0;
  80918. + int i, epcount;
  80919. +
  80920. + desc = (const usb_endpoint_descriptor_t *)ep_desc;
  80921. +
  80922. + if (!desc) {
  80923. + pcd->ep0.priv = usb_ep;
  80924. + ep = &pcd->ep0;
  80925. + retval = -DWC_E_INVALID;
  80926. + goto out;
  80927. + }
  80928. +
  80929. + num = UE_GET_ADDR(desc->bEndpointAddress);
  80930. + dir = UE_GET_DIR(desc->bEndpointAddress);
  80931. +
  80932. + if (!desc->wMaxPacketSize) {
  80933. + DWC_WARN("bad maxpacketsize\n");
  80934. + retval = -DWC_E_INVALID;
  80935. + goto out;
  80936. + }
  80937. +
  80938. + if (dir == UE_DIR_IN) {
  80939. + epcount = pcd->core_if->dev_if->num_in_eps;
  80940. + for (i = 0; i < epcount; i++) {
  80941. + if (num == pcd->in_ep[i].dwc_ep.num) {
  80942. + ep = &pcd->in_ep[i];
  80943. + break;
  80944. + }
  80945. + }
  80946. + } else {
  80947. + epcount = pcd->core_if->dev_if->num_out_eps;
  80948. + for (i = 0; i < epcount; i++) {
  80949. + if (num == pcd->out_ep[i].dwc_ep.num) {
  80950. + ep = &pcd->out_ep[i];
  80951. + break;
  80952. + }
  80953. + }
  80954. + }
  80955. +
  80956. + if (!ep) {
  80957. + DWC_WARN("bad address\n");
  80958. + retval = -DWC_E_INVALID;
  80959. + goto out;
  80960. + }
  80961. +
  80962. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  80963. +
  80964. + ep->desc = desc;
  80965. + ep->priv = usb_ep;
  80966. +
  80967. + /*
  80968. + * Activate the EP
  80969. + */
  80970. + ep->stopped = 0;
  80971. +
  80972. + ep->dwc_ep.is_in = (dir == UE_DIR_IN);
  80973. + ep->dwc_ep.maxpacket = UGETW(desc->wMaxPacketSize);
  80974. +
  80975. + ep->dwc_ep.type = desc->bmAttributes & UE_XFERTYPE;
  80976. +
  80977. + if (ep->dwc_ep.is_in) {
  80978. + if (!GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  80979. + ep->dwc_ep.tx_fifo_num = 0;
  80980. +
  80981. + if (ep->dwc_ep.type == UE_ISOCHRONOUS) {
  80982. + /*
  80983. + * if ISOC EP then assign a Periodic Tx FIFO.
  80984. + */
  80985. + ep->dwc_ep.tx_fifo_num =
  80986. + assign_perio_tx_fifo(GET_CORE_IF(pcd));
  80987. + }
  80988. + } else {
  80989. + /*
  80990. + * if Dedicated FIFOs mode is on then assign a Tx FIFO.
  80991. + */
  80992. + ep->dwc_ep.tx_fifo_num =
  80993. + assign_tx_fifo(GET_CORE_IF(pcd));
  80994. + }
  80995. +
  80996. + /* Calculating EP info controller base address */
  80997. + if (ep->dwc_ep.tx_fifo_num
  80998. + && GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  80999. + gdfifocfg.d32 =
  81000. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  81001. + core_global_regs->gdfifocfg);
  81002. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  81003. + dptxfsiz.d32 =
  81004. + (DWC_READ_REG32
  81005. + (&GET_CORE_IF(pcd)->core_global_regs->
  81006. + dtxfsiz[ep->dwc_ep.tx_fifo_num - 1]) >> 16);
  81007. + gdfifocfg.b.epinfobase =
  81008. + gdfifocfgbase.d32 + dptxfsiz.d32;
  81009. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  81010. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  81011. + core_global_regs->gdfifocfg,
  81012. + gdfifocfg.d32);
  81013. + }
  81014. + }
  81015. + }
  81016. + /* Set initial data PID. */
  81017. + if (ep->dwc_ep.type == UE_BULK) {
  81018. + ep->dwc_ep.data_pid_start = 0;
  81019. + }
  81020. +
  81021. + /* Alloc DMA Descriptors */
  81022. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  81023. +#ifndef DWC_UTE_PER_IO
  81024. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  81025. +#endif
  81026. + ep->dwc_ep.desc_addr =
  81027. + dwc_otg_ep_alloc_desc_chain(&ep->
  81028. + dwc_ep.dma_desc_addr,
  81029. + MAX_DMA_DESC_CNT);
  81030. + if (!ep->dwc_ep.desc_addr) {
  81031. + DWC_WARN("%s, can't allocate DMA descriptor\n",
  81032. + __func__);
  81033. + retval = -DWC_E_SHUTDOWN;
  81034. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81035. + goto out;
  81036. + }
  81037. +#ifndef DWC_UTE_PER_IO
  81038. + }
  81039. +#endif
  81040. + }
  81041. +
  81042. + DWC_DEBUGPL(DBG_PCD, "Activate %s: type=%d, mps=%d desc=%p\n",
  81043. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  81044. + ep->dwc_ep.type, ep->dwc_ep.maxpacket, ep->desc);
  81045. +#ifdef DWC_UTE_PER_IO
  81046. + ep->dwc_ep.xiso_bInterval = 1 << (ep->desc->bInterval - 1);
  81047. +#endif
  81048. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  81049. + ep->dwc_ep.bInterval = 1 << (ep->desc->bInterval - 1);
  81050. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  81051. + }
  81052. +
  81053. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  81054. +
  81055. +#ifdef DWC_UTE_CFI
  81056. + if (pcd->cfi->ops.ep_enable) {
  81057. + pcd->cfi->ops.ep_enable(pcd->cfi, pcd, ep);
  81058. + }
  81059. +#endif
  81060. +
  81061. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81062. +
  81063. +out:
  81064. + return retval;
  81065. +}
  81066. +
  81067. +/**
  81068. + * This function is being called from gadget
  81069. + * to disable PCD endpoint.
  81070. + */
  81071. +int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle)
  81072. +{
  81073. + dwc_otg_pcd_ep_t *ep;
  81074. + dwc_irqflags_t flags;
  81075. + dwc_otg_dev_dma_desc_t *desc_addr;
  81076. + dwc_dma_t dma_desc_addr;
  81077. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  81078. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  81079. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  81080. +
  81081. + ep = get_ep_from_handle(pcd, ep_handle);
  81082. +
  81083. + if (!ep || !ep->desc) {
  81084. + DWC_DEBUGPL(DBG_PCD, "bad ep address\n");
  81085. + return -DWC_E_INVALID;
  81086. + }
  81087. +
  81088. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81089. +
  81090. + dwc_otg_request_nuke(ep);
  81091. +
  81092. + dwc_otg_ep_deactivate(GET_CORE_IF(pcd), &ep->dwc_ep);
  81093. + if (pcd->core_if->core_params->dev_out_nak) {
  81094. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[ep->dwc_ep.num]);
  81095. + pcd->core_if->ep_xfer_info[ep->dwc_ep.num].state = 0;
  81096. + }
  81097. + ep->desc = NULL;
  81098. + ep->stopped = 1;
  81099. +
  81100. + gdfifocfg.d32 =
  81101. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg);
  81102. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  81103. +
  81104. + if (ep->dwc_ep.is_in) {
  81105. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  81106. + /* Flush the Tx FIFO */
  81107. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd),
  81108. + ep->dwc_ep.tx_fifo_num);
  81109. + }
  81110. + release_perio_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  81111. + release_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  81112. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  81113. + /* Decreasing EPinfo Base Addr */
  81114. + dptxfsiz.d32 =
  81115. + (DWC_READ_REG32
  81116. + (&GET_CORE_IF(pcd)->
  81117. + core_global_regs->dtxfsiz[ep->dwc_ep.tx_fifo_num-1]) >> 16);
  81118. + gdfifocfg.b.epinfobase = gdfifocfgbase.d32 - dptxfsiz.d32;
  81119. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  81120. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg,
  81121. + gdfifocfg.d32);
  81122. + }
  81123. + }
  81124. + }
  81125. +
  81126. + /* Free DMA Descriptors */
  81127. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  81128. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  81129. + desc_addr = ep->dwc_ep.desc_addr;
  81130. + dma_desc_addr = ep->dwc_ep.dma_desc_addr;
  81131. +
  81132. + /* Cannot call dma_free_coherent() with IRQs disabled */
  81133. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81134. + dwc_otg_ep_free_desc_chain(desc_addr, dma_desc_addr,
  81135. + MAX_DMA_DESC_CNT);
  81136. +
  81137. + goto out_unlocked;
  81138. + }
  81139. + }
  81140. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81141. +
  81142. +out_unlocked:
  81143. + DWC_DEBUGPL(DBG_PCD, "%d %s disabled\n", ep->dwc_ep.num,
  81144. + ep->dwc_ep.is_in ? "IN" : "OUT");
  81145. + return 0;
  81146. +
  81147. +}
  81148. +
  81149. +/******************************************************************************/
  81150. +#ifdef DWC_UTE_PER_IO
  81151. +
  81152. +/**
  81153. + * Free the request and its extended parts
  81154. + *
  81155. + */
  81156. +void dwc_pcd_xiso_ereq_free(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req)
  81157. +{
  81158. + DWC_FREE(req->ext_req.per_io_frame_descs);
  81159. + DWC_FREE(req);
  81160. +}
  81161. +
  81162. +/**
  81163. + * Start the next request in the endpoint's queue.
  81164. + *
  81165. + */
  81166. +int dwc_otg_pcd_xiso_start_next_request(dwc_otg_pcd_t * pcd,
  81167. + dwc_otg_pcd_ep_t * ep)
  81168. +{
  81169. + int i;
  81170. + dwc_otg_pcd_request_t *req = NULL;
  81171. + dwc_ep_t *dwcep = NULL;
  81172. + struct dwc_iso_xreq_port *ereq = NULL;
  81173. + struct dwc_iso_pkt_desc_port *ddesc_iso;
  81174. + uint16_t nat;
  81175. + depctl_data_t diepctl;
  81176. +
  81177. + dwcep = &ep->dwc_ep;
  81178. +
  81179. + if (dwcep->xiso_active_xfers > 0) {
  81180. +#if 0 //Disable this to decrease s/w overhead that is crucial for Isoc transfers
  81181. + DWC_WARN("There are currently active transfers for EP%d \
  81182. + (active=%d; queued=%d)", dwcep->num, dwcep->xiso_active_xfers,
  81183. + dwcep->xiso_queued_xfers);
  81184. +#endif
  81185. + return 0;
  81186. + }
  81187. +
  81188. + nat = UGETW(ep->desc->wMaxPacketSize);
  81189. + nat = (nat >> 11) & 0x03;
  81190. +
  81191. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  81192. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  81193. + ereq = &req->ext_req;
  81194. + ep->stopped = 0;
  81195. +
  81196. + /* Get the frame number */
  81197. + dwcep->xiso_frame_num =
  81198. + dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  81199. + DWC_DEBUG("FRM_NUM=%d", dwcep->xiso_frame_num);
  81200. +
  81201. + ddesc_iso = ereq->per_io_frame_descs;
  81202. +
  81203. + if (dwcep->is_in) {
  81204. + /* Setup DMA Descriptor chain for IN Isoc request */
  81205. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  81206. + //if ((i % (nat + 1)) == 0)
  81207. + if ( i > 0 )
  81208. + dwcep->xiso_frame_num =
  81209. + (dwcep->xiso_bInterval +
  81210. + dwcep->xiso_frame_num) & 0x3FFF;
  81211. + dwcep->desc_addr[i].buf =
  81212. + req->dma + ddesc_iso[i].offset;
  81213. + dwcep->desc_addr[i].status.b_iso_in.txbytes =
  81214. + ddesc_iso[i].length;
  81215. + dwcep->desc_addr[i].status.b_iso_in.framenum =
  81216. + dwcep->xiso_frame_num;
  81217. + dwcep->desc_addr[i].status.b_iso_in.bs =
  81218. + BS_HOST_READY;
  81219. + dwcep->desc_addr[i].status.b_iso_in.txsts = 0;
  81220. + dwcep->desc_addr[i].status.b_iso_in.sp =
  81221. + (ddesc_iso[i].length %
  81222. + dwcep->maxpacket) ? 1 : 0;
  81223. + dwcep->desc_addr[i].status.b_iso_in.ioc = 0;
  81224. + dwcep->desc_addr[i].status.b_iso_in.pid = nat + 1;
  81225. + dwcep->desc_addr[i].status.b_iso_in.l = 0;
  81226. +
  81227. + /* Process the last descriptor */
  81228. + if (i == ereq->pio_pkt_count - 1) {
  81229. + dwcep->desc_addr[i].status.b_iso_in.ioc = 1;
  81230. + dwcep->desc_addr[i].status.b_iso_in.l = 1;
  81231. + }
  81232. + }
  81233. +
  81234. + /* Setup and start the transfer for this endpoint */
  81235. + dwcep->xiso_active_xfers++;
  81236. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->dev_if->
  81237. + in_ep_regs[dwcep->num]->diepdma,
  81238. + dwcep->dma_desc_addr);
  81239. + diepctl.d32 = 0;
  81240. + diepctl.b.epena = 1;
  81241. + diepctl.b.cnak = 1;
  81242. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->dev_if->
  81243. + in_ep_regs[dwcep->num]->diepctl, 0,
  81244. + diepctl.d32);
  81245. + } else {
  81246. + /* Setup DMA Descriptor chain for OUT Isoc request */
  81247. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  81248. + //if ((i % (nat + 1)) == 0)
  81249. + dwcep->xiso_frame_num = (dwcep->xiso_bInterval +
  81250. + dwcep->xiso_frame_num) & 0x3FFF;
  81251. + dwcep->desc_addr[i].buf =
  81252. + req->dma + ddesc_iso[i].offset;
  81253. + dwcep->desc_addr[i].status.b_iso_out.rxbytes =
  81254. + ddesc_iso[i].length;
  81255. + dwcep->desc_addr[i].status.b_iso_out.framenum =
  81256. + dwcep->xiso_frame_num;
  81257. + dwcep->desc_addr[i].status.b_iso_out.bs =
  81258. + BS_HOST_READY;
  81259. + dwcep->desc_addr[i].status.b_iso_out.rxsts = 0;
  81260. + dwcep->desc_addr[i].status.b_iso_out.sp =
  81261. + (ddesc_iso[i].length %
  81262. + dwcep->maxpacket) ? 1 : 0;
  81263. + dwcep->desc_addr[i].status.b_iso_out.ioc = 0;
  81264. + dwcep->desc_addr[i].status.b_iso_out.pid = nat + 1;
  81265. + dwcep->desc_addr[i].status.b_iso_out.l = 0;
  81266. +
  81267. + /* Process the last descriptor */
  81268. + if (i == ereq->pio_pkt_count - 1) {
  81269. + dwcep->desc_addr[i].status.b_iso_out.ioc = 1;
  81270. + dwcep->desc_addr[i].status.b_iso_out.l = 1;
  81271. + }
  81272. + }
  81273. +
  81274. + /* Setup and start the transfer for this endpoint */
  81275. + dwcep->xiso_active_xfers++;
  81276. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  81277. + dev_if->out_ep_regs[dwcep->num]->
  81278. + doepdma, dwcep->dma_desc_addr);
  81279. + diepctl.d32 = 0;
  81280. + diepctl.b.epena = 1;
  81281. + diepctl.b.cnak = 1;
  81282. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  81283. + dev_if->out_ep_regs[dwcep->num]->
  81284. + doepctl, 0, diepctl.d32);
  81285. + }
  81286. +
  81287. + } else {
  81288. + ep->stopped = 1;
  81289. + }
  81290. +
  81291. + return 0;
  81292. +}
  81293. +
  81294. +/**
  81295. + * - Remove the request from the queue
  81296. + */
  81297. +void complete_xiso_ep(dwc_otg_pcd_ep_t * ep)
  81298. +{
  81299. + dwc_otg_pcd_request_t *req = NULL;
  81300. + struct dwc_iso_xreq_port *ereq = NULL;
  81301. + struct dwc_iso_pkt_desc_port *ddesc_iso = NULL;
  81302. + dwc_ep_t *dwcep = NULL;
  81303. + int i;
  81304. +
  81305. + //DWC_DEBUG();
  81306. + dwcep = &ep->dwc_ep;
  81307. +
  81308. + /* Get the first pending request from the queue */
  81309. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  81310. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  81311. + if (!req) {
  81312. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  81313. + return;
  81314. + }
  81315. + dwcep->xiso_active_xfers--;
  81316. + dwcep->xiso_queued_xfers--;
  81317. + /* Remove this request from the queue */
  81318. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  81319. + } else {
  81320. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  81321. + return;
  81322. + }
  81323. +
  81324. + ep->stopped = 1;
  81325. + ereq = &req->ext_req;
  81326. + ddesc_iso = ereq->per_io_frame_descs;
  81327. +
  81328. + if (dwcep->xiso_active_xfers < 0) {
  81329. + DWC_WARN("EP#%d (xiso_active_xfers=%d)", dwcep->num,
  81330. + dwcep->xiso_active_xfers);
  81331. + }
  81332. +
  81333. + /* Fill the Isoc descs of portable extended req from dma descriptors */
  81334. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  81335. + if (dwcep->is_in) { /* IN endpoints */
  81336. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  81337. + dwcep->desc_addr[i].status.b_iso_in.txbytes;
  81338. + ddesc_iso[i].status =
  81339. + dwcep->desc_addr[i].status.b_iso_in.txsts;
  81340. + } else { /* OUT endpoints */
  81341. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  81342. + dwcep->desc_addr[i].status.b_iso_out.rxbytes;
  81343. + ddesc_iso[i].status =
  81344. + dwcep->desc_addr[i].status.b_iso_out.rxsts;
  81345. + }
  81346. + }
  81347. +
  81348. + DWC_SPINUNLOCK(ep->pcd->lock);
  81349. +
  81350. + /* Call the completion function in the non-portable logic */
  81351. + ep->pcd->fops->xisoc_complete(ep->pcd, ep->priv, req->priv, 0,
  81352. + &req->ext_req);
  81353. +
  81354. + DWC_SPINLOCK(ep->pcd->lock);
  81355. +
  81356. + /* Free the request - specific freeing needed for extended request object */
  81357. + dwc_pcd_xiso_ereq_free(ep, req);
  81358. +
  81359. + /* Start the next request */
  81360. + dwc_otg_pcd_xiso_start_next_request(ep->pcd, ep);
  81361. +
  81362. + return;
  81363. +}
  81364. +
  81365. +/**
  81366. + * Create and initialize the Isoc pkt descriptors of the extended request.
  81367. + *
  81368. + */
  81369. +static int dwc_otg_pcd_xiso_create_pkt_descs(dwc_otg_pcd_request_t * req,
  81370. + void *ereq_nonport,
  81371. + int atomic_alloc)
  81372. +{
  81373. + struct dwc_iso_xreq_port *ereq = NULL;
  81374. + struct dwc_iso_xreq_port *req_mapped = NULL;
  81375. + struct dwc_iso_pkt_desc_port *ipds = NULL; /* To be created in this function */
  81376. + uint32_t pkt_count;
  81377. + int i;
  81378. +
  81379. + ereq = &req->ext_req;
  81380. + req_mapped = (struct dwc_iso_xreq_port *)ereq_nonport;
  81381. + pkt_count = req_mapped->pio_pkt_count;
  81382. +
  81383. + /* Create the isoc descs */
  81384. + if (atomic_alloc) {
  81385. + ipds = DWC_ALLOC_ATOMIC(sizeof(*ipds) * pkt_count);
  81386. + } else {
  81387. + ipds = DWC_ALLOC(sizeof(*ipds) * pkt_count);
  81388. + }
  81389. +
  81390. + if (!ipds) {
  81391. + DWC_ERROR("Failed to allocate isoc descriptors");
  81392. + return -DWC_E_NO_MEMORY;
  81393. + }
  81394. +
  81395. + /* Initialize the extended request fields */
  81396. + ereq->per_io_frame_descs = ipds;
  81397. + ereq->error_count = 0;
  81398. + ereq->pio_alloc_pkt_count = pkt_count;
  81399. + ereq->pio_pkt_count = pkt_count;
  81400. + ereq->tr_sub_flags = req_mapped->tr_sub_flags;
  81401. +
  81402. + /* Init the Isoc descriptors */
  81403. + for (i = 0; i < pkt_count; i++) {
  81404. + ipds[i].length = req_mapped->per_io_frame_descs[i].length;
  81405. + ipds[i].offset = req_mapped->per_io_frame_descs[i].offset;
  81406. + ipds[i].status = req_mapped->per_io_frame_descs[i].status; /* 0 */
  81407. + ipds[i].actual_length =
  81408. + req_mapped->per_io_frame_descs[i].actual_length;
  81409. + }
  81410. +
  81411. + return 0;
  81412. +}
  81413. +
  81414. +static void prn_ext_request(struct dwc_iso_xreq_port *ereq)
  81415. +{
  81416. + struct dwc_iso_pkt_desc_port *xfd = NULL;
  81417. + int i;
  81418. +
  81419. + DWC_DEBUG("per_io_frame_descs=%p", ereq->per_io_frame_descs);
  81420. + DWC_DEBUG("tr_sub_flags=%d", ereq->tr_sub_flags);
  81421. + DWC_DEBUG("error_count=%d", ereq->error_count);
  81422. + DWC_DEBUG("pio_alloc_pkt_count=%d", ereq->pio_alloc_pkt_count);
  81423. + DWC_DEBUG("pio_pkt_count=%d", ereq->pio_pkt_count);
  81424. + DWC_DEBUG("res=%d", ereq->res);
  81425. +
  81426. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  81427. + xfd = &ereq->per_io_frame_descs[0];
  81428. + DWC_DEBUG("FD #%d", i);
  81429. +
  81430. + DWC_DEBUG("xfd->actual_length=%d", xfd->actual_length);
  81431. + DWC_DEBUG("xfd->length=%d", xfd->length);
  81432. + DWC_DEBUG("xfd->offset=%d", xfd->offset);
  81433. + DWC_DEBUG("xfd->status=%d", xfd->status);
  81434. + }
  81435. +}
  81436. +
  81437. +/**
  81438. + *
  81439. + */
  81440. +int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  81441. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  81442. + int zero, void *req_handle, int atomic_alloc,
  81443. + void *ereq_nonport)
  81444. +{
  81445. + dwc_otg_pcd_request_t *req = NULL;
  81446. + dwc_otg_pcd_ep_t *ep;
  81447. + dwc_irqflags_t flags;
  81448. + int res;
  81449. +
  81450. + ep = get_ep_from_handle(pcd, ep_handle);
  81451. + if (!ep) {
  81452. + DWC_WARN("bad ep\n");
  81453. + return -DWC_E_INVALID;
  81454. + }
  81455. +
  81456. + /* We support this extension only for DDMA mode */
  81457. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  81458. + if (!GET_CORE_IF(pcd)->dma_desc_enable)
  81459. + return -DWC_E_INVALID;
  81460. +
  81461. + /* Create a dwc_otg_pcd_request_t object */
  81462. + if (atomic_alloc) {
  81463. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  81464. + } else {
  81465. + req = DWC_ALLOC(sizeof(*req));
  81466. + }
  81467. +
  81468. + if (!req) {
  81469. + return -DWC_E_NO_MEMORY;
  81470. + }
  81471. +
  81472. + /* Create the Isoc descs for this request which shall be the exact match
  81473. + * of the structure sent to us from the non-portable logic */
  81474. + res =
  81475. + dwc_otg_pcd_xiso_create_pkt_descs(req, ereq_nonport, atomic_alloc);
  81476. + if (res) {
  81477. + DWC_WARN("Failed to init the Isoc descriptors");
  81478. + DWC_FREE(req);
  81479. + return res;
  81480. + }
  81481. +
  81482. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81483. +
  81484. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  81485. + req->buf = buf;
  81486. + req->dma = dma_buf;
  81487. + req->length = buflen;
  81488. + req->sent_zlp = zero;
  81489. + req->priv = req_handle;
  81490. +
  81491. + //DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81492. + ep->dwc_ep.dma_addr = dma_buf;
  81493. + ep->dwc_ep.start_xfer_buff = buf;
  81494. + ep->dwc_ep.xfer_buff = buf;
  81495. + ep->dwc_ep.xfer_len = 0;
  81496. + ep->dwc_ep.xfer_count = 0;
  81497. + ep->dwc_ep.sent_zlp = 0;
  81498. + ep->dwc_ep.total_len = buflen;
  81499. +
  81500. + /* Add this request to the tail */
  81501. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  81502. + ep->dwc_ep.xiso_queued_xfers++;
  81503. +
  81504. +//DWC_DEBUG("CP_0");
  81505. +//DWC_DEBUG("req->ext_req.tr_sub_flags=%d", req->ext_req.tr_sub_flags);
  81506. +//prn_ext_request((struct dwc_iso_xreq_port *) ereq_nonport);
  81507. +//prn_ext_request(&req->ext_req);
  81508. +
  81509. + //DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81510. +
  81511. + /* If the req->status == ASAP then check if there is any active transfer
  81512. + * for this endpoint. If no active transfers, then get the first entry
  81513. + * from the queue and start that transfer
  81514. + */
  81515. + if (req->ext_req.tr_sub_flags == DWC_EREQ_TF_ASAP) {
  81516. + res = dwc_otg_pcd_xiso_start_next_request(pcd, ep);
  81517. + if (res) {
  81518. + DWC_WARN("Failed to start the next Isoc transfer");
  81519. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81520. + DWC_FREE(req);
  81521. + return res;
  81522. + }
  81523. + }
  81524. +
  81525. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81526. + return 0;
  81527. +}
  81528. +
  81529. +#endif
  81530. +/* END ifdef DWC_UTE_PER_IO ***************************************************/
  81531. +int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  81532. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  81533. + int zero, void *req_handle, int atomic_alloc)
  81534. +{
  81535. + dwc_irqflags_t flags;
  81536. + dwc_otg_pcd_request_t *req;
  81537. + dwc_otg_pcd_ep_t *ep;
  81538. + uint32_t max_transfer;
  81539. +
  81540. + ep = get_ep_from_handle(pcd, ep_handle);
  81541. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  81542. + DWC_WARN("bad ep\n");
  81543. + return -DWC_E_INVALID;
  81544. + }
  81545. +
  81546. + if (atomic_alloc) {
  81547. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  81548. + } else {
  81549. + req = DWC_ALLOC(sizeof(*req));
  81550. + }
  81551. +
  81552. + if (!req) {
  81553. + return -DWC_E_NO_MEMORY;
  81554. + }
  81555. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  81556. + if (!GET_CORE_IF(pcd)->core_params->opt) {
  81557. + if (ep->dwc_ep.num != 0) {
  81558. + DWC_ERROR("queue req %p, len %d buf %p\n",
  81559. + req_handle, buflen, buf);
  81560. + }
  81561. + }
  81562. +
  81563. + req->buf = buf;
  81564. + req->dma = dma_buf;
  81565. + req->length = buflen;
  81566. + req->sent_zlp = zero;
  81567. + req->priv = req_handle;
  81568. + req->dw_align_buf = NULL;
  81569. + if ((dma_buf & 0x3) && GET_CORE_IF(pcd)->dma_enable
  81570. + && !GET_CORE_IF(pcd)->dma_desc_enable)
  81571. + req->dw_align_buf = DWC_DMA_ALLOC(buflen,
  81572. + &req->dw_align_buf_dma);
  81573. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81574. +
  81575. + /*
  81576. + * After adding request to the queue for IN ISOC wait for In Token Received
  81577. + * when TX FIFO is empty interrupt and for OUT ISOC wait for OUT Token
  81578. + * Received when EP is disabled interrupt to obtain starting microframe
  81579. + * (odd/even) start transfer
  81580. + */
  81581. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  81582. + if (req != 0) {
  81583. + depctl_data_t depctl = {.d32 =
  81584. + DWC_READ_REG32(&pcd->core_if->dev_if->
  81585. + in_ep_regs[ep->dwc_ep.num]->
  81586. + diepctl) };
  81587. + ++pcd->request_pending;
  81588. +
  81589. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  81590. + if (ep->dwc_ep.is_in) {
  81591. + depctl.b.cnak = 1;
  81592. + DWC_WRITE_REG32(&pcd->core_if->dev_if->
  81593. + in_ep_regs[ep->dwc_ep.num]->
  81594. + diepctl, depctl.d32);
  81595. + }
  81596. +
  81597. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81598. + }
  81599. + return 0;
  81600. + }
  81601. +
  81602. + /*
  81603. + * For EP0 IN without premature status, zlp is required?
  81604. + */
  81605. + if (ep->dwc_ep.num == 0 && ep->dwc_ep.is_in) {
  81606. + DWC_DEBUGPL(DBG_PCDV, "%d-OUT ZLP\n", ep->dwc_ep.num);
  81607. + //_req->zero = 1;
  81608. + }
  81609. +
  81610. + /* Start the transfer */
  81611. + if (DWC_CIRCLEQ_EMPTY(&ep->queue) && !ep->stopped) {
  81612. + /* EP0 Transfer? */
  81613. + if (ep->dwc_ep.num == 0) {
  81614. + switch (pcd->ep0state) {
  81615. + case EP0_IN_DATA_PHASE:
  81616. + DWC_DEBUGPL(DBG_PCD,
  81617. + "%s ep0: EP0_IN_DATA_PHASE\n",
  81618. + __func__);
  81619. + break;
  81620. +
  81621. + case EP0_OUT_DATA_PHASE:
  81622. + DWC_DEBUGPL(DBG_PCD,
  81623. + "%s ep0: EP0_OUT_DATA_PHASE\n",
  81624. + __func__);
  81625. + if (pcd->request_config) {
  81626. + /* Complete STATUS PHASE */
  81627. + ep->dwc_ep.is_in = 1;
  81628. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  81629. + }
  81630. + break;
  81631. +
  81632. + case EP0_IN_STATUS_PHASE:
  81633. + DWC_DEBUGPL(DBG_PCD,
  81634. + "%s ep0: EP0_IN_STATUS_PHASE\n",
  81635. + __func__);
  81636. + break;
  81637. +
  81638. + default:
  81639. + DWC_DEBUGPL(DBG_ANY, "ep0: odd state %d\n",
  81640. + pcd->ep0state);
  81641. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81642. + return -DWC_E_SHUTDOWN;
  81643. + }
  81644. +
  81645. + ep->dwc_ep.dma_addr = dma_buf;
  81646. + ep->dwc_ep.start_xfer_buff = buf;
  81647. + ep->dwc_ep.xfer_buff = buf;
  81648. + ep->dwc_ep.xfer_len = buflen;
  81649. + ep->dwc_ep.xfer_count = 0;
  81650. + ep->dwc_ep.sent_zlp = 0;
  81651. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  81652. +
  81653. + if (zero) {
  81654. + if ((ep->dwc_ep.xfer_len %
  81655. + ep->dwc_ep.maxpacket == 0)
  81656. + && (ep->dwc_ep.xfer_len != 0)) {
  81657. + ep->dwc_ep.sent_zlp = 1;
  81658. + }
  81659. +
  81660. + }
  81661. +
  81662. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  81663. + &ep->dwc_ep);
  81664. + } // non-ep0 endpoints
  81665. + else {
  81666. +#ifdef DWC_UTE_CFI
  81667. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  81668. + /* store the request length */
  81669. + ep->dwc_ep.cfi_req_len = buflen;
  81670. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd,
  81671. + ep, req);
  81672. + } else {
  81673. +#endif
  81674. + max_transfer =
  81675. + GET_CORE_IF(ep->pcd)->core_params->
  81676. + max_transfer_size;
  81677. +
  81678. + /* Setup and start the Transfer */
  81679. + if (req->dw_align_buf){
  81680. + if (ep->dwc_ep.is_in)
  81681. + dwc_memcpy(req->dw_align_buf,
  81682. + buf, buflen);
  81683. + ep->dwc_ep.dma_addr =
  81684. + req->dw_align_buf_dma;
  81685. + ep->dwc_ep.start_xfer_buff =
  81686. + req->dw_align_buf;
  81687. + ep->dwc_ep.xfer_buff =
  81688. + req->dw_align_buf;
  81689. + } else {
  81690. + ep->dwc_ep.dma_addr = dma_buf;
  81691. + ep->dwc_ep.start_xfer_buff = buf;
  81692. + ep->dwc_ep.xfer_buff = buf;
  81693. + }
  81694. + ep->dwc_ep.xfer_len = 0;
  81695. + ep->dwc_ep.xfer_count = 0;
  81696. + ep->dwc_ep.sent_zlp = 0;
  81697. + ep->dwc_ep.total_len = buflen;
  81698. +
  81699. + ep->dwc_ep.maxxfer = max_transfer;
  81700. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  81701. + uint32_t out_max_xfer =
  81702. + DDMA_MAX_TRANSFER_SIZE -
  81703. + (DDMA_MAX_TRANSFER_SIZE % 4);
  81704. + if (ep->dwc_ep.is_in) {
  81705. + if (ep->dwc_ep.maxxfer >
  81706. + DDMA_MAX_TRANSFER_SIZE) {
  81707. + ep->dwc_ep.maxxfer =
  81708. + DDMA_MAX_TRANSFER_SIZE;
  81709. + }
  81710. + } else {
  81711. + if (ep->dwc_ep.maxxfer >
  81712. + out_max_xfer) {
  81713. + ep->dwc_ep.maxxfer =
  81714. + out_max_xfer;
  81715. + }
  81716. + }
  81717. + }
  81718. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  81719. + ep->dwc_ep.maxxfer -=
  81720. + (ep->dwc_ep.maxxfer %
  81721. + ep->dwc_ep.maxpacket);
  81722. + }
  81723. +
  81724. + if (zero) {
  81725. + if ((ep->dwc_ep.total_len %
  81726. + ep->dwc_ep.maxpacket == 0)
  81727. + && (ep->dwc_ep.total_len != 0)) {
  81728. + ep->dwc_ep.sent_zlp = 1;
  81729. + }
  81730. + }
  81731. +#ifdef DWC_UTE_CFI
  81732. + }
  81733. +#endif
  81734. + dwc_otg_ep_start_transfer(GET_CORE_IF(pcd),
  81735. + &ep->dwc_ep);
  81736. + }
  81737. + }
  81738. +
  81739. + if (req != 0) {
  81740. + ++pcd->request_pending;
  81741. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  81742. + if (ep->dwc_ep.is_in && ep->stopped
  81743. + && !(GET_CORE_IF(pcd)->dma_enable)) {
  81744. + /** @todo NGS Create a function for this. */
  81745. + diepmsk_data_t diepmsk = {.d32 = 0 };
  81746. + diepmsk.b.intktxfemp = 1;
  81747. + if (GET_CORE_IF(pcd)->multiproc_int_enable) {
  81748. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  81749. + dev_if->dev_global_regs->diepeachintmsk
  81750. + [ep->dwc_ep.num], 0,
  81751. + diepmsk.d32);
  81752. + } else {
  81753. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  81754. + dev_if->dev_global_regs->
  81755. + diepmsk, 0, diepmsk.d32);
  81756. + }
  81757. +
  81758. + }
  81759. + }
  81760. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81761. +
  81762. + return 0;
  81763. +}
  81764. +
  81765. +int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  81766. + void *req_handle)
  81767. +{
  81768. + dwc_irqflags_t flags;
  81769. + dwc_otg_pcd_request_t *req;
  81770. + dwc_otg_pcd_ep_t *ep;
  81771. +
  81772. + ep = get_ep_from_handle(pcd, ep_handle);
  81773. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  81774. + DWC_WARN("bad argument\n");
  81775. + return -DWC_E_INVALID;
  81776. + }
  81777. +
  81778. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81779. +
  81780. + /* make sure it's actually queued on this endpoint */
  81781. + DWC_CIRCLEQ_FOREACH(req, &ep->queue, queue_entry) {
  81782. + if (req->priv == (void *)req_handle) {
  81783. + break;
  81784. + }
  81785. + }
  81786. +
  81787. + if (req->priv != (void *)req_handle) {
  81788. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81789. + return -DWC_E_INVALID;
  81790. + }
  81791. +
  81792. + if (!DWC_CIRCLEQ_EMPTY_ENTRY(req, queue_entry)) {
  81793. + dwc_otg_request_done(ep, req, -DWC_E_RESTART);
  81794. + } else {
  81795. + req = NULL;
  81796. + }
  81797. +
  81798. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81799. +
  81800. + return req ? 0 : -DWC_E_SHUTDOWN;
  81801. +
  81802. +}
  81803. +
  81804. +/**
  81805. + * dwc_otg_pcd_ep_wedge - sets the halt feature and ignores clear requests
  81806. + *
  81807. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  81808. + * requests. If the gadget driver clears the halt status, it will
  81809. + * automatically unwedge the endpoint.
  81810. + *
  81811. + * Returns zero on success, else negative DWC error code.
  81812. + */
  81813. +int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle)
  81814. +{
  81815. + dwc_otg_pcd_ep_t *ep;
  81816. + dwc_irqflags_t flags;
  81817. + int retval = 0;
  81818. +
  81819. + ep = get_ep_from_handle(pcd, ep_handle);
  81820. +
  81821. + if ((!ep->desc && ep != &pcd->ep0) ||
  81822. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  81823. + DWC_WARN("%s, bad ep\n", __func__);
  81824. + return -DWC_E_INVALID;
  81825. + }
  81826. +
  81827. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81828. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  81829. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  81830. + ep->dwc_ep.is_in ? "IN" : "OUT");
  81831. + retval = -DWC_E_AGAIN;
  81832. + } else {
  81833. + /* This code needs to be reviewed */
  81834. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  81835. + dtxfsts_data_t txstatus;
  81836. + fifosize_data_t txfifosize;
  81837. +
  81838. + txfifosize.d32 =
  81839. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  81840. + core_global_regs->dtxfsiz[ep->dwc_ep.
  81841. + tx_fifo_num]);
  81842. + txstatus.d32 =
  81843. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  81844. + dev_if->in_ep_regs[ep->dwc_ep.num]->
  81845. + dtxfsts);
  81846. +
  81847. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  81848. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  81849. + retval = -DWC_E_AGAIN;
  81850. + } else {
  81851. + if (ep->dwc_ep.num == 0) {
  81852. + pcd->ep0state = EP0_STALL;
  81853. + }
  81854. +
  81855. + ep->stopped = 1;
  81856. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  81857. + &ep->dwc_ep);
  81858. + }
  81859. + } else {
  81860. + if (ep->dwc_ep.num == 0) {
  81861. + pcd->ep0state = EP0_STALL;
  81862. + }
  81863. +
  81864. + ep->stopped = 1;
  81865. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  81866. + }
  81867. + }
  81868. +
  81869. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81870. +
  81871. + return retval;
  81872. +}
  81873. +
  81874. +int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value)
  81875. +{
  81876. + dwc_otg_pcd_ep_t *ep;
  81877. + dwc_irqflags_t flags;
  81878. + int retval = 0;
  81879. +
  81880. + ep = get_ep_from_handle(pcd, ep_handle);
  81881. +
  81882. + if (!ep || (!ep->desc && ep != &pcd->ep0) ||
  81883. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  81884. + DWC_WARN("%s, bad ep\n", __func__);
  81885. + return -DWC_E_INVALID;
  81886. + }
  81887. +
  81888. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81889. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  81890. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  81891. + ep->dwc_ep.is_in ? "IN" : "OUT");
  81892. + retval = -DWC_E_AGAIN;
  81893. + } else if (value == 0) {
  81894. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  81895. + } else if (value == 1) {
  81896. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  81897. + dtxfsts_data_t txstatus;
  81898. + fifosize_data_t txfifosize;
  81899. +
  81900. + txfifosize.d32 =
  81901. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->
  81902. + dtxfsiz[ep->dwc_ep.tx_fifo_num]);
  81903. + txstatus.d32 =
  81904. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  81905. + in_ep_regs[ep->dwc_ep.num]->dtxfsts);
  81906. +
  81907. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  81908. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  81909. + retval = -DWC_E_AGAIN;
  81910. + } else {
  81911. + if (ep->dwc_ep.num == 0) {
  81912. + pcd->ep0state = EP0_STALL;
  81913. + }
  81914. +
  81915. + ep->stopped = 1;
  81916. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  81917. + &ep->dwc_ep);
  81918. + }
  81919. + } else {
  81920. + if (ep->dwc_ep.num == 0) {
  81921. + pcd->ep0state = EP0_STALL;
  81922. + }
  81923. +
  81924. + ep->stopped = 1;
  81925. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  81926. + }
  81927. + } else if (value == 2) {
  81928. + ep->dwc_ep.stall_clear_flag = 0;
  81929. + } else if (value == 3) {
  81930. + ep->dwc_ep.stall_clear_flag = 1;
  81931. + }
  81932. +
  81933. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81934. +
  81935. + return retval;
  81936. +}
  81937. +
  81938. +/**
  81939. + * This function initiates remote wakeup of the host from suspend state.
  81940. + */
  81941. +void dwc_otg_pcd_rem_wkup_from_suspend(dwc_otg_pcd_t * pcd, int set)
  81942. +{
  81943. + dctl_data_t dctl = { 0 };
  81944. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  81945. + dsts_data_t dsts;
  81946. +
  81947. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  81948. + if (!dsts.b.suspsts) {
  81949. + DWC_WARN("Remote wakeup while is not in suspend state\n");
  81950. + }
  81951. + /* Check if DEVICE_REMOTE_WAKEUP feature enabled */
  81952. + if (pcd->remote_wakeup_enable) {
  81953. + if (set) {
  81954. +
  81955. + if (core_if->adp_enable) {
  81956. + gpwrdn_data_t gpwrdn;
  81957. +
  81958. + dwc_otg_adp_probe_stop(core_if);
  81959. +
  81960. + /* Mask SRP detected interrupt from Power Down Logic */
  81961. + gpwrdn.d32 = 0;
  81962. + gpwrdn.b.srp_det_msk = 1;
  81963. + DWC_MODIFY_REG32(&core_if->
  81964. + core_global_regs->gpwrdn,
  81965. + gpwrdn.d32, 0);
  81966. +
  81967. + /* Disable Power Down Logic */
  81968. + gpwrdn.d32 = 0;
  81969. + gpwrdn.b.pmuactv = 1;
  81970. + DWC_MODIFY_REG32(&core_if->
  81971. + core_global_regs->gpwrdn,
  81972. + gpwrdn.d32, 0);
  81973. +
  81974. + /*
  81975. + * Initialize the Core for Device mode.
  81976. + */
  81977. + core_if->op_state = B_PERIPHERAL;
  81978. + dwc_otg_core_init(core_if);
  81979. + dwc_otg_enable_global_interrupts(core_if);
  81980. + cil_pcd_start(core_if);
  81981. +
  81982. + dwc_otg_initiate_srp(core_if);
  81983. + }
  81984. +
  81985. + dctl.b.rmtwkupsig = 1;
  81986. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  81987. + dctl, 0, dctl.d32);
  81988. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  81989. +
  81990. + dwc_mdelay(2);
  81991. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  81992. + dctl, dctl.d32, 0);
  81993. + DWC_DEBUGPL(DBG_PCD, "Clear Remote Wakeup\n");
  81994. + }
  81995. + } else {
  81996. + DWC_DEBUGPL(DBG_PCD, "Remote Wakeup is disabled\n");
  81997. + }
  81998. +}
  81999. +
  82000. +#ifdef CONFIG_USB_DWC_OTG_LPM
  82001. +/**
  82002. + * This function initiates remote wakeup of the host from L1 sleep state.
  82003. + */
  82004. +void dwc_otg_pcd_rem_wkup_from_sleep(dwc_otg_pcd_t * pcd, int set)
  82005. +{
  82006. + glpmcfg_data_t lpmcfg;
  82007. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82008. +
  82009. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  82010. +
  82011. + /* Check if we are in L1 state */
  82012. + if (!lpmcfg.b.prt_sleep_sts) {
  82013. + DWC_DEBUGPL(DBG_PCD, "Device is not in sleep state\n");
  82014. + return;
  82015. + }
  82016. +
  82017. + /* Check if host allows remote wakeup */
  82018. + if (!lpmcfg.b.rem_wkup_en) {
  82019. + DWC_DEBUGPL(DBG_PCD, "Host does not allow remote wakeup\n");
  82020. + return;
  82021. + }
  82022. +
  82023. + /* Check if Resume OK */
  82024. + if (!lpmcfg.b.sleep_state_resumeok) {
  82025. + DWC_DEBUGPL(DBG_PCD, "Sleep state resume is not OK\n");
  82026. + return;
  82027. + }
  82028. +
  82029. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  82030. + lpmcfg.b.en_utmi_sleep = 0;
  82031. + lpmcfg.b.hird_thres &= (~(1 << 4));
  82032. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  82033. +
  82034. + if (set) {
  82035. + dctl_data_t dctl = {.d32 = 0 };
  82036. + dctl.b.rmtwkupsig = 1;
  82037. + /* Set RmtWkUpSig bit to start remote wakup signaling.
  82038. + * Hardware will automatically clear this bit.
  82039. + */
  82040. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl,
  82041. + 0, dctl.d32);
  82042. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  82043. + }
  82044. +
  82045. +}
  82046. +#endif
  82047. +
  82048. +/**
  82049. + * Performs remote wakeup.
  82050. + */
  82051. +void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set)
  82052. +{
  82053. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82054. + dwc_irqflags_t flags;
  82055. + if (dwc_otg_is_device_mode(core_if)) {
  82056. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  82057. +#ifdef CONFIG_USB_DWC_OTG_LPM
  82058. + if (core_if->lx_state == DWC_OTG_L1) {
  82059. + dwc_otg_pcd_rem_wkup_from_sleep(pcd, set);
  82060. + } else {
  82061. +#endif
  82062. + dwc_otg_pcd_rem_wkup_from_suspend(pcd, set);
  82063. +#ifdef CONFIG_USB_DWC_OTG_LPM
  82064. + }
  82065. +#endif
  82066. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82067. + }
  82068. + return;
  82069. +}
  82070. +
  82071. +void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs)
  82072. +{
  82073. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82074. + dctl_data_t dctl = { 0 };
  82075. +
  82076. + if (dwc_otg_is_device_mode(core_if)) {
  82077. + dctl.b.sftdiscon = 1;
  82078. + DWC_PRINTF("Soft disconnect for %d useconds\n",no_of_usecs);
  82079. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  82080. + dwc_udelay(no_of_usecs);
  82081. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32,0);
  82082. +
  82083. + } else{
  82084. + DWC_PRINTF("NOT SUPPORTED IN HOST MODE\n");
  82085. + }
  82086. + return;
  82087. +
  82088. +}
  82089. +
  82090. +int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd)
  82091. +{
  82092. + dsts_data_t dsts;
  82093. + gotgctl_data_t gotgctl;
  82094. +
  82095. + /*
  82096. + * This function starts the Protocol if no session is in progress. If
  82097. + * a session is already in progress, but the device is suspended,
  82098. + * remote wakeup signaling is started.
  82099. + */
  82100. +
  82101. + /* Check if valid session */
  82102. + gotgctl.d32 =
  82103. + DWC_READ_REG32(&(GET_CORE_IF(pcd)->core_global_regs->gotgctl));
  82104. + if (gotgctl.b.bsesvld) {
  82105. + /* Check if suspend state */
  82106. + dsts.d32 =
  82107. + DWC_READ_REG32(&
  82108. + (GET_CORE_IF(pcd)->dev_if->
  82109. + dev_global_regs->dsts));
  82110. + if (dsts.b.suspsts) {
  82111. + dwc_otg_pcd_remote_wakeup(pcd, 1);
  82112. + }
  82113. + } else {
  82114. + dwc_otg_pcd_initiate_srp(pcd);
  82115. + }
  82116. +
  82117. + return 0;
  82118. +
  82119. +}
  82120. +
  82121. +/**
  82122. + * Start the SRP timer to detect when the SRP does not complete within
  82123. + * 6 seconds.
  82124. + *
  82125. + * @param pcd the pcd structure.
  82126. + */
  82127. +void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd)
  82128. +{
  82129. + dwc_irqflags_t flags;
  82130. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  82131. + dwc_otg_initiate_srp(GET_CORE_IF(pcd));
  82132. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82133. +}
  82134. +
  82135. +int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd)
  82136. +{
  82137. + return dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  82138. +}
  82139. +
  82140. +int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd)
  82141. +{
  82142. + return GET_CORE_IF(pcd)->core_params->lpm_enable;
  82143. +}
  82144. +
  82145. +uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd)
  82146. +{
  82147. + return pcd->b_hnp_enable;
  82148. +}
  82149. +
  82150. +uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd)
  82151. +{
  82152. + return pcd->a_hnp_support;
  82153. +}
  82154. +
  82155. +uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd)
  82156. +{
  82157. + return pcd->a_alt_hnp_support;
  82158. +}
  82159. +
  82160. +int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd)
  82161. +{
  82162. + return pcd->remote_wakeup_enable;
  82163. +}
  82164. +
  82165. +#endif /* DWC_HOST_ONLY */
  82166. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd.h linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_pcd.h
  82167. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 1970-01-01 01:00:00.000000000 +0100
  82168. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 2014-02-18 11:52:14.000000000 +0100
  82169. @@ -0,0 +1,266 @@
  82170. +/* ==========================================================================
  82171. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.h $
  82172. + * $Revision: #48 $
  82173. + * $Date: 2012/08/10 $
  82174. + * $Change: 2047372 $
  82175. + *
  82176. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  82177. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  82178. + * otherwise expressly agreed to in writing between Synopsys and you.
  82179. + *
  82180. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  82181. + * any End User Software License Agreement or Agreement for Licensed Product
  82182. + * with Synopsys or any supplement thereto. You are permitted to use and
  82183. + * redistribute this Software in source and binary forms, with or without
  82184. + * modification, provided that redistributions of source code must retain this
  82185. + * notice. You may not view, use, disclose, copy or distribute this file or
  82186. + * any information contained herein except pursuant to this license grant from
  82187. + * Synopsys. If you do not agree with this notice, including the disclaimer
  82188. + * below, then you are not authorized to use the Software.
  82189. + *
  82190. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  82191. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  82192. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  82193. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  82194. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  82195. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  82196. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  82197. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  82198. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  82199. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  82200. + * DAMAGE.
  82201. + * ========================================================================== */
  82202. +#ifndef DWC_HOST_ONLY
  82203. +#if !defined(__DWC_PCD_H__)
  82204. +#define __DWC_PCD_H__
  82205. +
  82206. +#include "dwc_otg_os_dep.h"
  82207. +#include "usb.h"
  82208. +#include "dwc_otg_cil.h"
  82209. +#include "dwc_otg_pcd_if.h"
  82210. +struct cfiobject;
  82211. +
  82212. +/**
  82213. + * @file
  82214. + *
  82215. + * This file contains the structures, constants, and interfaces for
  82216. + * the Perpherial Contoller Driver (PCD).
  82217. + *
  82218. + * The Peripheral Controller Driver (PCD) for Linux will implement the
  82219. + * Gadget API, so that the existing Gadget drivers can be used. For
  82220. + * the Mass Storage Function driver the File-backed USB Storage Gadget
  82221. + * (FBS) driver will be used. The FBS driver supports the
  82222. + * Control-Bulk (CB), Control-Bulk-Interrupt (CBI), and Bulk-Only
  82223. + * transports.
  82224. + *
  82225. + */
  82226. +
  82227. +/** Invalid DMA Address */
  82228. +#define DWC_DMA_ADDR_INVALID (~(dwc_dma_t)0)
  82229. +
  82230. +/** Max Transfer size for any EP */
  82231. +#define DDMA_MAX_TRANSFER_SIZE 65535
  82232. +
  82233. +/**
  82234. + * Get the pointer to the core_if from the pcd pointer.
  82235. + */
  82236. +#define GET_CORE_IF( _pcd ) (_pcd->core_if)
  82237. +
  82238. +/**
  82239. + * States of EP0.
  82240. + */
  82241. +typedef enum ep0_state {
  82242. + EP0_DISCONNECT, /* no host */
  82243. + EP0_IDLE,
  82244. + EP0_IN_DATA_PHASE,
  82245. + EP0_OUT_DATA_PHASE,
  82246. + EP0_IN_STATUS_PHASE,
  82247. + EP0_OUT_STATUS_PHASE,
  82248. + EP0_STALL,
  82249. +} ep0state_e;
  82250. +
  82251. +/** Fordward declaration.*/
  82252. +struct dwc_otg_pcd;
  82253. +
  82254. +/** DWC_otg iso request structure.
  82255. + *
  82256. + */
  82257. +typedef struct usb_iso_request dwc_otg_pcd_iso_request_t;
  82258. +
  82259. +#ifdef DWC_UTE_PER_IO
  82260. +
  82261. +/**
  82262. + * This shall be the exact analogy of the same type structure defined in the
  82263. + * usb_gadget.h. Each descriptor contains
  82264. + */
  82265. +struct dwc_iso_pkt_desc_port {
  82266. + uint32_t offset;
  82267. + uint32_t length; /* expected length */
  82268. + uint32_t actual_length;
  82269. + uint32_t status;
  82270. +};
  82271. +
  82272. +struct dwc_iso_xreq_port {
  82273. + /** transfer/submission flag */
  82274. + uint32_t tr_sub_flags;
  82275. + /** Start the request ASAP */
  82276. +#define DWC_EREQ_TF_ASAP 0x00000002
  82277. + /** Just enqueue the request w/o initiating a transfer */
  82278. +#define DWC_EREQ_TF_ENQUEUE 0x00000004
  82279. +
  82280. + /**
  82281. + * count of ISO packets attached to this request - shall
  82282. + * not exceed the pio_alloc_pkt_count
  82283. + */
  82284. + uint32_t pio_pkt_count;
  82285. + /** count of ISO packets allocated for this request */
  82286. + uint32_t pio_alloc_pkt_count;
  82287. + /** number of ISO packet errors */
  82288. + uint32_t error_count;
  82289. + /** reserved for future extension */
  82290. + uint32_t res;
  82291. + /** Will be allocated and freed in the UTE gadget and based on the CFC value */
  82292. + struct dwc_iso_pkt_desc_port *per_io_frame_descs;
  82293. +};
  82294. +#endif
  82295. +/** DWC_otg request structure.
  82296. + * This structure is a list of requests.
  82297. + */
  82298. +typedef struct dwc_otg_pcd_request {
  82299. + void *priv;
  82300. + void *buf;
  82301. + dwc_dma_t dma;
  82302. + uint32_t length;
  82303. + uint32_t actual;
  82304. + unsigned sent_zlp:1;
  82305. + /**
  82306. + * Used instead of original buffer if
  82307. + * it(physical address) is not dword-aligned.
  82308. + **/
  82309. + uint8_t *dw_align_buf;
  82310. + dwc_dma_t dw_align_buf_dma;
  82311. +
  82312. + DWC_CIRCLEQ_ENTRY(dwc_otg_pcd_request) queue_entry;
  82313. +#ifdef DWC_UTE_PER_IO
  82314. + struct dwc_iso_xreq_port ext_req;
  82315. + //void *priv_ereq_nport; /* */
  82316. +#endif
  82317. +} dwc_otg_pcd_request_t;
  82318. +
  82319. +DWC_CIRCLEQ_HEAD(req_list, dwc_otg_pcd_request);
  82320. +
  82321. +/** PCD EP structure.
  82322. + * This structure describes an EP, there is an array of EPs in the PCD
  82323. + * structure.
  82324. + */
  82325. +typedef struct dwc_otg_pcd_ep {
  82326. + /** USB EP Descriptor */
  82327. + const usb_endpoint_descriptor_t *desc;
  82328. +
  82329. + /** queue of dwc_otg_pcd_requests. */
  82330. + struct req_list queue;
  82331. + unsigned stopped:1;
  82332. + unsigned disabling:1;
  82333. + unsigned dma:1;
  82334. + unsigned queue_sof:1;
  82335. +
  82336. +#ifdef DWC_EN_ISOC
  82337. + /** ISOC req handle passed */
  82338. + void *iso_req_handle;
  82339. +#endif //_EN_ISOC_
  82340. +
  82341. + /** DWC_otg ep data. */
  82342. + dwc_ep_t dwc_ep;
  82343. +
  82344. + /** Pointer to PCD */
  82345. + struct dwc_otg_pcd *pcd;
  82346. +
  82347. + void *priv;
  82348. +} dwc_otg_pcd_ep_t;
  82349. +
  82350. +/** DWC_otg PCD Structure.
  82351. + * This structure encapsulates the data for the dwc_otg PCD.
  82352. + */
  82353. +struct dwc_otg_pcd {
  82354. + const struct dwc_otg_pcd_function_ops *fops;
  82355. + /** The DWC otg device pointer */
  82356. + struct dwc_otg_device *otg_dev;
  82357. + /** Core Interface */
  82358. + dwc_otg_core_if_t *core_if;
  82359. + /** State of EP0 */
  82360. + ep0state_e ep0state;
  82361. + /** EP0 Request is pending */
  82362. + unsigned ep0_pending:1;
  82363. + /** Indicates when SET CONFIGURATION Request is in process */
  82364. + unsigned request_config:1;
  82365. + /** The state of the Remote Wakeup Enable. */
  82366. + unsigned remote_wakeup_enable:1;
  82367. + /** The state of the B-Device HNP Enable. */
  82368. + unsigned b_hnp_enable:1;
  82369. + /** The state of A-Device HNP Support. */
  82370. + unsigned a_hnp_support:1;
  82371. + /** The state of the A-Device Alt HNP support. */
  82372. + unsigned a_alt_hnp_support:1;
  82373. + /** Count of pending Requests */
  82374. + unsigned request_pending;
  82375. +
  82376. + /** SETUP packet for EP0
  82377. + * This structure is allocated as a DMA buffer on PCD initialization
  82378. + * with enough space for up to 3 setup packets.
  82379. + */
  82380. + union {
  82381. + usb_device_request_t req;
  82382. + uint32_t d32[2];
  82383. + } *setup_pkt;
  82384. +
  82385. + dwc_dma_t setup_pkt_dma_handle;
  82386. +
  82387. + /* Additional buffer and flag for CTRL_WR premature case */
  82388. + uint8_t *backup_buf;
  82389. + unsigned data_terminated;
  82390. +
  82391. + /** 2-byte dma buffer used to return status from GET_STATUS */
  82392. + uint16_t *status_buf;
  82393. + dwc_dma_t status_buf_dma_handle;
  82394. +
  82395. + /** EP0 */
  82396. + dwc_otg_pcd_ep_t ep0;
  82397. +
  82398. + /** Array of IN EPs. */
  82399. + dwc_otg_pcd_ep_t in_ep[MAX_EPS_CHANNELS - 1];
  82400. + /** Array of OUT EPs. */
  82401. + dwc_otg_pcd_ep_t out_ep[MAX_EPS_CHANNELS - 1];
  82402. + /** number of valid EPs in the above array. */
  82403. +// unsigned num_eps : 4;
  82404. + dwc_spinlock_t *lock;
  82405. +
  82406. + /** Tasklet to defer starting of TEST mode transmissions until
  82407. + * Status Phase has been completed.
  82408. + */
  82409. + dwc_tasklet_t *test_mode_tasklet;
  82410. +
  82411. + /** Tasklet to delay starting of xfer in DMA mode */
  82412. + dwc_tasklet_t *start_xfer_tasklet;
  82413. +
  82414. + /** The test mode to enter when the tasklet is executed. */
  82415. + unsigned test_mode;
  82416. + /** The cfi_api structure that implements most of the CFI API
  82417. + * and OTG specific core configuration functionality
  82418. + */
  82419. +#ifdef DWC_UTE_CFI
  82420. + struct cfiobject *cfi;
  82421. +#endif
  82422. +
  82423. +};
  82424. +
  82425. +//FIXME this functions should be static, and this prototypes should be removed
  82426. +extern void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep);
  82427. +extern void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep,
  82428. + dwc_otg_pcd_request_t * req, int32_t status);
  82429. +
  82430. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  82431. + void *req_handle);
  82432. +
  82433. +extern void do_test_mode(void *data);
  82434. +#endif
  82435. +#endif /* DWC_HOST_ONLY */
  82436. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h
  82437. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 1970-01-01 01:00:00.000000000 +0100
  82438. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 2014-02-18 11:52:14.000000000 +0100
  82439. @@ -0,0 +1,360 @@
  82440. +/* ==========================================================================
  82441. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_if.h $
  82442. + * $Revision: #11 $
  82443. + * $Date: 2011/10/26 $
  82444. + * $Change: 1873028 $
  82445. + *
  82446. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  82447. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  82448. + * otherwise expressly agreed to in writing between Synopsys and you.
  82449. + *
  82450. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  82451. + * any End User Software License Agreement or Agreement for Licensed Product
  82452. + * with Synopsys or any supplement thereto. You are permitted to use and
  82453. + * redistribute this Software in source and binary forms, with or without
  82454. + * modification, provided that redistributions of source code must retain this
  82455. + * notice. You may not view, use, disclose, copy or distribute this file or
  82456. + * any information contained herein except pursuant to this license grant from
  82457. + * Synopsys. If you do not agree with this notice, including the disclaimer
  82458. + * below, then you are not authorized to use the Software.
  82459. + *
  82460. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  82461. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  82462. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  82463. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  82464. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  82465. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  82466. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  82467. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  82468. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  82469. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  82470. + * DAMAGE.
  82471. + * ========================================================================== */
  82472. +#ifndef DWC_HOST_ONLY
  82473. +
  82474. +#if !defined(__DWC_PCD_IF_H__)
  82475. +#define __DWC_PCD_IF_H__
  82476. +
  82477. +//#include "dwc_os.h"
  82478. +#include "dwc_otg_core_if.h"
  82479. +
  82480. +/** @file
  82481. + * This file defines DWC_OTG PCD Core API.
  82482. + */
  82483. +
  82484. +struct dwc_otg_pcd;
  82485. +typedef struct dwc_otg_pcd dwc_otg_pcd_t;
  82486. +
  82487. +/** Maxpacket size for EP0 */
  82488. +#define MAX_EP0_SIZE 64
  82489. +/** Maxpacket size for any EP */
  82490. +#define MAX_PACKET_SIZE 1024
  82491. +
  82492. +/** @name Function Driver Callbacks */
  82493. +/** @{ */
  82494. +
  82495. +/** This function will be called whenever a previously queued request has
  82496. + * completed. The status value will be set to -DWC_E_SHUTDOWN to indicated a
  82497. + * failed or aborted transfer, or -DWC_E_RESTART to indicate the device was reset,
  82498. + * or -DWC_E_TIMEOUT to indicate it timed out, or -DWC_E_INVALID to indicate invalid
  82499. + * parameters. */
  82500. +typedef int (*dwc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  82501. + void *req_handle, int32_t status,
  82502. + uint32_t actual);
  82503. +/**
  82504. + * This function will be called whenever a previousle queued ISOC request has
  82505. + * completed. Count of ISOC packets could be read using dwc_otg_pcd_get_iso_packet_count
  82506. + * function.
  82507. + * The status of each ISOC packet could be read using dwc_otg_pcd_get_iso_packet_*
  82508. + * functions.
  82509. + */
  82510. +typedef int (*dwc_isoc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  82511. + void *req_handle, int proc_buf_num);
  82512. +/** This function should handle any SETUP request that cannot be handled by the
  82513. + * PCD Core. This includes most GET_DESCRIPTORs, SET_CONFIGS, Any
  82514. + * class-specific requests, etc. The function must non-blocking.
  82515. + *
  82516. + * Returns 0 on success.
  82517. + * Returns -DWC_E_NOT_SUPPORTED if the request is not supported.
  82518. + * Returns -DWC_E_INVALID if the setup request had invalid parameters or bytes.
  82519. + * Returns -DWC_E_SHUTDOWN on any other error. */
  82520. +typedef int (*dwc_setup_cb_t) (dwc_otg_pcd_t * pcd, uint8_t * bytes);
  82521. +/** This is called whenever the device has been disconnected. The function
  82522. + * driver should take appropriate action to clean up all pending requests in the
  82523. + * PCD Core, remove all endpoints (except ep0), and initialize back to reset
  82524. + * state. */
  82525. +typedef int (*dwc_disconnect_cb_t) (dwc_otg_pcd_t * pcd);
  82526. +/** This function is called when device has been connected. */
  82527. +typedef int (*dwc_connect_cb_t) (dwc_otg_pcd_t * pcd, int speed);
  82528. +/** This function is called when device has been suspended */
  82529. +typedef int (*dwc_suspend_cb_t) (dwc_otg_pcd_t * pcd);
  82530. +/** This function is called when device has received LPM tokens, i.e.
  82531. + * device has been sent to sleep state. */
  82532. +typedef int (*dwc_sleep_cb_t) (dwc_otg_pcd_t * pcd);
  82533. +/** This function is called when device has been resumed
  82534. + * from suspend(L2) or L1 sleep state. */
  82535. +typedef int (*dwc_resume_cb_t) (dwc_otg_pcd_t * pcd);
  82536. +/** This function is called whenever hnp params has been changed.
  82537. + * User can call get_b_hnp_enable, get_a_hnp_support, get_a_alt_hnp_support functions
  82538. + * to get hnp parameters. */
  82539. +typedef int (*dwc_hnp_params_changed_cb_t) (dwc_otg_pcd_t * pcd);
  82540. +/** This function is called whenever USB RESET is detected. */
  82541. +typedef int (*dwc_reset_cb_t) (dwc_otg_pcd_t * pcd);
  82542. +
  82543. +typedef int (*cfi_setup_cb_t) (dwc_otg_pcd_t * pcd, void *ctrl_req_bytes);
  82544. +
  82545. +/**
  82546. + *
  82547. + * @param ep_handle Void pointer to the usb_ep structure
  82548. + * @param ereq_port Pointer to the extended request structure created in the
  82549. + * portable part.
  82550. + */
  82551. +typedef int (*xiso_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  82552. + void *req_handle, int32_t status,
  82553. + void *ereq_port);
  82554. +/** Function Driver Ops Data Structure */
  82555. +struct dwc_otg_pcd_function_ops {
  82556. + dwc_connect_cb_t connect;
  82557. + dwc_disconnect_cb_t disconnect;
  82558. + dwc_setup_cb_t setup;
  82559. + dwc_completion_cb_t complete;
  82560. + dwc_isoc_completion_cb_t isoc_complete;
  82561. + dwc_suspend_cb_t suspend;
  82562. + dwc_sleep_cb_t sleep;
  82563. + dwc_resume_cb_t resume;
  82564. + dwc_reset_cb_t reset;
  82565. + dwc_hnp_params_changed_cb_t hnp_changed;
  82566. + cfi_setup_cb_t cfi_setup;
  82567. +#ifdef DWC_UTE_PER_IO
  82568. + xiso_completion_cb_t xisoc_complete;
  82569. +#endif
  82570. +};
  82571. +/** @} */
  82572. +
  82573. +/** @name Function Driver Functions */
  82574. +/** @{ */
  82575. +
  82576. +/** Call this function to get pointer on dwc_otg_pcd_t,
  82577. + * this pointer will be used for all PCD API functions.
  82578. + *
  82579. + * @param core_if The DWC_OTG Core
  82580. + */
  82581. +extern dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if);
  82582. +
  82583. +/** Frees PCD allocated by dwc_otg_pcd_init
  82584. + *
  82585. + * @param pcd The PCD
  82586. + */
  82587. +extern void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd);
  82588. +
  82589. +/** Call this to bind the function driver to the PCD Core.
  82590. + *
  82591. + * @param pcd Pointer on dwc_otg_pcd_t returned by dwc_otg_pcd_init function.
  82592. + * @param fops The Function Driver Ops data structure containing pointers to all callbacks.
  82593. + */
  82594. +extern void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  82595. + const struct dwc_otg_pcd_function_ops *fops);
  82596. +
  82597. +/** Enables an endpoint for use. This function enables an endpoint in
  82598. + * the PCD. The endpoint is described by the ep_desc which has the
  82599. + * same format as a USB ep descriptor. The ep_handle parameter is used to refer
  82600. + * to the endpoint from other API functions and in callbacks. Normally this
  82601. + * should be called after a SET_CONFIGURATION/SET_INTERFACE to configure the
  82602. + * core for that interface.
  82603. + *
  82604. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  82605. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  82606. + * Returns 0 on success.
  82607. + *
  82608. + * @param pcd The PCD
  82609. + * @param ep_desc Endpoint descriptor
  82610. + * @param usb_ep Handle on endpoint, that will be used to identify endpoint.
  82611. + */
  82612. +extern int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  82613. + const uint8_t * ep_desc, void *usb_ep);
  82614. +
  82615. +/** Disable the endpoint referenced by ep_handle.
  82616. + *
  82617. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  82618. + * Returns -DWC_E_SHUTDOWN if any other error occurred.
  82619. + * Returns 0 on success. */
  82620. +extern int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle);
  82621. +
  82622. +/** Queue a data transfer request on the endpoint referenced by ep_handle.
  82623. + * After the transfer is completes, the complete callback will be called with
  82624. + * the request status.
  82625. + *
  82626. + * @param pcd The PCD
  82627. + * @param ep_handle The handle of the endpoint
  82628. + * @param buf The buffer for the data
  82629. + * @param dma_buf The DMA buffer for the data
  82630. + * @param buflen The length of the data transfer
  82631. + * @param zero Specifies whether to send zero length last packet.
  82632. + * @param req_handle Set this handle to any value to use to reference this
  82633. + * request in the ep_dequeue function or from the complete callback
  82634. + * @param atomic_alloc If driver need to perform atomic allocations
  82635. + * for internal data structures.
  82636. + *
  82637. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  82638. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  82639. + * Returns 0 on success. */
  82640. +extern int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  82641. + uint8_t * buf, dwc_dma_t dma_buf,
  82642. + uint32_t buflen, int zero, void *req_handle,
  82643. + int atomic_alloc);
  82644. +#ifdef DWC_UTE_PER_IO
  82645. +/**
  82646. + *
  82647. + * @param ereq_nonport Pointer to the extended request part of the
  82648. + * usb_request structure defined in usb_gadget.h file.
  82649. + */
  82650. +extern int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  82651. + uint8_t * buf, dwc_dma_t dma_buf,
  82652. + uint32_t buflen, int zero,
  82653. + void *req_handle, int atomic_alloc,
  82654. + void *ereq_nonport);
  82655. +
  82656. +#endif
  82657. +
  82658. +/** De-queue the specified data transfer that has not yet completed.
  82659. + *
  82660. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  82661. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  82662. + * Returns 0 on success. */
  82663. +extern int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  82664. + void *req_handle);
  82665. +
  82666. +/** Halt (STALL) an endpoint or clear it.
  82667. + *
  82668. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  82669. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  82670. + * Returns -DWC_E_AGAIN if the STALL cannot be sent and must be tried again later
  82671. + * Returns 0 on success. */
  82672. +extern int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value);
  82673. +
  82674. +/** This function */
  82675. +extern int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle);
  82676. +
  82677. +/** This function should be called on every hardware interrupt */
  82678. +extern int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd);
  82679. +
  82680. +/** This function returns current frame number */
  82681. +extern int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd);
  82682. +
  82683. +/**
  82684. + * Start isochronous transfers on the endpoint referenced by ep_handle.
  82685. + * For isochronous transfers duble buffering is used.
  82686. + * After processing each of buffers comlete callback will be called with
  82687. + * status for each transaction.
  82688. + *
  82689. + * @param pcd The PCD
  82690. + * @param ep_handle The handle of the endpoint
  82691. + * @param buf0 The virtual address of first data buffer
  82692. + * @param buf1 The virtual address of second data buffer
  82693. + * @param dma0 The DMA address of first data buffer
  82694. + * @param dma1 The DMA address of second data buffer
  82695. + * @param sync_frame Data pattern frame number
  82696. + * @param dp_frame Data size for pattern frame
  82697. + * @param data_per_frame Data size for regular frame
  82698. + * @param start_frame Frame number to start transfers, if -1 then start transfers ASAP.
  82699. + * @param buf_proc_intrvl Interval of ISOC Buffer processing
  82700. + * @param req_handle Handle of ISOC request
  82701. + * @param atomic_alloc Specefies whether to perform atomic allocation for
  82702. + * internal data structures.
  82703. + *
  82704. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  82705. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function.
  82706. + * Returns -DW_E_SHUTDOWN for any other error.
  82707. + * Returns 0 on success
  82708. + */
  82709. +extern int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  82710. + uint8_t * buf0, uint8_t * buf1,
  82711. + dwc_dma_t dma0, dwc_dma_t dma1,
  82712. + int sync_frame, int dp_frame,
  82713. + int data_per_frame, int start_frame,
  82714. + int buf_proc_intrvl, void *req_handle,
  82715. + int atomic_alloc);
  82716. +
  82717. +/** Stop ISOC transfers on endpoint referenced by ep_handle.
  82718. + *
  82719. + * @param pcd The PCD
  82720. + * @param ep_handle The handle of the endpoint
  82721. + * @param req_handle Handle of ISOC request
  82722. + *
  82723. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function
  82724. + * Returns 0 on success
  82725. + */
  82726. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  82727. + void *req_handle);
  82728. +
  82729. +/** Get ISOC packet status.
  82730. + *
  82731. + * @param pcd The PCD
  82732. + * @param ep_handle The handle of the endpoint
  82733. + * @param iso_req_handle Isochronoush request handle
  82734. + * @param packet Number of packet
  82735. + * @param status Out parameter for returning status
  82736. + * @param actual Out parameter for returning actual length
  82737. + * @param offset Out parameter for returning offset
  82738. + *
  82739. + */
  82740. +extern void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd,
  82741. + void *ep_handle,
  82742. + void *iso_req_handle, int packet,
  82743. + int *status, int *actual,
  82744. + int *offset);
  82745. +
  82746. +/** Get ISOC packet count.
  82747. + *
  82748. + * @param pcd The PCD
  82749. + * @param ep_handle The handle of the endpoint
  82750. + * @param iso_req_handle
  82751. + */
  82752. +extern int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd,
  82753. + void *ep_handle,
  82754. + void *iso_req_handle);
  82755. +
  82756. +/** This function starts the SRP Protocol if no session is in progress. If
  82757. + * a session is already in progress, but the device is suspended,
  82758. + * remote wakeup signaling is started.
  82759. + */
  82760. +extern int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd);
  82761. +
  82762. +/** This function returns 1 if LPM support is enabled, and 0 otherwise. */
  82763. +extern int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd);
  82764. +
  82765. +/** This function returns 1 if remote wakeup is allowed and 0, otherwise. */
  82766. +extern int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd);
  82767. +
  82768. +/** Initiate SRP */
  82769. +extern void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd);
  82770. +
  82771. +/** Starts remote wakeup signaling. */
  82772. +extern void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set);
  82773. +
  82774. +/** Starts micorsecond soft disconnect. */
  82775. +extern void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs);
  82776. +/** This function returns whether device is dualspeed.*/
  82777. +extern uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd);
  82778. +
  82779. +/** This function returns whether device is otg. */
  82780. +extern uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd);
  82781. +
  82782. +/** These functions allow to get hnp parameters */
  82783. +extern uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd);
  82784. +extern uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd);
  82785. +extern uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd);
  82786. +
  82787. +/** CFI specific Interface functions */
  82788. +/** Allocate a cfi buffer */
  82789. +extern uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep,
  82790. + dwc_dma_t * addr, size_t buflen,
  82791. + int flags);
  82792. +
  82793. +/******************************************************************************/
  82794. +
  82795. +/** @} */
  82796. +
  82797. +#endif /* __DWC_PCD_IF_H__ */
  82798. +
  82799. +#endif /* DWC_HOST_ONLY */
  82800. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c
  82801. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  82802. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 2014-02-18 11:52:14.000000000 +0100
  82803. @@ -0,0 +1,5147 @@
  82804. +/* ==========================================================================
  82805. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_intr.c $
  82806. + * $Revision: #116 $
  82807. + * $Date: 2012/08/10 $
  82808. + * $Change: 2047372 $
  82809. + *
  82810. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  82811. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  82812. + * otherwise expressly agreed to in writing between Synopsys and you.
  82813. + *
  82814. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  82815. + * any End User Software License Agreement or Agreement for Licensed Product
  82816. + * with Synopsys or any supplement thereto. You are permitted to use and
  82817. + * redistribute this Software in source and binary forms, with or without
  82818. + * modification, provided that redistributions of source code must retain this
  82819. + * notice. You may not view, use, disclose, copy or distribute this file or
  82820. + * any information contained herein except pursuant to this license grant from
  82821. + * Synopsys. If you do not agree with this notice, including the disclaimer
  82822. + * below, then you are not authorized to use the Software.
  82823. + *
  82824. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  82825. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  82826. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  82827. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  82828. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  82829. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  82830. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  82831. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  82832. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  82833. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  82834. + * DAMAGE.
  82835. + * ========================================================================== */
  82836. +#ifndef DWC_HOST_ONLY
  82837. +
  82838. +#include "dwc_otg_pcd.h"
  82839. +
  82840. +#ifdef DWC_UTE_CFI
  82841. +#include "dwc_otg_cfi.h"
  82842. +#endif
  82843. +
  82844. +#ifdef DWC_UTE_PER_IO
  82845. +extern void complete_xiso_ep(dwc_otg_pcd_ep_t * ep);
  82846. +#endif
  82847. +//#define PRINT_CFI_DMA_DESCS
  82848. +
  82849. +#define DEBUG_EP0
  82850. +
  82851. +/**
  82852. + * This function updates OTG.
  82853. + */
  82854. +static void dwc_otg_pcd_update_otg(dwc_otg_pcd_t * pcd, const unsigned reset)
  82855. +{
  82856. +
  82857. + if (reset) {
  82858. + pcd->b_hnp_enable = 0;
  82859. + pcd->a_hnp_support = 0;
  82860. + pcd->a_alt_hnp_support = 0;
  82861. + }
  82862. +
  82863. + if (pcd->fops->hnp_changed) {
  82864. + pcd->fops->hnp_changed(pcd);
  82865. + }
  82866. +}
  82867. +
  82868. +/** @file
  82869. + * This file contains the implementation of the PCD Interrupt handlers.
  82870. + *
  82871. + * The PCD handles the device interrupts. Many conditions can cause a
  82872. + * device interrupt. When an interrupt occurs, the device interrupt
  82873. + * service routine determines the cause of the interrupt and
  82874. + * dispatches handling to the appropriate function. These interrupt
  82875. + * handling functions are described below.
  82876. + * All interrupt registers are processed from LSB to MSB.
  82877. + */
  82878. +
  82879. +/**
  82880. + * This function prints the ep0 state for debug purposes.
  82881. + */
  82882. +static inline void print_ep0_state(dwc_otg_pcd_t * pcd)
  82883. +{
  82884. +#ifdef DEBUG
  82885. + char str[40];
  82886. +
  82887. + switch (pcd->ep0state) {
  82888. + case EP0_DISCONNECT:
  82889. + dwc_strcpy(str, "EP0_DISCONNECT");
  82890. + break;
  82891. + case EP0_IDLE:
  82892. + dwc_strcpy(str, "EP0_IDLE");
  82893. + break;
  82894. + case EP0_IN_DATA_PHASE:
  82895. + dwc_strcpy(str, "EP0_IN_DATA_PHASE");
  82896. + break;
  82897. + case EP0_OUT_DATA_PHASE:
  82898. + dwc_strcpy(str, "EP0_OUT_DATA_PHASE");
  82899. + break;
  82900. + case EP0_IN_STATUS_PHASE:
  82901. + dwc_strcpy(str, "EP0_IN_STATUS_PHASE");
  82902. + break;
  82903. + case EP0_OUT_STATUS_PHASE:
  82904. + dwc_strcpy(str, "EP0_OUT_STATUS_PHASE");
  82905. + break;
  82906. + case EP0_STALL:
  82907. + dwc_strcpy(str, "EP0_STALL");
  82908. + break;
  82909. + default:
  82910. + dwc_strcpy(str, "EP0_INVALID");
  82911. + }
  82912. +
  82913. + DWC_DEBUGPL(DBG_ANY, "%s(%d)\n", str, pcd->ep0state);
  82914. +#endif
  82915. +}
  82916. +
  82917. +/**
  82918. + * This function calculate the size of the payload in the memory
  82919. + * for out endpoints and prints size for debug purposes(used in
  82920. + * 2.93a DevOutNak feature).
  82921. + */
  82922. +static inline void print_memory_payload(dwc_otg_pcd_t * pcd, dwc_ep_t * ep)
  82923. +{
  82924. +#ifdef DEBUG
  82925. + deptsiz_data_t deptsiz_init = {.d32 = 0 };
  82926. + deptsiz_data_t deptsiz_updt = {.d32 = 0 };
  82927. + int pack_num;
  82928. + unsigned payload;
  82929. +
  82930. + deptsiz_init.d32 = pcd->core_if->start_doeptsiz_val[ep->num];
  82931. + deptsiz_updt.d32 =
  82932. + DWC_READ_REG32(&pcd->core_if->dev_if->
  82933. + out_ep_regs[ep->num]->doeptsiz);
  82934. + /* Payload will be */
  82935. + payload = deptsiz_init.b.xfersize - deptsiz_updt.b.xfersize;
  82936. + /* Packet count is decremented every time a packet
  82937. + * is written to the RxFIFO not in to the external memory
  82938. + * So, if payload == 0, then it means no packet was sent to ext memory*/
  82939. + pack_num = (!payload) ? 0 : (deptsiz_init.b.pktcnt - deptsiz_updt.b.pktcnt);
  82940. + DWC_DEBUGPL(DBG_PCDV,
  82941. + "Payload for EP%d-%s\n",
  82942. + ep->num, (ep->is_in ? "IN" : "OUT"));
  82943. + DWC_DEBUGPL(DBG_PCDV,
  82944. + "Number of transfered bytes = 0x%08x\n", payload);
  82945. + DWC_DEBUGPL(DBG_PCDV,
  82946. + "Number of transfered packets = %d\n", pack_num);
  82947. +#endif
  82948. +}
  82949. +
  82950. +
  82951. +#ifdef DWC_UTE_CFI
  82952. +static inline void print_desc(struct dwc_otg_dma_desc *ddesc,
  82953. + const uint8_t * epname, int descnum)
  82954. +{
  82955. + CFI_INFO
  82956. + ("%s DMA_DESC(%d) buf=0x%08x bytes=0x%04x; sp=0x%x; l=0x%x; sts=0x%02x; bs=0x%02x\n",
  82957. + epname, descnum, ddesc->buf, ddesc->status.b.bytes,
  82958. + ddesc->status.b.sp, ddesc->status.b.l, ddesc->status.b.sts,
  82959. + ddesc->status.b.bs);
  82960. +}
  82961. +#endif
  82962. +
  82963. +/**
  82964. + * This function returns pointer to in ep struct with number ep_num
  82965. + */
  82966. +static inline dwc_otg_pcd_ep_t *get_in_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  82967. +{
  82968. + int i;
  82969. + int num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  82970. + if (ep_num == 0) {
  82971. + return &pcd->ep0;
  82972. + } else {
  82973. + for (i = 0; i < num_in_eps; ++i) {
  82974. + if (pcd->in_ep[i].dwc_ep.num == ep_num)
  82975. + return &pcd->in_ep[i];
  82976. + }
  82977. + return 0;
  82978. + }
  82979. +}
  82980. +
  82981. +/**
  82982. + * This function returns pointer to out ep struct with number ep_num
  82983. + */
  82984. +static inline dwc_otg_pcd_ep_t *get_out_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  82985. +{
  82986. + int i;
  82987. + int num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  82988. + if (ep_num == 0) {
  82989. + return &pcd->ep0;
  82990. + } else {
  82991. + for (i = 0; i < num_out_eps; ++i) {
  82992. + if (pcd->out_ep[i].dwc_ep.num == ep_num)
  82993. + return &pcd->out_ep[i];
  82994. + }
  82995. + return 0;
  82996. + }
  82997. +}
  82998. +
  82999. +/**
  83000. + * This functions gets a pointer to an EP from the wIndex address
  83001. + * value of the control request.
  83002. + */
  83003. +dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex)
  83004. +{
  83005. + dwc_otg_pcd_ep_t *ep;
  83006. + uint32_t ep_num = UE_GET_ADDR(wIndex);
  83007. +
  83008. + if (ep_num == 0) {
  83009. + ep = &pcd->ep0;
  83010. + } else if (UE_GET_DIR(wIndex) == UE_DIR_IN) { /* in ep */
  83011. + ep = &pcd->in_ep[ep_num - 1];
  83012. + } else {
  83013. + ep = &pcd->out_ep[ep_num - 1];
  83014. + }
  83015. +
  83016. + return ep;
  83017. +}
  83018. +
  83019. +/**
  83020. + * This function checks the EP request queue, if the queue is not
  83021. + * empty the next request is started.
  83022. + */
  83023. +void start_next_request(dwc_otg_pcd_ep_t * ep)
  83024. +{
  83025. + dwc_otg_pcd_request_t *req = 0;
  83026. + uint32_t max_transfer =
  83027. + GET_CORE_IF(ep->pcd)->core_params->max_transfer_size;
  83028. +
  83029. +#ifdef DWC_UTE_CFI
  83030. + struct dwc_otg_pcd *pcd;
  83031. + pcd = ep->pcd;
  83032. +#endif
  83033. +
  83034. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  83035. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  83036. +
  83037. +#ifdef DWC_UTE_CFI
  83038. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  83039. + ep->dwc_ep.cfi_req_len = req->length;
  83040. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd, ep, req);
  83041. + } else {
  83042. +#endif
  83043. + /* Setup and start the Transfer */
  83044. + if (req->dw_align_buf) {
  83045. + ep->dwc_ep.dma_addr = req->dw_align_buf_dma;
  83046. + ep->dwc_ep.start_xfer_buff = req->dw_align_buf;
  83047. + ep->dwc_ep.xfer_buff = req->dw_align_buf;
  83048. + } else {
  83049. + ep->dwc_ep.dma_addr = req->dma;
  83050. + ep->dwc_ep.start_xfer_buff = req->buf;
  83051. + ep->dwc_ep.xfer_buff = req->buf;
  83052. + }
  83053. + ep->dwc_ep.sent_zlp = 0;
  83054. + ep->dwc_ep.total_len = req->length;
  83055. + ep->dwc_ep.xfer_len = 0;
  83056. + ep->dwc_ep.xfer_count = 0;
  83057. +
  83058. + ep->dwc_ep.maxxfer = max_transfer;
  83059. + if (GET_CORE_IF(ep->pcd)->dma_desc_enable) {
  83060. + uint32_t out_max_xfer = DDMA_MAX_TRANSFER_SIZE
  83061. + - (DDMA_MAX_TRANSFER_SIZE % 4);
  83062. + if (ep->dwc_ep.is_in) {
  83063. + if (ep->dwc_ep.maxxfer >
  83064. + DDMA_MAX_TRANSFER_SIZE) {
  83065. + ep->dwc_ep.maxxfer =
  83066. + DDMA_MAX_TRANSFER_SIZE;
  83067. + }
  83068. + } else {
  83069. + if (ep->dwc_ep.maxxfer > out_max_xfer) {
  83070. + ep->dwc_ep.maxxfer =
  83071. + out_max_xfer;
  83072. + }
  83073. + }
  83074. + }
  83075. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  83076. + ep->dwc_ep.maxxfer -=
  83077. + (ep->dwc_ep.maxxfer % ep->dwc_ep.maxpacket);
  83078. + }
  83079. + if (req->sent_zlp) {
  83080. + if ((ep->dwc_ep.total_len %
  83081. + ep->dwc_ep.maxpacket == 0)
  83082. + && (ep->dwc_ep.total_len != 0)) {
  83083. + ep->dwc_ep.sent_zlp = 1;
  83084. + }
  83085. +
  83086. + }
  83087. +#ifdef DWC_UTE_CFI
  83088. + }
  83089. +#endif
  83090. + dwc_otg_ep_start_transfer(GET_CORE_IF(ep->pcd), &ep->dwc_ep);
  83091. + } else if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  83092. + DWC_PRINTF("There are no more ISOC requests \n");
  83093. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  83094. + }
  83095. +}
  83096. +
  83097. +/**
  83098. + * This function handles the SOF Interrupts. At this time the SOF
  83099. + * Interrupt is disabled.
  83100. + */
  83101. +int32_t dwc_otg_pcd_handle_sof_intr(dwc_otg_pcd_t * pcd)
  83102. +{
  83103. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83104. +
  83105. + gintsts_data_t gintsts;
  83106. +
  83107. + DWC_DEBUGPL(DBG_PCD, "SOF\n");
  83108. +
  83109. + /* Clear interrupt */
  83110. + gintsts.d32 = 0;
  83111. + gintsts.b.sofintr = 1;
  83112. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  83113. +
  83114. + return 1;
  83115. +}
  83116. +
  83117. +/**
  83118. + * This function handles the Rx Status Queue Level Interrupt, which
  83119. + * indicates that there is a least one packet in the Rx FIFO. The
  83120. + * packets are moved from the FIFO to memory, where they will be
  83121. + * processed when the Endpoint Interrupt Register indicates Transfer
  83122. + * Complete or SETUP Phase Done.
  83123. + *
  83124. + * Repeat the following until the Rx Status Queue is empty:
  83125. + * -# Read the Receive Status Pop Register (GRXSTSP) to get Packet
  83126. + * info
  83127. + * -# If Receive FIFO is empty then skip to step Clear the interrupt
  83128. + * and exit
  83129. + * -# If SETUP Packet call dwc_otg_read_setup_packet to copy the
  83130. + * SETUP data to the buffer
  83131. + * -# If OUT Data Packet call dwc_otg_read_packet to copy the data
  83132. + * to the destination buffer
  83133. + */
  83134. +int32_t dwc_otg_pcd_handle_rx_status_q_level_intr(dwc_otg_pcd_t * pcd)
  83135. +{
  83136. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83137. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  83138. + gintmsk_data_t gintmask = {.d32 = 0 };
  83139. + device_grxsts_data_t status;
  83140. + dwc_otg_pcd_ep_t *ep;
  83141. + gintsts_data_t gintsts;
  83142. +#ifdef DEBUG
  83143. + static char *dpid_str[] = { "D0", "D2", "D1", "MDATA" };
  83144. +#endif
  83145. +
  83146. + //DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, _pcd);
  83147. + /* Disable the Rx Status Queue Level interrupt */
  83148. + gintmask.b.rxstsqlvl = 1;
  83149. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmask.d32, 0);
  83150. +
  83151. + /* Get the Status from the top of the FIFO */
  83152. + status.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  83153. +
  83154. + DWC_DEBUGPL(DBG_PCD, "EP:%d BCnt:%d DPID:%s "
  83155. + "pktsts:%x Frame:%d(0x%0x)\n",
  83156. + status.b.epnum, status.b.bcnt,
  83157. + dpid_str[status.b.dpid],
  83158. + status.b.pktsts, status.b.fn, status.b.fn);
  83159. + /* Get pointer to EP structure */
  83160. + ep = get_out_ep(pcd, status.b.epnum);
  83161. +
  83162. + switch (status.b.pktsts) {
  83163. + case DWC_DSTS_GOUT_NAK:
  83164. + DWC_DEBUGPL(DBG_PCDV, "Global OUT NAK\n");
  83165. + break;
  83166. + case DWC_STS_DATA_UPDT:
  83167. + DWC_DEBUGPL(DBG_PCDV, "OUT Data Packet\n");
  83168. + if (status.b.bcnt && ep->dwc_ep.xfer_buff) {
  83169. + /** @todo NGS Check for buffer overflow? */
  83170. + dwc_otg_read_packet(core_if,
  83171. + ep->dwc_ep.xfer_buff,
  83172. + status.b.bcnt);
  83173. + ep->dwc_ep.xfer_count += status.b.bcnt;
  83174. + ep->dwc_ep.xfer_buff += status.b.bcnt;
  83175. + }
  83176. + break;
  83177. + case DWC_STS_XFER_COMP:
  83178. + DWC_DEBUGPL(DBG_PCDV, "OUT Complete\n");
  83179. + break;
  83180. + case DWC_DSTS_SETUP_COMP:
  83181. +#ifdef DEBUG_EP0
  83182. + DWC_DEBUGPL(DBG_PCDV, "Setup Complete\n");
  83183. +#endif
  83184. + break;
  83185. + case DWC_DSTS_SETUP_UPDT:
  83186. + dwc_otg_read_setup_packet(core_if, pcd->setup_pkt->d32);
  83187. +#ifdef DEBUG_EP0
  83188. + DWC_DEBUGPL(DBG_PCD,
  83189. + "SETUP PKT: %02x.%02x v%04x i%04x l%04x\n",
  83190. + pcd->setup_pkt->req.bmRequestType,
  83191. + pcd->setup_pkt->req.bRequest,
  83192. + UGETW(pcd->setup_pkt->req.wValue),
  83193. + UGETW(pcd->setup_pkt->req.wIndex),
  83194. + UGETW(pcd->setup_pkt->req.wLength));
  83195. +#endif
  83196. + ep->dwc_ep.xfer_count += status.b.bcnt;
  83197. + break;
  83198. + default:
  83199. + DWC_DEBUGPL(DBG_PCDV, "Invalid Packet Status (0x%0x)\n",
  83200. + status.b.pktsts);
  83201. + break;
  83202. + }
  83203. +
  83204. + /* Enable the Rx Status Queue Level interrupt */
  83205. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmask.d32);
  83206. + /* Clear interrupt */
  83207. + gintsts.d32 = 0;
  83208. + gintsts.b.rxstsqlvl = 1;
  83209. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  83210. +
  83211. + //DWC_DEBUGPL(DBG_PCDV, "EXIT: %s\n", __func__);
  83212. + return 1;
  83213. +}
  83214. +
  83215. +/**
  83216. + * This function examines the Device IN Token Learning Queue to
  83217. + * determine the EP number of the last IN token received. This
  83218. + * implementation is for the Mass Storage device where there are only
  83219. + * 2 IN EPs (Control-IN and BULK-IN).
  83220. + *
  83221. + * The EP numbers for the first six IN Tokens are in DTKNQR1 and there
  83222. + * are 8 EP Numbers in each of the other possible DTKNQ Registers.
  83223. + *
  83224. + * @param core_if Programming view of DWC_otg controller.
  83225. + *
  83226. + */
  83227. +static inline int get_ep_of_last_in_token(dwc_otg_core_if_t * core_if)
  83228. +{
  83229. + dwc_otg_device_global_regs_t *dev_global_regs =
  83230. + core_if->dev_if->dev_global_regs;
  83231. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  83232. + /* Number of Token Queue Registers */
  83233. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  83234. + dtknq1_data_t dtknqr1;
  83235. + uint32_t in_tkn_epnums[4];
  83236. + int ndx = 0;
  83237. + int i = 0;
  83238. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  83239. + int epnum = 0;
  83240. +
  83241. + //DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  83242. +
  83243. + /* Read the DTKNQ Registers */
  83244. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  83245. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  83246. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  83247. + in_tkn_epnums[i]);
  83248. + if (addr == &dev_global_regs->dvbusdis) {
  83249. + addr = &dev_global_regs->dtknqr3_dthrctl;
  83250. + } else {
  83251. + ++addr;
  83252. + }
  83253. +
  83254. + }
  83255. +
  83256. + /* Copy the DTKNQR1 data to the bit field. */
  83257. + dtknqr1.d32 = in_tkn_epnums[0];
  83258. + /* Get the EP numbers */
  83259. + in_tkn_epnums[0] = dtknqr1.b.epnums0_5;
  83260. + ndx = dtknqr1.b.intknwptr - 1;
  83261. +
  83262. + //DWC_DEBUGPL(DBG_PCDV,"ndx=%d\n",ndx);
  83263. + if (ndx == -1) {
  83264. + /** @todo Find a simpler way to calculate the max
  83265. + * queue position.*/
  83266. + int cnt = TOKEN_Q_DEPTH;
  83267. + if (TOKEN_Q_DEPTH <= 6) {
  83268. + cnt = TOKEN_Q_DEPTH - 1;
  83269. + } else if (TOKEN_Q_DEPTH <= 14) {
  83270. + cnt = TOKEN_Q_DEPTH - 7;
  83271. + } else if (TOKEN_Q_DEPTH <= 22) {
  83272. + cnt = TOKEN_Q_DEPTH - 15;
  83273. + } else {
  83274. + cnt = TOKEN_Q_DEPTH - 23;
  83275. + }
  83276. + epnum = (in_tkn_epnums[DTKNQ_REG_CNT - 1] >> (cnt * 4)) & 0xF;
  83277. + } else {
  83278. + if (ndx <= 5) {
  83279. + epnum = (in_tkn_epnums[0] >> (ndx * 4)) & 0xF;
  83280. + } else if (ndx <= 13) {
  83281. + ndx -= 6;
  83282. + epnum = (in_tkn_epnums[1] >> (ndx * 4)) & 0xF;
  83283. + } else if (ndx <= 21) {
  83284. + ndx -= 14;
  83285. + epnum = (in_tkn_epnums[2] >> (ndx * 4)) & 0xF;
  83286. + } else if (ndx <= 29) {
  83287. + ndx -= 22;
  83288. + epnum = (in_tkn_epnums[3] >> (ndx * 4)) & 0xF;
  83289. + }
  83290. + }
  83291. + //DWC_DEBUGPL(DBG_PCD,"epnum=%d\n",epnum);
  83292. + return epnum;
  83293. +}
  83294. +
  83295. +/**
  83296. + * This interrupt occurs when the non-periodic Tx FIFO is half-empty.
  83297. + * The active request is checked for the next packet to be loaded into
  83298. + * the non-periodic Tx FIFO.
  83299. + */
  83300. +int32_t dwc_otg_pcd_handle_np_tx_fifo_empty_intr(dwc_otg_pcd_t * pcd)
  83301. +{
  83302. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83303. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  83304. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  83305. + gnptxsts_data_t txstatus = {.d32 = 0 };
  83306. + gintsts_data_t gintsts;
  83307. +
  83308. + int epnum = 0;
  83309. + dwc_otg_pcd_ep_t *ep = 0;
  83310. + uint32_t len = 0;
  83311. + int dwords;
  83312. +
  83313. + /* Get the epnum from the IN Token Learning Queue. */
  83314. + epnum = get_ep_of_last_in_token(core_if);
  83315. + ep = get_in_ep(pcd, epnum);
  83316. +
  83317. + DWC_DEBUGPL(DBG_PCD, "NP TxFifo Empty: %d \n", epnum);
  83318. +
  83319. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  83320. +
  83321. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  83322. + if (len > ep->dwc_ep.maxpacket) {
  83323. + len = ep->dwc_ep.maxpacket;
  83324. + }
  83325. + dwords = (len + 3) / 4;
  83326. +
  83327. + /* While there is space in the queue and space in the FIFO and
  83328. + * More data to tranfer, Write packets to the Tx FIFO */
  83329. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  83330. + DWC_DEBUGPL(DBG_PCDV, "b4 GNPTXSTS=0x%08x\n", txstatus.d32);
  83331. +
  83332. + while (txstatus.b.nptxqspcavail > 0 &&
  83333. + txstatus.b.nptxfspcavail > dwords &&
  83334. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len) {
  83335. + /* Write the FIFO */
  83336. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  83337. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  83338. +
  83339. + if (len > ep->dwc_ep.maxpacket) {
  83340. + len = ep->dwc_ep.maxpacket;
  83341. + }
  83342. +
  83343. + dwords = (len + 3) / 4;
  83344. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  83345. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n", txstatus.d32);
  83346. + }
  83347. +
  83348. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n",
  83349. + DWC_READ_REG32(&global_regs->gnptxsts));
  83350. +
  83351. + /* Clear interrupt */
  83352. + gintsts.d32 = 0;
  83353. + gintsts.b.nptxfempty = 1;
  83354. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  83355. +
  83356. + return 1;
  83357. +}
  83358. +
  83359. +/**
  83360. + * This function is called when dedicated Tx FIFO Empty interrupt occurs.
  83361. + * The active request is checked for the next packet to be loaded into
  83362. + * apropriate Tx FIFO.
  83363. + */
  83364. +static int32_t write_empty_tx_fifo(dwc_otg_pcd_t * pcd, uint32_t epnum)
  83365. +{
  83366. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83367. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  83368. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  83369. + dtxfsts_data_t txstatus = {.d32 = 0 };
  83370. + dwc_otg_pcd_ep_t *ep = 0;
  83371. + uint32_t len = 0;
  83372. + int dwords;
  83373. +
  83374. + ep = get_in_ep(pcd, epnum);
  83375. +
  83376. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  83377. +
  83378. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  83379. +
  83380. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  83381. +
  83382. + if (len > ep->dwc_ep.maxpacket) {
  83383. + len = ep->dwc_ep.maxpacket;
  83384. + }
  83385. +
  83386. + dwords = (len + 3) / 4;
  83387. +
  83388. + /* While there is space in the queue and space in the FIFO and
  83389. + * More data to tranfer, Write packets to the Tx FIFO */
  83390. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  83391. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  83392. +
  83393. + while (txstatus.b.txfspcavail > dwords &&
  83394. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len &&
  83395. + ep->dwc_ep.xfer_len != 0) {
  83396. + /* Write the FIFO */
  83397. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  83398. +
  83399. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  83400. + if (len > ep->dwc_ep.maxpacket) {
  83401. + len = ep->dwc_ep.maxpacket;
  83402. + }
  83403. +
  83404. + dwords = (len + 3) / 4;
  83405. + txstatus.d32 =
  83406. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  83407. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  83408. + txstatus.d32);
  83409. + }
  83410. +
  83411. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  83412. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  83413. +
  83414. + return 1;
  83415. +}
  83416. +
  83417. +/**
  83418. + * This function is called when the Device is disconnected. It stops
  83419. + * any active requests and informs the Gadget driver of the
  83420. + * disconnect.
  83421. + */
  83422. +void dwc_otg_pcd_stop(dwc_otg_pcd_t * pcd)
  83423. +{
  83424. + int i, num_in_eps, num_out_eps;
  83425. + dwc_otg_pcd_ep_t *ep;
  83426. +
  83427. + gintmsk_data_t intr_mask = {.d32 = 0 };
  83428. +
  83429. + DWC_SPINLOCK(pcd->lock);
  83430. +
  83431. + num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  83432. + num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  83433. +
  83434. + DWC_DEBUGPL(DBG_PCDV, "%s() \n", __func__);
  83435. + /* don't disconnect drivers more than once */
  83436. + if (pcd->ep0state == EP0_DISCONNECT) {
  83437. + DWC_DEBUGPL(DBG_ANY, "%s() Already Disconnected\n", __func__);
  83438. + DWC_SPINUNLOCK(pcd->lock);
  83439. + return;
  83440. + }
  83441. + pcd->ep0state = EP0_DISCONNECT;
  83442. +
  83443. + /* Reset the OTG state. */
  83444. + dwc_otg_pcd_update_otg(pcd, 1);
  83445. +
  83446. + /* Disable the NP Tx Fifo Empty Interrupt. */
  83447. + intr_mask.b.nptxfempty = 1;
  83448. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  83449. + intr_mask.d32, 0);
  83450. +
  83451. + /* Flush the FIFOs */
  83452. + /**@todo NGS Flush Periodic FIFOs */
  83453. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd), 0x10);
  83454. + dwc_otg_flush_rx_fifo(GET_CORE_IF(pcd));
  83455. +
  83456. + /* prevent new request submissions, kill any outstanding requests */
  83457. + ep = &pcd->ep0;
  83458. + dwc_otg_request_nuke(ep);
  83459. + /* prevent new request submissions, kill any outstanding requests */
  83460. + for (i = 0; i < num_in_eps; i++) {
  83461. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[i];
  83462. + dwc_otg_request_nuke(ep);
  83463. + }
  83464. + /* prevent new request submissions, kill any outstanding requests */
  83465. + for (i = 0; i < num_out_eps; i++) {
  83466. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[i];
  83467. + dwc_otg_request_nuke(ep);
  83468. + }
  83469. +
  83470. + /* report disconnect; the driver is already quiesced */
  83471. + if (pcd->fops->disconnect) {
  83472. + DWC_SPINUNLOCK(pcd->lock);
  83473. + pcd->fops->disconnect(pcd);
  83474. + DWC_SPINLOCK(pcd->lock);
  83475. + }
  83476. + DWC_SPINUNLOCK(pcd->lock);
  83477. +}
  83478. +
  83479. +/**
  83480. + * This interrupt indicates that ...
  83481. + */
  83482. +int32_t dwc_otg_pcd_handle_i2c_intr(dwc_otg_pcd_t * pcd)
  83483. +{
  83484. + gintmsk_data_t intr_mask = {.d32 = 0 };
  83485. + gintsts_data_t gintsts;
  83486. +
  83487. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "i2cintr");
  83488. + intr_mask.b.i2cintr = 1;
  83489. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  83490. + intr_mask.d32, 0);
  83491. +
  83492. + /* Clear interrupt */
  83493. + gintsts.d32 = 0;
  83494. + gintsts.b.i2cintr = 1;
  83495. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  83496. + gintsts.d32);
  83497. + return 1;
  83498. +}
  83499. +
  83500. +/**
  83501. + * This interrupt indicates that ...
  83502. + */
  83503. +int32_t dwc_otg_pcd_handle_early_suspend_intr(dwc_otg_pcd_t * pcd)
  83504. +{
  83505. + gintsts_data_t gintsts;
  83506. +#if defined(VERBOSE)
  83507. + DWC_PRINTF("Early Suspend Detected\n");
  83508. +#endif
  83509. +
  83510. + /* Clear interrupt */
  83511. + gintsts.d32 = 0;
  83512. + gintsts.b.erlysuspend = 1;
  83513. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  83514. + gintsts.d32);
  83515. + return 1;
  83516. +}
  83517. +
  83518. +/**
  83519. + * This function configures EPO to receive SETUP packets.
  83520. + *
  83521. + * @todo NGS: Update the comments from the HW FS.
  83522. + *
  83523. + * -# Program the following fields in the endpoint specific registers
  83524. + * for Control OUT EP 0, in order to receive a setup packet
  83525. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  83526. + * setup packets)
  83527. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  83528. + * to back setup packets)
  83529. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  83530. + * store any setup packets received
  83531. + *
  83532. + * @param core_if Programming view of DWC_otg controller.
  83533. + * @param pcd Programming view of the PCD.
  83534. + */
  83535. +static inline void ep0_out_start(dwc_otg_core_if_t * core_if,
  83536. + dwc_otg_pcd_t * pcd)
  83537. +{
  83538. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  83539. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  83540. + dwc_otg_dev_dma_desc_t *dma_desc;
  83541. + depctl_data_t doepctl = {.d32 = 0 };
  83542. +
  83543. +#ifdef VERBOSE
  83544. + DWC_DEBUGPL(DBG_PCDV, "%s() doepctl0=%0x\n", __func__,
  83545. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  83546. +#endif
  83547. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  83548. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  83549. + if (doepctl.b.epena) {
  83550. + return;
  83551. + }
  83552. + }
  83553. +
  83554. + doeptsize0.b.supcnt = 3;
  83555. + doeptsize0.b.pktcnt = 1;
  83556. + doeptsize0.b.xfersize = 8 * 3;
  83557. +
  83558. + if (core_if->dma_enable) {
  83559. + if (!core_if->dma_desc_enable) {
  83560. + /** put here as for Hermes mode deptisz register should not be written */
  83561. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  83562. + doeptsize0.d32);
  83563. +
  83564. + /** @todo dma needs to handle multiple setup packets (up to 3) */
  83565. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  83566. + pcd->setup_pkt_dma_handle);
  83567. + } else {
  83568. + dev_if->setup_desc_index =
  83569. + (dev_if->setup_desc_index + 1) & 1;
  83570. + dma_desc =
  83571. + dev_if->setup_desc_addr[dev_if->setup_desc_index];
  83572. +
  83573. + /** DMA Descriptor Setup */
  83574. + dma_desc->status.b.bs = BS_HOST_BUSY;
  83575. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  83576. + dma_desc->status.b.sr = 0;
  83577. + dma_desc->status.b.mtrf = 0;
  83578. + }
  83579. + dma_desc->status.b.l = 1;
  83580. + dma_desc->status.b.ioc = 1;
  83581. + dma_desc->status.b.bytes = pcd->ep0.dwc_ep.maxpacket;
  83582. + dma_desc->buf = pcd->setup_pkt_dma_handle;
  83583. + dma_desc->status.b.sts = 0;
  83584. + dma_desc->status.b.bs = BS_HOST_READY;
  83585. +
  83586. + /** DOEPDMA0 Register write */
  83587. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  83588. + dev_if->dma_setup_desc_addr
  83589. + [dev_if->setup_desc_index]);
  83590. + }
  83591. +
  83592. + } else {
  83593. + /** put here as for Hermes mode deptisz register should not be written */
  83594. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  83595. + doeptsize0.d32);
  83596. + }
  83597. +
  83598. + /** DOEPCTL0 Register write cnak will be set after setup interrupt */
  83599. + doepctl.d32 = 0;
  83600. + doepctl.b.epena = 1;
  83601. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  83602. + doepctl.b.cnak = 1;
  83603. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  83604. + } else {
  83605. + DWC_MODIFY_REG32(&dev_if->out_ep_regs[0]->doepctl, 0, doepctl.d32);
  83606. + }
  83607. +
  83608. +#ifdef VERBOSE
  83609. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  83610. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  83611. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  83612. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  83613. +#endif
  83614. +}
  83615. +
  83616. +/**
  83617. + * This interrupt occurs when a USB Reset is detected. When the USB
  83618. + * Reset Interrupt occurs the device state is set to DEFAULT and the
  83619. + * EP0 state is set to IDLE.
  83620. + * -# Set the NAK bit for all OUT endpoints (DOEPCTLn.SNAK = 1)
  83621. + * -# Unmask the following interrupt bits
  83622. + * - DAINTMSK.INEP0 = 1 (Control 0 IN endpoint)
  83623. + * - DAINTMSK.OUTEP0 = 1 (Control 0 OUT endpoint)
  83624. + * - DOEPMSK.SETUP = 1
  83625. + * - DOEPMSK.XferCompl = 1
  83626. + * - DIEPMSK.XferCompl = 1
  83627. + * - DIEPMSK.TimeOut = 1
  83628. + * -# Program the following fields in the endpoint specific registers
  83629. + * for Control OUT EP 0, in order to receive a setup packet
  83630. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  83631. + * setup packets)
  83632. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  83633. + * to back setup packets)
  83634. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  83635. + * store any setup packets received
  83636. + * At this point, all the required initialization, except for enabling
  83637. + * the control 0 OUT endpoint is done, for receiving SETUP packets.
  83638. + */
  83639. +int32_t dwc_otg_pcd_handle_usb_reset_intr(dwc_otg_pcd_t * pcd)
  83640. +{
  83641. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83642. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  83643. + depctl_data_t doepctl = {.d32 = 0 };
  83644. + depctl_data_t diepctl = {.d32 = 0 };
  83645. + daint_data_t daintmsk = {.d32 = 0 };
  83646. + doepmsk_data_t doepmsk = {.d32 = 0 };
  83647. + diepmsk_data_t diepmsk = {.d32 = 0 };
  83648. + dcfg_data_t dcfg = {.d32 = 0 };
  83649. + grstctl_t resetctl = {.d32 = 0 };
  83650. + dctl_data_t dctl = {.d32 = 0 };
  83651. + int i = 0;
  83652. + gintsts_data_t gintsts;
  83653. + pcgcctl_data_t power = {.d32 = 0 };
  83654. +
  83655. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  83656. + if (power.b.stoppclk) {
  83657. + power.d32 = 0;
  83658. + power.b.stoppclk = 1;
  83659. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  83660. +
  83661. + power.b.pwrclmp = 1;
  83662. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  83663. +
  83664. + power.b.rstpdwnmodule = 1;
  83665. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  83666. + }
  83667. +
  83668. + core_if->lx_state = DWC_OTG_L0;
  83669. +
  83670. + DWC_PRINTF("USB RESET\n");
  83671. +#ifdef DWC_EN_ISOC
  83672. + for (i = 1; i < 16; ++i) {
  83673. + dwc_otg_pcd_ep_t *ep;
  83674. + dwc_ep_t *dwc_ep;
  83675. + ep = get_in_ep(pcd, i);
  83676. + if (ep != 0) {
  83677. + dwc_ep = &ep->dwc_ep;
  83678. + dwc_ep->next_frame = 0xffffffff;
  83679. + }
  83680. + }
  83681. +#endif /* DWC_EN_ISOC */
  83682. +
  83683. + /* reset the HNP settings */
  83684. + dwc_otg_pcd_update_otg(pcd, 1);
  83685. +
  83686. + /* Clear the Remote Wakeup Signalling */
  83687. + dctl.b.rmtwkupsig = 1;
  83688. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  83689. +
  83690. + /* Set NAK for all OUT EPs */
  83691. + doepctl.b.snak = 1;
  83692. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  83693. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  83694. + }
  83695. +
  83696. + /* Flush the NP Tx FIFO */
  83697. + dwc_otg_flush_tx_fifo(core_if, 0x10);
  83698. + /* Flush the Learning Queue */
  83699. + resetctl.b.intknqflsh = 1;
  83700. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  83701. +
  83702. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  83703. + core_if->start_predict = 0;
  83704. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  83705. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  83706. + }
  83707. + core_if->nextep_seq[0] = 0;
  83708. + core_if->first_in_nextep_seq = 0;
  83709. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  83710. + diepctl.b.nextep = 0;
  83711. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  83712. +
  83713. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  83714. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  83715. + dcfg.b.epmscnt = 2;
  83716. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  83717. +
  83718. + DWC_DEBUGPL(DBG_PCDV,
  83719. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  83720. + __func__, core_if->first_in_nextep_seq);
  83721. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  83722. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  83723. + }
  83724. + }
  83725. +
  83726. + if (core_if->multiproc_int_enable) {
  83727. + daintmsk.b.inep0 = 1;
  83728. + daintmsk.b.outep0 = 1;
  83729. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk,
  83730. + daintmsk.d32);
  83731. +
  83732. + doepmsk.b.setup = 1;
  83733. + doepmsk.b.xfercompl = 1;
  83734. + doepmsk.b.ahberr = 1;
  83735. + doepmsk.b.epdisabled = 1;
  83736. +
  83737. + if ((core_if->dma_desc_enable) ||
  83738. + (core_if->dma_enable
  83739. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  83740. + doepmsk.b.stsphsercvd = 1;
  83741. + }
  83742. + if (core_if->dma_desc_enable)
  83743. + doepmsk.b.bna = 1;
  83744. +/*
  83745. + doepmsk.b.babble = 1;
  83746. + doepmsk.b.nyet = 1;
  83747. +
  83748. + if (core_if->dma_enable) {
  83749. + doepmsk.b.nak = 1;
  83750. + }
  83751. +*/
  83752. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepeachintmsk[0],
  83753. + doepmsk.d32);
  83754. +
  83755. + diepmsk.b.xfercompl = 1;
  83756. + diepmsk.b.timeout = 1;
  83757. + diepmsk.b.epdisabled = 1;
  83758. + diepmsk.b.ahberr = 1;
  83759. + diepmsk.b.intknepmis = 1;
  83760. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  83761. + diepmsk.b.intknepmis = 0;
  83762. +
  83763. +/* if (core_if->dma_desc_enable) {
  83764. + diepmsk.b.bna = 1;
  83765. + }
  83766. +*/
  83767. +/*
  83768. + if (core_if->dma_enable) {
  83769. + diepmsk.b.nak = 1;
  83770. + }
  83771. +*/
  83772. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepeachintmsk[0],
  83773. + diepmsk.d32);
  83774. + } else {
  83775. + daintmsk.b.inep0 = 1;
  83776. + daintmsk.b.outep0 = 1;
  83777. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk,
  83778. + daintmsk.d32);
  83779. +
  83780. + doepmsk.b.setup = 1;
  83781. + doepmsk.b.xfercompl = 1;
  83782. + doepmsk.b.ahberr = 1;
  83783. + doepmsk.b.epdisabled = 1;
  83784. +
  83785. + if ((core_if->dma_desc_enable) ||
  83786. + (core_if->dma_enable
  83787. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  83788. + doepmsk.b.stsphsercvd = 1;
  83789. + }
  83790. + if (core_if->dma_desc_enable)
  83791. + doepmsk.b.bna = 1;
  83792. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, doepmsk.d32);
  83793. +
  83794. + diepmsk.b.xfercompl = 1;
  83795. + diepmsk.b.timeout = 1;
  83796. + diepmsk.b.epdisabled = 1;
  83797. + diepmsk.b.ahberr = 1;
  83798. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  83799. + diepmsk.b.intknepmis = 0;
  83800. +/*
  83801. + if (core_if->dma_desc_enable) {
  83802. + diepmsk.b.bna = 1;
  83803. + }
  83804. +*/
  83805. +
  83806. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, diepmsk.d32);
  83807. + }
  83808. +
  83809. + /* Reset Device Address */
  83810. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  83811. + dcfg.b.devaddr = 0;
  83812. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  83813. +
  83814. + /* setup EP0 to receive SETUP packets */
  83815. + if (core_if->snpsid <= OTG_CORE_REV_2_94a)
  83816. + ep0_out_start(core_if, pcd);
  83817. +
  83818. + /* Clear interrupt */
  83819. + gintsts.d32 = 0;
  83820. + gintsts.b.usbreset = 1;
  83821. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  83822. +
  83823. + return 1;
  83824. +}
  83825. +
  83826. +/**
  83827. + * Get the device speed from the device status register and convert it
  83828. + * to USB speed constant.
  83829. + *
  83830. + * @param core_if Programming view of DWC_otg controller.
  83831. + */
  83832. +static int get_device_speed(dwc_otg_core_if_t * core_if)
  83833. +{
  83834. + dsts_data_t dsts;
  83835. + int speed = 0;
  83836. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  83837. +
  83838. + switch (dsts.b.enumspd) {
  83839. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  83840. + speed = USB_SPEED_HIGH;
  83841. + break;
  83842. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  83843. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  83844. + speed = USB_SPEED_FULL;
  83845. + break;
  83846. +
  83847. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  83848. + speed = USB_SPEED_LOW;
  83849. + break;
  83850. + }
  83851. +
  83852. + return speed;
  83853. +}
  83854. +
  83855. +/**
  83856. + * Read the device status register and set the device speed in the
  83857. + * data structure.
  83858. + * Set up EP0 to receive SETUP packets by calling dwc_ep0_activate.
  83859. + */
  83860. +int32_t dwc_otg_pcd_handle_enum_done_intr(dwc_otg_pcd_t * pcd)
  83861. +{
  83862. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  83863. + gintsts_data_t gintsts;
  83864. + gusbcfg_data_t gusbcfg;
  83865. + dwc_otg_core_global_regs_t *global_regs =
  83866. + GET_CORE_IF(pcd)->core_global_regs;
  83867. + uint8_t utmi16b, utmi8b;
  83868. + int speed;
  83869. + DWC_DEBUGPL(DBG_PCD, "SPEED ENUM\n");
  83870. +
  83871. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_2_60a) {
  83872. + utmi16b = 6; //vahrama old value was 6;
  83873. + utmi8b = 9;
  83874. + } else {
  83875. + utmi16b = 4;
  83876. + utmi8b = 8;
  83877. + }
  83878. + dwc_otg_ep0_activate(GET_CORE_IF(pcd), &ep0->dwc_ep);
  83879. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a) {
  83880. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  83881. + }
  83882. +
  83883. +#ifdef DEBUG_EP0
  83884. + print_ep0_state(pcd);
  83885. +#endif
  83886. +
  83887. + if (pcd->ep0state == EP0_DISCONNECT) {
  83888. + pcd->ep0state = EP0_IDLE;
  83889. + } else if (pcd->ep0state == EP0_STALL) {
  83890. + pcd->ep0state = EP0_IDLE;
  83891. + }
  83892. +
  83893. + pcd->ep0state = EP0_IDLE;
  83894. +
  83895. + ep0->stopped = 0;
  83896. +
  83897. + speed = get_device_speed(GET_CORE_IF(pcd));
  83898. + pcd->fops->connect(pcd, speed);
  83899. +
  83900. + /* Set USB turnaround time based on device speed and PHY interface. */
  83901. + gusbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  83902. + if (speed == USB_SPEED_HIGH) {
  83903. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  83904. + DWC_HWCFG2_HS_PHY_TYPE_ULPI) {
  83905. + /* ULPI interface */
  83906. + gusbcfg.b.usbtrdtim = 9;
  83907. + }
  83908. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  83909. + DWC_HWCFG2_HS_PHY_TYPE_UTMI) {
  83910. + /* UTMI+ interface */
  83911. + if (GET_CORE_IF(pcd)->hwcfg4.b.utmi_phy_data_width == 0) {
  83912. + gusbcfg.b.usbtrdtim = utmi8b;
  83913. + } else if (GET_CORE_IF(pcd)->hwcfg4.
  83914. + b.utmi_phy_data_width == 1) {
  83915. + gusbcfg.b.usbtrdtim = utmi16b;
  83916. + } else if (GET_CORE_IF(pcd)->
  83917. + core_params->phy_utmi_width == 8) {
  83918. + gusbcfg.b.usbtrdtim = utmi8b;
  83919. + } else {
  83920. + gusbcfg.b.usbtrdtim = utmi16b;
  83921. + }
  83922. + }
  83923. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  83924. + DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI) {
  83925. + /* UTMI+ OR ULPI interface */
  83926. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  83927. + /* ULPI interface */
  83928. + gusbcfg.b.usbtrdtim = 9;
  83929. + } else {
  83930. + /* UTMI+ interface */
  83931. + if (GET_CORE_IF(pcd)->
  83932. + core_params->phy_utmi_width == 16) {
  83933. + gusbcfg.b.usbtrdtim = utmi16b;
  83934. + } else {
  83935. + gusbcfg.b.usbtrdtim = utmi8b;
  83936. + }
  83937. + }
  83938. + }
  83939. + } else {
  83940. + /* Full or low speed */
  83941. + gusbcfg.b.usbtrdtim = 9;
  83942. + }
  83943. + DWC_WRITE_REG32(&global_regs->gusbcfg, gusbcfg.d32);
  83944. +
  83945. + /* Clear interrupt */
  83946. + gintsts.d32 = 0;
  83947. + gintsts.b.enumdone = 1;
  83948. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  83949. + gintsts.d32);
  83950. + return 1;
  83951. +}
  83952. +
  83953. +/**
  83954. + * This interrupt indicates that the ISO OUT Packet was dropped due to
  83955. + * Rx FIFO full or Rx Status Queue Full. If this interrupt occurs
  83956. + * read all the data from the Rx FIFO.
  83957. + */
  83958. +int32_t dwc_otg_pcd_handle_isoc_out_packet_dropped_intr(dwc_otg_pcd_t * pcd)
  83959. +{
  83960. + gintmsk_data_t intr_mask = {.d32 = 0 };
  83961. + gintsts_data_t gintsts;
  83962. +
  83963. + DWC_WARN("INTERRUPT Handler not implemented for %s\n",
  83964. + "ISOC Out Dropped");
  83965. +
  83966. + intr_mask.b.isooutdrop = 1;
  83967. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  83968. + intr_mask.d32, 0);
  83969. +
  83970. + /* Clear interrupt */
  83971. + gintsts.d32 = 0;
  83972. + gintsts.b.isooutdrop = 1;
  83973. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  83974. + gintsts.d32);
  83975. +
  83976. + return 1;
  83977. +}
  83978. +
  83979. +/**
  83980. + * This interrupt indicates the end of the portion of the micro-frame
  83981. + * for periodic transactions. If there is a periodic transaction for
  83982. + * the next frame, load the packets into the EP periodic Tx FIFO.
  83983. + */
  83984. +int32_t dwc_otg_pcd_handle_end_periodic_frame_intr(dwc_otg_pcd_t * pcd)
  83985. +{
  83986. + gintmsk_data_t intr_mask = {.d32 = 0 };
  83987. + gintsts_data_t gintsts;
  83988. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "EOP");
  83989. +
  83990. + intr_mask.b.eopframe = 1;
  83991. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  83992. + intr_mask.d32, 0);
  83993. +
  83994. + /* Clear interrupt */
  83995. + gintsts.d32 = 0;
  83996. + gintsts.b.eopframe = 1;
  83997. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  83998. + gintsts.d32);
  83999. +
  84000. + return 1;
  84001. +}
  84002. +
  84003. +/**
  84004. + * This interrupt indicates that EP of the packet on the top of the
  84005. + * non-periodic Tx FIFO does not match EP of the IN Token received.
  84006. + *
  84007. + * The "Device IN Token Queue" Registers are read to determine the
  84008. + * order the IN Tokens have been received. The non-periodic Tx FIFO
  84009. + * is flushed, so it can be reloaded in the order seen in the IN Token
  84010. + * Queue.
  84011. + */
  84012. +int32_t dwc_otg_pcd_handle_ep_mismatch_intr(dwc_otg_pcd_t * pcd)
  84013. +{
  84014. + gintsts_data_t gintsts;
  84015. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84016. + dctl_data_t dctl;
  84017. + gintmsk_data_t intr_mask = {.d32 = 0 };
  84018. +
  84019. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  84020. + core_if->start_predict = 1;
  84021. +
  84022. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  84023. +
  84024. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  84025. + if (!gintsts.b.ginnakeff) {
  84026. + /* Disable EP Mismatch interrupt */
  84027. + intr_mask.d32 = 0;
  84028. + intr_mask.b.epmismatch = 1;
  84029. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
  84030. + /* Enable the Global IN NAK Effective Interrupt */
  84031. + intr_mask.d32 = 0;
  84032. + intr_mask.b.ginnakeff = 1;
  84033. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  84034. + /* Set the global non-periodic IN NAK handshake */
  84035. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  84036. + dctl.b.sgnpinnak = 1;
  84037. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  84038. + } else {
  84039. + DWC_PRINTF("gintsts.b.ginnakeff = 1! dctl.b.sgnpinnak not set\n");
  84040. + }
  84041. + /* Disabling of all EP's will be done in dwc_otg_pcd_handle_in_nak_effective()
  84042. + * handler after Global IN NAK Effective interrupt will be asserted */
  84043. + }
  84044. + /* Clear interrupt */
  84045. + gintsts.d32 = 0;
  84046. + gintsts.b.epmismatch = 1;
  84047. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  84048. +
  84049. + return 1;
  84050. +}
  84051. +
  84052. +/**
  84053. + * This interrupt is valid only in DMA mode. This interrupt indicates that the
  84054. + * core has stopped fetching data for IN endpoints due to the unavailability of
  84055. + * TxFIFO space or Request Queue space. This interrupt is used by the
  84056. + * application for an endpoint mismatch algorithm.
  84057. + *
  84058. + * @param pcd The PCD
  84059. + */
  84060. +int32_t dwc_otg_pcd_handle_ep_fetsusp_intr(dwc_otg_pcd_t * pcd)
  84061. +{
  84062. + gintsts_data_t gintsts;
  84063. + gintmsk_data_t gintmsk_data;
  84064. + dctl_data_t dctl;
  84065. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84066. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  84067. +
  84068. + /* Clear the global non-periodic IN NAK handshake */
  84069. + dctl.d32 = 0;
  84070. + dctl.b.cgnpinnak = 1;
  84071. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  84072. +
  84073. + /* Mask GINTSTS.FETSUSP interrupt */
  84074. + gintmsk_data.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  84075. + gintmsk_data.b.fetsusp = 0;
  84076. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_data.d32);
  84077. +
  84078. + /* Clear interrupt */
  84079. + gintsts.d32 = 0;
  84080. + gintsts.b.fetsusp = 1;
  84081. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  84082. +
  84083. + return 1;
  84084. +}
  84085. +/**
  84086. + * This funcion stalls EP0.
  84087. + */
  84088. +static inline void ep0_do_stall(dwc_otg_pcd_t * pcd, const int err_val)
  84089. +{
  84090. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  84091. + usb_device_request_t *ctrl = &pcd->setup_pkt->req;
  84092. + DWC_WARN("req %02x.%02x protocol STALL; err %d\n",
  84093. + ctrl->bmRequestType, ctrl->bRequest, err_val);
  84094. +
  84095. + ep0->dwc_ep.is_in = 1;
  84096. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep0->dwc_ep);
  84097. + pcd->ep0.stopped = 1;
  84098. + pcd->ep0state = EP0_IDLE;
  84099. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  84100. +}
  84101. +
  84102. +/**
  84103. + * This functions delegates the setup command to the gadget driver.
  84104. + */
  84105. +static inline void do_gadget_setup(dwc_otg_pcd_t * pcd,
  84106. + usb_device_request_t * ctrl)
  84107. +{
  84108. + int ret = 0;
  84109. + DWC_SPINUNLOCK(pcd->lock);
  84110. + ret = pcd->fops->setup(pcd, (uint8_t *) ctrl);
  84111. + DWC_SPINLOCK(pcd->lock);
  84112. + if (ret < 0) {
  84113. + ep0_do_stall(pcd, ret);
  84114. + }
  84115. +
  84116. + /** @todo This is a g_file_storage gadget driver specific
  84117. + * workaround: a DELAYED_STATUS result from the fsg_setup
  84118. + * routine will result in the gadget queueing a EP0 IN status
  84119. + * phase for a two-stage control transfer. Exactly the same as
  84120. + * a SET_CONFIGURATION/SET_INTERFACE except that this is a class
  84121. + * specific request. Need a generic way to know when the gadget
  84122. + * driver will queue the status phase. Can we assume when we
  84123. + * call the gadget driver setup() function that it will always
  84124. + * queue and require the following flag? Need to look into
  84125. + * this.
  84126. + */
  84127. +
  84128. + if (ret == 256 + 999) {
  84129. + pcd->request_config = 1;
  84130. + }
  84131. +}
  84132. +
  84133. +#ifdef DWC_UTE_CFI
  84134. +/**
  84135. + * This functions delegates the CFI setup commands to the gadget driver.
  84136. + * This function will return a negative value to indicate a failure.
  84137. + */
  84138. +static inline int cfi_gadget_setup(dwc_otg_pcd_t * pcd,
  84139. + struct cfi_usb_ctrlrequest *ctrl_req)
  84140. +{
  84141. + int ret = 0;
  84142. +
  84143. + if (pcd->fops && pcd->fops->cfi_setup) {
  84144. + DWC_SPINUNLOCK(pcd->lock);
  84145. + ret = pcd->fops->cfi_setup(pcd, ctrl_req);
  84146. + DWC_SPINLOCK(pcd->lock);
  84147. + if (ret < 0) {
  84148. + ep0_do_stall(pcd, ret);
  84149. + return ret;
  84150. + }
  84151. + }
  84152. +
  84153. + return ret;
  84154. +}
  84155. +#endif
  84156. +
  84157. +/**
  84158. + * This function starts the Zero-Length Packet for the IN status phase
  84159. + * of a 2 stage control transfer.
  84160. + */
  84161. +static inline void do_setup_in_status_phase(dwc_otg_pcd_t * pcd)
  84162. +{
  84163. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  84164. + if (pcd->ep0state == EP0_STALL) {
  84165. + return;
  84166. + }
  84167. +
  84168. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  84169. +
  84170. + /* Prepare for more SETUP Packets */
  84171. + DWC_DEBUGPL(DBG_PCD, "EP0 IN ZLP\n");
  84172. + if ((GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a)
  84173. + && (pcd->core_if->dma_desc_enable)
  84174. + && (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len)) {
  84175. + DWC_DEBUGPL(DBG_PCDV,
  84176. + "Data terminated wait next packet in out_desc_addr\n");
  84177. + pcd->backup_buf = phys_to_virt(ep0->dwc_ep.dma_addr);
  84178. + pcd->data_terminated = 1;
  84179. + }
  84180. + ep0->dwc_ep.xfer_len = 0;
  84181. + ep0->dwc_ep.xfer_count = 0;
  84182. + ep0->dwc_ep.is_in = 1;
  84183. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  84184. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  84185. +
  84186. + /* Prepare for more SETUP Packets */
  84187. + //ep0_out_start(GET_CORE_IF(pcd), pcd);
  84188. +}
  84189. +
  84190. +/**
  84191. + * This function starts the Zero-Length Packet for the OUT status phase
  84192. + * of a 2 stage control transfer.
  84193. + */
  84194. +static inline void do_setup_out_status_phase(dwc_otg_pcd_t * pcd)
  84195. +{
  84196. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  84197. + if (pcd->ep0state == EP0_STALL) {
  84198. + DWC_DEBUGPL(DBG_PCD, "EP0 STALLED\n");
  84199. + return;
  84200. + }
  84201. + pcd->ep0state = EP0_OUT_STATUS_PHASE;
  84202. +
  84203. + DWC_DEBUGPL(DBG_PCD, "EP0 OUT ZLP\n");
  84204. + ep0->dwc_ep.xfer_len = 0;
  84205. + ep0->dwc_ep.xfer_count = 0;
  84206. + ep0->dwc_ep.is_in = 0;
  84207. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  84208. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  84209. +
  84210. + /* Prepare for more SETUP Packets */
  84211. + if (GET_CORE_IF(pcd)->dma_enable == 0) {
  84212. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  84213. + }
  84214. +}
  84215. +
  84216. +/**
  84217. + * Clear the EP halt (STALL) and if pending requests start the
  84218. + * transfer.
  84219. + */
  84220. +static inline void pcd_clear_halt(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  84221. +{
  84222. + if (ep->dwc_ep.stall_clear_flag == 0)
  84223. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  84224. +
  84225. + /* Reactive the EP */
  84226. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  84227. + if (ep->stopped) {
  84228. + ep->stopped = 0;
  84229. + /* If there is a request in the EP queue start it */
  84230. +
  84231. + /** @todo FIXME: this causes an EP mismatch in DMA mode.
  84232. + * epmismatch not yet implemented. */
  84233. +
  84234. + /*
  84235. + * Above fixme is solved by implmenting a tasklet to call the
  84236. + * start_next_request(), outside of interrupt context at some
  84237. + * time after the current time, after a clear-halt setup packet.
  84238. + * Still need to implement ep mismatch in the future if a gadget
  84239. + * ever uses more than one endpoint at once
  84240. + */
  84241. + ep->queue_sof = 1;
  84242. + DWC_TASK_SCHEDULE(pcd->start_xfer_tasklet);
  84243. + }
  84244. + /* Start Control Status Phase */
  84245. + do_setup_in_status_phase(pcd);
  84246. +}
  84247. +
  84248. +/**
  84249. + * This function is called when the SET_FEATURE TEST_MODE Setup packet
  84250. + * is sent from the host. The Device Control register is written with
  84251. + * the Test Mode bits set to the specified Test Mode. This is done as
  84252. + * a tasklet so that the "Status" phase of the control transfer
  84253. + * completes before transmitting the TEST packets.
  84254. + *
  84255. + * @todo This has not been tested since the tasklet struct was put
  84256. + * into the PCD struct!
  84257. + *
  84258. + */
  84259. +void do_test_mode(void *data)
  84260. +{
  84261. + dctl_data_t dctl;
  84262. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  84263. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84264. + int test_mode = pcd->test_mode;
  84265. +
  84266. +// DWC_WARN("%s() has not been tested since being rewritten!\n", __func__);
  84267. +
  84268. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  84269. + switch (test_mode) {
  84270. + case 1: // TEST_J
  84271. + dctl.b.tstctl = 1;
  84272. + break;
  84273. +
  84274. + case 2: // TEST_K
  84275. + dctl.b.tstctl = 2;
  84276. + break;
  84277. +
  84278. + case 3: // TEST_SE0_NAK
  84279. + dctl.b.tstctl = 3;
  84280. + break;
  84281. +
  84282. + case 4: // TEST_PACKET
  84283. + dctl.b.tstctl = 4;
  84284. + break;
  84285. +
  84286. + case 5: // TEST_FORCE_ENABLE
  84287. + dctl.b.tstctl = 5;
  84288. + break;
  84289. + }
  84290. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  84291. +}
  84292. +
  84293. +/**
  84294. + * This function process the GET_STATUS Setup Commands.
  84295. + */
  84296. +static inline void do_get_status(dwc_otg_pcd_t * pcd)
  84297. +{
  84298. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  84299. + dwc_otg_pcd_ep_t *ep;
  84300. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  84301. + uint16_t *status = pcd->status_buf;
  84302. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84303. +
  84304. +#ifdef DEBUG_EP0
  84305. + DWC_DEBUGPL(DBG_PCD,
  84306. + "GET_STATUS %02x.%02x v%04x i%04x l%04x\n",
  84307. + ctrl.bmRequestType, ctrl.bRequest,
  84308. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  84309. + UGETW(ctrl.wLength));
  84310. +#endif
  84311. +
  84312. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  84313. + case UT_DEVICE:
  84314. + if(UGETW(ctrl.wIndex) == 0xF000) { /* OTG Status selector */
  84315. + DWC_PRINTF("wIndex - %d\n", UGETW(ctrl.wIndex));
  84316. + DWC_PRINTF("OTG VERSION - %d\n", core_if->otg_ver);
  84317. + DWC_PRINTF("OTG CAP - %d, %d\n",
  84318. + core_if->core_params->otg_cap,
  84319. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  84320. + if (core_if->otg_ver == 1
  84321. + && core_if->core_params->otg_cap ==
  84322. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  84323. + uint8_t *otgsts = (uint8_t*)pcd->status_buf;
  84324. + *otgsts = (core_if->otg_sts & 0x1);
  84325. + pcd->ep0_pending = 1;
  84326. + ep0->dwc_ep.start_xfer_buff =
  84327. + (uint8_t *) otgsts;
  84328. + ep0->dwc_ep.xfer_buff = (uint8_t *) otgsts;
  84329. + ep0->dwc_ep.dma_addr =
  84330. + pcd->status_buf_dma_handle;
  84331. + ep0->dwc_ep.xfer_len = 1;
  84332. + ep0->dwc_ep.xfer_count = 0;
  84333. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  84334. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  84335. + &ep0->dwc_ep);
  84336. + return;
  84337. + } else {
  84338. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84339. + return;
  84340. + }
  84341. + break;
  84342. + } else {
  84343. + *status = 0x1; /* Self powered */
  84344. + *status |= pcd->remote_wakeup_enable << 1;
  84345. + break;
  84346. + }
  84347. + case UT_INTERFACE:
  84348. + *status = 0;
  84349. + break;
  84350. +
  84351. + case UT_ENDPOINT:
  84352. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  84353. + if (ep == 0 || UGETW(ctrl.wLength) > 2) {
  84354. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84355. + return;
  84356. + }
  84357. + /** @todo check for EP stall */
  84358. + *status = ep->stopped;
  84359. + break;
  84360. + }
  84361. + pcd->ep0_pending = 1;
  84362. + ep0->dwc_ep.start_xfer_buff = (uint8_t *) status;
  84363. + ep0->dwc_ep.xfer_buff = (uint8_t *) status;
  84364. + ep0->dwc_ep.dma_addr = pcd->status_buf_dma_handle;
  84365. + ep0->dwc_ep.xfer_len = 2;
  84366. + ep0->dwc_ep.xfer_count = 0;
  84367. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  84368. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  84369. +}
  84370. +
  84371. +/**
  84372. + * This function process the SET_FEATURE Setup Commands.
  84373. + */
  84374. +static inline void do_set_feature(dwc_otg_pcd_t * pcd)
  84375. +{
  84376. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84377. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  84378. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  84379. + dwc_otg_pcd_ep_t *ep = 0;
  84380. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  84381. + gotgctl_data_t gotgctl = {.d32 = 0 };
  84382. +
  84383. + DWC_DEBUGPL(DBG_PCD, "SET_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  84384. + ctrl.bmRequestType, ctrl.bRequest,
  84385. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  84386. + UGETW(ctrl.wLength));
  84387. + DWC_DEBUGPL(DBG_PCD, "otg_cap=%d\n", otg_cap_param);
  84388. +
  84389. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  84390. + case UT_DEVICE:
  84391. + switch (UGETW(ctrl.wValue)) {
  84392. + case UF_DEVICE_REMOTE_WAKEUP:
  84393. + pcd->remote_wakeup_enable = 1;
  84394. + break;
  84395. +
  84396. + case UF_TEST_MODE:
  84397. + /* Setup the Test Mode tasklet to do the Test
  84398. + * Packet generation after the SETUP Status
  84399. + * phase has completed. */
  84400. +
  84401. + /** @todo This has not been tested since the
  84402. + * tasklet struct was put into the PCD
  84403. + * struct! */
  84404. + pcd->test_mode = UGETW(ctrl.wIndex) >> 8;
  84405. + DWC_TASK_SCHEDULE(pcd->test_mode_tasklet);
  84406. + break;
  84407. +
  84408. + case UF_DEVICE_B_HNP_ENABLE:
  84409. + DWC_DEBUGPL(DBG_PCDV,
  84410. + "SET_FEATURE: USB_DEVICE_B_HNP_ENABLE\n");
  84411. +
  84412. + /* dev may initiate HNP */
  84413. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  84414. + pcd->b_hnp_enable = 1;
  84415. + dwc_otg_pcd_update_otg(pcd, 0);
  84416. + DWC_DEBUGPL(DBG_PCD, "Request B HNP\n");
  84417. + /**@todo Is the gotgctl.devhnpen cleared
  84418. + * by a USB Reset? */
  84419. + gotgctl.b.devhnpen = 1;
  84420. + gotgctl.b.hnpreq = 1;
  84421. + DWC_WRITE_REG32(&global_regs->gotgctl,
  84422. + gotgctl.d32);
  84423. + } else {
  84424. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84425. + return;
  84426. + }
  84427. + break;
  84428. +
  84429. + case UF_DEVICE_A_HNP_SUPPORT:
  84430. + /* RH port supports HNP */
  84431. + DWC_DEBUGPL(DBG_PCDV,
  84432. + "SET_FEATURE: USB_DEVICE_A_HNP_SUPPORT\n");
  84433. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  84434. + pcd->a_hnp_support = 1;
  84435. + dwc_otg_pcd_update_otg(pcd, 0);
  84436. + } else {
  84437. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84438. + return;
  84439. + }
  84440. + break;
  84441. +
  84442. + case UF_DEVICE_A_ALT_HNP_SUPPORT:
  84443. + /* other RH port does */
  84444. + DWC_DEBUGPL(DBG_PCDV,
  84445. + "SET_FEATURE: USB_DEVICE_A_ALT_HNP_SUPPORT\n");
  84446. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  84447. + pcd->a_alt_hnp_support = 1;
  84448. + dwc_otg_pcd_update_otg(pcd, 0);
  84449. + } else {
  84450. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84451. + return;
  84452. + }
  84453. + break;
  84454. +
  84455. + default:
  84456. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84457. + return;
  84458. +
  84459. + }
  84460. + do_setup_in_status_phase(pcd);
  84461. + break;
  84462. +
  84463. + case UT_INTERFACE:
  84464. + do_gadget_setup(pcd, &ctrl);
  84465. + break;
  84466. +
  84467. + case UT_ENDPOINT:
  84468. + if (UGETW(ctrl.wValue) == UF_ENDPOINT_HALT) {
  84469. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  84470. + if (ep == 0) {
  84471. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84472. + return;
  84473. + }
  84474. + ep->stopped = 1;
  84475. + dwc_otg_ep_set_stall(core_if, &ep->dwc_ep);
  84476. + }
  84477. + do_setup_in_status_phase(pcd);
  84478. + break;
  84479. + }
  84480. +}
  84481. +
  84482. +/**
  84483. + * This function process the CLEAR_FEATURE Setup Commands.
  84484. + */
  84485. +static inline void do_clear_feature(dwc_otg_pcd_t * pcd)
  84486. +{
  84487. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  84488. + dwc_otg_pcd_ep_t *ep = 0;
  84489. +
  84490. + DWC_DEBUGPL(DBG_PCD,
  84491. + "CLEAR_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  84492. + ctrl.bmRequestType, ctrl.bRequest,
  84493. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  84494. + UGETW(ctrl.wLength));
  84495. +
  84496. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  84497. + case UT_DEVICE:
  84498. + switch (UGETW(ctrl.wValue)) {
  84499. + case UF_DEVICE_REMOTE_WAKEUP:
  84500. + pcd->remote_wakeup_enable = 0;
  84501. + break;
  84502. +
  84503. + case UF_TEST_MODE:
  84504. + /** @todo Add CLEAR_FEATURE for TEST modes. */
  84505. + break;
  84506. +
  84507. + default:
  84508. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84509. + return;
  84510. + }
  84511. + do_setup_in_status_phase(pcd);
  84512. + break;
  84513. +
  84514. + case UT_ENDPOINT:
  84515. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  84516. + if (ep == 0) {
  84517. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84518. + return;
  84519. + }
  84520. +
  84521. + pcd_clear_halt(pcd, ep);
  84522. +
  84523. + break;
  84524. + }
  84525. +}
  84526. +
  84527. +/**
  84528. + * This function process the SET_ADDRESS Setup Commands.
  84529. + */
  84530. +static inline void do_set_address(dwc_otg_pcd_t * pcd)
  84531. +{
  84532. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  84533. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  84534. +
  84535. + if (ctrl.bmRequestType == UT_DEVICE) {
  84536. + dcfg_data_t dcfg = {.d32 = 0 };
  84537. +
  84538. +#ifdef DEBUG_EP0
  84539. +// DWC_DEBUGPL(DBG_PCDV, "SET_ADDRESS:%d\n", ctrl.wValue);
  84540. +#endif
  84541. + dcfg.b.devaddr = UGETW(ctrl.wValue);
  84542. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dcfg, 0, dcfg.d32);
  84543. + do_setup_in_status_phase(pcd);
  84544. + }
  84545. +}
  84546. +
  84547. +/**
  84548. + * This function processes SETUP commands. In Linux, the USB Command
  84549. + * processing is done in two places - the first being the PCD and the
  84550. + * second in the Gadget Driver (for example, the File-Backed Storage
  84551. + * Gadget Driver).
  84552. + *
  84553. + * <table>
  84554. + * <tr><td>Command </td><td>Driver </td><td>Description</td></tr>
  84555. + *
  84556. + * <tr><td>GET_STATUS </td><td>PCD </td><td>Command is processed as
  84557. + * defined in chapter 9 of the USB 2.0 Specification chapter 9
  84558. + * </td></tr>
  84559. + *
  84560. + * <tr><td>CLEAR_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  84561. + * requests are the ENDPOINT_HALT feature is procesed, all others the
  84562. + * interface requests are ignored.</td></tr>
  84563. + *
  84564. + * <tr><td>SET_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  84565. + * requests are processed by the PCD. Interface requests are passed
  84566. + * to the Gadget Driver.</td></tr>
  84567. + *
  84568. + * <tr><td>SET_ADDRESS </td><td>PCD </td><td>Program the DCFG reg,
  84569. + * with device address received </td></tr>
  84570. + *
  84571. + * <tr><td>GET_DESCRIPTOR </td><td>Gadget Driver </td><td>Return the
  84572. + * requested descriptor</td></tr>
  84573. + *
  84574. + * <tr><td>SET_DESCRIPTOR </td><td>Gadget Driver </td><td>Optional -
  84575. + * not implemented by any of the existing Gadget Drivers.</td></tr>
  84576. + *
  84577. + * <tr><td>SET_CONFIGURATION </td><td>Gadget Driver </td><td>Disable
  84578. + * all EPs and enable EPs for new configuration.</td></tr>
  84579. + *
  84580. + * <tr><td>GET_CONFIGURATION </td><td>Gadget Driver </td><td>Return
  84581. + * the current configuration</td></tr>
  84582. + *
  84583. + * <tr><td>SET_INTERFACE </td><td>Gadget Driver </td><td>Disable all
  84584. + * EPs and enable EPs for new configuration.</td></tr>
  84585. + *
  84586. + * <tr><td>GET_INTERFACE </td><td>Gadget Driver </td><td>Return the
  84587. + * current interface.</td></tr>
  84588. + *
  84589. + * <tr><td>SYNC_FRAME </td><td>PCD </td><td>Display debug
  84590. + * message.</td></tr>
  84591. + * </table>
  84592. + *
  84593. + * When the SETUP Phase Done interrupt occurs, the PCD SETUP commands are
  84594. + * processed by pcd_setup. Calling the Function Driver's setup function from
  84595. + * pcd_setup processes the gadget SETUP commands.
  84596. + */
  84597. +static inline void pcd_setup(dwc_otg_pcd_t * pcd)
  84598. +{
  84599. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84600. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  84601. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  84602. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  84603. +
  84604. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  84605. +
  84606. +#ifdef DWC_UTE_CFI
  84607. + int retval = 0;
  84608. + struct cfi_usb_ctrlrequest cfi_req;
  84609. +#endif
  84610. +
  84611. + doeptsize0.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doeptsiz);
  84612. +
  84613. + /** In BDMA more then 1 setup packet is not supported till 3.00a */
  84614. + if (core_if->dma_enable && core_if->dma_desc_enable == 0
  84615. + && (doeptsize0.b.supcnt < 2)
  84616. + && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  84617. + DWC_ERROR
  84618. + ("\n\n----------- CANNOT handle > 1 setup packet in DMA mode\n\n");
  84619. + }
  84620. + if ((core_if->snpsid >= OTG_CORE_REV_3_00a)
  84621. + && (core_if->dma_enable == 1) && (core_if->dma_desc_enable == 0)) {
  84622. + ctrl =
  84623. + (pcd->setup_pkt +
  84624. + (3 - doeptsize0.b.supcnt - 1 +
  84625. + ep0->dwc_ep.stp_rollover))->req;
  84626. + }
  84627. +#ifdef DEBUG_EP0
  84628. + DWC_DEBUGPL(DBG_PCD, "SETUP %02x.%02x v%04x i%04x l%04x\n",
  84629. + ctrl.bmRequestType, ctrl.bRequest,
  84630. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  84631. + UGETW(ctrl.wLength));
  84632. +#endif
  84633. +
  84634. + /* Clean up the request queue */
  84635. + dwc_otg_request_nuke(ep0);
  84636. + ep0->stopped = 0;
  84637. +
  84638. + if (ctrl.bmRequestType & UE_DIR_IN) {
  84639. + ep0->dwc_ep.is_in = 1;
  84640. + pcd->ep0state = EP0_IN_DATA_PHASE;
  84641. + } else {
  84642. + ep0->dwc_ep.is_in = 0;
  84643. + pcd->ep0state = EP0_OUT_DATA_PHASE;
  84644. + }
  84645. +
  84646. + if (UGETW(ctrl.wLength) == 0) {
  84647. + ep0->dwc_ep.is_in = 1;
  84648. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  84649. + }
  84650. +
  84651. + if (UT_GET_TYPE(ctrl.bmRequestType) != UT_STANDARD) {
  84652. +
  84653. +#ifdef DWC_UTE_CFI
  84654. + DWC_MEMCPY(&cfi_req, &ctrl, sizeof(usb_device_request_t));
  84655. +
  84656. + //printk(KERN_ALERT "CFI: req_type=0x%02x; req=0x%02x\n",
  84657. + ctrl.bRequestType, ctrl.bRequest);
  84658. + if (UT_GET_TYPE(cfi_req.bRequestType) == UT_VENDOR) {
  84659. + if (cfi_req.bRequest > 0xB0 && cfi_req.bRequest < 0xBF) {
  84660. + retval = cfi_setup(pcd, &cfi_req);
  84661. + if (retval < 0) {
  84662. + ep0_do_stall(pcd, retval);
  84663. + pcd->ep0_pending = 0;
  84664. + return;
  84665. + }
  84666. +
  84667. + /* if need gadget setup then call it and check the retval */
  84668. + if (pcd->cfi->need_gadget_att) {
  84669. + retval =
  84670. + cfi_gadget_setup(pcd,
  84671. + &pcd->
  84672. + cfi->ctrl_req);
  84673. + if (retval < 0) {
  84674. + pcd->ep0_pending = 0;
  84675. + return;
  84676. + }
  84677. + }
  84678. +
  84679. + if (pcd->cfi->need_status_in_complete) {
  84680. + do_setup_in_status_phase(pcd);
  84681. + }
  84682. + return;
  84683. + }
  84684. + }
  84685. +#endif
  84686. +
  84687. + /* handle non-standard (class/vendor) requests in the gadget driver */
  84688. + do_gadget_setup(pcd, &ctrl);
  84689. + return;
  84690. + }
  84691. +
  84692. + /** @todo NGS: Handle bad setup packet? */
  84693. +
  84694. +///////////////////////////////////////////
  84695. +//// --- Standard Request handling --- ////
  84696. +
  84697. + switch (ctrl.bRequest) {
  84698. + case UR_GET_STATUS:
  84699. + do_get_status(pcd);
  84700. + break;
  84701. +
  84702. + case UR_CLEAR_FEATURE:
  84703. + do_clear_feature(pcd);
  84704. + break;
  84705. +
  84706. + case UR_SET_FEATURE:
  84707. + do_set_feature(pcd);
  84708. + break;
  84709. +
  84710. + case UR_SET_ADDRESS:
  84711. + do_set_address(pcd);
  84712. + break;
  84713. +
  84714. + case UR_SET_INTERFACE:
  84715. + case UR_SET_CONFIG:
  84716. +// _pcd->request_config = 1; /* Configuration changed */
  84717. + do_gadget_setup(pcd, &ctrl);
  84718. + break;
  84719. +
  84720. + case UR_SYNCH_FRAME:
  84721. + do_gadget_setup(pcd, &ctrl);
  84722. + break;
  84723. +
  84724. + default:
  84725. + /* Call the Gadget Driver's setup functions */
  84726. + do_gadget_setup(pcd, &ctrl);
  84727. + break;
  84728. + }
  84729. +}
  84730. +
  84731. +/**
  84732. + * This function completes the ep0 control transfer.
  84733. + */
  84734. +static int32_t ep0_complete_request(dwc_otg_pcd_ep_t * ep)
  84735. +{
  84736. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  84737. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  84738. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  84739. + dev_if->in_ep_regs[ep->dwc_ep.num];
  84740. +#ifdef DEBUG_EP0
  84741. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  84742. + dev_if->out_ep_regs[ep->dwc_ep.num];
  84743. +#endif
  84744. + deptsiz0_data_t deptsiz;
  84745. + dev_dma_desc_sts_t desc_sts;
  84746. + dwc_otg_pcd_request_t *req;
  84747. + int is_last = 0;
  84748. + dwc_otg_pcd_t *pcd = ep->pcd;
  84749. +
  84750. +#ifdef DWC_UTE_CFI
  84751. + struct cfi_usb_ctrlrequest *ctrlreq;
  84752. + int retval = -DWC_E_NOT_SUPPORTED;
  84753. +#endif
  84754. +
  84755. + desc_sts.b.bytes = 0;
  84756. +
  84757. + if (pcd->ep0_pending && DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  84758. + if (ep->dwc_ep.is_in) {
  84759. +#ifdef DEBUG_EP0
  84760. + DWC_DEBUGPL(DBG_PCDV, "Do setup OUT status phase\n");
  84761. +#endif
  84762. + do_setup_out_status_phase(pcd);
  84763. + } else {
  84764. +#ifdef DEBUG_EP0
  84765. + DWC_DEBUGPL(DBG_PCDV, "Do setup IN status phase\n");
  84766. +#endif
  84767. +
  84768. +#ifdef DWC_UTE_CFI
  84769. + ctrlreq = &pcd->cfi->ctrl_req;
  84770. +
  84771. + if (UT_GET_TYPE(ctrlreq->bRequestType) == UT_VENDOR) {
  84772. + if (ctrlreq->bRequest > 0xB0
  84773. + && ctrlreq->bRequest < 0xBF) {
  84774. +
  84775. + /* Return if the PCD failed to handle the request */
  84776. + if ((retval =
  84777. + pcd->cfi->ops.
  84778. + ctrl_write_complete(pcd->cfi,
  84779. + pcd)) < 0) {
  84780. + CFI_INFO
  84781. + ("ERROR setting a new value in the PCD(%d)\n",
  84782. + retval);
  84783. + ep0_do_stall(pcd, retval);
  84784. + pcd->ep0_pending = 0;
  84785. + return 0;
  84786. + }
  84787. +
  84788. + /* If the gadget needs to be notified on the request */
  84789. + if (pcd->cfi->need_gadget_att == 1) {
  84790. + //retval = do_gadget_setup(pcd, &pcd->cfi->ctrl_req);
  84791. + retval =
  84792. + cfi_gadget_setup(pcd,
  84793. + &pcd->cfi->
  84794. + ctrl_req);
  84795. +
  84796. + /* Return from the function if the gadget failed to process
  84797. + * the request properly - this should never happen !!!
  84798. + */
  84799. + if (retval < 0) {
  84800. + CFI_INFO
  84801. + ("ERROR setting a new value in the gadget(%d)\n",
  84802. + retval);
  84803. + pcd->ep0_pending = 0;
  84804. + return 0;
  84805. + }
  84806. + }
  84807. +
  84808. + CFI_INFO("%s: RETVAL=%d\n", __func__,
  84809. + retval);
  84810. + /* If we hit here then the PCD and the gadget has properly
  84811. + * handled the request - so send the ZLP IN to the host.
  84812. + */
  84813. + /* @todo: MAS - decide whether we need to start the setup
  84814. + * stage based on the need_setup value of the cfi object
  84815. + */
  84816. + do_setup_in_status_phase(pcd);
  84817. + pcd->ep0_pending = 0;
  84818. + return 1;
  84819. + }
  84820. + }
  84821. +#endif
  84822. +
  84823. + do_setup_in_status_phase(pcd);
  84824. + }
  84825. + pcd->ep0_pending = 0;
  84826. + return 1;
  84827. + }
  84828. +
  84829. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  84830. + return 0;
  84831. + }
  84832. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  84833. +
  84834. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE
  84835. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  84836. + is_last = 1;
  84837. + } else if (ep->dwc_ep.is_in) {
  84838. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  84839. + if (core_if->dma_desc_enable != 0)
  84840. + desc_sts = dev_if->in_desc_addr->status;
  84841. +#ifdef DEBUG_EP0
  84842. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xfersize=%d pktcnt=%d\n",
  84843. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  84844. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  84845. +#endif
  84846. +
  84847. + if (((core_if->dma_desc_enable == 0)
  84848. + && (deptsiz.b.xfersize == 0))
  84849. + || ((core_if->dma_desc_enable != 0)
  84850. + && (desc_sts.b.bytes == 0))) {
  84851. + req->actual = ep->dwc_ep.xfer_count;
  84852. + /* Is a Zero Len Packet needed? */
  84853. + if (req->sent_zlp) {
  84854. +#ifdef DEBUG_EP0
  84855. + DWC_DEBUGPL(DBG_PCD, "Setup Rx ZLP\n");
  84856. +#endif
  84857. + req->sent_zlp = 0;
  84858. + }
  84859. + do_setup_out_status_phase(pcd);
  84860. + }
  84861. + } else {
  84862. + /* ep0-OUT */
  84863. +#ifdef DEBUG_EP0
  84864. + deptsiz.d32 = DWC_READ_REG32(&out_ep_regs->doeptsiz);
  84865. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xsize=%d pktcnt=%d\n",
  84866. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  84867. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  84868. +#endif
  84869. + req->actual = ep->dwc_ep.xfer_count;
  84870. +
  84871. + /* Is a Zero Len Packet needed? */
  84872. + if (req->sent_zlp) {
  84873. +#ifdef DEBUG_EP0
  84874. + DWC_DEBUGPL(DBG_PCDV, "Setup Tx ZLP\n");
  84875. +#endif
  84876. + req->sent_zlp = 0;
  84877. + }
  84878. + /* For older cores do setup in status phase in Slave/BDMA modes,
  84879. + * starting from 3.00 do that only in slave, and for DMA modes
  84880. + * just re-enable ep 0 OUT here*/
  84881. + if (core_if->dma_enable == 0
  84882. + || (core_if->dma_desc_enable == 0
  84883. + && core_if->snpsid <= OTG_CORE_REV_2_94a)) {
  84884. + do_setup_in_status_phase(pcd);
  84885. + } else if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  84886. + DWC_DEBUGPL(DBG_PCDV,
  84887. + "Enable out ep before in status phase\n");
  84888. + ep0_out_start(core_if, pcd);
  84889. + }
  84890. + }
  84891. +
  84892. + /* Complete the request */
  84893. + if (is_last) {
  84894. + dwc_otg_request_done(ep, req, 0);
  84895. + ep->dwc_ep.start_xfer_buff = 0;
  84896. + ep->dwc_ep.xfer_buff = 0;
  84897. + ep->dwc_ep.xfer_len = 0;
  84898. + return 1;
  84899. + }
  84900. + return 0;
  84901. +}
  84902. +
  84903. +#ifdef DWC_UTE_CFI
  84904. +/**
  84905. + * This function calculates traverses all the CFI DMA descriptors and
  84906. + * and accumulates the bytes that are left to be transfered.
  84907. + *
  84908. + * @return The total bytes left to transfered, or a negative value as failure
  84909. + */
  84910. +static inline int cfi_calc_desc_residue(dwc_otg_pcd_ep_t * ep)
  84911. +{
  84912. + int32_t ret = 0;
  84913. + int i;
  84914. + struct dwc_otg_dma_desc *ddesc = NULL;
  84915. + struct cfi_ep *cfiep;
  84916. +
  84917. + /* See if the pcd_ep has its respective cfi_ep mapped */
  84918. + cfiep = get_cfi_ep_by_pcd_ep(ep->pcd->cfi, ep);
  84919. + if (!cfiep) {
  84920. + CFI_INFO("%s: Failed to find ep\n", __func__);
  84921. + return -1;
  84922. + }
  84923. +
  84924. + ddesc = ep->dwc_ep.descs;
  84925. +
  84926. + for (i = 0; (i < cfiep->desc_count) && (i < MAX_DMA_DESCS_PER_EP); i++) {
  84927. +
  84928. +#if defined(PRINT_CFI_DMA_DESCS)
  84929. + print_desc(ddesc, ep->ep.name, i);
  84930. +#endif
  84931. + ret += ddesc->status.b.bytes;
  84932. + ddesc++;
  84933. + }
  84934. +
  84935. + if (ret)
  84936. + CFI_INFO("!!!!!!!!!! WARNING (%s) - residue=%d\n", __func__,
  84937. + ret);
  84938. +
  84939. + return ret;
  84940. +}
  84941. +#endif
  84942. +
  84943. +/**
  84944. + * This function completes the request for the EP. If there are
  84945. + * additional requests for the EP in the queue they will be started.
  84946. + */
  84947. +static void complete_ep(dwc_otg_pcd_ep_t * ep)
  84948. +{
  84949. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  84950. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  84951. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  84952. + dev_if->in_ep_regs[ep->dwc_ep.num];
  84953. + deptsiz_data_t deptsiz;
  84954. + dev_dma_desc_sts_t desc_sts;
  84955. + dwc_otg_pcd_request_t *req = 0;
  84956. + dwc_otg_dev_dma_desc_t *dma_desc;
  84957. + uint32_t byte_count = 0;
  84958. + int is_last = 0;
  84959. + int i;
  84960. +
  84961. + DWC_DEBUGPL(DBG_PCDV, "%s() %d-%s\n", __func__, ep->dwc_ep.num,
  84962. + (ep->dwc_ep.is_in ? "IN" : "OUT"));
  84963. +
  84964. + /* Get any pending requests */
  84965. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  84966. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  84967. + if (!req) {
  84968. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  84969. + return;
  84970. + }
  84971. + } else {
  84972. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  84973. + return;
  84974. + }
  84975. +
  84976. + DWC_DEBUGPL(DBG_PCD, "Requests %d\n", ep->pcd->request_pending);
  84977. +
  84978. + if (ep->dwc_ep.is_in) {
  84979. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  84980. +
  84981. + if (core_if->dma_enable) {
  84982. + if (core_if->dma_desc_enable == 0) {
  84983. + if (deptsiz.b.xfersize == 0
  84984. + && deptsiz.b.pktcnt == 0) {
  84985. + byte_count =
  84986. + ep->dwc_ep.xfer_len -
  84987. + ep->dwc_ep.xfer_count;
  84988. +
  84989. + ep->dwc_ep.xfer_buff += byte_count;
  84990. + ep->dwc_ep.dma_addr += byte_count;
  84991. + ep->dwc_ep.xfer_count += byte_count;
  84992. +
  84993. + DWC_DEBUGPL(DBG_PCDV,
  84994. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  84995. + ep->dwc_ep.num,
  84996. + (ep->dwc_ep.
  84997. + is_in ? "IN" : "OUT"),
  84998. + ep->dwc_ep.xfer_len,
  84999. + deptsiz.b.xfersize,
  85000. + deptsiz.b.pktcnt);
  85001. +
  85002. + if (ep->dwc_ep.xfer_len <
  85003. + ep->dwc_ep.total_len) {
  85004. + dwc_otg_ep_start_transfer
  85005. + (core_if, &ep->dwc_ep);
  85006. + } else if (ep->dwc_ep.sent_zlp) {
  85007. + /*
  85008. + * This fragment of code should initiate 0
  85009. + * length transfer in case if it is queued
  85010. + * a transfer with size divisible to EPs max
  85011. + * packet size and with usb_request zero field
  85012. + * is set, which means that after data is transfered,
  85013. + * it is also should be transfered
  85014. + * a 0 length packet at the end. For Slave and
  85015. + * Buffer DMA modes in this case SW has
  85016. + * to initiate 2 transfers one with transfer size,
  85017. + * and the second with 0 size. For Descriptor
  85018. + * DMA mode SW is able to initiate a transfer,
  85019. + * which will handle all the packets including
  85020. + * the last 0 length.
  85021. + */
  85022. + ep->dwc_ep.sent_zlp = 0;
  85023. + dwc_otg_ep_start_zl_transfer
  85024. + (core_if, &ep->dwc_ep);
  85025. + } else {
  85026. + is_last = 1;
  85027. + }
  85028. + } else {
  85029. + if (ep->dwc_ep.type ==
  85030. + DWC_OTG_EP_TYPE_ISOC) {
  85031. + req->actual = 0;
  85032. + dwc_otg_request_done(ep, req, 0);
  85033. +
  85034. + ep->dwc_ep.start_xfer_buff = 0;
  85035. + ep->dwc_ep.xfer_buff = 0;
  85036. + ep->dwc_ep.xfer_len = 0;
  85037. +
  85038. + /* If there is a request in the queue start it. */
  85039. + start_next_request(ep);
  85040. + } else
  85041. + DWC_WARN
  85042. + ("Incomplete transfer (%d - %s [siz=%d pkt=%d])\n",
  85043. + ep->dwc_ep.num,
  85044. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  85045. + deptsiz.b.xfersize,
  85046. + deptsiz.b.pktcnt);
  85047. + }
  85048. + } else {
  85049. + dma_desc = ep->dwc_ep.desc_addr;
  85050. + byte_count = 0;
  85051. + ep->dwc_ep.sent_zlp = 0;
  85052. +
  85053. +#ifdef DWC_UTE_CFI
  85054. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  85055. + ep->dwc_ep.buff_mode);
  85056. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  85057. + int residue;
  85058. +
  85059. + residue = cfi_calc_desc_residue(ep);
  85060. + if (residue < 0)
  85061. + return;
  85062. +
  85063. + byte_count = residue;
  85064. + } else {
  85065. +#endif
  85066. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  85067. + ++i) {
  85068. + desc_sts = dma_desc->status;
  85069. + byte_count += desc_sts.b.bytes;
  85070. + dma_desc++;
  85071. + }
  85072. +#ifdef DWC_UTE_CFI
  85073. + }
  85074. +#endif
  85075. + if (byte_count == 0) {
  85076. + ep->dwc_ep.xfer_count =
  85077. + ep->dwc_ep.total_len;
  85078. + is_last = 1;
  85079. + } else {
  85080. + DWC_WARN("Incomplete transfer\n");
  85081. + }
  85082. + }
  85083. + } else {
  85084. + if (deptsiz.b.xfersize == 0 && deptsiz.b.pktcnt == 0) {
  85085. + DWC_DEBUGPL(DBG_PCDV,
  85086. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  85087. + ep->dwc_ep.num,
  85088. + ep->dwc_ep.is_in ? "IN" : "OUT",
  85089. + ep->dwc_ep.xfer_len,
  85090. + deptsiz.b.xfersize,
  85091. + deptsiz.b.pktcnt);
  85092. +
  85093. + /* Check if the whole transfer was completed,
  85094. + * if no, setup transfer for next portion of data
  85095. + */
  85096. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  85097. + dwc_otg_ep_start_transfer(core_if,
  85098. + &ep->dwc_ep);
  85099. + } else if (ep->dwc_ep.sent_zlp) {
  85100. + /*
  85101. + * This fragment of code should initiate 0
  85102. + * length trasfer in case if it is queued
  85103. + * a trasfer with size divisible to EPs max
  85104. + * packet size and with usb_request zero field
  85105. + * is set, which means that after data is transfered,
  85106. + * it is also should be transfered
  85107. + * a 0 length packet at the end. For Slave and
  85108. + * Buffer DMA modes in this case SW has
  85109. + * to initiate 2 transfers one with transfer size,
  85110. + * and the second with 0 size. For Desriptor
  85111. + * DMA mode SW is able to initiate a transfer,
  85112. + * which will handle all the packets including
  85113. + * the last 0 legth.
  85114. + */
  85115. + ep->dwc_ep.sent_zlp = 0;
  85116. + dwc_otg_ep_start_zl_transfer(core_if,
  85117. + &ep->dwc_ep);
  85118. + } else {
  85119. + is_last = 1;
  85120. + }
  85121. + } else {
  85122. + DWC_WARN
  85123. + ("Incomplete transfer (%d-%s [siz=%d pkt=%d])\n",
  85124. + ep->dwc_ep.num,
  85125. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  85126. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  85127. + }
  85128. + }
  85129. + } else {
  85130. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  85131. + dev_if->out_ep_regs[ep->dwc_ep.num];
  85132. + desc_sts.d32 = 0;
  85133. + if (core_if->dma_enable) {
  85134. + if (core_if->dma_desc_enable) {
  85135. + dma_desc = ep->dwc_ep.desc_addr;
  85136. + byte_count = 0;
  85137. + ep->dwc_ep.sent_zlp = 0;
  85138. +
  85139. +#ifdef DWC_UTE_CFI
  85140. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  85141. + ep->dwc_ep.buff_mode);
  85142. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  85143. + int residue;
  85144. + residue = cfi_calc_desc_residue(ep);
  85145. + if (residue < 0)
  85146. + return;
  85147. + byte_count = residue;
  85148. + } else {
  85149. +#endif
  85150. +
  85151. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  85152. + ++i) {
  85153. + desc_sts = dma_desc->status;
  85154. + byte_count += desc_sts.b.bytes;
  85155. + dma_desc++;
  85156. + }
  85157. +
  85158. +#ifdef DWC_UTE_CFI
  85159. + }
  85160. +#endif
  85161. + /* Checking for interrupt Out transfers with not
  85162. + * dword aligned mps sizes
  85163. + */
  85164. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_INTR &&
  85165. + (ep->dwc_ep.maxpacket%4)) {
  85166. + ep->dwc_ep.xfer_count =
  85167. + ep->dwc_ep.total_len - byte_count;
  85168. + if ((ep->dwc_ep.xfer_len %
  85169. + ep->dwc_ep.maxpacket)
  85170. + && (ep->dwc_ep.xfer_len /
  85171. + ep->dwc_ep.maxpacket <
  85172. + MAX_DMA_DESC_CNT))
  85173. + ep->dwc_ep.xfer_len -=
  85174. + (ep->dwc_ep.desc_cnt -
  85175. + 1) * ep->dwc_ep.maxpacket +
  85176. + ep->dwc_ep.xfer_len %
  85177. + ep->dwc_ep.maxpacket;
  85178. + else
  85179. + ep->dwc_ep.xfer_len -=
  85180. + ep->dwc_ep.desc_cnt *
  85181. + ep->dwc_ep.maxpacket;
  85182. + if (ep->dwc_ep.xfer_len > 0) {
  85183. + dwc_otg_ep_start_transfer
  85184. + (core_if, &ep->dwc_ep);
  85185. + } else {
  85186. + is_last = 1;
  85187. + }
  85188. + } else {
  85189. + ep->dwc_ep.xfer_count =
  85190. + ep->dwc_ep.total_len - byte_count +
  85191. + ((4 -
  85192. + (ep->dwc_ep.
  85193. + total_len & 0x3)) & 0x3);
  85194. + is_last = 1;
  85195. + }
  85196. + } else {
  85197. + deptsiz.d32 = 0;
  85198. + deptsiz.d32 =
  85199. + DWC_READ_REG32(&out_ep_regs->doeptsiz);
  85200. +
  85201. + byte_count = (ep->dwc_ep.xfer_len -
  85202. + ep->dwc_ep.xfer_count -
  85203. + deptsiz.b.xfersize);
  85204. + ep->dwc_ep.xfer_buff += byte_count;
  85205. + ep->dwc_ep.dma_addr += byte_count;
  85206. + ep->dwc_ep.xfer_count += byte_count;
  85207. +
  85208. + /* Check if the whole transfer was completed,
  85209. + * if no, setup transfer for next portion of data
  85210. + */
  85211. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  85212. + dwc_otg_ep_start_transfer(core_if,
  85213. + &ep->dwc_ep);
  85214. + } else if (ep->dwc_ep.sent_zlp) {
  85215. + /*
  85216. + * This fragment of code should initiate 0
  85217. + * length trasfer in case if it is queued
  85218. + * a trasfer with size divisible to EPs max
  85219. + * packet size and with usb_request zero field
  85220. + * is set, which means that after data is transfered,
  85221. + * it is also should be transfered
  85222. + * a 0 length packet at the end. For Slave and
  85223. + * Buffer DMA modes in this case SW has
  85224. + * to initiate 2 transfers one with transfer size,
  85225. + * and the second with 0 size. For Desriptor
  85226. + * DMA mode SW is able to initiate a transfer,
  85227. + * which will handle all the packets including
  85228. + * the last 0 legth.
  85229. + */
  85230. + ep->dwc_ep.sent_zlp = 0;
  85231. + dwc_otg_ep_start_zl_transfer(core_if,
  85232. + &ep->dwc_ep);
  85233. + } else {
  85234. + is_last = 1;
  85235. + }
  85236. + }
  85237. + } else {
  85238. + /* Check if the whole transfer was completed,
  85239. + * if no, setup transfer for next portion of data
  85240. + */
  85241. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  85242. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  85243. + } else if (ep->dwc_ep.sent_zlp) {
  85244. + /*
  85245. + * This fragment of code should initiate 0
  85246. + * length transfer in case if it is queued
  85247. + * a transfer with size divisible to EPs max
  85248. + * packet size and with usb_request zero field
  85249. + * is set, which means that after data is transfered,
  85250. + * it is also should be transfered
  85251. + * a 0 length packet at the end. For Slave and
  85252. + * Buffer DMA modes in this case SW has
  85253. + * to initiate 2 transfers one with transfer size,
  85254. + * and the second with 0 size. For Descriptor
  85255. + * DMA mode SW is able to initiate a transfer,
  85256. + * which will handle all the packets including
  85257. + * the last 0 length.
  85258. + */
  85259. + ep->dwc_ep.sent_zlp = 0;
  85260. + dwc_otg_ep_start_zl_transfer(core_if,
  85261. + &ep->dwc_ep);
  85262. + } else {
  85263. + is_last = 1;
  85264. + }
  85265. + }
  85266. +
  85267. + DWC_DEBUGPL(DBG_PCDV,
  85268. + "addr %p, %d-%s len=%d cnt=%d xsize=%d pktcnt=%d\n",
  85269. + &out_ep_regs->doeptsiz, ep->dwc_ep.num,
  85270. + ep->dwc_ep.is_in ? "IN" : "OUT",
  85271. + ep->dwc_ep.xfer_len, ep->dwc_ep.xfer_count,
  85272. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  85273. + }
  85274. +
  85275. + /* Complete the request */
  85276. + if (is_last) {
  85277. +#ifdef DWC_UTE_CFI
  85278. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  85279. + req->actual = ep->dwc_ep.cfi_req_len - byte_count;
  85280. + } else {
  85281. +#endif
  85282. + req->actual = ep->dwc_ep.xfer_count;
  85283. +#ifdef DWC_UTE_CFI
  85284. + }
  85285. +#endif
  85286. + if (req->dw_align_buf) {
  85287. + if (!ep->dwc_ep.is_in) {
  85288. + dwc_memcpy(req->buf, req->dw_align_buf, req->length);
  85289. + }
  85290. + DWC_DMA_FREE(req->length, req->dw_align_buf,
  85291. + req->dw_align_buf_dma);
  85292. + }
  85293. +
  85294. + dwc_otg_request_done(ep, req, 0);
  85295. +
  85296. + ep->dwc_ep.start_xfer_buff = 0;
  85297. + ep->dwc_ep.xfer_buff = 0;
  85298. + ep->dwc_ep.xfer_len = 0;
  85299. +
  85300. + /* If there is a request in the queue start it. */
  85301. + start_next_request(ep);
  85302. + }
  85303. +}
  85304. +
  85305. +#ifdef DWC_EN_ISOC
  85306. +
  85307. +/**
  85308. + * This function BNA interrupt for Isochronous EPs
  85309. + *
  85310. + */
  85311. +static void dwc_otg_pcd_handle_iso_bna(dwc_otg_pcd_ep_t * ep)
  85312. +{
  85313. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  85314. + volatile uint32_t *addr;
  85315. + depctl_data_t depctl = {.d32 = 0 };
  85316. + dwc_otg_pcd_t *pcd = ep->pcd;
  85317. + dwc_otg_dev_dma_desc_t *dma_desc;
  85318. + int i;
  85319. +
  85320. + dma_desc =
  85321. + dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * (dwc_ep->proc_buf_num);
  85322. +
  85323. + if (dwc_ep->is_in) {
  85324. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  85325. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  85326. + sts.d32 = dma_desc->status.d32;
  85327. + sts.b_iso_in.bs = BS_HOST_READY;
  85328. + dma_desc->status.d32 = sts.d32;
  85329. + }
  85330. + } else {
  85331. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  85332. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  85333. + sts.d32 = dma_desc->status.d32;
  85334. + sts.b_iso_out.bs = BS_HOST_READY;
  85335. + dma_desc->status.d32 = sts.d32;
  85336. + }
  85337. + }
  85338. +
  85339. + if (dwc_ep->is_in == 0) {
  85340. + addr =
  85341. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->
  85342. + num]->doepctl;
  85343. + } else {
  85344. + addr =
  85345. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  85346. + }
  85347. + depctl.b.epena = 1;
  85348. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  85349. +}
  85350. +
  85351. +/**
  85352. + * This function sets latest iso packet information(non-PTI mode)
  85353. + *
  85354. + * @param core_if Programming view of DWC_otg controller.
  85355. + * @param ep The EP to start the transfer on.
  85356. + *
  85357. + */
  85358. +void set_current_pkt_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  85359. +{
  85360. + deptsiz_data_t deptsiz = {.d32 = 0 };
  85361. + dma_addr_t dma_addr;
  85362. + uint32_t offset;
  85363. +
  85364. + if (ep->proc_buf_num)
  85365. + dma_addr = ep->dma_addr1;
  85366. + else
  85367. + dma_addr = ep->dma_addr0;
  85368. +
  85369. + if (ep->is_in) {
  85370. + deptsiz.d32 =
  85371. + DWC_READ_REG32(&core_if->dev_if->
  85372. + in_ep_regs[ep->num]->dieptsiz);
  85373. + offset = ep->data_per_frame;
  85374. + } else {
  85375. + deptsiz.d32 =
  85376. + DWC_READ_REG32(&core_if->dev_if->
  85377. + out_ep_regs[ep->num]->doeptsiz);
  85378. + offset =
  85379. + ep->data_per_frame +
  85380. + (0x4 & (0x4 - (ep->data_per_frame & 0x3)));
  85381. + }
  85382. +
  85383. + if (!deptsiz.b.xfersize) {
  85384. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  85385. + ep->pkt_info[ep->cur_pkt].offset =
  85386. + ep->cur_pkt_dma_addr - dma_addr;
  85387. + ep->pkt_info[ep->cur_pkt].status = 0;
  85388. + } else {
  85389. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  85390. + ep->pkt_info[ep->cur_pkt].offset =
  85391. + ep->cur_pkt_dma_addr - dma_addr;
  85392. + ep->pkt_info[ep->cur_pkt].status = -DWC_E_NO_DATA;
  85393. + }
  85394. + ep->cur_pkt_addr += offset;
  85395. + ep->cur_pkt_dma_addr += offset;
  85396. + ep->cur_pkt++;
  85397. +}
  85398. +
  85399. +/**
  85400. + * This function sets latest iso packet information(DDMA mode)
  85401. + *
  85402. + * @param core_if Programming view of DWC_otg controller.
  85403. + * @param dwc_ep The EP to start the transfer on.
  85404. + *
  85405. + */
  85406. +static void set_ddma_iso_pkts_info(dwc_otg_core_if_t * core_if,
  85407. + dwc_ep_t * dwc_ep)
  85408. +{
  85409. + dwc_otg_dev_dma_desc_t *dma_desc;
  85410. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  85411. + iso_pkt_info_t *iso_packet;
  85412. + uint32_t data_per_desc;
  85413. + uint32_t offset;
  85414. + int i, j;
  85415. +
  85416. + iso_packet = dwc_ep->pkt_info;
  85417. +
  85418. + /** Reinit closed DMA Descriptors*/
  85419. + /** ISO OUT EP */
  85420. + if (dwc_ep->is_in == 0) {
  85421. + dma_desc =
  85422. + dwc_ep->iso_desc_addr +
  85423. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  85424. + offset = 0;
  85425. +
  85426. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  85427. + i += dwc_ep->pkt_per_frm) {
  85428. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  85429. + data_per_desc =
  85430. + ((j + 1) * dwc_ep->maxpacket >
  85431. + dwc_ep->
  85432. + data_per_frame) ? dwc_ep->data_per_frame -
  85433. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  85434. + data_per_desc +=
  85435. + (data_per_desc % 4) ? (4 -
  85436. + data_per_desc %
  85437. + 4) : 0;
  85438. +
  85439. + sts.d32 = dma_desc->status.d32;
  85440. +
  85441. + /* Write status in iso_packet_decsriptor */
  85442. + iso_packet->status =
  85443. + sts.b_iso_out.rxsts +
  85444. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  85445. + if (iso_packet->status) {
  85446. + iso_packet->status = -DWC_E_NO_DATA;
  85447. + }
  85448. +
  85449. + /* Received data length */
  85450. + if (!sts.b_iso_out.rxbytes) {
  85451. + iso_packet->length =
  85452. + data_per_desc -
  85453. + sts.b_iso_out.rxbytes;
  85454. + } else {
  85455. + iso_packet->length =
  85456. + data_per_desc -
  85457. + sts.b_iso_out.rxbytes + (4 -
  85458. + dwc_ep->data_per_frame
  85459. + % 4);
  85460. + }
  85461. +
  85462. + iso_packet->offset = offset;
  85463. +
  85464. + offset += data_per_desc;
  85465. + dma_desc++;
  85466. + iso_packet++;
  85467. + }
  85468. + }
  85469. +
  85470. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  85471. + data_per_desc =
  85472. + ((j + 1) * dwc_ep->maxpacket >
  85473. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  85474. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  85475. + data_per_desc +=
  85476. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  85477. +
  85478. + sts.d32 = dma_desc->status.d32;
  85479. +
  85480. + /* Write status in iso_packet_decsriptor */
  85481. + iso_packet->status =
  85482. + sts.b_iso_out.rxsts +
  85483. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  85484. + if (iso_packet->status) {
  85485. + iso_packet->status = -DWC_E_NO_DATA;
  85486. + }
  85487. +
  85488. + /* Received data length */
  85489. + iso_packet->length =
  85490. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  85491. +
  85492. + iso_packet->offset = offset;
  85493. +
  85494. + offset += data_per_desc;
  85495. + iso_packet++;
  85496. + dma_desc++;
  85497. + }
  85498. +
  85499. + sts.d32 = dma_desc->status.d32;
  85500. +
  85501. + /* Write status in iso_packet_decsriptor */
  85502. + iso_packet->status =
  85503. + sts.b_iso_out.rxsts + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  85504. + if (iso_packet->status) {
  85505. + iso_packet->status = -DWC_E_NO_DATA;
  85506. + }
  85507. + /* Received data length */
  85508. + if (!sts.b_iso_out.rxbytes) {
  85509. + iso_packet->length =
  85510. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  85511. + } else {
  85512. + iso_packet->length =
  85513. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes +
  85514. + (4 - dwc_ep->data_per_frame % 4);
  85515. + }
  85516. +
  85517. + iso_packet->offset = offset;
  85518. + } else {
  85519. +/** ISO IN EP */
  85520. +
  85521. + dma_desc =
  85522. + dwc_ep->iso_desc_addr +
  85523. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  85524. +
  85525. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  85526. + sts.d32 = dma_desc->status.d32;
  85527. +
  85528. + /* Write status in iso packet descriptor */
  85529. + iso_packet->status =
  85530. + sts.b_iso_in.txsts +
  85531. + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  85532. + if (iso_packet->status != 0) {
  85533. + iso_packet->status = -DWC_E_NO_DATA;
  85534. +
  85535. + }
  85536. + /* Bytes has been transfered */
  85537. + iso_packet->length =
  85538. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  85539. +
  85540. + dma_desc++;
  85541. + iso_packet++;
  85542. + }
  85543. +
  85544. + sts.d32 = dma_desc->status.d32;
  85545. + while (sts.b_iso_in.bs == BS_DMA_BUSY) {
  85546. + sts.d32 = dma_desc->status.d32;
  85547. + }
  85548. +
  85549. + /* Write status in iso packet descriptor ??? do be done with ERROR codes */
  85550. + iso_packet->status =
  85551. + sts.b_iso_in.txsts + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  85552. + if (iso_packet->status != 0) {
  85553. + iso_packet->status = -DWC_E_NO_DATA;
  85554. + }
  85555. +
  85556. + /* Bytes has been transfered */
  85557. + iso_packet->length =
  85558. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  85559. + }
  85560. +}
  85561. +
  85562. +/**
  85563. + * This function reinitialize DMA Descriptors for Isochronous transfer
  85564. + *
  85565. + * @param core_if Programming view of DWC_otg controller.
  85566. + * @param dwc_ep The EP to start the transfer on.
  85567. + *
  85568. + */
  85569. +static void reinit_ddma_iso_xfer(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  85570. +{
  85571. + int i, j;
  85572. + dwc_otg_dev_dma_desc_t *dma_desc;
  85573. + dma_addr_t dma_ad;
  85574. + volatile uint32_t *addr;
  85575. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  85576. + uint32_t data_per_desc;
  85577. +
  85578. + if (dwc_ep->is_in == 0) {
  85579. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  85580. + } else {
  85581. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  85582. + }
  85583. +
  85584. + if (dwc_ep->proc_buf_num == 0) {
  85585. + /** Buffer 0 descriptors setup */
  85586. + dma_ad = dwc_ep->dma_addr0;
  85587. + } else {
  85588. + /** Buffer 1 descriptors setup */
  85589. + dma_ad = dwc_ep->dma_addr1;
  85590. + }
  85591. +
  85592. + /** Reinit closed DMA Descriptors*/
  85593. + /** ISO OUT EP */
  85594. + if (dwc_ep->is_in == 0) {
  85595. + dma_desc =
  85596. + dwc_ep->iso_desc_addr +
  85597. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  85598. +
  85599. + sts.b_iso_out.bs = BS_HOST_READY;
  85600. + sts.b_iso_out.rxsts = 0;
  85601. + sts.b_iso_out.l = 0;
  85602. + sts.b_iso_out.sp = 0;
  85603. + sts.b_iso_out.ioc = 0;
  85604. + sts.b_iso_out.pid = 0;
  85605. + sts.b_iso_out.framenum = 0;
  85606. +
  85607. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  85608. + i += dwc_ep->pkt_per_frm) {
  85609. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  85610. + data_per_desc =
  85611. + ((j + 1) * dwc_ep->maxpacket >
  85612. + dwc_ep->
  85613. + data_per_frame) ? dwc_ep->data_per_frame -
  85614. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  85615. + data_per_desc +=
  85616. + (data_per_desc % 4) ? (4 -
  85617. + data_per_desc %
  85618. + 4) : 0;
  85619. + sts.b_iso_out.rxbytes = data_per_desc;
  85620. + dma_desc->buf = dma_ad;
  85621. + dma_desc->status.d32 = sts.d32;
  85622. +
  85623. + dma_ad += data_per_desc;
  85624. + dma_desc++;
  85625. + }
  85626. + }
  85627. +
  85628. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  85629. +
  85630. + data_per_desc =
  85631. + ((j + 1) * dwc_ep->maxpacket >
  85632. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  85633. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  85634. + data_per_desc +=
  85635. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  85636. + sts.b_iso_out.rxbytes = data_per_desc;
  85637. +
  85638. + dma_desc->buf = dma_ad;
  85639. + dma_desc->status.d32 = sts.d32;
  85640. +
  85641. + dma_desc++;
  85642. + dma_ad += data_per_desc;
  85643. + }
  85644. +
  85645. + sts.b_iso_out.ioc = 1;
  85646. + sts.b_iso_out.l = dwc_ep->proc_buf_num;
  85647. +
  85648. + data_per_desc =
  85649. + ((j + 1) * dwc_ep->maxpacket >
  85650. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  85651. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  85652. + data_per_desc +=
  85653. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  85654. + sts.b_iso_out.rxbytes = data_per_desc;
  85655. +
  85656. + dma_desc->buf = dma_ad;
  85657. + dma_desc->status.d32 = sts.d32;
  85658. + } else {
  85659. +/** ISO IN EP */
  85660. +
  85661. + dma_desc =
  85662. + dwc_ep->iso_desc_addr +
  85663. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  85664. +
  85665. + sts.b_iso_in.bs = BS_HOST_READY;
  85666. + sts.b_iso_in.txsts = 0;
  85667. + sts.b_iso_in.sp = 0;
  85668. + sts.b_iso_in.ioc = 0;
  85669. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  85670. + sts.b_iso_in.framenum = dwc_ep->next_frame;
  85671. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  85672. + sts.b_iso_in.l = 0;
  85673. +
  85674. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  85675. + dma_desc->buf = dma_ad;
  85676. + dma_desc->status.d32 = sts.d32;
  85677. +
  85678. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  85679. + dma_ad += dwc_ep->data_per_frame;
  85680. + dma_desc++;
  85681. + }
  85682. +
  85683. + sts.b_iso_in.ioc = 1;
  85684. + sts.b_iso_in.l = dwc_ep->proc_buf_num;
  85685. +
  85686. + dma_desc->buf = dma_ad;
  85687. + dma_desc->status.d32 = sts.d32;
  85688. +
  85689. + dwc_ep->next_frame =
  85690. + sts.b_iso_in.framenum + dwc_ep->bInterval * 1;
  85691. + }
  85692. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  85693. +}
  85694. +
  85695. +/**
  85696. + * This function is to handle Iso EP transfer complete interrupt
  85697. + * in case Iso out packet was dropped
  85698. + *
  85699. + * @param core_if Programming view of DWC_otg controller.
  85700. + * @param dwc_ep The EP for wihich transfer complete was asserted
  85701. + *
  85702. + */
  85703. +static uint32_t handle_iso_out_pkt_dropped(dwc_otg_core_if_t * core_if,
  85704. + dwc_ep_t * dwc_ep)
  85705. +{
  85706. + uint32_t dma_addr;
  85707. + uint32_t drp_pkt;
  85708. + uint32_t drp_pkt_cnt;
  85709. + deptsiz_data_t deptsiz = {.d32 = 0 };
  85710. + depctl_data_t depctl = {.d32 = 0 };
  85711. + int i;
  85712. +
  85713. + deptsiz.d32 =
  85714. + DWC_READ_REG32(&core_if->dev_if->
  85715. + out_ep_regs[dwc_ep->num]->doeptsiz);
  85716. +
  85717. + drp_pkt = dwc_ep->pkt_cnt - deptsiz.b.pktcnt;
  85718. + drp_pkt_cnt = dwc_ep->pkt_per_frm - (drp_pkt % dwc_ep->pkt_per_frm);
  85719. +
  85720. + /* Setting dropped packets status */
  85721. + for (i = 0; i < drp_pkt_cnt; ++i) {
  85722. + dwc_ep->pkt_info[drp_pkt].status = -DWC_E_NO_DATA;
  85723. + drp_pkt++;
  85724. + deptsiz.b.pktcnt--;
  85725. + }
  85726. +
  85727. + if (deptsiz.b.pktcnt > 0) {
  85728. + deptsiz.b.xfersize =
  85729. + dwc_ep->xfer_len - (dwc_ep->pkt_cnt -
  85730. + deptsiz.b.pktcnt) * dwc_ep->maxpacket;
  85731. + } else {
  85732. + deptsiz.b.xfersize = 0;
  85733. + deptsiz.b.pktcnt = 0;
  85734. + }
  85735. +
  85736. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz,
  85737. + deptsiz.d32);
  85738. +
  85739. + if (deptsiz.b.pktcnt > 0) {
  85740. + if (dwc_ep->proc_buf_num) {
  85741. + dma_addr =
  85742. + dwc_ep->dma_addr1 + dwc_ep->xfer_len -
  85743. + deptsiz.b.xfersize;
  85744. + } else {
  85745. + dma_addr =
  85746. + dwc_ep->dma_addr0 + dwc_ep->xfer_len -
  85747. + deptsiz.b.xfersize;;
  85748. + }
  85749. +
  85750. + DWC_WRITE_REG32(&core_if->dev_if->
  85751. + out_ep_regs[dwc_ep->num]->doepdma, dma_addr);
  85752. +
  85753. + /** Re-enable endpoint, clear nak */
  85754. + depctl.d32 = 0;
  85755. + depctl.b.epena = 1;
  85756. + depctl.b.cnak = 1;
  85757. +
  85758. + DWC_MODIFY_REG32(&core_if->dev_if->
  85759. + out_ep_regs[dwc_ep->num]->doepctl, depctl.d32,
  85760. + depctl.d32);
  85761. + return 0;
  85762. + } else {
  85763. + return 1;
  85764. + }
  85765. +}
  85766. +
  85767. +/**
  85768. + * This function sets iso packets information(PTI mode)
  85769. + *
  85770. + * @param core_if Programming view of DWC_otg controller.
  85771. + * @param ep The EP to start the transfer on.
  85772. + *
  85773. + */
  85774. +static uint32_t set_iso_pkts_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  85775. +{
  85776. + int i, j;
  85777. + dma_addr_t dma_ad;
  85778. + iso_pkt_info_t *packet_info = ep->pkt_info;
  85779. + uint32_t offset;
  85780. + uint32_t frame_data;
  85781. + deptsiz_data_t deptsiz;
  85782. +
  85783. + if (ep->proc_buf_num == 0) {
  85784. + /** Buffer 0 descriptors setup */
  85785. + dma_ad = ep->dma_addr0;
  85786. + } else {
  85787. + /** Buffer 1 descriptors setup */
  85788. + dma_ad = ep->dma_addr1;
  85789. + }
  85790. +
  85791. + if (ep->is_in) {
  85792. + deptsiz.d32 =
  85793. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  85794. + dieptsiz);
  85795. + } else {
  85796. + deptsiz.d32 =
  85797. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  85798. + doeptsiz);
  85799. + }
  85800. +
  85801. + if (!deptsiz.b.xfersize) {
  85802. + offset = 0;
  85803. + for (i = 0; i < ep->pkt_cnt; i += ep->pkt_per_frm) {
  85804. + frame_data = ep->data_per_frame;
  85805. + for (j = 0; j < ep->pkt_per_frm; ++j) {
  85806. +
  85807. + /* Packet status - is not set as initially
  85808. + * it is set to 0 and if packet was sent
  85809. + successfully, status field will remain 0*/
  85810. +
  85811. + /* Bytes has been transfered */
  85812. + packet_info->length =
  85813. + (ep->maxpacket <
  85814. + frame_data) ? ep->maxpacket : frame_data;
  85815. +
  85816. + /* Received packet offset */
  85817. + packet_info->offset = offset;
  85818. + offset += packet_info->length;
  85819. + frame_data -= packet_info->length;
  85820. +
  85821. + packet_info++;
  85822. + }
  85823. + }
  85824. + return 1;
  85825. + } else {
  85826. + /* This is a workaround for in case of Transfer Complete with
  85827. + * PktDrpSts interrupts merging - in this case Transfer complete
  85828. + * interrupt for Isoc Out Endpoint is asserted without PktDrpSts
  85829. + * set and with DOEPTSIZ register non zero. Investigations showed,
  85830. + * that this happens when Out packet is dropped, but because of
  85831. + * interrupts merging during first interrupt handling PktDrpSts
  85832. + * bit is cleared and for next merged interrupts it is not reset.
  85833. + * In this case SW hadles the interrupt as if PktDrpSts bit is set.
  85834. + */
  85835. + if (ep->is_in) {
  85836. + return 1;
  85837. + } else {
  85838. + return handle_iso_out_pkt_dropped(core_if, ep);
  85839. + }
  85840. + }
  85841. +}
  85842. +
  85843. +/**
  85844. + * This function is to handle Iso EP transfer complete interrupt
  85845. + *
  85846. + * @param pcd The PCD
  85847. + * @param ep The EP for which transfer complete was asserted
  85848. + *
  85849. + */
  85850. +static void complete_iso_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  85851. +{
  85852. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  85853. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  85854. + uint8_t is_last = 0;
  85855. +
  85856. + if (ep->dwc_ep.next_frame == 0xffffffff) {
  85857. + DWC_WARN("Next frame is not set!\n");
  85858. + return;
  85859. + }
  85860. +
  85861. + if (core_if->dma_enable) {
  85862. + if (core_if->dma_desc_enable) {
  85863. + set_ddma_iso_pkts_info(core_if, dwc_ep);
  85864. + reinit_ddma_iso_xfer(core_if, dwc_ep);
  85865. + is_last = 1;
  85866. + } else {
  85867. + if (core_if->pti_enh_enable) {
  85868. + if (set_iso_pkts_info(core_if, dwc_ep)) {
  85869. + dwc_ep->proc_buf_num =
  85870. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  85871. + dwc_otg_iso_ep_start_buf_transfer
  85872. + (core_if, dwc_ep);
  85873. + is_last = 1;
  85874. + }
  85875. + } else {
  85876. + set_current_pkt_info(core_if, dwc_ep);
  85877. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  85878. + is_last = 1;
  85879. + dwc_ep->cur_pkt = 0;
  85880. + dwc_ep->proc_buf_num =
  85881. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  85882. + if (dwc_ep->proc_buf_num) {
  85883. + dwc_ep->cur_pkt_addr =
  85884. + dwc_ep->xfer_buff1;
  85885. + dwc_ep->cur_pkt_dma_addr =
  85886. + dwc_ep->dma_addr1;
  85887. + } else {
  85888. + dwc_ep->cur_pkt_addr =
  85889. + dwc_ep->xfer_buff0;
  85890. + dwc_ep->cur_pkt_dma_addr =
  85891. + dwc_ep->dma_addr0;
  85892. + }
  85893. +
  85894. + }
  85895. + dwc_otg_iso_ep_start_frm_transfer(core_if,
  85896. + dwc_ep);
  85897. + }
  85898. + }
  85899. + } else {
  85900. + set_current_pkt_info(core_if, dwc_ep);
  85901. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  85902. + is_last = 1;
  85903. + dwc_ep->cur_pkt = 0;
  85904. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  85905. + if (dwc_ep->proc_buf_num) {
  85906. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
  85907. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
  85908. + } else {
  85909. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
  85910. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
  85911. + }
  85912. +
  85913. + }
  85914. + dwc_otg_iso_ep_start_frm_transfer(core_if, dwc_ep);
  85915. + }
  85916. + if (is_last)
  85917. + dwc_otg_iso_buffer_done(pcd, ep, ep->iso_req_handle);
  85918. +}
  85919. +#endif /* DWC_EN_ISOC */
  85920. +
  85921. +/**
  85922. + * This function handle BNA interrupt for Non Isochronous EPs
  85923. + *
  85924. + */
  85925. +static void dwc_otg_pcd_handle_noniso_bna(dwc_otg_pcd_ep_t * ep)
  85926. +{
  85927. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  85928. + volatile uint32_t *addr;
  85929. + depctl_data_t depctl = {.d32 = 0 };
  85930. + dwc_otg_pcd_t *pcd = ep->pcd;
  85931. + dwc_otg_dev_dma_desc_t *dma_desc;
  85932. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  85933. + dwc_otg_core_if_t *core_if = ep->pcd->core_if;
  85934. + int i, start;
  85935. +
  85936. + if (!dwc_ep->desc_cnt)
  85937. + DWC_WARN("Ep%d %s Descriptor count = %d \n", dwc_ep->num,
  85938. + (dwc_ep->is_in ? "IN" : "OUT"), dwc_ep->desc_cnt);
  85939. +
  85940. + if (core_if->core_params->cont_on_bna && !dwc_ep->is_in
  85941. + && dwc_ep->type != DWC_OTG_EP_TYPE_CONTROL) {
  85942. + uint32_t doepdma;
  85943. + dwc_otg_dev_out_ep_regs_t *out_regs =
  85944. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  85945. + doepdma = DWC_READ_REG32(&(out_regs->doepdma));
  85946. + start = (doepdma - dwc_ep->dma_desc_addr)/sizeof(dwc_otg_dev_dma_desc_t);
  85947. + dma_desc = &(dwc_ep->desc_addr[start]);
  85948. + } else {
  85949. + start = 0;
  85950. + dma_desc = dwc_ep->desc_addr;
  85951. + }
  85952. +
  85953. +
  85954. + for (i = start; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  85955. + sts.d32 = dma_desc->status.d32;
  85956. + sts.b.bs = BS_HOST_READY;
  85957. + dma_desc->status.d32 = sts.d32;
  85958. + }
  85959. +
  85960. + if (dwc_ep->is_in == 0) {
  85961. + addr =
  85962. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->num]->
  85963. + doepctl;
  85964. + } else {
  85965. + addr =
  85966. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  85967. + }
  85968. + depctl.b.epena = 1;
  85969. + depctl.b.cnak = 1;
  85970. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  85971. +}
  85972. +
  85973. +/**
  85974. + * This function handles EP0 Control transfers.
  85975. + *
  85976. + * The state of the control transfers are tracked in
  85977. + * <code>ep0state</code>.
  85978. + */
  85979. +static void handle_ep0(dwc_otg_pcd_t * pcd)
  85980. +{
  85981. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85982. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  85983. + dev_dma_desc_sts_t desc_sts;
  85984. + deptsiz0_data_t deptsiz;
  85985. + uint32_t byte_count;
  85986. +
  85987. +#ifdef DEBUG_EP0
  85988. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  85989. + print_ep0_state(pcd);
  85990. +#endif
  85991. +
  85992. +// DWC_PRINTF("HANDLE EP0\n");
  85993. +
  85994. + switch (pcd->ep0state) {
  85995. + case EP0_DISCONNECT:
  85996. + break;
  85997. +
  85998. + case EP0_IDLE:
  85999. + pcd->request_config = 0;
  86000. +
  86001. + pcd_setup(pcd);
  86002. + break;
  86003. +
  86004. + case EP0_IN_DATA_PHASE:
  86005. +#ifdef DEBUG_EP0
  86006. + DWC_DEBUGPL(DBG_PCD, "DATA_IN EP%d-%s: type=%d, mps=%d\n",
  86007. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  86008. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  86009. +#endif
  86010. +
  86011. + if (core_if->dma_enable != 0) {
  86012. + /*
  86013. + * For EP0 we can only program 1 packet at a time so we
  86014. + * need to do the make calculations after each complete.
  86015. + * Call write_packet to make the calculations, as in
  86016. + * slave mode, and use those values to determine if we
  86017. + * can complete.
  86018. + */
  86019. + if (core_if->dma_desc_enable == 0) {
  86020. + deptsiz.d32 =
  86021. + DWC_READ_REG32(&core_if->
  86022. + dev_if->in_ep_regs[0]->
  86023. + dieptsiz);
  86024. + byte_count =
  86025. + ep0->dwc_ep.xfer_len - deptsiz.b.xfersize;
  86026. + } else {
  86027. + desc_sts =
  86028. + core_if->dev_if->in_desc_addr->status;
  86029. + byte_count =
  86030. + ep0->dwc_ep.xfer_len - desc_sts.b.bytes;
  86031. + }
  86032. + ep0->dwc_ep.xfer_count += byte_count;
  86033. + ep0->dwc_ep.xfer_buff += byte_count;
  86034. + ep0->dwc_ep.dma_addr += byte_count;
  86035. + }
  86036. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  86037. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  86038. + &ep0->dwc_ep);
  86039. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  86040. + } else if (ep0->dwc_ep.sent_zlp) {
  86041. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  86042. + &ep0->dwc_ep);
  86043. + ep0->dwc_ep.sent_zlp = 0;
  86044. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  86045. + } else {
  86046. + ep0_complete_request(ep0);
  86047. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  86048. + }
  86049. + break;
  86050. + case EP0_OUT_DATA_PHASE:
  86051. +#ifdef DEBUG_EP0
  86052. + DWC_DEBUGPL(DBG_PCD, "DATA_OUT EP%d-%s: type=%d, mps=%d\n",
  86053. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  86054. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  86055. +#endif
  86056. + if (core_if->dma_enable != 0) {
  86057. + if (core_if->dma_desc_enable == 0) {
  86058. + deptsiz.d32 =
  86059. + DWC_READ_REG32(&core_if->
  86060. + dev_if->out_ep_regs[0]->
  86061. + doeptsiz);
  86062. + byte_count =
  86063. + ep0->dwc_ep.maxpacket - deptsiz.b.xfersize;
  86064. + } else {
  86065. + desc_sts =
  86066. + core_if->dev_if->out_desc_addr->status;
  86067. + byte_count =
  86068. + ep0->dwc_ep.maxpacket - desc_sts.b.bytes;
  86069. + }
  86070. + ep0->dwc_ep.xfer_count += byte_count;
  86071. + ep0->dwc_ep.xfer_buff += byte_count;
  86072. + ep0->dwc_ep.dma_addr += byte_count;
  86073. + }
  86074. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  86075. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  86076. + &ep0->dwc_ep);
  86077. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  86078. + } else if (ep0->dwc_ep.sent_zlp) {
  86079. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  86080. + &ep0->dwc_ep);
  86081. + ep0->dwc_ep.sent_zlp = 0;
  86082. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  86083. + } else {
  86084. + ep0_complete_request(ep0);
  86085. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  86086. + }
  86087. + break;
  86088. +
  86089. + case EP0_IN_STATUS_PHASE:
  86090. + case EP0_OUT_STATUS_PHASE:
  86091. + DWC_DEBUGPL(DBG_PCD, "CASE: EP0_STATUS\n");
  86092. + ep0_complete_request(ep0);
  86093. + pcd->ep0state = EP0_IDLE;
  86094. + ep0->stopped = 1;
  86095. + ep0->dwc_ep.is_in = 0; /* OUT for next SETUP */
  86096. +
  86097. + /* Prepare for more SETUP Packets */
  86098. + if (core_if->dma_enable) {
  86099. + ep0_out_start(core_if, pcd);
  86100. + }
  86101. + break;
  86102. +
  86103. + case EP0_STALL:
  86104. + DWC_ERROR("EP0 STALLed, should not get here pcd_setup()\n");
  86105. + break;
  86106. + }
  86107. +#ifdef DEBUG_EP0
  86108. + print_ep0_state(pcd);
  86109. +#endif
  86110. +}
  86111. +
  86112. +/**
  86113. + * Restart transfer
  86114. + */
  86115. +static void restart_transfer(dwc_otg_pcd_t * pcd, const uint32_t epnum)
  86116. +{
  86117. + dwc_otg_core_if_t *core_if;
  86118. + dwc_otg_dev_if_t *dev_if;
  86119. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  86120. + dwc_otg_pcd_ep_t *ep;
  86121. +
  86122. + ep = get_in_ep(pcd, epnum);
  86123. +
  86124. +#ifdef DWC_EN_ISOC
  86125. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  86126. + return;
  86127. + }
  86128. +#endif /* DWC_EN_ISOC */
  86129. +
  86130. + core_if = GET_CORE_IF(pcd);
  86131. + dev_if = core_if->dev_if;
  86132. +
  86133. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  86134. +
  86135. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x xfer_len=%0x"
  86136. + " stopped=%d\n", ep->dwc_ep.xfer_buff,
  86137. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len, ep->stopped);
  86138. + /*
  86139. + * If xfersize is 0 and pktcnt in not 0, resend the last packet.
  86140. + */
  86141. + if (dieptsiz.b.pktcnt && dieptsiz.b.xfersize == 0 &&
  86142. + ep->dwc_ep.start_xfer_buff != 0) {
  86143. + if (ep->dwc_ep.total_len <= ep->dwc_ep.maxpacket) {
  86144. + ep->dwc_ep.xfer_count = 0;
  86145. + ep->dwc_ep.xfer_buff = ep->dwc_ep.start_xfer_buff;
  86146. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  86147. + } else {
  86148. + ep->dwc_ep.xfer_count -= ep->dwc_ep.maxpacket;
  86149. + /* convert packet size to dwords. */
  86150. + ep->dwc_ep.xfer_buff -= ep->dwc_ep.maxpacket;
  86151. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  86152. + }
  86153. + ep->stopped = 0;
  86154. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x "
  86155. + "xfer_len=%0x stopped=%d\n",
  86156. + ep->dwc_ep.xfer_buff,
  86157. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len,
  86158. + ep->stopped);
  86159. + if (epnum == 0) {
  86160. + dwc_otg_ep0_start_transfer(core_if, &ep->dwc_ep);
  86161. + } else {
  86162. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  86163. + }
  86164. + }
  86165. +}
  86166. +
  86167. +/*
  86168. + * This function create new nextep sequnce based on Learn Queue.
  86169. + *
  86170. + * @param core_if Programming view of DWC_otg controller
  86171. + */
  86172. +void predict_nextep_seq( dwc_otg_core_if_t * core_if)
  86173. +{
  86174. + dwc_otg_device_global_regs_t *dev_global_regs =
  86175. + core_if->dev_if->dev_global_regs;
  86176. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  86177. + /* Number of Token Queue Registers */
  86178. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  86179. + dtknq1_data_t dtknqr1;
  86180. + uint32_t in_tkn_epnums[4];
  86181. + uint8_t seqnum[MAX_EPS_CHANNELS];
  86182. + uint8_t intkn_seq[TOKEN_Q_DEPTH];
  86183. + grstctl_t resetctl = {.d32 = 0 };
  86184. + uint8_t temp;
  86185. + int ndx = 0;
  86186. + int start = 0;
  86187. + int end = 0;
  86188. + int sort_done = 0;
  86189. + int i = 0;
  86190. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  86191. +
  86192. +
  86193. + DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  86194. +
  86195. + /* Read the DTKNQ Registers */
  86196. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  86197. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  86198. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  86199. + in_tkn_epnums[i]);
  86200. + if (addr == &dev_global_regs->dvbusdis) {
  86201. + addr = &dev_global_regs->dtknqr3_dthrctl;
  86202. + } else {
  86203. + ++addr;
  86204. + }
  86205. +
  86206. + }
  86207. +
  86208. + /* Copy the DTKNQR1 data to the bit field. */
  86209. + dtknqr1.d32 = in_tkn_epnums[0];
  86210. + if (dtknqr1.b.wrap_bit) {
  86211. + ndx = dtknqr1.b.intknwptr;
  86212. + end = ndx -1;
  86213. + if (end < 0)
  86214. + end = TOKEN_Q_DEPTH -1;
  86215. + } else {
  86216. + ndx = 0;
  86217. + end = dtknqr1.b.intknwptr -1;
  86218. + if (end < 0)
  86219. + end = 0;
  86220. + }
  86221. + start = ndx;
  86222. +
  86223. + /* Fill seqnum[] by initial values: EP number + 31 */
  86224. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  86225. + seqnum[i] = i +31;
  86226. + }
  86227. +
  86228. + /* Fill intkn_seq[] from in_tkn_epnums[0] */
  86229. + for (i=0; i < 6; i++)
  86230. + intkn_seq[i] = (in_tkn_epnums[0] >> ((7-i) * 4)) & 0xf;
  86231. +
  86232. + if (TOKEN_Q_DEPTH > 6) {
  86233. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  86234. + for (i=6; i < 14; i++)
  86235. + intkn_seq[i] =
  86236. + (in_tkn_epnums[1] >> ((7 - (i - 6)) * 4)) & 0xf;
  86237. + }
  86238. +
  86239. + if (TOKEN_Q_DEPTH > 14) {
  86240. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  86241. + for (i=14; i < 22; i++)
  86242. + intkn_seq[i] =
  86243. + (in_tkn_epnums[2] >> ((7 - (i - 14)) * 4)) & 0xf;
  86244. + }
  86245. +
  86246. + if (TOKEN_Q_DEPTH > 22) {
  86247. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  86248. + for (i=22; i < 30; i++)
  86249. + intkn_seq[i] =
  86250. + (in_tkn_epnums[3] >> ((7 - (i - 22)) * 4)) & 0xf;
  86251. + }
  86252. +
  86253. + DWC_DEBUGPL(DBG_PCDV, "%s start=%d end=%d intkn_seq[]:\n", __func__,
  86254. + start, end);
  86255. + for (i=0; i<TOKEN_Q_DEPTH; i++)
  86256. + DWC_DEBUGPL(DBG_PCDV,"%d\n", intkn_seq[i]);
  86257. +
  86258. + /* Update seqnum based on intkn_seq[] */
  86259. + i = 0;
  86260. + do {
  86261. + seqnum[intkn_seq[ndx]] = i;
  86262. + ndx++;
  86263. + i++;
  86264. + if (ndx == TOKEN_Q_DEPTH)
  86265. + ndx = 0;
  86266. + } while ( i < TOKEN_Q_DEPTH );
  86267. +
  86268. + /* Mark non active EP's in seqnum[] by 0xff */
  86269. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  86270. + if (core_if->nextep_seq[i] == 0xff )
  86271. + seqnum[i] = 0xff;
  86272. + }
  86273. +
  86274. + /* Sort seqnum[] */
  86275. + sort_done = 0;
  86276. + while (!sort_done) {
  86277. + sort_done = 1;
  86278. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  86279. + if (seqnum[i] > seqnum[i+1]) {
  86280. + temp = seqnum[i];
  86281. + seqnum[i] = seqnum[i+1];
  86282. + seqnum[i+1] = temp;
  86283. + sort_done = 0;
  86284. + }
  86285. + }
  86286. + }
  86287. +
  86288. + ndx = start + seqnum[0];
  86289. + if (ndx >= TOKEN_Q_DEPTH)
  86290. + ndx = ndx % TOKEN_Q_DEPTH;
  86291. + core_if->first_in_nextep_seq = intkn_seq[ndx];
  86292. +
  86293. + /* Update seqnum[] by EP numbers */
  86294. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  86295. + ndx = start + i;
  86296. + if (seqnum[i] < 31) {
  86297. + ndx = start + seqnum[i];
  86298. + if (ndx >= TOKEN_Q_DEPTH)
  86299. + ndx = ndx % TOKEN_Q_DEPTH;
  86300. + seqnum[i] = intkn_seq[ndx];
  86301. + } else {
  86302. + if (seqnum[i] < 0xff) {
  86303. + seqnum[i] = seqnum[i] - 31;
  86304. + } else {
  86305. + break;
  86306. + }
  86307. + }
  86308. + }
  86309. +
  86310. + /* Update nextep_seq[] based on seqnum[] */
  86311. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  86312. + if (seqnum[i] != 0xff) {
  86313. + if (seqnum[i+1] != 0xff) {
  86314. + core_if->nextep_seq[seqnum[i]] = seqnum[i+1];
  86315. + } else {
  86316. + core_if->nextep_seq[seqnum[i]] = core_if->first_in_nextep_seq;
  86317. + break;
  86318. + }
  86319. + } else {
  86320. + break;
  86321. + }
  86322. + }
  86323. +
  86324. + DWC_DEBUGPL(DBG_PCDV, "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  86325. + __func__, core_if->first_in_nextep_seq);
  86326. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  86327. + DWC_DEBUGPL(DBG_PCDV,"%2d\n", core_if->nextep_seq[i]);
  86328. + }
  86329. +
  86330. + /* Flush the Learning Queue */
  86331. + resetctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->grstctl);
  86332. + resetctl.b.intknqflsh = 1;
  86333. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  86334. +
  86335. +
  86336. +}
  86337. +
  86338. +/**
  86339. + * handle the IN EP disable interrupt.
  86340. + */
  86341. +static inline void handle_in_ep_disable_intr(dwc_otg_pcd_t * pcd,
  86342. + const uint32_t epnum)
  86343. +{
  86344. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86345. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86346. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  86347. + dctl_data_t dctl = {.d32 = 0 };
  86348. + dwc_otg_pcd_ep_t *ep;
  86349. + dwc_ep_t *dwc_ep;
  86350. + gintmsk_data_t gintmsk_data;
  86351. + depctl_data_t depctl;
  86352. + uint32_t diepdma;
  86353. + uint32_t remain_to_transfer = 0;
  86354. + uint8_t i;
  86355. + uint32_t xfer_size;
  86356. +
  86357. + ep = get_in_ep(pcd, epnum);
  86358. + dwc_ep = &ep->dwc_ep;
  86359. +
  86360. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  86361. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  86362. + complete_ep(ep);
  86363. + return;
  86364. + }
  86365. +
  86366. + DWC_DEBUGPL(DBG_PCD, "diepctl%d=%0x\n", epnum,
  86367. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl));
  86368. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  86369. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  86370. +
  86371. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  86372. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  86373. +
  86374. + if ((core_if->start_predict == 0) || (depctl.b.eptype & 1)) {
  86375. + if (ep->stopped) {
  86376. + if (core_if->en_multiple_tx_fifo)
  86377. + /* Flush the Tx FIFO */
  86378. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  86379. + /* Clear the Global IN NP NAK */
  86380. + dctl.d32 = 0;
  86381. + dctl.b.cgnpinnak = 1;
  86382. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  86383. + /* Restart the transaction */
  86384. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  86385. + restart_transfer(pcd, epnum);
  86386. + }
  86387. + } else {
  86388. + /* Restart the transaction */
  86389. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  86390. + restart_transfer(pcd, epnum);
  86391. + }
  86392. + DWC_DEBUGPL(DBG_ANY, "STOPPED!!!\n");
  86393. + }
  86394. + return;
  86395. + }
  86396. +
  86397. + if (core_if->start_predict > 2) { // NP IN EP
  86398. + core_if->start_predict--;
  86399. + return;
  86400. + }
  86401. +
  86402. + core_if->start_predict--;
  86403. +
  86404. + if (core_if->start_predict == 1) { // All NP IN Ep's disabled now
  86405. +
  86406. + predict_nextep_seq(core_if);
  86407. +
  86408. + /* Update all active IN EP's NextEP field based of nextep_seq[] */
  86409. + for ( i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  86410. + depctl.d32 =
  86411. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  86412. + if (core_if->nextep_seq[i] != 0xff) { // Active NP IN EP
  86413. + depctl.b.nextep = core_if->nextep_seq[i];
  86414. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  86415. + }
  86416. + }
  86417. + /* Flush Shared NP TxFIFO */
  86418. + dwc_otg_flush_tx_fifo(core_if, 0);
  86419. + /* Rewind buffers */
  86420. + if (!core_if->dma_desc_enable) {
  86421. + i = core_if->first_in_nextep_seq;
  86422. + do {
  86423. + ep = get_in_ep(pcd, i);
  86424. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  86425. + xfer_size = ep->dwc_ep.total_len - ep->dwc_ep.xfer_count;
  86426. + if (xfer_size > ep->dwc_ep.maxxfer)
  86427. + xfer_size = ep->dwc_ep.maxxfer;
  86428. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  86429. + if (dieptsiz.b.pktcnt != 0) {
  86430. + if (xfer_size == 0) {
  86431. + remain_to_transfer = 0;
  86432. + } else {
  86433. + if ((xfer_size % ep->dwc_ep.maxpacket) == 0) {
  86434. + remain_to_transfer =
  86435. + dieptsiz.b.pktcnt * ep->dwc_ep.maxpacket;
  86436. + } else {
  86437. + remain_to_transfer = ((dieptsiz.b.pktcnt -1) * ep->dwc_ep.maxpacket)
  86438. + + (xfer_size % ep->dwc_ep.maxpacket);
  86439. + }
  86440. + }
  86441. + diepdma = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepdma);
  86442. + dieptsiz.b.xfersize = remain_to_transfer;
  86443. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, dieptsiz.d32);
  86444. + diepdma = ep->dwc_ep.dma_addr + (xfer_size - remain_to_transfer);
  86445. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, diepdma);
  86446. + }
  86447. + i = core_if->nextep_seq[i];
  86448. + } while (i != core_if->first_in_nextep_seq);
  86449. + } else { // dma_desc_enable
  86450. + DWC_PRINTF("%s Learning Queue not supported in DDMA\n", __func__);
  86451. + }
  86452. +
  86453. + /* Restart transfers in predicted sequences */
  86454. + i = core_if->first_in_nextep_seq;
  86455. + do {
  86456. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  86457. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  86458. + if (dieptsiz.b.pktcnt != 0) {
  86459. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  86460. + depctl.b.epena = 1;
  86461. + depctl.b.cnak = 1;
  86462. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  86463. + }
  86464. + i = core_if->nextep_seq[i];
  86465. + } while (i != core_if->first_in_nextep_seq);
  86466. +
  86467. + /* Clear the global non-periodic IN NAK handshake */
  86468. + dctl.d32 = 0;
  86469. + dctl.b.cgnpinnak = 1;
  86470. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  86471. +
  86472. + /* Unmask EP Mismatch interrupt */
  86473. + gintmsk_data.d32 = 0;
  86474. + gintmsk_data.b.epmismatch = 1;
  86475. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk_data.d32);
  86476. +
  86477. + core_if->start_predict = 0;
  86478. +
  86479. + }
  86480. +}
  86481. +
  86482. +/**
  86483. + * Handler for the IN EP timeout handshake interrupt.
  86484. + */
  86485. +static inline void handle_in_ep_timeout_intr(dwc_otg_pcd_t * pcd,
  86486. + const uint32_t epnum)
  86487. +{
  86488. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86489. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86490. +
  86491. +#ifdef DEBUG
  86492. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  86493. + uint32_t num = 0;
  86494. +#endif
  86495. + dctl_data_t dctl = {.d32 = 0 };
  86496. + dwc_otg_pcd_ep_t *ep;
  86497. +
  86498. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86499. +
  86500. + ep = get_in_ep(pcd, epnum);
  86501. +
  86502. + /* Disable the NP Tx Fifo Empty Interrrupt */
  86503. + if (!core_if->dma_enable) {
  86504. + intr_mask.b.nptxfempty = 1;
  86505. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  86506. + intr_mask.d32, 0);
  86507. + }
  86508. + /** @todo NGS Check EP type.
  86509. + * Implement for Periodic EPs */
  86510. + /*
  86511. + * Non-periodic EP
  86512. + */
  86513. + /* Enable the Global IN NAK Effective Interrupt */
  86514. + intr_mask.b.ginnakeff = 1;
  86515. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  86516. +
  86517. + /* Set Global IN NAK */
  86518. + dctl.b.sgnpinnak = 1;
  86519. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  86520. +
  86521. + ep->stopped = 1;
  86522. +
  86523. +#ifdef DEBUG
  86524. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[num]->dieptsiz);
  86525. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  86526. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  86527. +#endif
  86528. +
  86529. +#ifdef DISABLE_PERIODIC_EP
  86530. + /*
  86531. + * Set the NAK bit for this EP to
  86532. + * start the disable process.
  86533. + */
  86534. + diepctl.d32 = 0;
  86535. + diepctl.b.snak = 1;
  86536. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[num]->diepctl, diepctl.d32,
  86537. + diepctl.d32);
  86538. + ep->disabling = 1;
  86539. + ep->stopped = 1;
  86540. +#endif
  86541. +}
  86542. +
  86543. +/**
  86544. + * Handler for the IN EP NAK interrupt.
  86545. + */
  86546. +static inline int32_t handle_in_ep_nak_intr(dwc_otg_pcd_t * pcd,
  86547. + const uint32_t epnum)
  86548. +{
  86549. + /** @todo implement ISR */
  86550. + dwc_otg_core_if_t *core_if;
  86551. + diepmsk_data_t intr_mask = {.d32 = 0 };
  86552. +
  86553. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "IN EP NAK");
  86554. + core_if = GET_CORE_IF(pcd);
  86555. + intr_mask.b.nak = 1;
  86556. +
  86557. + if (core_if->multiproc_int_enable) {
  86558. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  86559. + diepeachintmsk[epnum], intr_mask.d32, 0);
  86560. + } else {
  86561. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->diepmsk,
  86562. + intr_mask.d32, 0);
  86563. + }
  86564. +
  86565. + return 1;
  86566. +}
  86567. +
  86568. +/**
  86569. + * Handler for the OUT EP Babble interrupt.
  86570. + */
  86571. +static inline int32_t handle_out_ep_babble_intr(dwc_otg_pcd_t * pcd,
  86572. + const uint32_t epnum)
  86573. +{
  86574. + /** @todo implement ISR */
  86575. + dwc_otg_core_if_t *core_if;
  86576. + doepmsk_data_t intr_mask = {.d32 = 0 };
  86577. +
  86578. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  86579. + "OUT EP Babble");
  86580. + core_if = GET_CORE_IF(pcd);
  86581. + intr_mask.b.babble = 1;
  86582. +
  86583. + if (core_if->multiproc_int_enable) {
  86584. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  86585. + doepeachintmsk[epnum], intr_mask.d32, 0);
  86586. + } else {
  86587. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  86588. + intr_mask.d32, 0);
  86589. + }
  86590. +
  86591. + return 1;
  86592. +}
  86593. +
  86594. +/**
  86595. + * Handler for the OUT EP NAK interrupt.
  86596. + */
  86597. +static inline int32_t handle_out_ep_nak_intr(dwc_otg_pcd_t * pcd,
  86598. + const uint32_t epnum)
  86599. +{
  86600. + /** @todo implement ISR */
  86601. + dwc_otg_core_if_t *core_if;
  86602. + doepmsk_data_t intr_mask = {.d32 = 0 };
  86603. +
  86604. + DWC_DEBUGPL(DBG_ANY, "INTERRUPT Handler not implemented for %s\n", "OUT EP NAK");
  86605. + core_if = GET_CORE_IF(pcd);
  86606. + intr_mask.b.nak = 1;
  86607. +
  86608. + if (core_if->multiproc_int_enable) {
  86609. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  86610. + doepeachintmsk[epnum], intr_mask.d32, 0);
  86611. + } else {
  86612. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  86613. + intr_mask.d32, 0);
  86614. + }
  86615. +
  86616. + return 1;
  86617. +}
  86618. +
  86619. +/**
  86620. + * Handler for the OUT EP NYET interrupt.
  86621. + */
  86622. +static inline int32_t handle_out_ep_nyet_intr(dwc_otg_pcd_t * pcd,
  86623. + const uint32_t epnum)
  86624. +{
  86625. + /** @todo implement ISR */
  86626. + dwc_otg_core_if_t *core_if;
  86627. + doepmsk_data_t intr_mask = {.d32 = 0 };
  86628. +
  86629. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "OUT EP NYET");
  86630. + core_if = GET_CORE_IF(pcd);
  86631. + intr_mask.b.nyet = 1;
  86632. +
  86633. + if (core_if->multiproc_int_enable) {
  86634. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  86635. + doepeachintmsk[epnum], intr_mask.d32, 0);
  86636. + } else {
  86637. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  86638. + intr_mask.d32, 0);
  86639. + }
  86640. +
  86641. + return 1;
  86642. +}
  86643. +
  86644. +/**
  86645. + * This interrupt indicates that an IN EP has a pending Interrupt.
  86646. + * The sequence for handling the IN EP interrupt is shown below:
  86647. + * -# Read the Device All Endpoint Interrupt register
  86648. + * -# Repeat the following for each IN EP interrupt bit set (from
  86649. + * LSB to MSB).
  86650. + * -# Read the Device Endpoint Interrupt (DIEPINTn) register
  86651. + * -# If "Transfer Complete" call the request complete function
  86652. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  86653. + * -# If "AHB Error Interrupt" log error
  86654. + * -# If "Time-out Handshake" log error
  86655. + * -# If "IN Token Received when TxFIFO Empty" write packet to Tx
  86656. + * FIFO.
  86657. + * -# If "IN Token EP Mismatch" (disable, this is handled by EP
  86658. + * Mismatch Interrupt)
  86659. + */
  86660. +static int32_t dwc_otg_pcd_handle_in_ep_intr(dwc_otg_pcd_t * pcd)
  86661. +{
  86662. +#define CLEAR_IN_EP_INTR(__core_if,__epnum,__intr) \
  86663. +do { \
  86664. + diepint_data_t diepint = {.d32=0}; \
  86665. + diepint.b.__intr = 1; \
  86666. + DWC_WRITE_REG32(&__core_if->dev_if->in_ep_regs[__epnum]->diepint, \
  86667. + diepint.d32); \
  86668. +} while (0)
  86669. +
  86670. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86671. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86672. + diepint_data_t diepint = {.d32 = 0 };
  86673. + depctl_data_t depctl = {.d32 = 0 };
  86674. + uint32_t ep_intr;
  86675. + uint32_t epnum = 0;
  86676. + dwc_otg_pcd_ep_t *ep;
  86677. + dwc_ep_t *dwc_ep;
  86678. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86679. +
  86680. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, pcd);
  86681. +
  86682. + /* Read in the device interrupt bits */
  86683. + ep_intr = dwc_otg_read_dev_all_in_ep_intr(core_if);
  86684. +
  86685. + /* Service the Device IN interrupts for each endpoint */
  86686. + while (ep_intr) {
  86687. + if (ep_intr & 0x1) {
  86688. + uint32_t empty_msk;
  86689. + /* Get EP pointer */
  86690. + ep = get_in_ep(pcd, epnum);
  86691. + dwc_ep = &ep->dwc_ep;
  86692. +
  86693. + depctl.d32 =
  86694. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  86695. + empty_msk =
  86696. + DWC_READ_REG32(&dev_if->
  86697. + dev_global_regs->dtknqr4_fifoemptymsk);
  86698. +
  86699. + DWC_DEBUGPL(DBG_PCDV,
  86700. + "IN EP INTERRUPT - %d\nepmty_msk - %8x diepctl - %8x\n",
  86701. + epnum, empty_msk, depctl.d32);
  86702. +
  86703. + DWC_DEBUGPL(DBG_PCD,
  86704. + "EP%d-%s: type=%d, mps=%d\n",
  86705. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  86706. + dwc_ep->type, dwc_ep->maxpacket);
  86707. +
  86708. + diepint.d32 =
  86709. + dwc_otg_read_dev_in_ep_intr(core_if, dwc_ep);
  86710. +
  86711. + DWC_DEBUGPL(DBG_PCDV,
  86712. + "EP %d Interrupt Register - 0x%x\n", epnum,
  86713. + diepint.d32);
  86714. + /* Transfer complete */
  86715. + if (diepint.b.xfercompl) {
  86716. + /* Disable the NP Tx FIFO Empty
  86717. + * Interrupt */
  86718. + if (core_if->en_multiple_tx_fifo == 0) {
  86719. + intr_mask.b.nptxfempty = 1;
  86720. + DWC_MODIFY_REG32
  86721. + (&core_if->core_global_regs->gintmsk,
  86722. + intr_mask.d32, 0);
  86723. + } else {
  86724. + /* Disable the Tx FIFO Empty Interrupt for this EP */
  86725. + uint32_t fifoemptymsk =
  86726. + 0x1 << dwc_ep->num;
  86727. + DWC_MODIFY_REG32(&core_if->
  86728. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  86729. + fifoemptymsk, 0);
  86730. + }
  86731. + /* Clear the bit in DIEPINTn for this interrupt */
  86732. + CLEAR_IN_EP_INTR(core_if, epnum, xfercompl);
  86733. +
  86734. + /* Complete the transfer */
  86735. + if (epnum == 0) {
  86736. + handle_ep0(pcd);
  86737. + }
  86738. +#ifdef DWC_EN_ISOC
  86739. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  86740. + if (!ep->stopped)
  86741. + complete_iso_ep(pcd, ep);
  86742. + }
  86743. +#endif /* DWC_EN_ISOC */
  86744. +#ifdef DWC_UTE_PER_IO
  86745. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  86746. + if (!ep->stopped)
  86747. + complete_xiso_ep(ep);
  86748. + }
  86749. +#endif /* DWC_UTE_PER_IO */
  86750. + else {
  86751. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC &&
  86752. + dwc_ep->bInterval > 1) {
  86753. + dwc_ep->frame_num += dwc_ep->bInterval;
  86754. + if (dwc_ep->frame_num > 0x3FFF)
  86755. + {
  86756. + dwc_ep->frm_overrun = 1;
  86757. + dwc_ep->frame_num &= 0x3FFF;
  86758. + } else
  86759. + dwc_ep->frm_overrun = 0;
  86760. + }
  86761. + complete_ep(ep);
  86762. + if(diepint.b.nak)
  86763. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  86764. + }
  86765. + }
  86766. + /* Endpoint disable */
  86767. + if (diepint.b.epdisabled) {
  86768. + DWC_DEBUGPL(DBG_ANY, "EP%d IN disabled\n",
  86769. + epnum);
  86770. + handle_in_ep_disable_intr(pcd, epnum);
  86771. +
  86772. + /* Clear the bit in DIEPINTn for this interrupt */
  86773. + CLEAR_IN_EP_INTR(core_if, epnum, epdisabled);
  86774. + }
  86775. + /* AHB Error */
  86776. + if (diepint.b.ahberr) {
  86777. + DWC_ERROR("EP%d IN AHB Error\n", epnum);
  86778. + /* Clear the bit in DIEPINTn for this interrupt */
  86779. + CLEAR_IN_EP_INTR(core_if, epnum, ahberr);
  86780. + }
  86781. + /* TimeOUT Handshake (non-ISOC IN EPs) */
  86782. + if (diepint.b.timeout) {
  86783. + DWC_ERROR("EP%d IN Time-out\n", epnum);
  86784. + handle_in_ep_timeout_intr(pcd, epnum);
  86785. +
  86786. + CLEAR_IN_EP_INTR(core_if, epnum, timeout);
  86787. + }
  86788. + /** IN Token received with TxF Empty */
  86789. + if (diepint.b.intktxfemp) {
  86790. + DWC_DEBUGPL(DBG_ANY,
  86791. + "EP%d IN TKN TxFifo Empty\n",
  86792. + epnum);
  86793. + if (!ep->stopped && epnum != 0) {
  86794. +
  86795. + diepmsk_data_t diepmsk = {.d32 = 0 };
  86796. + diepmsk.b.intktxfemp = 1;
  86797. +
  86798. + if (core_if->multiproc_int_enable) {
  86799. + DWC_MODIFY_REG32
  86800. + (&dev_if->dev_global_regs->diepeachintmsk
  86801. + [epnum], diepmsk.d32, 0);
  86802. + } else {
  86803. + DWC_MODIFY_REG32
  86804. + (&dev_if->dev_global_regs->diepmsk,
  86805. + diepmsk.d32, 0);
  86806. + }
  86807. + } else if (core_if->dma_desc_enable
  86808. + && epnum == 0
  86809. + && pcd->ep0state ==
  86810. + EP0_OUT_STATUS_PHASE) {
  86811. + // EP0 IN set STALL
  86812. + depctl.d32 =
  86813. + DWC_READ_REG32(&dev_if->in_ep_regs
  86814. + [epnum]->diepctl);
  86815. +
  86816. + /* set the disable and stall bits */
  86817. + if (depctl.b.epena) {
  86818. + depctl.b.epdis = 1;
  86819. + }
  86820. + depctl.b.stall = 1;
  86821. + DWC_WRITE_REG32(&dev_if->in_ep_regs
  86822. + [epnum]->diepctl,
  86823. + depctl.d32);
  86824. + }
  86825. + CLEAR_IN_EP_INTR(core_if, epnum, intktxfemp);
  86826. + }
  86827. + /** IN Token Received with EP mismatch */
  86828. + if (diepint.b.intknepmis) {
  86829. + DWC_DEBUGPL(DBG_ANY,
  86830. + "EP%d IN TKN EP Mismatch\n", epnum);
  86831. + CLEAR_IN_EP_INTR(core_if, epnum, intknepmis);
  86832. + }
  86833. + /** IN Endpoint NAK Effective */
  86834. + if (diepint.b.inepnakeff) {
  86835. + DWC_DEBUGPL(DBG_ANY,
  86836. + "EP%d IN EP NAK Effective\n",
  86837. + epnum);
  86838. + /* Periodic EP */
  86839. + if (ep->disabling) {
  86840. + depctl.d32 = 0;
  86841. + depctl.b.snak = 1;
  86842. + depctl.b.epdis = 1;
  86843. + DWC_MODIFY_REG32(&dev_if->in_ep_regs
  86844. + [epnum]->diepctl,
  86845. + depctl.d32,
  86846. + depctl.d32);
  86847. + }
  86848. + CLEAR_IN_EP_INTR(core_if, epnum, inepnakeff);
  86849. +
  86850. + }
  86851. +
  86852. + /** IN EP Tx FIFO Empty Intr */
  86853. + if (diepint.b.emptyintr) {
  86854. + DWC_DEBUGPL(DBG_ANY,
  86855. + "EP%d Tx FIFO Empty Intr \n",
  86856. + epnum);
  86857. + write_empty_tx_fifo(pcd, epnum);
  86858. +
  86859. + CLEAR_IN_EP_INTR(core_if, epnum, emptyintr);
  86860. +
  86861. + }
  86862. +
  86863. + /** IN EP BNA Intr */
  86864. + if (diepint.b.bna) {
  86865. + CLEAR_IN_EP_INTR(core_if, epnum, bna);
  86866. + if (core_if->dma_desc_enable) {
  86867. +#ifdef DWC_EN_ISOC
  86868. + if (dwc_ep->type ==
  86869. + DWC_OTG_EP_TYPE_ISOC) {
  86870. + /*
  86871. + * This checking is performed to prevent first "false" BNA
  86872. + * handling occuring right after reconnect
  86873. + */
  86874. + if (dwc_ep->next_frame !=
  86875. + 0xffffffff)
  86876. + dwc_otg_pcd_handle_iso_bna(ep);
  86877. + } else
  86878. +#endif /* DWC_EN_ISOC */
  86879. + {
  86880. + dwc_otg_pcd_handle_noniso_bna(ep);
  86881. + }
  86882. + }
  86883. + }
  86884. + /* NAK Interrutp */
  86885. + if (diepint.b.nak) {
  86886. + DWC_DEBUGPL(DBG_ANY, "EP%d IN NAK Interrupt\n",
  86887. + epnum);
  86888. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  86889. + depctl_data_t depctl;
  86890. + if (ep->dwc_ep.frame_num == 0xFFFFFFFF) {
  86891. + ep->dwc_ep.frame_num = core_if->frame_num;
  86892. + if (ep->dwc_ep.bInterval > 1) {
  86893. + depctl.d32 = 0;
  86894. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  86895. + if (ep->dwc_ep.frame_num & 0x1) {
  86896. + depctl.b.setd1pid = 1;
  86897. + depctl.b.setd0pid = 0;
  86898. + } else {
  86899. + depctl.b.setd0pid = 1;
  86900. + depctl.b.setd1pid = 0;
  86901. + }
  86902. + DWC_WRITE_REG32(&dev_if->in_ep_regs[epnum]->diepctl, depctl.d32);
  86903. + }
  86904. + start_next_request(ep);
  86905. + }
  86906. + ep->dwc_ep.frame_num += ep->dwc_ep.bInterval;
  86907. + if (dwc_ep->frame_num > 0x3FFF) {
  86908. + dwc_ep->frm_overrun = 1;
  86909. + dwc_ep->frame_num &= 0x3FFF;
  86910. + } else
  86911. + dwc_ep->frm_overrun = 0;
  86912. + }
  86913. +
  86914. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  86915. + }
  86916. + }
  86917. + epnum++;
  86918. + ep_intr >>= 1;
  86919. + }
  86920. +
  86921. + return 1;
  86922. +#undef CLEAR_IN_EP_INTR
  86923. +}
  86924. +
  86925. +/**
  86926. + * This interrupt indicates that an OUT EP has a pending Interrupt.
  86927. + * The sequence for handling the OUT EP interrupt is shown below:
  86928. + * -# Read the Device All Endpoint Interrupt register
  86929. + * -# Repeat the following for each OUT EP interrupt bit set (from
  86930. + * LSB to MSB).
  86931. + * -# Read the Device Endpoint Interrupt (DOEPINTn) register
  86932. + * -# If "Transfer Complete" call the request complete function
  86933. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  86934. + * -# If "AHB Error Interrupt" log error
  86935. + * -# If "Setup Phase Done" process Setup Packet (See Standard USB
  86936. + * Command Processing)
  86937. + */
  86938. +static int32_t dwc_otg_pcd_handle_out_ep_intr(dwc_otg_pcd_t * pcd)
  86939. +{
  86940. +#define CLEAR_OUT_EP_INTR(__core_if,__epnum,__intr) \
  86941. +do { \
  86942. + doepint_data_t doepint = {.d32=0}; \
  86943. + doepint.b.__intr = 1; \
  86944. + DWC_WRITE_REG32(&__core_if->dev_if->out_ep_regs[__epnum]->doepint, \
  86945. + doepint.d32); \
  86946. +} while (0)
  86947. +
  86948. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86949. + uint32_t ep_intr;
  86950. + doepint_data_t doepint = {.d32 = 0 };
  86951. + uint32_t epnum = 0;
  86952. + dwc_otg_pcd_ep_t *ep;
  86953. + dwc_ep_t *dwc_ep;
  86954. + dctl_data_t dctl = {.d32 = 0 };
  86955. + gintmsk_data_t gintmsk = {.d32 = 0 };
  86956. +
  86957. +
  86958. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  86959. +
  86960. + /* Read in the device interrupt bits */
  86961. + ep_intr = dwc_otg_read_dev_all_out_ep_intr(core_if);
  86962. +
  86963. + while (ep_intr) {
  86964. + if (ep_intr & 0x1) {
  86965. + /* Get EP pointer */
  86966. + ep = get_out_ep(pcd, epnum);
  86967. + dwc_ep = &ep->dwc_ep;
  86968. +
  86969. +#ifdef VERBOSE
  86970. + DWC_DEBUGPL(DBG_PCDV,
  86971. + "EP%d-%s: type=%d, mps=%d\n",
  86972. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  86973. + dwc_ep->type, dwc_ep->maxpacket);
  86974. +#endif
  86975. + doepint.d32 =
  86976. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep);
  86977. + /* Moved this interrupt upper due to core deffect of asserting
  86978. + * OUT EP 0 xfercompl along with stsphsrcvd in BDMA */
  86979. + if (doepint.b.stsphsercvd) {
  86980. + deptsiz0_data_t deptsiz;
  86981. + CLEAR_OUT_EP_INTR(core_if, epnum, stsphsercvd);
  86982. + deptsiz.d32 =
  86983. + DWC_READ_REG32(&core_if->dev_if->
  86984. + out_ep_regs[0]->doeptsiz);
  86985. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  86986. + && core_if->dma_enable
  86987. + && core_if->dma_desc_enable == 0
  86988. + && doepint.b.xfercompl
  86989. + && deptsiz.b.xfersize == 24) {
  86990. + CLEAR_OUT_EP_INTR(core_if, epnum,
  86991. + xfercompl);
  86992. + doepint.b.xfercompl = 0;
  86993. + ep0_out_start(core_if, pcd);
  86994. + }
  86995. + if ((core_if->dma_desc_enable) ||
  86996. + (core_if->dma_enable
  86997. + && core_if->snpsid >=
  86998. + OTG_CORE_REV_3_00a)) {
  86999. + do_setup_in_status_phase(pcd);
  87000. + }
  87001. + }
  87002. + /* Transfer complete */
  87003. + if (doepint.b.xfercompl) {
  87004. +
  87005. + if (epnum == 0) {
  87006. + /* Clear the bit in DOEPINTn for this interrupt */
  87007. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  87008. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  87009. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  87010. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepint),
  87011. + doepint.d32);
  87012. + DWC_DEBUGPL(DBG_PCDV, "DOEPCTL=%x \n",
  87013. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepctl));
  87014. +
  87015. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  87016. + && core_if->dma_enable == 0) {
  87017. + doepint_data_t doepint;
  87018. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  87019. + out_ep_regs[0]->doepint);
  87020. + if (pcd->ep0state == EP0_IDLE && doepint.b.sr) {
  87021. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  87022. + goto exit_xfercompl;
  87023. + }
  87024. + }
  87025. + /* In case of DDMA look at SR bit to go to the Data Stage */
  87026. + if (core_if->dma_desc_enable) {
  87027. + dev_dma_desc_sts_t status = {.d32 = 0};
  87028. + if (pcd->ep0state == EP0_IDLE) {
  87029. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  87030. + dev_if->setup_desc_index]->status.d32;
  87031. + if(pcd->data_terminated) {
  87032. + pcd->data_terminated = 0;
  87033. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  87034. + dwc_memcpy(&pcd->setup_pkt->req, pcd->backup_buf, 8);
  87035. + }
  87036. + if (status.b.sr) {
  87037. + if (doepint.b.setup) {
  87038. + DWC_DEBUGPL(DBG_PCDV, "DMA DESC EP0_IDLE SR=1 setup=1\n");
  87039. + /* Already started data stage, clear setup */
  87040. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  87041. + doepint.b.setup = 0;
  87042. + handle_ep0(pcd);
  87043. + /* Prepare for more setup packets */
  87044. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  87045. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  87046. + ep0_out_start(core_if, pcd);
  87047. + }
  87048. +
  87049. + goto exit_xfercompl;
  87050. + } else {
  87051. + /* Prepare for more setup packets */
  87052. + DWC_DEBUGPL(DBG_PCDV,
  87053. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  87054. + ep0_out_start(core_if, pcd);
  87055. + }
  87056. + }
  87057. + } else {
  87058. + dwc_otg_pcd_request_t *req;
  87059. + dev_dma_desc_sts_t status = {.d32 = 0};
  87060. + diepint_data_t diepint0;
  87061. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  87062. + in_ep_regs[0]->diepint);
  87063. +
  87064. + if (pcd->ep0state == EP0_STALL || pcd->ep0state == EP0_DISCONNECT) {
  87065. + DWC_ERROR("EP0 is stalled/disconnected\n");
  87066. + }
  87067. +
  87068. + /* Clear IN xfercompl if set */
  87069. + if (diepint0.b.xfercompl && (pcd->ep0state == EP0_IN_STATUS_PHASE
  87070. + || pcd->ep0state == EP0_IN_DATA_PHASE)) {
  87071. + DWC_WRITE_REG32(&core_if->dev_if->
  87072. + in_ep_regs[0]->diepint, diepint0.d32);
  87073. + }
  87074. +
  87075. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  87076. + dev_if->setup_desc_index]->status.d32;
  87077. +
  87078. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len
  87079. + && (pcd->ep0state == EP0_OUT_DATA_PHASE))
  87080. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  87081. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE)
  87082. + status.d32 = core_if->dev_if->
  87083. + out_desc_addr->status.d32;
  87084. +
  87085. + if (status.b.sr) {
  87086. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  87087. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  87088. + } else {
  87089. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  87090. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  87091. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  87092. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  87093. + /* Read arrived setup packet from req->buf */
  87094. + dwc_memcpy(&pcd->setup_pkt->req,
  87095. + req->buf + ep->dwc_ep.xfer_count, 8);
  87096. + }
  87097. + req->actual = ep->dwc_ep.xfer_count;
  87098. + dwc_otg_request_done(ep, req, -ECONNRESET);
  87099. + ep->dwc_ep.start_xfer_buff = 0;
  87100. + ep->dwc_ep.xfer_buff = 0;
  87101. + ep->dwc_ep.xfer_len = 0;
  87102. + }
  87103. + pcd->ep0state = EP0_IDLE;
  87104. + if (doepint.b.setup) {
  87105. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  87106. + /* Data stage started, clear setup */
  87107. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  87108. + doepint.b.setup = 0;
  87109. + handle_ep0(pcd);
  87110. + /* Prepare for setup packets if ep0in was enabled*/
  87111. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  87112. + ep0_out_start(core_if, pcd);
  87113. + }
  87114. +
  87115. + goto exit_xfercompl;
  87116. + } else {
  87117. + /* Prepare for more setup packets */
  87118. + DWC_DEBUGPL(DBG_PCDV,
  87119. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  87120. + ep0_out_start(core_if, pcd);
  87121. + }
  87122. + }
  87123. + }
  87124. + }
  87125. + if (core_if->snpsid >= OTG_CORE_REV_2_94a && core_if->dma_enable
  87126. + && core_if->dma_desc_enable == 0) {
  87127. + doepint_data_t doepint_temp = {.d32 = 0};
  87128. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  87129. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  87130. + out_ep_regs[ep->dwc_ep.num]->doepint);
  87131. + doeptsize0.d32 = DWC_READ_REG32(&core_if->dev_if->
  87132. + out_ep_regs[ep->dwc_ep.num]->doeptsiz);
  87133. + if (pcd->ep0state == EP0_IDLE) {
  87134. + if (doepint_temp.b.sr) {
  87135. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  87136. + }
  87137. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  87138. + out_ep_regs[0]->doepint);
  87139. + if (doeptsize0.b.supcnt == 3) {
  87140. + DWC_DEBUGPL(DBG_ANY, "Rolling over!!!!!!!\n");
  87141. + ep->dwc_ep.stp_rollover = 1;
  87142. + }
  87143. + if (doepint.b.setup) {
  87144. +retry:
  87145. + /* Already started data stage, clear setup */
  87146. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  87147. + doepint.b.setup = 0;
  87148. + handle_ep0(pcd);
  87149. + ep->dwc_ep.stp_rollover = 0;
  87150. + /* Prepare for more setup packets */
  87151. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  87152. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  87153. + ep0_out_start(core_if, pcd);
  87154. + }
  87155. + goto exit_xfercompl;
  87156. + } else {
  87157. + /* Prepare for more setup packets */
  87158. + DWC_DEBUGPL(DBG_ANY,
  87159. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  87160. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  87161. + out_ep_regs[0]->doepint);
  87162. + if(doepint.b.setup)
  87163. + goto retry;
  87164. + ep0_out_start(core_if, pcd);
  87165. + }
  87166. + } else {
  87167. + dwc_otg_pcd_request_t *req;
  87168. + diepint_data_t diepint0 = {.d32 = 0};
  87169. + doepint_data_t doepint_temp = {.d32 = 0};
  87170. + depctl_data_t diepctl0;
  87171. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  87172. + in_ep_regs[0]->diepint);
  87173. + diepctl0.d32 = DWC_READ_REG32(&core_if->dev_if->
  87174. + in_ep_regs[0]->diepctl);
  87175. +
  87176. + if (pcd->ep0state == EP0_IN_DATA_PHASE
  87177. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  87178. + if (diepint0.b.xfercompl) {
  87179. + DWC_WRITE_REG32(&core_if->dev_if->
  87180. + in_ep_regs[0]->diepint, diepint0.d32);
  87181. + }
  87182. + if (diepctl0.b.epena) {
  87183. + diepint_data_t diepint = {.d32 = 0};
  87184. + diepctl0.b.snak = 1;
  87185. + DWC_WRITE_REG32(&core_if->dev_if->
  87186. + in_ep_regs[0]->diepctl, diepctl0.d32);
  87187. + do {
  87188. + dwc_udelay(10);
  87189. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  87190. + in_ep_regs[0]->diepint);
  87191. + } while (!diepint.b.inepnakeff);
  87192. + diepint.b.inepnakeff = 1;
  87193. + DWC_WRITE_REG32(&core_if->dev_if->
  87194. + in_ep_regs[0]->diepint, diepint.d32);
  87195. + diepctl0.d32 = 0;
  87196. + diepctl0.b.epdis = 1;
  87197. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl,
  87198. + diepctl0.d32);
  87199. + do {
  87200. + dwc_udelay(10);
  87201. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  87202. + in_ep_regs[0]->diepint);
  87203. + } while (!diepint.b.epdisabled);
  87204. + diepint.b.epdisabled = 1;
  87205. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepint,
  87206. + diepint.d32);
  87207. + }
  87208. + }
  87209. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  87210. + out_ep_regs[ep->dwc_ep.num]->doepint);
  87211. + if (doepint_temp.b.sr) {
  87212. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  87213. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  87214. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  87215. + } else {
  87216. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  87217. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  87218. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  87219. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  87220. + /* Read arrived setup packet from req->buf */
  87221. + dwc_memcpy(&pcd->setup_pkt->req,
  87222. + req->buf + ep->dwc_ep.xfer_count, 8);
  87223. + }
  87224. + req->actual = ep->dwc_ep.xfer_count;
  87225. + dwc_otg_request_done(ep, req, -ECONNRESET);
  87226. + ep->dwc_ep.start_xfer_buff = 0;
  87227. + ep->dwc_ep.xfer_buff = 0;
  87228. + ep->dwc_ep.xfer_len = 0;
  87229. + }
  87230. + pcd->ep0state = EP0_IDLE;
  87231. + if (doepint.b.setup) {
  87232. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  87233. + /* Data stage started, clear setup */
  87234. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  87235. + doepint.b.setup = 0;
  87236. + handle_ep0(pcd);
  87237. + /* Prepare for setup packets if ep0in was enabled*/
  87238. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  87239. + ep0_out_start(core_if, pcd);
  87240. + }
  87241. + goto exit_xfercompl;
  87242. + } else {
  87243. + /* Prepare for more setup packets */
  87244. + DWC_DEBUGPL(DBG_PCDV,
  87245. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  87246. + ep0_out_start(core_if, pcd);
  87247. + }
  87248. + }
  87249. + }
  87250. + }
  87251. + if (core_if->dma_enable == 0 || pcd->ep0state != EP0_IDLE)
  87252. + handle_ep0(pcd);
  87253. +exit_xfercompl:
  87254. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  87255. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep), doepint.d32);
  87256. + } else {
  87257. + if (core_if->dma_desc_enable == 0
  87258. + || pcd->ep0state != EP0_IDLE)
  87259. + handle_ep0(pcd);
  87260. + }
  87261. +#ifdef DWC_EN_ISOC
  87262. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  87263. + if (doepint.b.pktdrpsts == 0) {
  87264. + /* Clear the bit in DOEPINTn for this interrupt */
  87265. + CLEAR_OUT_EP_INTR(core_if,
  87266. + epnum,
  87267. + xfercompl);
  87268. + complete_iso_ep(pcd, ep);
  87269. + } else {
  87270. +
  87271. + doepint_data_t doepint = {.d32 = 0 };
  87272. + doepint.b.xfercompl = 1;
  87273. + doepint.b.pktdrpsts = 1;
  87274. + DWC_WRITE_REG32
  87275. + (&core_if->dev_if->out_ep_regs
  87276. + [epnum]->doepint,
  87277. + doepint.d32);
  87278. + if (handle_iso_out_pkt_dropped
  87279. + (core_if, dwc_ep)) {
  87280. + complete_iso_ep(pcd,
  87281. + ep);
  87282. + }
  87283. + }
  87284. +#endif /* DWC_EN_ISOC */
  87285. +#ifdef DWC_UTE_PER_IO
  87286. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  87287. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  87288. + if (!ep->stopped)
  87289. + complete_xiso_ep(ep);
  87290. +#endif /* DWC_UTE_PER_IO */
  87291. + } else {
  87292. + /* Clear the bit in DOEPINTn for this interrupt */
  87293. + CLEAR_OUT_EP_INTR(core_if, epnum,
  87294. + xfercompl);
  87295. +
  87296. + if (core_if->core_params->dev_out_nak) {
  87297. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[epnum]);
  87298. + pcd->core_if->ep_xfer_info[epnum].state = 0;
  87299. +#ifdef DEBUG
  87300. + print_memory_payload(pcd, dwc_ep);
  87301. +#endif
  87302. + }
  87303. + complete_ep(ep);
  87304. + }
  87305. +
  87306. + }
  87307. +
  87308. + /* Endpoint disable */
  87309. + if (doepint.b.epdisabled) {
  87310. +
  87311. + /* Clear the bit in DOEPINTn for this interrupt */
  87312. + CLEAR_OUT_EP_INTR(core_if, epnum, epdisabled);
  87313. + if (core_if->core_params->dev_out_nak) {
  87314. +#ifdef DEBUG
  87315. + print_memory_payload(pcd, dwc_ep);
  87316. +#endif
  87317. + /* In case of timeout condition */
  87318. + if (core_if->ep_xfer_info[epnum].state == 2) {
  87319. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  87320. + dev_global_regs->dctl);
  87321. + dctl.b.cgoutnak = 1;
  87322. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  87323. + dctl.d32);
  87324. + /* Unmask goutnakeff interrupt which was masked
  87325. + * during handle nak out interrupt */
  87326. + gintmsk.b.goutnakeff = 1;
  87327. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  87328. + 0, gintmsk.d32);
  87329. +
  87330. + complete_ep(ep);
  87331. + }
  87332. + }
  87333. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  87334. + {
  87335. + dctl_data_t dctl;
  87336. + gintmsk_data_t intr_mask = {.d32 = 0};
  87337. + dwc_otg_pcd_request_t *req = 0;
  87338. +
  87339. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  87340. + dev_global_regs->dctl);
  87341. + dctl.b.cgoutnak = 1;
  87342. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  87343. + dctl.d32);
  87344. +
  87345. + intr_mask.d32 = 0;
  87346. + intr_mask.b.incomplisoout = 1;
  87347. +
  87348. + /* Get any pending requests */
  87349. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  87350. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  87351. + if (!req) {
  87352. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  87353. + } else {
  87354. + dwc_otg_request_done(ep, req, 0);
  87355. + start_next_request(ep);
  87356. + }
  87357. + } else {
  87358. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  87359. + }
  87360. + }
  87361. + }
  87362. + /* AHB Error */
  87363. + if (doepint.b.ahberr) {
  87364. + DWC_ERROR("EP%d OUT AHB Error\n", epnum);
  87365. + DWC_ERROR("EP%d DEPDMA=0x%08x \n",
  87366. + epnum, core_if->dev_if->out_ep_regs[epnum]->doepdma);
  87367. + CLEAR_OUT_EP_INTR(core_if, epnum, ahberr);
  87368. + }
  87369. + /* Setup Phase Done (contorl EPs) */
  87370. + if (doepint.b.setup) {
  87371. +#ifdef DEBUG_EP0
  87372. + DWC_DEBUGPL(DBG_PCD, "EP%d SETUP Done\n", epnum);
  87373. +#endif
  87374. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  87375. +
  87376. + handle_ep0(pcd);
  87377. + }
  87378. +
  87379. + /** OUT EP BNA Intr */
  87380. + if (doepint.b.bna) {
  87381. + CLEAR_OUT_EP_INTR(core_if, epnum, bna);
  87382. + if (core_if->dma_desc_enable) {
  87383. +#ifdef DWC_EN_ISOC
  87384. + if (dwc_ep->type ==
  87385. + DWC_OTG_EP_TYPE_ISOC) {
  87386. + /*
  87387. + * This checking is performed to prevent first "false" BNA
  87388. + * handling occuring right after reconnect
  87389. + */
  87390. + if (dwc_ep->next_frame !=
  87391. + 0xffffffff)
  87392. + dwc_otg_pcd_handle_iso_bna(ep);
  87393. + } else
  87394. +#endif /* DWC_EN_ISOC */
  87395. + {
  87396. + dwc_otg_pcd_handle_noniso_bna(ep);
  87397. + }
  87398. + }
  87399. + }
  87400. + /* Babble Interrupt */
  87401. + if (doepint.b.babble) {
  87402. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Babble\n",
  87403. + epnum);
  87404. + handle_out_ep_babble_intr(pcd, epnum);
  87405. +
  87406. + CLEAR_OUT_EP_INTR(core_if, epnum, babble);
  87407. + }
  87408. + if (doepint.b.outtknepdis) {
  87409. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Token received when EP is \
  87410. + disabled\n",epnum);
  87411. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  87412. + doepmsk_data_t doepmsk = {.d32 = 0};
  87413. + ep->dwc_ep.frame_num = core_if->frame_num;
  87414. + if (ep->dwc_ep.bInterval > 1) {
  87415. + depctl_data_t depctl;
  87416. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  87417. + out_ep_regs[epnum]->doepctl);
  87418. + if (ep->dwc_ep.frame_num & 0x1) {
  87419. + depctl.b.setd1pid = 1;
  87420. + depctl.b.setd0pid = 0;
  87421. + } else {
  87422. + depctl.b.setd0pid = 1;
  87423. + depctl.b.setd1pid = 0;
  87424. + }
  87425. + DWC_WRITE_REG32(&core_if->dev_if->
  87426. + out_ep_regs[epnum]->doepctl, depctl.d32);
  87427. + }
  87428. + start_next_request(ep);
  87429. + doepmsk.b.outtknepdis = 1;
  87430. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  87431. + doepmsk.d32, 0);
  87432. + }
  87433. + CLEAR_OUT_EP_INTR(core_if, epnum, outtknepdis);
  87434. + }
  87435. +
  87436. + /* NAK Interrutp */
  87437. + if (doepint.b.nak) {
  87438. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NAK\n", epnum);
  87439. + handle_out_ep_nak_intr(pcd, epnum);
  87440. +
  87441. + CLEAR_OUT_EP_INTR(core_if, epnum, nak);
  87442. + }
  87443. + /* NYET Interrutp */
  87444. + if (doepint.b.nyet) {
  87445. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NYET\n", epnum);
  87446. + handle_out_ep_nyet_intr(pcd, epnum);
  87447. +
  87448. + CLEAR_OUT_EP_INTR(core_if, epnum, nyet);
  87449. + }
  87450. + }
  87451. +
  87452. + epnum++;
  87453. + ep_intr >>= 1;
  87454. + }
  87455. +
  87456. + return 1;
  87457. +
  87458. +#undef CLEAR_OUT_EP_INTR
  87459. +}
  87460. +static int drop_transfer(uint32_t trgt_fr, uint32_t curr_fr, uint8_t frm_overrun)
  87461. +{
  87462. + int retval = 0;
  87463. + if(!frm_overrun && curr_fr >= trgt_fr)
  87464. + retval = 1;
  87465. + else if (frm_overrun
  87466. + && (curr_fr >= trgt_fr && ((curr_fr - trgt_fr) < 0x3FFF / 2)))
  87467. + retval = 1;
  87468. + return retval;
  87469. +}
  87470. +/**
  87471. + * Incomplete ISO IN Transfer Interrupt.
  87472. + * This interrupt indicates one of the following conditions occurred
  87473. + * while transmitting an ISOC transaction.
  87474. + * - Corrupted IN Token for ISOC EP.
  87475. + * - Packet not complete in FIFO.
  87476. + * The follow actions will be taken:
  87477. + * -# Determine the EP
  87478. + * -# Set incomplete flag in dwc_ep structure
  87479. + * -# Disable EP; when "Endpoint Disabled" interrupt is received
  87480. + * Flush FIFO
  87481. + */
  87482. +int32_t dwc_otg_pcd_handle_incomplete_isoc_in_intr(dwc_otg_pcd_t * pcd)
  87483. +{
  87484. + gintsts_data_t gintsts;
  87485. +
  87486. +#ifdef DWC_EN_ISOC
  87487. + dwc_otg_dev_if_t *dev_if;
  87488. + deptsiz_data_t deptsiz = {.d32 = 0 };
  87489. + depctl_data_t depctl = {.d32 = 0 };
  87490. + dsts_data_t dsts = {.d32 = 0 };
  87491. + dwc_ep_t *dwc_ep;
  87492. + int i;
  87493. +
  87494. + dev_if = GET_CORE_IF(pcd)->dev_if;
  87495. +
  87496. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  87497. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  87498. + if (dwc_ep->active && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  87499. + deptsiz.d32 =
  87500. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  87501. + depctl.d32 =
  87502. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  87503. +
  87504. + if (depctl.b.epdis && deptsiz.d32) {
  87505. + set_current_pkt_info(GET_CORE_IF(pcd), dwc_ep);
  87506. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  87507. + dwc_ep->cur_pkt = 0;
  87508. + dwc_ep->proc_buf_num =
  87509. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  87510. +
  87511. + if (dwc_ep->proc_buf_num) {
  87512. + dwc_ep->cur_pkt_addr =
  87513. + dwc_ep->xfer_buff1;
  87514. + dwc_ep->cur_pkt_dma_addr =
  87515. + dwc_ep->dma_addr1;
  87516. + } else {
  87517. + dwc_ep->cur_pkt_addr =
  87518. + dwc_ep->xfer_buff0;
  87519. + dwc_ep->cur_pkt_dma_addr =
  87520. + dwc_ep->dma_addr0;
  87521. + }
  87522. +
  87523. + }
  87524. +
  87525. + dsts.d32 =
  87526. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  87527. + dev_global_regs->dsts);
  87528. + dwc_ep->next_frame = dsts.b.soffn;
  87529. +
  87530. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  87531. + (pcd),
  87532. + dwc_ep);
  87533. + }
  87534. + }
  87535. + }
  87536. +
  87537. +#else
  87538. + depctl_data_t depctl = {.d32 = 0 };
  87539. + dwc_ep_t *dwc_ep;
  87540. + dwc_otg_dev_if_t *dev_if;
  87541. + int i;
  87542. + dev_if = GET_CORE_IF(pcd)->dev_if;
  87543. +
  87544. + DWC_DEBUGPL(DBG_PCD,"Incomplete ISO IN \n");
  87545. +
  87546. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  87547. + dwc_ep = &pcd->in_ep[i-1].dwc_ep;
  87548. + depctl.d32 =
  87549. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  87550. + if (depctl.b.epena && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  87551. + if (drop_transfer(dwc_ep->frame_num, GET_CORE_IF(pcd)->frame_num,
  87552. + dwc_ep->frm_overrun))
  87553. + {
  87554. + depctl.d32 =
  87555. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  87556. + depctl.b.snak = 1;
  87557. + depctl.b.epdis = 1;
  87558. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32, depctl.d32);
  87559. + }
  87560. + }
  87561. + }
  87562. +
  87563. + /*intr_mask.b.incomplisoin = 1;
  87564. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  87565. + intr_mask.d32, 0); */
  87566. +#endif //DWC_EN_ISOC
  87567. +
  87568. + /* Clear interrupt */
  87569. + gintsts.d32 = 0;
  87570. + gintsts.b.incomplisoin = 1;
  87571. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  87572. + gintsts.d32);
  87573. +
  87574. + return 1;
  87575. +}
  87576. +
  87577. +/**
  87578. + * Incomplete ISO OUT Transfer Interrupt.
  87579. + *
  87580. + * This interrupt indicates that the core has dropped an ISO OUT
  87581. + * packet. The following conditions can be the cause:
  87582. + * - FIFO Full, the entire packet would not fit in the FIFO.
  87583. + * - CRC Error
  87584. + * - Corrupted Token
  87585. + * The follow actions will be taken:
  87586. + * -# Determine the EP
  87587. + * -# Set incomplete flag in dwc_ep structure
  87588. + * -# Read any data from the FIFO
  87589. + * -# Disable EP. When "Endpoint Disabled" interrupt is received
  87590. + * re-enable EP.
  87591. + */
  87592. +int32_t dwc_otg_pcd_handle_incomplete_isoc_out_intr(dwc_otg_pcd_t * pcd)
  87593. +{
  87594. +
  87595. + gintsts_data_t gintsts;
  87596. +
  87597. +#ifdef DWC_EN_ISOC
  87598. + dwc_otg_dev_if_t *dev_if;
  87599. + deptsiz_data_t deptsiz = {.d32 = 0 };
  87600. + depctl_data_t depctl = {.d32 = 0 };
  87601. + dsts_data_t dsts = {.d32 = 0 };
  87602. + dwc_ep_t *dwc_ep;
  87603. + int i;
  87604. +
  87605. + dev_if = GET_CORE_IF(pcd)->dev_if;
  87606. +
  87607. + for (i = 1; i <= dev_if->num_out_eps; ++i) {
  87608. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  87609. + if (pcd->out_ep[i].dwc_ep.active &&
  87610. + pcd->out_ep[i].dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  87611. + deptsiz.d32 =
  87612. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doeptsiz);
  87613. + depctl.d32 =
  87614. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  87615. +
  87616. + if (depctl.b.epdis && deptsiz.d32) {
  87617. + set_current_pkt_info(GET_CORE_IF(pcd),
  87618. + &pcd->out_ep[i].dwc_ep);
  87619. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  87620. + dwc_ep->cur_pkt = 0;
  87621. + dwc_ep->proc_buf_num =
  87622. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  87623. +
  87624. + if (dwc_ep->proc_buf_num) {
  87625. + dwc_ep->cur_pkt_addr =
  87626. + dwc_ep->xfer_buff1;
  87627. + dwc_ep->cur_pkt_dma_addr =
  87628. + dwc_ep->dma_addr1;
  87629. + } else {
  87630. + dwc_ep->cur_pkt_addr =
  87631. + dwc_ep->xfer_buff0;
  87632. + dwc_ep->cur_pkt_dma_addr =
  87633. + dwc_ep->dma_addr0;
  87634. + }
  87635. +
  87636. + }
  87637. +
  87638. + dsts.d32 =
  87639. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  87640. + dev_global_regs->dsts);
  87641. + dwc_ep->next_frame = dsts.b.soffn;
  87642. +
  87643. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  87644. + (pcd),
  87645. + dwc_ep);
  87646. + }
  87647. + }
  87648. + }
  87649. +#else
  87650. + /** @todo implement ISR */
  87651. + gintmsk_data_t intr_mask = {.d32 = 0 };
  87652. + dwc_otg_core_if_t *core_if;
  87653. + deptsiz_data_t deptsiz = {.d32 = 0 };
  87654. + depctl_data_t depctl = {.d32 = 0 };
  87655. + dctl_data_t dctl = {.d32 = 0 };
  87656. + dwc_ep_t *dwc_ep = NULL;
  87657. + int i;
  87658. + core_if = GET_CORE_IF(pcd);
  87659. +
  87660. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  87661. + dwc_ep = &pcd->out_ep[i].dwc_ep;
  87662. + depctl.d32 =
  87663. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  87664. + if (depctl.b.epena && depctl.b.dpid == (core_if->frame_num & 0x1)) {
  87665. + core_if->dev_if->isoc_ep = dwc_ep;
  87666. + deptsiz.d32 =
  87667. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz);
  87668. + break;
  87669. + }
  87670. + }
  87671. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  87672. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  87673. + intr_mask.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  87674. +
  87675. + if (!intr_mask.b.goutnakeff) {
  87676. + /* Unmask it */
  87677. + intr_mask.b.goutnakeff = 1;
  87678. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32);
  87679. + }
  87680. + if (!gintsts.b.goutnakeff) {
  87681. + dctl.b.sgoutnak = 1;
  87682. + }
  87683. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  87684. +
  87685. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  87686. + if (depctl.b.epena) {
  87687. + depctl.b.epdis = 1;
  87688. + depctl.b.snak = 1;
  87689. + }
  87690. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl, depctl.d32);
  87691. +
  87692. + intr_mask.d32 = 0;
  87693. + intr_mask.b.incomplisoout = 1;
  87694. +
  87695. +#endif /* DWC_EN_ISOC */
  87696. +
  87697. + /* Clear interrupt */
  87698. + gintsts.d32 = 0;
  87699. + gintsts.b.incomplisoout = 1;
  87700. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  87701. + gintsts.d32);
  87702. +
  87703. + return 1;
  87704. +}
  87705. +
  87706. +/**
  87707. + * This function handles the Global IN NAK Effective interrupt.
  87708. + *
  87709. + */
  87710. +int32_t dwc_otg_pcd_handle_in_nak_effective(dwc_otg_pcd_t * pcd)
  87711. +{
  87712. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  87713. + depctl_data_t diepctl = {.d32 = 0 };
  87714. + gintmsk_data_t intr_mask = {.d32 = 0 };
  87715. + gintsts_data_t gintsts;
  87716. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87717. + int i;
  87718. +
  87719. + DWC_DEBUGPL(DBG_PCD, "Global IN NAK Effective\n");
  87720. +
  87721. + /* Disable all active IN EPs */
  87722. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  87723. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  87724. + if (!(diepctl.b.eptype & 1) && diepctl.b.epena) {
  87725. + if (core_if->start_predict > 0)
  87726. + core_if->start_predict++;
  87727. + diepctl.b.epdis = 1;
  87728. + diepctl.b.snak = 1;
  87729. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, diepctl.d32);
  87730. + }
  87731. + }
  87732. +
  87733. +
  87734. + /* Disable the Global IN NAK Effective Interrupt */
  87735. + intr_mask.b.ginnakeff = 1;
  87736. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  87737. + intr_mask.d32, 0);
  87738. +
  87739. + /* Clear interrupt */
  87740. + gintsts.d32 = 0;
  87741. + gintsts.b.ginnakeff = 1;
  87742. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  87743. + gintsts.d32);
  87744. +
  87745. + return 1;
  87746. +}
  87747. +
  87748. +/**
  87749. + * OUT NAK Effective.
  87750. + *
  87751. + */
  87752. +int32_t dwc_otg_pcd_handle_out_nak_effective(dwc_otg_pcd_t * pcd)
  87753. +{
  87754. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  87755. + gintmsk_data_t intr_mask = {.d32 = 0 };
  87756. + gintsts_data_t gintsts;
  87757. + depctl_data_t doepctl;
  87758. + int i;
  87759. +
  87760. + /* Disable the Global OUT NAK Effective Interrupt */
  87761. + intr_mask.b.goutnakeff = 1;
  87762. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  87763. + intr_mask.d32, 0);
  87764. +
  87765. + /* If DEV OUT NAK enabled*/
  87766. + if (pcd->core_if->core_params->dev_out_nak) {
  87767. + /* Run over all out endpoints to determine the ep number on
  87768. + * which the timeout has happened
  87769. + */
  87770. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  87771. + if ( pcd->core_if->ep_xfer_info[i].state == 2 )
  87772. + break;
  87773. + }
  87774. + if (i > dev_if->num_out_eps) {
  87775. + dctl_data_t dctl;
  87776. + dctl.d32 =
  87777. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  87778. + dctl.b.cgoutnak = 1;
  87779. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl,
  87780. + dctl.d32);
  87781. + goto out;
  87782. + }
  87783. +
  87784. + /* Disable the endpoint */
  87785. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  87786. + if (doepctl.b.epena) {
  87787. + doepctl.b.epdis = 1;
  87788. + doepctl.b.snak = 1;
  87789. + }
  87790. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  87791. + return 1;
  87792. + }
  87793. + /* We come here from Incomplete ISO OUT handler */
  87794. + if (dev_if->isoc_ep) {
  87795. + dwc_ep_t *dwc_ep = (dwc_ep_t *)dev_if->isoc_ep;
  87796. + uint32_t epnum = dwc_ep->num;
  87797. + doepint_data_t doepint;
  87798. + doepint.d32 =
  87799. + DWC_READ_REG32(&dev_if->out_ep_regs[dwc_ep->num]->doepint);
  87800. + dev_if->isoc_ep = NULL;
  87801. + doepctl.d32 =
  87802. + DWC_READ_REG32(&dev_if->out_ep_regs[epnum]->doepctl);
  87803. + DWC_PRINTF("Before disable DOEPCTL = %08x\n", doepctl.d32);
  87804. + if (doepctl.b.epena) {
  87805. + doepctl.b.epdis = 1;
  87806. + doepctl.b.snak = 1;
  87807. + }
  87808. + DWC_WRITE_REG32(&dev_if->out_ep_regs[epnum]->doepctl,
  87809. + doepctl.d32);
  87810. + return 1;
  87811. + } else
  87812. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  87813. + "Global OUT NAK Effective\n");
  87814. +
  87815. +out:
  87816. + /* Clear interrupt */
  87817. + gintsts.d32 = 0;
  87818. + gintsts.b.goutnakeff = 1;
  87819. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  87820. + gintsts.d32);
  87821. +
  87822. + return 1;
  87823. +}
  87824. +
  87825. +/**
  87826. + * PCD interrupt handler.
  87827. + *
  87828. + * The PCD handles the device interrupts. Many conditions can cause a
  87829. + * device interrupt. When an interrupt occurs, the device interrupt
  87830. + * service routine determines the cause of the interrupt and
  87831. + * dispatches handling to the appropriate function. These interrupt
  87832. + * handling functions are described below.
  87833. + *
  87834. + * All interrupt registers are processed from LSB to MSB.
  87835. + *
  87836. + */
  87837. +int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd)
  87838. +{
  87839. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87840. +#ifdef VERBOSE
  87841. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  87842. +#endif
  87843. + gintsts_data_t gintr_status;
  87844. + int32_t retval = 0;
  87845. +
  87846. + /* Exit from ISR if core is hibernated */
  87847. + if (core_if->hibernation_suspend == 1) {
  87848. + return retval;
  87849. + }
  87850. +#ifdef VERBOSE
  87851. + DWC_DEBUGPL(DBG_ANY, "%s() gintsts=%08x gintmsk=%08x\n",
  87852. + __func__,
  87853. + DWC_READ_REG32(&global_regs->gintsts),
  87854. + DWC_READ_REG32(&global_regs->gintmsk));
  87855. +#endif
  87856. +
  87857. + if (dwc_otg_is_device_mode(core_if)) {
  87858. + DWC_SPINLOCK(pcd->lock);
  87859. +#ifdef VERBOSE
  87860. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%08x gintmsk=%08x\n",
  87861. + __func__,
  87862. + DWC_READ_REG32(&global_regs->gintsts),
  87863. + DWC_READ_REG32(&global_regs->gintmsk));
  87864. +#endif
  87865. +
  87866. + gintr_status.d32 = dwc_otg_read_core_intr(core_if);
  87867. +
  87868. + DWC_DEBUGPL(DBG_PCDV, "%s: gintsts&gintmsk=%08x\n",
  87869. + __func__, gintr_status.d32);
  87870. +
  87871. + if (gintr_status.b.sofintr) {
  87872. + retval |= dwc_otg_pcd_handle_sof_intr(pcd);
  87873. + }
  87874. + if (gintr_status.b.rxstsqlvl) {
  87875. + retval |=
  87876. + dwc_otg_pcd_handle_rx_status_q_level_intr(pcd);
  87877. + }
  87878. + if (gintr_status.b.nptxfempty) {
  87879. + retval |= dwc_otg_pcd_handle_np_tx_fifo_empty_intr(pcd);
  87880. + }
  87881. + if (gintr_status.b.goutnakeff) {
  87882. + retval |= dwc_otg_pcd_handle_out_nak_effective(pcd);
  87883. + }
  87884. + if (gintr_status.b.i2cintr) {
  87885. + retval |= dwc_otg_pcd_handle_i2c_intr(pcd);
  87886. + }
  87887. + if (gintr_status.b.erlysuspend) {
  87888. + retval |= dwc_otg_pcd_handle_early_suspend_intr(pcd);
  87889. + }
  87890. + if (gintr_status.b.usbreset) {
  87891. + retval |= dwc_otg_pcd_handle_usb_reset_intr(pcd);
  87892. + }
  87893. + if (gintr_status.b.enumdone) {
  87894. + retval |= dwc_otg_pcd_handle_enum_done_intr(pcd);
  87895. + }
  87896. + if (gintr_status.b.isooutdrop) {
  87897. + retval |=
  87898. + dwc_otg_pcd_handle_isoc_out_packet_dropped_intr
  87899. + (pcd);
  87900. + }
  87901. + if (gintr_status.b.eopframe) {
  87902. + retval |=
  87903. + dwc_otg_pcd_handle_end_periodic_frame_intr(pcd);
  87904. + }
  87905. + if (gintr_status.b.inepint) {
  87906. + if (!core_if->multiproc_int_enable) {
  87907. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  87908. + }
  87909. + }
  87910. + if (gintr_status.b.outepintr) {
  87911. + if (!core_if->multiproc_int_enable) {
  87912. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  87913. + }
  87914. + }
  87915. + if (gintr_status.b.epmismatch) {
  87916. + retval |= dwc_otg_pcd_handle_ep_mismatch_intr(pcd);
  87917. + }
  87918. + if (gintr_status.b.fetsusp) {
  87919. + retval |= dwc_otg_pcd_handle_ep_fetsusp_intr(pcd);
  87920. + }
  87921. + if (gintr_status.b.ginnakeff) {
  87922. + retval |= dwc_otg_pcd_handle_in_nak_effective(pcd);
  87923. + }
  87924. + if (gintr_status.b.incomplisoin) {
  87925. + retval |=
  87926. + dwc_otg_pcd_handle_incomplete_isoc_in_intr(pcd);
  87927. + }
  87928. + if (gintr_status.b.incomplisoout) {
  87929. + retval |=
  87930. + dwc_otg_pcd_handle_incomplete_isoc_out_intr(pcd);
  87931. + }
  87932. +
  87933. + /* In MPI mode Device Endpoints interrupts are asserted
  87934. + * without setting outepintr and inepint bits set, so these
  87935. + * Interrupt handlers are called without checking these bit-fields
  87936. + */
  87937. + if (core_if->multiproc_int_enable) {
  87938. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  87939. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  87940. + }
  87941. +#ifdef VERBOSE
  87942. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%0x\n", __func__,
  87943. + DWC_READ_REG32(&global_regs->gintsts));
  87944. +#endif
  87945. + DWC_SPINUNLOCK(pcd->lock);
  87946. + }
  87947. + return retval;
  87948. +}
  87949. +
  87950. +#endif /* DWC_HOST_ONLY */
  87951. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c
  87952. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  87953. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 2014-02-18 11:52:14.000000000 +0100
  87954. @@ -0,0 +1,1358 @@
  87955. + /* ==========================================================================
  87956. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_linux.c $
  87957. + * $Revision: #21 $
  87958. + * $Date: 2012/08/10 $
  87959. + * $Change: 2047372 $
  87960. + *
  87961. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  87962. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  87963. + * otherwise expressly agreed to in writing between Synopsys and you.
  87964. + *
  87965. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  87966. + * any End User Software License Agreement or Agreement for Licensed Product
  87967. + * with Synopsys or any supplement thereto. You are permitted to use and
  87968. + * redistribute this Software in source and binary forms, with or without
  87969. + * modification, provided that redistributions of source code must retain this
  87970. + * notice. You may not view, use, disclose, copy or distribute this file or
  87971. + * any information contained herein except pursuant to this license grant from
  87972. + * Synopsys. If you do not agree with this notice, including the disclaimer
  87973. + * below, then you are not authorized to use the Software.
  87974. + *
  87975. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  87976. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  87977. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  87978. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  87979. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  87980. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  87981. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  87982. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  87983. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  87984. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  87985. + * DAMAGE.
  87986. + * ========================================================================== */
  87987. +#ifndef DWC_HOST_ONLY
  87988. +
  87989. +/** @file
  87990. + * This file implements the Peripheral Controller Driver.
  87991. + *
  87992. + * The Peripheral Controller Driver (PCD) is responsible for
  87993. + * translating requests from the Function Driver into the appropriate
  87994. + * actions on the DWC_otg controller. It isolates the Function Driver
  87995. + * from the specifics of the controller by providing an API to the
  87996. + * Function Driver.
  87997. + *
  87998. + * The Peripheral Controller Driver for Linux will implement the
  87999. + * Gadget API, so that the existing Gadget drivers can be used.
  88000. + * (Gadget Driver is the Linux terminology for a Function Driver.)
  88001. + *
  88002. + * The Linux Gadget API is defined in the header file
  88003. + * <code><linux/usb_gadget.h></code>. The USB EP operations API is
  88004. + * defined in the structure <code>usb_ep_ops</code> and the USB
  88005. + * Controller API is defined in the structure
  88006. + * <code>usb_gadget_ops</code>.
  88007. + *
  88008. + */
  88009. +
  88010. +#include "dwc_otg_os_dep.h"
  88011. +#include "dwc_otg_pcd_if.h"
  88012. +#include "dwc_otg_pcd.h"
  88013. +#include "dwc_otg_driver.h"
  88014. +#include "dwc_otg_dbg.h"
  88015. +
  88016. +static struct gadget_wrapper {
  88017. + dwc_otg_pcd_t *pcd;
  88018. +
  88019. + struct usb_gadget gadget;
  88020. + struct usb_gadget_driver *driver;
  88021. +
  88022. + struct usb_ep ep0;
  88023. + struct usb_ep in_ep[16];
  88024. + struct usb_ep out_ep[16];
  88025. +
  88026. +} *gadget_wrapper;
  88027. +
  88028. +/* Display the contents of the buffer */
  88029. +extern void dump_msg(const u8 * buf, unsigned int length);
  88030. +/**
  88031. + * Get the dwc_otg_pcd_ep_t* from usb_ep* pointer - NULL in case
  88032. + * if the endpoint is not found
  88033. + */
  88034. +static struct dwc_otg_pcd_ep *ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  88035. +{
  88036. + int i;
  88037. + if (pcd->ep0.priv == handle) {
  88038. + return &pcd->ep0;
  88039. + }
  88040. +
  88041. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  88042. + if (pcd->in_ep[i].priv == handle)
  88043. + return &pcd->in_ep[i];
  88044. + if (pcd->out_ep[i].priv == handle)
  88045. + return &pcd->out_ep[i];
  88046. + }
  88047. +
  88048. + return NULL;
  88049. +}
  88050. +
  88051. +/* USB Endpoint Operations */
  88052. +/*
  88053. + * The following sections briefly describe the behavior of the Gadget
  88054. + * API endpoint operations implemented in the DWC_otg driver
  88055. + * software. Detailed descriptions of the generic behavior of each of
  88056. + * these functions can be found in the Linux header file
  88057. + * include/linux/usb_gadget.h.
  88058. + *
  88059. + * The Gadget API provides wrapper functions for each of the function
  88060. + * pointers defined in usb_ep_ops. The Gadget Driver calls the wrapper
  88061. + * function, which then calls the underlying PCD function. The
  88062. + * following sections are named according to the wrapper
  88063. + * functions. Within each section, the corresponding DWC_otg PCD
  88064. + * function name is specified.
  88065. + *
  88066. + */
  88067. +
  88068. +/**
  88069. + * This function is called by the Gadget Driver for each EP to be
  88070. + * configured for the current configuration (SET_CONFIGURATION).
  88071. + *
  88072. + * This function initializes the dwc_otg_ep_t data structure, and then
  88073. + * calls dwc_otg_ep_activate.
  88074. + */
  88075. +static int ep_enable(struct usb_ep *usb_ep,
  88076. + const struct usb_endpoint_descriptor *ep_desc)
  88077. +{
  88078. + int retval;
  88079. +
  88080. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, ep_desc);
  88081. +
  88082. + if (!usb_ep || !ep_desc || ep_desc->bDescriptorType != USB_DT_ENDPOINT) {
  88083. + DWC_WARN("%s, bad ep or descriptor\n", __func__);
  88084. + return -EINVAL;
  88085. + }
  88086. + if (usb_ep == &gadget_wrapper->ep0) {
  88087. + DWC_WARN("%s, bad ep(0)\n", __func__);
  88088. + return -EINVAL;
  88089. + }
  88090. +
  88091. + /* Check FIFO size? */
  88092. + if (!ep_desc->wMaxPacketSize) {
  88093. + DWC_WARN("%s, bad %s maxpacket\n", __func__, usb_ep->name);
  88094. + return -ERANGE;
  88095. + }
  88096. +
  88097. + if (!gadget_wrapper->driver ||
  88098. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  88099. + DWC_WARN("%s, bogus device state\n", __func__);
  88100. + return -ESHUTDOWN;
  88101. + }
  88102. +
  88103. + /* Delete after check - MAS */
  88104. +#if 0
  88105. + nat = (uint32_t) ep_desc->wMaxPacketSize;
  88106. + printk(KERN_ALERT "%s: nat (before) =%d\n", __func__, nat);
  88107. + nat = (nat >> 11) & 0x03;
  88108. + printk(KERN_ALERT "%s: nat (after) =%d\n", __func__, nat);
  88109. +#endif
  88110. + retval = dwc_otg_pcd_ep_enable(gadget_wrapper->pcd,
  88111. + (const uint8_t *)ep_desc,
  88112. + (void *)usb_ep);
  88113. + if (retval) {
  88114. + DWC_WARN("dwc_otg_pcd_ep_enable failed\n");
  88115. + return -EINVAL;
  88116. + }
  88117. +
  88118. + usb_ep->maxpacket = le16_to_cpu(ep_desc->wMaxPacketSize);
  88119. +
  88120. + return 0;
  88121. +}
  88122. +
  88123. +/**
  88124. + * This function is called when an EP is disabled due to disconnect or
  88125. + * change in configuration. Any pending requests will terminate with a
  88126. + * status of -ESHUTDOWN.
  88127. + *
  88128. + * This function modifies the dwc_otg_ep_t data structure for this EP,
  88129. + * and then calls dwc_otg_ep_deactivate.
  88130. + */
  88131. +static int ep_disable(struct usb_ep *usb_ep)
  88132. +{
  88133. + int retval;
  88134. +
  88135. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, usb_ep);
  88136. + if (!usb_ep) {
  88137. + DWC_DEBUGPL(DBG_PCD, "%s, %s not enabled\n", __func__,
  88138. + usb_ep ? usb_ep->name : NULL);
  88139. + return -EINVAL;
  88140. + }
  88141. +
  88142. + retval = dwc_otg_pcd_ep_disable(gadget_wrapper->pcd, usb_ep);
  88143. + if (retval) {
  88144. + retval = -EINVAL;
  88145. + }
  88146. +
  88147. + return retval;
  88148. +}
  88149. +
  88150. +/**
  88151. + * This function allocates a request object to use with the specified
  88152. + * endpoint.
  88153. + *
  88154. + * @param ep The endpoint to be used with with the request
  88155. + * @param gfp_flags the GFP_* flags to use.
  88156. + */
  88157. +static struct usb_request *dwc_otg_pcd_alloc_request(struct usb_ep *ep,
  88158. + gfp_t gfp_flags)
  88159. +{
  88160. + struct usb_request *usb_req;
  88161. +
  88162. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d)\n", __func__, ep, gfp_flags);
  88163. + if (0 == ep) {
  88164. + DWC_WARN("%s() %s\n", __func__, "Invalid EP!\n");
  88165. + return 0;
  88166. + }
  88167. + usb_req = kmalloc(sizeof(*usb_req), gfp_flags);
  88168. + if (0 == usb_req) {
  88169. + DWC_WARN("%s() %s\n", __func__, "request allocation failed!\n");
  88170. + return 0;
  88171. + }
  88172. + memset(usb_req, 0, sizeof(*usb_req));
  88173. + usb_req->dma = DWC_DMA_ADDR_INVALID;
  88174. +
  88175. + return usb_req;
  88176. +}
  88177. +
  88178. +/**
  88179. + * This function frees a request object.
  88180. + *
  88181. + * @param ep The endpoint associated with the request
  88182. + * @param req The request being freed
  88183. + */
  88184. +static void dwc_otg_pcd_free_request(struct usb_ep *ep, struct usb_request *req)
  88185. +{
  88186. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, ep, req);
  88187. +
  88188. + if (0 == ep || 0 == req) {
  88189. + DWC_WARN("%s() %s\n", __func__,
  88190. + "Invalid ep or req argument!\n");
  88191. + return;
  88192. + }
  88193. +
  88194. + kfree(req);
  88195. +}
  88196. +
  88197. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  88198. +/**
  88199. + * This function allocates an I/O buffer to be used for a transfer
  88200. + * to/from the specified endpoint.
  88201. + *
  88202. + * @param usb_ep The endpoint to be used with with the request
  88203. + * @param bytes The desired number of bytes for the buffer
  88204. + * @param dma Pointer to the buffer's DMA address; must be valid
  88205. + * @param gfp_flags the GFP_* flags to use.
  88206. + * @return address of a new buffer or null is buffer could not be allocated.
  88207. + */
  88208. +static void *dwc_otg_pcd_alloc_buffer(struct usb_ep *usb_ep, unsigned bytes,
  88209. + dma_addr_t * dma, gfp_t gfp_flags)
  88210. +{
  88211. + void *buf;
  88212. + dwc_otg_pcd_t *pcd = 0;
  88213. +
  88214. + pcd = gadget_wrapper->pcd;
  88215. +
  88216. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d,%p,%0x)\n", __func__, usb_ep, bytes,
  88217. + dma, gfp_flags);
  88218. +
  88219. + /* Check dword alignment */
  88220. + if ((bytes & 0x3UL) != 0) {
  88221. + DWC_WARN("%s() Buffer size is not a multiple of"
  88222. + "DWORD size (%d)", __func__, bytes);
  88223. + }
  88224. +
  88225. + buf = dma_alloc_coherent(NULL, bytes, dma, gfp_flags);
  88226. +
  88227. + /* Check dword alignment */
  88228. + if (((int)buf & 0x3UL) != 0) {
  88229. + DWC_WARN("%s() Buffer is not DWORD aligned (%p)",
  88230. + __func__, buf);
  88231. + }
  88232. +
  88233. + return buf;
  88234. +}
  88235. +
  88236. +/**
  88237. + * This function frees an I/O buffer that was allocated by alloc_buffer.
  88238. + *
  88239. + * @param usb_ep the endpoint associated with the buffer
  88240. + * @param buf address of the buffer
  88241. + * @param dma The buffer's DMA address
  88242. + * @param bytes The number of bytes of the buffer
  88243. + */
  88244. +static void dwc_otg_pcd_free_buffer(struct usb_ep *usb_ep, void *buf,
  88245. + dma_addr_t dma, unsigned bytes)
  88246. +{
  88247. + dwc_otg_pcd_t *pcd = 0;
  88248. +
  88249. + pcd = gadget_wrapper->pcd;
  88250. +
  88251. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%0x,%d)\n", __func__, buf, dma, bytes);
  88252. +
  88253. + dma_free_coherent(NULL, bytes, buf, dma);
  88254. +}
  88255. +#endif
  88256. +
  88257. +/**
  88258. + * This function is used to submit an I/O Request to an EP.
  88259. + *
  88260. + * - When the request completes the request's completion callback
  88261. + * is called to return the request to the driver.
  88262. + * - An EP, except control EPs, may have multiple requests
  88263. + * pending.
  88264. + * - Once submitted the request cannot be examined or modified.
  88265. + * - Each request is turned into one or more packets.
  88266. + * - A BULK EP can queue any amount of data; the transfer is
  88267. + * packetized.
  88268. + * - Zero length Packets are specified with the request 'zero'
  88269. + * flag.
  88270. + */
  88271. +static int ep_queue(struct usb_ep *usb_ep, struct usb_request *usb_req,
  88272. + gfp_t gfp_flags)
  88273. +{
  88274. + dwc_otg_pcd_t *pcd;
  88275. + struct dwc_otg_pcd_ep *ep = NULL;
  88276. + int retval = 0, is_isoc_ep = 0;
  88277. + dma_addr_t dma_addr = DWC_DMA_ADDR_INVALID;
  88278. +
  88279. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p,%d)\n",
  88280. + __func__, usb_ep, usb_req, gfp_flags);
  88281. +
  88282. + if (!usb_req || !usb_req->complete || !usb_req->buf) {
  88283. + DWC_WARN("bad params\n");
  88284. + return -EINVAL;
  88285. + }
  88286. +
  88287. + if (!usb_ep) {
  88288. + DWC_WARN("bad ep\n");
  88289. + return -EINVAL;
  88290. + }
  88291. +
  88292. + pcd = gadget_wrapper->pcd;
  88293. + if (!gadget_wrapper->driver ||
  88294. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  88295. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  88296. + gadget_wrapper->gadget.speed);
  88297. + DWC_WARN("bogus device state\n");
  88298. + return -ESHUTDOWN;
  88299. + }
  88300. +
  88301. + DWC_DEBUGPL(DBG_PCD, "%s queue req %p, len %d buf %p\n",
  88302. + usb_ep->name, usb_req, usb_req->length, usb_req->buf);
  88303. +
  88304. + usb_req->status = -EINPROGRESS;
  88305. + usb_req->actual = 0;
  88306. +
  88307. + ep = ep_from_handle(pcd, usb_ep);
  88308. + if (ep == NULL)
  88309. + is_isoc_ep = 0;
  88310. + else
  88311. + is_isoc_ep = (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) ? 1 : 0;
  88312. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  88313. + dma_addr = usb_req->dma;
  88314. +#else
  88315. + if (GET_CORE_IF(pcd)->dma_enable) {
  88316. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  88317. + struct device *dev = NULL;
  88318. +
  88319. + if (otg_dev != NULL)
  88320. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  88321. +
  88322. + if (usb_req->length != 0 &&
  88323. + usb_req->dma == DWC_DMA_ADDR_INVALID) {
  88324. + dma_addr = dma_map_single(dev, usb_req->buf,
  88325. + usb_req->length,
  88326. + ep->dwc_ep.is_in ?
  88327. + DMA_TO_DEVICE:
  88328. + DMA_FROM_DEVICE);
  88329. + }
  88330. + }
  88331. +#endif
  88332. +
  88333. +#ifdef DWC_UTE_PER_IO
  88334. + if (is_isoc_ep == 1) {
  88335. + retval = dwc_otg_pcd_xiso_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  88336. + usb_req->length, usb_req->zero, usb_req,
  88337. + gfp_flags == GFP_ATOMIC ? 1 : 0, &usb_req->ext_req);
  88338. + if (retval)
  88339. + return -EINVAL;
  88340. +
  88341. + return 0;
  88342. + }
  88343. +#endif
  88344. + retval = dwc_otg_pcd_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  88345. + usb_req->length, usb_req->zero, usb_req,
  88346. + gfp_flags == GFP_ATOMIC ? 1 : 0);
  88347. + if (retval) {
  88348. + return -EINVAL;
  88349. + }
  88350. +
  88351. + return 0;
  88352. +}
  88353. +
  88354. +/**
  88355. + * This function cancels an I/O request from an EP.
  88356. + */
  88357. +static int ep_dequeue(struct usb_ep *usb_ep, struct usb_request *usb_req)
  88358. +{
  88359. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, usb_req);
  88360. +
  88361. + if (!usb_ep || !usb_req) {
  88362. + DWC_WARN("bad argument\n");
  88363. + return -EINVAL;
  88364. + }
  88365. + if (!gadget_wrapper->driver ||
  88366. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  88367. + DWC_WARN("bogus device state\n");
  88368. + return -ESHUTDOWN;
  88369. + }
  88370. + if (dwc_otg_pcd_ep_dequeue(gadget_wrapper->pcd, usb_ep, usb_req)) {
  88371. + return -EINVAL;
  88372. + }
  88373. +
  88374. + return 0;
  88375. +}
  88376. +
  88377. +/**
  88378. + * usb_ep_set_halt stalls an endpoint.
  88379. + *
  88380. + * usb_ep_clear_halt clears an endpoint halt and resets its data
  88381. + * toggle.
  88382. + *
  88383. + * Both of these functions are implemented with the same underlying
  88384. + * function. The behavior depends on the value argument.
  88385. + *
  88386. + * @param[in] usb_ep the Endpoint to halt or clear halt.
  88387. + * @param[in] value
  88388. + * - 0 means clear_halt.
  88389. + * - 1 means set_halt,
  88390. + * - 2 means clear stall lock flag.
  88391. + * - 3 means set stall lock flag.
  88392. + */
  88393. +static int ep_halt(struct usb_ep *usb_ep, int value)
  88394. +{
  88395. + int retval = 0;
  88396. +
  88397. + DWC_DEBUGPL(DBG_PCD, "HALT %s %d\n", usb_ep->name, value);
  88398. +
  88399. + if (!usb_ep) {
  88400. + DWC_WARN("bad ep\n");
  88401. + return -EINVAL;
  88402. + }
  88403. +
  88404. + retval = dwc_otg_pcd_ep_halt(gadget_wrapper->pcd, usb_ep, value);
  88405. + if (retval == -DWC_E_AGAIN) {
  88406. + return -EAGAIN;
  88407. + } else if (retval) {
  88408. + retval = -EINVAL;
  88409. + }
  88410. +
  88411. + return retval;
  88412. +}
  88413. +
  88414. +//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  88415. +#if 0
  88416. +/**
  88417. + * ep_wedge: sets the halt feature and ignores clear requests
  88418. + *
  88419. + * @usb_ep: the endpoint being wedged
  88420. + *
  88421. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  88422. + * requests. If the gadget driver clears the halt status, it will
  88423. + * automatically unwedge the endpoint.
  88424. + *
  88425. + * Returns zero on success, else negative errno. *
  88426. + * Check usb_ep_set_wedge() at "usb_gadget.h" for details
  88427. + */
  88428. +static int ep_wedge(struct usb_ep *usb_ep)
  88429. +{
  88430. + int retval = 0;
  88431. +
  88432. + DWC_DEBUGPL(DBG_PCD, "WEDGE %s\n", usb_ep->name);
  88433. +
  88434. + if (!usb_ep) {
  88435. + DWC_WARN("bad ep\n");
  88436. + return -EINVAL;
  88437. + }
  88438. +
  88439. + retval = dwc_otg_pcd_ep_wedge(gadget_wrapper->pcd, usb_ep);
  88440. + if (retval == -DWC_E_AGAIN) {
  88441. + retval = -EAGAIN;
  88442. + } else if (retval) {
  88443. + retval = -EINVAL;
  88444. + }
  88445. +
  88446. + return retval;
  88447. +}
  88448. +#endif
  88449. +
  88450. +#ifdef DWC_EN_ISOC
  88451. +/**
  88452. + * This function is used to submit an ISOC Transfer Request to an EP.
  88453. + *
  88454. + * - Every time a sync period completes the request's completion callback
  88455. + * is called to provide data to the gadget driver.
  88456. + * - Once submitted the request cannot be modified.
  88457. + * - Each request is turned into periodic data packets untill ISO
  88458. + * Transfer is stopped..
  88459. + */
  88460. +static int iso_ep_start(struct usb_ep *usb_ep, struct usb_iso_request *req,
  88461. + gfp_t gfp_flags)
  88462. +{
  88463. + int retval = 0;
  88464. +
  88465. + if (!req || !req->process_buffer || !req->buf0 || !req->buf1) {
  88466. + DWC_WARN("bad params\n");
  88467. + return -EINVAL;
  88468. + }
  88469. +
  88470. + if (!usb_ep) {
  88471. + DWC_PRINTF("bad params\n");
  88472. + return -EINVAL;
  88473. + }
  88474. +
  88475. + req->status = -EINPROGRESS;
  88476. +
  88477. + retval =
  88478. + dwc_otg_pcd_iso_ep_start(gadget_wrapper->pcd, usb_ep, req->buf0,
  88479. + req->buf1, req->dma0, req->dma1,
  88480. + req->sync_frame, req->data_pattern_frame,
  88481. + req->data_per_frame,
  88482. + req->
  88483. + flags & USB_REQ_ISO_ASAP ? -1 :
  88484. + req->start_frame, req->buf_proc_intrvl,
  88485. + req, gfp_flags == GFP_ATOMIC ? 1 : 0);
  88486. +
  88487. + if (retval) {
  88488. + return -EINVAL;
  88489. + }
  88490. +
  88491. + return retval;
  88492. +}
  88493. +
  88494. +/**
  88495. + * This function stops ISO EP Periodic Data Transfer.
  88496. + */
  88497. +static int iso_ep_stop(struct usb_ep *usb_ep, struct usb_iso_request *req)
  88498. +{
  88499. + int retval = 0;
  88500. + if (!usb_ep) {
  88501. + DWC_WARN("bad ep\n");
  88502. + }
  88503. +
  88504. + if (!gadget_wrapper->driver ||
  88505. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  88506. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  88507. + gadget_wrapper->gadget.speed);
  88508. + DWC_WARN("bogus device state\n");
  88509. + }
  88510. +
  88511. + dwc_otg_pcd_iso_ep_stop(gadget_wrapper->pcd, usb_ep, req);
  88512. + if (retval) {
  88513. + retval = -EINVAL;
  88514. + }
  88515. +
  88516. + return retval;
  88517. +}
  88518. +
  88519. +static struct usb_iso_request *alloc_iso_request(struct usb_ep *ep,
  88520. + int packets, gfp_t gfp_flags)
  88521. +{
  88522. + struct usb_iso_request *pReq = NULL;
  88523. + uint32_t req_size;
  88524. +
  88525. + req_size = sizeof(struct usb_iso_request);
  88526. + req_size +=
  88527. + (2 * packets * (sizeof(struct usb_gadget_iso_packet_descriptor)));
  88528. +
  88529. + pReq = kmalloc(req_size, gfp_flags);
  88530. + if (!pReq) {
  88531. + DWC_WARN("Can't allocate Iso Request\n");
  88532. + return 0;
  88533. + }
  88534. + pReq->iso_packet_desc0 = (void *)(pReq + 1);
  88535. +
  88536. + pReq->iso_packet_desc1 = pReq->iso_packet_desc0 + packets;
  88537. +
  88538. + return pReq;
  88539. +}
  88540. +
  88541. +static void free_iso_request(struct usb_ep *ep, struct usb_iso_request *req)
  88542. +{
  88543. + kfree(req);
  88544. +}
  88545. +
  88546. +static struct usb_isoc_ep_ops dwc_otg_pcd_ep_ops = {
  88547. + .ep_ops = {
  88548. + .enable = ep_enable,
  88549. + .disable = ep_disable,
  88550. +
  88551. + .alloc_request = dwc_otg_pcd_alloc_request,
  88552. + .free_request = dwc_otg_pcd_free_request,
  88553. +
  88554. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  88555. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  88556. + .free_buffer = dwc_otg_pcd_free_buffer,
  88557. +#endif
  88558. +
  88559. + .queue = ep_queue,
  88560. + .dequeue = ep_dequeue,
  88561. +
  88562. + .set_halt = ep_halt,
  88563. + .fifo_status = 0,
  88564. + .fifo_flush = 0,
  88565. + },
  88566. + .iso_ep_start = iso_ep_start,
  88567. + .iso_ep_stop = iso_ep_stop,
  88568. + .alloc_iso_request = alloc_iso_request,
  88569. + .free_iso_request = free_iso_request,
  88570. +};
  88571. +
  88572. +#else
  88573. +
  88574. + int (*enable) (struct usb_ep *ep,
  88575. + const struct usb_endpoint_descriptor *desc);
  88576. + int (*disable) (struct usb_ep *ep);
  88577. +
  88578. + struct usb_request *(*alloc_request) (struct usb_ep *ep,
  88579. + gfp_t gfp_flags);
  88580. + void (*free_request) (struct usb_ep *ep, struct usb_request *req);
  88581. +
  88582. + int (*queue) (struct usb_ep *ep, struct usb_request *req,
  88583. + gfp_t gfp_flags);
  88584. + int (*dequeue) (struct usb_ep *ep, struct usb_request *req);
  88585. +
  88586. + int (*set_halt) (struct usb_ep *ep, int value);
  88587. + int (*set_wedge) (struct usb_ep *ep);
  88588. +
  88589. + int (*fifo_status) (struct usb_ep *ep);
  88590. + void (*fifo_flush) (struct usb_ep *ep);
  88591. +static struct usb_ep_ops dwc_otg_pcd_ep_ops = {
  88592. + .enable = ep_enable,
  88593. + .disable = ep_disable,
  88594. +
  88595. + .alloc_request = dwc_otg_pcd_alloc_request,
  88596. + .free_request = dwc_otg_pcd_free_request,
  88597. +
  88598. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  88599. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  88600. + .free_buffer = dwc_otg_pcd_free_buffer,
  88601. +#else
  88602. + /* .set_wedge = ep_wedge, */
  88603. + .set_wedge = NULL, /* uses set_halt instead */
  88604. +#endif
  88605. +
  88606. + .queue = ep_queue,
  88607. + .dequeue = ep_dequeue,
  88608. +
  88609. + .set_halt = ep_halt,
  88610. + .fifo_status = 0,
  88611. + .fifo_flush = 0,
  88612. +
  88613. +};
  88614. +
  88615. +#endif /* _EN_ISOC_ */
  88616. +/* Gadget Operations */
  88617. +/**
  88618. + * The following gadget operations will be implemented in the DWC_otg
  88619. + * PCD. Functions in the API that are not described below are not
  88620. + * implemented.
  88621. + *
  88622. + * The Gadget API provides wrapper functions for each of the function
  88623. + * pointers defined in usb_gadget_ops. The Gadget Driver calls the
  88624. + * wrapper function, which then calls the underlying PCD function. The
  88625. + * following sections are named according to the wrapper functions
  88626. + * (except for ioctl, which doesn't have a wrapper function). Within
  88627. + * each section, the corresponding DWC_otg PCD function name is
  88628. + * specified.
  88629. + *
  88630. + */
  88631. +
  88632. +/**
  88633. + *Gets the USB Frame number of the last SOF.
  88634. + */
  88635. +static int get_frame_number(struct usb_gadget *gadget)
  88636. +{
  88637. + struct gadget_wrapper *d;
  88638. +
  88639. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  88640. +
  88641. + if (gadget == 0) {
  88642. + return -ENODEV;
  88643. + }
  88644. +
  88645. + d = container_of(gadget, struct gadget_wrapper, gadget);
  88646. + return dwc_otg_pcd_get_frame_number(d->pcd);
  88647. +}
  88648. +
  88649. +#ifdef CONFIG_USB_DWC_OTG_LPM
  88650. +static int test_lpm_enabled(struct usb_gadget *gadget)
  88651. +{
  88652. + struct gadget_wrapper *d;
  88653. +
  88654. + d = container_of(gadget, struct gadget_wrapper, gadget);
  88655. +
  88656. + return dwc_otg_pcd_is_lpm_enabled(d->pcd);
  88657. +}
  88658. +#endif
  88659. +
  88660. +/**
  88661. + * Initiates Session Request Protocol (SRP) to wakeup the host if no
  88662. + * session is in progress. If a session is already in progress, but
  88663. + * the device is suspended, remote wakeup signaling is started.
  88664. + *
  88665. + */
  88666. +static int wakeup(struct usb_gadget *gadget)
  88667. +{
  88668. + struct gadget_wrapper *d;
  88669. +
  88670. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  88671. +
  88672. + if (gadget == 0) {
  88673. + return -ENODEV;
  88674. + } else {
  88675. + d = container_of(gadget, struct gadget_wrapper, gadget);
  88676. + }
  88677. + dwc_otg_pcd_wakeup(d->pcd);
  88678. + return 0;
  88679. +}
  88680. +
  88681. +static const struct usb_gadget_ops dwc_otg_pcd_ops = {
  88682. + .get_frame = get_frame_number,
  88683. + .wakeup = wakeup,
  88684. +#ifdef CONFIG_USB_DWC_OTG_LPM
  88685. + .lpm_support = test_lpm_enabled,
  88686. +#endif
  88687. + // current versions must always be self-powered
  88688. +};
  88689. +
  88690. +static int _setup(dwc_otg_pcd_t * pcd, uint8_t * bytes)
  88691. +{
  88692. + int retval = -DWC_E_NOT_SUPPORTED;
  88693. + if (gadget_wrapper->driver && gadget_wrapper->driver->setup) {
  88694. + retval = gadget_wrapper->driver->setup(&gadget_wrapper->gadget,
  88695. + (struct usb_ctrlrequest
  88696. + *)bytes);
  88697. + }
  88698. +
  88699. + if (retval == -ENOTSUPP) {
  88700. + retval = -DWC_E_NOT_SUPPORTED;
  88701. + } else if (retval < 0) {
  88702. + retval = -DWC_E_INVALID;
  88703. + }
  88704. +
  88705. + return retval;
  88706. +}
  88707. +
  88708. +#ifdef DWC_EN_ISOC
  88709. +static int _isoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  88710. + void *req_handle, int proc_buf_num)
  88711. +{
  88712. + int i, packet_count;
  88713. + struct usb_gadget_iso_packet_descriptor *iso_packet = 0;
  88714. + struct usb_iso_request *iso_req = req_handle;
  88715. +
  88716. + if (proc_buf_num) {
  88717. + iso_packet = iso_req->iso_packet_desc1;
  88718. + } else {
  88719. + iso_packet = iso_req->iso_packet_desc0;
  88720. + }
  88721. + packet_count =
  88722. + dwc_otg_pcd_get_iso_packet_count(pcd, ep_handle, req_handle);
  88723. + for (i = 0; i < packet_count; ++i) {
  88724. + int status;
  88725. + int actual;
  88726. + int offset;
  88727. + dwc_otg_pcd_get_iso_packet_params(pcd, ep_handle, req_handle,
  88728. + i, &status, &actual, &offset);
  88729. + switch (status) {
  88730. + case -DWC_E_NO_DATA:
  88731. + status = -ENODATA;
  88732. + break;
  88733. + default:
  88734. + if (status) {
  88735. + DWC_PRINTF("unknown status in isoc packet\n");
  88736. + }
  88737. +
  88738. + }
  88739. + iso_packet[i].status = status;
  88740. + iso_packet[i].offset = offset;
  88741. + iso_packet[i].actual_length = actual;
  88742. + }
  88743. +
  88744. + iso_req->status = 0;
  88745. + iso_req->process_buffer(ep_handle, iso_req);
  88746. +
  88747. + return 0;
  88748. +}
  88749. +#endif /* DWC_EN_ISOC */
  88750. +
  88751. +#ifdef DWC_UTE_PER_IO
  88752. +/**
  88753. + * Copy the contents of the extended request to the Linux usb_request's
  88754. + * extended part and call the gadget's completion.
  88755. + *
  88756. + * @param pcd Pointer to the pcd structure
  88757. + * @param ep_handle Void pointer to the usb_ep structure
  88758. + * @param req_handle Void pointer to the usb_request structure
  88759. + * @param status Request status returned from the portable logic
  88760. + * @param ereq_port Void pointer to the extended request structure
  88761. + * created in the the portable part that contains the
  88762. + * results of the processed iso packets.
  88763. + */
  88764. +static int _xisoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  88765. + void *req_handle, int32_t status, void *ereq_port)
  88766. +{
  88767. + struct dwc_ute_iso_req_ext *ereqorg = NULL;
  88768. + struct dwc_iso_xreq_port *ereqport = NULL;
  88769. + struct dwc_ute_iso_packet_descriptor *desc_org = NULL;
  88770. + int i;
  88771. + struct usb_request *req;
  88772. + //struct dwc_ute_iso_packet_descriptor *
  88773. + //int status = 0;
  88774. +
  88775. + req = (struct usb_request *)req_handle;
  88776. + ereqorg = &req->ext_req;
  88777. + ereqport = (struct dwc_iso_xreq_port *)ereq_port;
  88778. + desc_org = ereqorg->per_io_frame_descs;
  88779. +
  88780. + if (req && req->complete) {
  88781. + /* Copy the request data from the portable logic to our request */
  88782. + for (i = 0; i < ereqport->pio_pkt_count; i++) {
  88783. + desc_org[i].actual_length =
  88784. + ereqport->per_io_frame_descs[i].actual_length;
  88785. + desc_org[i].status =
  88786. + ereqport->per_io_frame_descs[i].status;
  88787. + }
  88788. +
  88789. + switch (status) {
  88790. + case -DWC_E_SHUTDOWN:
  88791. + req->status = -ESHUTDOWN;
  88792. + break;
  88793. + case -DWC_E_RESTART:
  88794. + req->status = -ECONNRESET;
  88795. + break;
  88796. + case -DWC_E_INVALID:
  88797. + req->status = -EINVAL;
  88798. + break;
  88799. + case -DWC_E_TIMEOUT:
  88800. + req->status = -ETIMEDOUT;
  88801. + break;
  88802. + default:
  88803. + req->status = status;
  88804. + }
  88805. +
  88806. + /* And call the gadget's completion */
  88807. + req->complete(ep_handle, req);
  88808. + }
  88809. +
  88810. + return 0;
  88811. +}
  88812. +#endif /* DWC_UTE_PER_IO */
  88813. +
  88814. +static int _complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  88815. + void *req_handle, int32_t status, uint32_t actual)
  88816. +{
  88817. + struct usb_request *req = (struct usb_request *)req_handle;
  88818. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  88819. + struct dwc_otg_pcd_ep *ep = NULL;
  88820. +#endif
  88821. +
  88822. + if (req && req->complete) {
  88823. + switch (status) {
  88824. + case -DWC_E_SHUTDOWN:
  88825. + req->status = -ESHUTDOWN;
  88826. + break;
  88827. + case -DWC_E_RESTART:
  88828. + req->status = -ECONNRESET;
  88829. + break;
  88830. + case -DWC_E_INVALID:
  88831. + req->status = -EINVAL;
  88832. + break;
  88833. + case -DWC_E_TIMEOUT:
  88834. + req->status = -ETIMEDOUT;
  88835. + break;
  88836. + default:
  88837. + req->status = status;
  88838. +
  88839. + }
  88840. +
  88841. + req->actual = actual;
  88842. + DWC_SPINUNLOCK(pcd->lock);
  88843. + req->complete(ep_handle, req);
  88844. + DWC_SPINLOCK(pcd->lock);
  88845. + }
  88846. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  88847. + ep = ep_from_handle(pcd, ep_handle);
  88848. + if (GET_CORE_IF(pcd)->dma_enable) {
  88849. + if (req->length != 0) {
  88850. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  88851. + struct device *dev = NULL;
  88852. +
  88853. + if (otg_dev != NULL)
  88854. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  88855. +
  88856. + dma_unmap_single(dev, req->dma, req->length,
  88857. + ep->dwc_ep.is_in ?
  88858. + DMA_TO_DEVICE: DMA_FROM_DEVICE);
  88859. + }
  88860. + }
  88861. +#endif
  88862. +
  88863. + return 0;
  88864. +}
  88865. +
  88866. +static int _connect(dwc_otg_pcd_t * pcd, int speed)
  88867. +{
  88868. + gadget_wrapper->gadget.speed = speed;
  88869. + return 0;
  88870. +}
  88871. +
  88872. +static int _disconnect(dwc_otg_pcd_t * pcd)
  88873. +{
  88874. + if (gadget_wrapper->driver && gadget_wrapper->driver->disconnect) {
  88875. + gadget_wrapper->driver->disconnect(&gadget_wrapper->gadget);
  88876. + }
  88877. + return 0;
  88878. +}
  88879. +
  88880. +static int _resume(dwc_otg_pcd_t * pcd)
  88881. +{
  88882. + if (gadget_wrapper->driver && gadget_wrapper->driver->resume) {
  88883. + gadget_wrapper->driver->resume(&gadget_wrapper->gadget);
  88884. + }
  88885. +
  88886. + return 0;
  88887. +}
  88888. +
  88889. +static int _suspend(dwc_otg_pcd_t * pcd)
  88890. +{
  88891. + if (gadget_wrapper->driver && gadget_wrapper->driver->suspend) {
  88892. + gadget_wrapper->driver->suspend(&gadget_wrapper->gadget);
  88893. + }
  88894. + return 0;
  88895. +}
  88896. +
  88897. +/**
  88898. + * This function updates the otg values in the gadget structure.
  88899. + */
  88900. +static int _hnp_changed(dwc_otg_pcd_t * pcd)
  88901. +{
  88902. +
  88903. + if (!gadget_wrapper->gadget.is_otg)
  88904. + return 0;
  88905. +
  88906. + gadget_wrapper->gadget.b_hnp_enable = get_b_hnp_enable(pcd);
  88907. + gadget_wrapper->gadget.a_hnp_support = get_a_hnp_support(pcd);
  88908. + gadget_wrapper->gadget.a_alt_hnp_support = get_a_alt_hnp_support(pcd);
  88909. + return 0;
  88910. +}
  88911. +
  88912. +static int _reset(dwc_otg_pcd_t * pcd)
  88913. +{
  88914. + return 0;
  88915. +}
  88916. +
  88917. +#ifdef DWC_UTE_CFI
  88918. +static int _cfi_setup(dwc_otg_pcd_t * pcd, void *cfi_req)
  88919. +{
  88920. + int retval = -DWC_E_INVALID;
  88921. + if (gadget_wrapper->driver->cfi_feature_setup) {
  88922. + retval =
  88923. + gadget_wrapper->driver->
  88924. + cfi_feature_setup(&gadget_wrapper->gadget,
  88925. + (struct cfi_usb_ctrlrequest *)cfi_req);
  88926. + }
  88927. +
  88928. + return retval;
  88929. +}
  88930. +#endif
  88931. +
  88932. +static const struct dwc_otg_pcd_function_ops fops = {
  88933. + .complete = _complete,
  88934. +#ifdef DWC_EN_ISOC
  88935. + .isoc_complete = _isoc_complete,
  88936. +#endif
  88937. + .setup = _setup,
  88938. + .disconnect = _disconnect,
  88939. + .connect = _connect,
  88940. + .resume = _resume,
  88941. + .suspend = _suspend,
  88942. + .hnp_changed = _hnp_changed,
  88943. + .reset = _reset,
  88944. +#ifdef DWC_UTE_CFI
  88945. + .cfi_setup = _cfi_setup,
  88946. +#endif
  88947. +#ifdef DWC_UTE_PER_IO
  88948. + .xisoc_complete = _xisoc_complete,
  88949. +#endif
  88950. +};
  88951. +
  88952. +/**
  88953. + * This function is the top level PCD interrupt handler.
  88954. + */
  88955. +static irqreturn_t dwc_otg_pcd_irq(int irq, void *dev)
  88956. +{
  88957. + dwc_otg_pcd_t *pcd = dev;
  88958. + int32_t retval = IRQ_NONE;
  88959. +
  88960. + retval = dwc_otg_pcd_handle_intr(pcd);
  88961. + if (retval != 0) {
  88962. + S3C2410X_CLEAR_EINTPEND();
  88963. + }
  88964. + return IRQ_RETVAL(retval);
  88965. +}
  88966. +
  88967. +/**
  88968. + * This function initialized the usb_ep structures to there default
  88969. + * state.
  88970. + *
  88971. + * @param d Pointer on gadget_wrapper.
  88972. + */
  88973. +void gadget_add_eps(struct gadget_wrapper *d)
  88974. +{
  88975. + static const char *names[] = {
  88976. +
  88977. + "ep0",
  88978. + "ep1in",
  88979. + "ep2in",
  88980. + "ep3in",
  88981. + "ep4in",
  88982. + "ep5in",
  88983. + "ep6in",
  88984. + "ep7in",
  88985. + "ep8in",
  88986. + "ep9in",
  88987. + "ep10in",
  88988. + "ep11in",
  88989. + "ep12in",
  88990. + "ep13in",
  88991. + "ep14in",
  88992. + "ep15in",
  88993. + "ep1out",
  88994. + "ep2out",
  88995. + "ep3out",
  88996. + "ep4out",
  88997. + "ep5out",
  88998. + "ep6out",
  88999. + "ep7out",
  89000. + "ep8out",
  89001. + "ep9out",
  89002. + "ep10out",
  89003. + "ep11out",
  89004. + "ep12out",
  89005. + "ep13out",
  89006. + "ep14out",
  89007. + "ep15out"
  89008. + };
  89009. +
  89010. + int i;
  89011. + struct usb_ep *ep;
  89012. + int8_t dev_endpoints;
  89013. +
  89014. + DWC_DEBUGPL(DBG_PCDV, "%s\n", __func__);
  89015. +
  89016. + INIT_LIST_HEAD(&d->gadget.ep_list);
  89017. + d->gadget.ep0 = &d->ep0;
  89018. + d->gadget.speed = USB_SPEED_UNKNOWN;
  89019. +
  89020. + INIT_LIST_HEAD(&d->gadget.ep0->ep_list);
  89021. +
  89022. + /**
  89023. + * Initialize the EP0 structure.
  89024. + */
  89025. + ep = &d->ep0;
  89026. +
  89027. + /* Init the usb_ep structure. */
  89028. + ep->name = names[0];
  89029. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  89030. +
  89031. + /**
  89032. + * @todo NGS: What should the max packet size be set to
  89033. + * here? Before EP type is set?
  89034. + */
  89035. + ep->maxpacket = MAX_PACKET_SIZE;
  89036. + dwc_otg_pcd_ep_enable(d->pcd, NULL, ep);
  89037. +
  89038. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  89039. +
  89040. + /**
  89041. + * Initialize the EP structures.
  89042. + */
  89043. + dev_endpoints = d->pcd->core_if->dev_if->num_in_eps;
  89044. +
  89045. + for (i = 0; i < dev_endpoints; i++) {
  89046. + ep = &d->in_ep[i];
  89047. +
  89048. + /* Init the usb_ep structure. */
  89049. + ep->name = names[d->pcd->in_ep[i].dwc_ep.num];
  89050. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  89051. +
  89052. + /**
  89053. + * @todo NGS: What should the max packet size be set to
  89054. + * here? Before EP type is set?
  89055. + */
  89056. + ep->maxpacket = MAX_PACKET_SIZE;
  89057. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  89058. + }
  89059. +
  89060. + dev_endpoints = d->pcd->core_if->dev_if->num_out_eps;
  89061. +
  89062. + for (i = 0; i < dev_endpoints; i++) {
  89063. + ep = &d->out_ep[i];
  89064. +
  89065. + /* Init the usb_ep structure. */
  89066. + ep->name = names[15 + d->pcd->out_ep[i].dwc_ep.num];
  89067. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  89068. +
  89069. + /**
  89070. + * @todo NGS: What should the max packet size be set to
  89071. + * here? Before EP type is set?
  89072. + */
  89073. + ep->maxpacket = MAX_PACKET_SIZE;
  89074. +
  89075. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  89076. + }
  89077. +
  89078. + /* remove ep0 from the list. There is a ep0 pointer. */
  89079. + list_del_init(&d->ep0.ep_list);
  89080. +
  89081. + d->ep0.maxpacket = MAX_EP0_SIZE;
  89082. +}
  89083. +
  89084. +/**
  89085. + * This function releases the Gadget device.
  89086. + * required by device_unregister().
  89087. + *
  89088. + * @todo Should this do something? Should it free the PCD?
  89089. + */
  89090. +static void dwc_otg_pcd_gadget_release(struct device *dev)
  89091. +{
  89092. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, dev);
  89093. +}
  89094. +
  89095. +static struct gadget_wrapper *alloc_wrapper(dwc_bus_dev_t *_dev)
  89096. +{
  89097. + static char pcd_name[] = "dwc_otg_pcd";
  89098. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  89099. + struct gadget_wrapper *d;
  89100. + int retval;
  89101. +
  89102. + d = DWC_ALLOC(sizeof(*d));
  89103. + if (d == NULL) {
  89104. + return NULL;
  89105. + }
  89106. +
  89107. + memset(d, 0, sizeof(*d));
  89108. +
  89109. + d->gadget.name = pcd_name;
  89110. + d->pcd = otg_dev->pcd;
  89111. +
  89112. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  89113. + strcpy(d->gadget.dev.bus_id, "gadget");
  89114. +#else
  89115. + dev_set_name(&d->gadget.dev, "%s", "gadget");
  89116. +#endif
  89117. +
  89118. + d->gadget.dev.parent = &_dev->dev;
  89119. + d->gadget.dev.release = dwc_otg_pcd_gadget_release;
  89120. + d->gadget.ops = &dwc_otg_pcd_ops;
  89121. + d->gadget.max_speed = dwc_otg_pcd_is_dualspeed(otg_dev->pcd) ? USB_SPEED_HIGH:USB_SPEED_FULL;
  89122. + d->gadget.is_otg = dwc_otg_pcd_is_otg(otg_dev->pcd);
  89123. +
  89124. + d->driver = 0;
  89125. + /* Register the gadget device */
  89126. + retval = device_register(&d->gadget.dev);
  89127. + if (retval != 0) {
  89128. + DWC_ERROR("device_register failed\n");
  89129. + DWC_FREE(d);
  89130. + return NULL;
  89131. + }
  89132. +
  89133. + return d;
  89134. +}
  89135. +
  89136. +static void free_wrapper(struct gadget_wrapper *d)
  89137. +{
  89138. + if (d->driver) {
  89139. + /* should have been done already by driver model core */
  89140. + DWC_WARN("driver '%s' is still registered\n",
  89141. + d->driver->driver.name);
  89142. + usb_gadget_unregister_driver(d->driver);
  89143. + }
  89144. +
  89145. + device_unregister(&d->gadget.dev);
  89146. + DWC_FREE(d);
  89147. +}
  89148. +
  89149. +/**
  89150. + * This function initialized the PCD portion of the driver.
  89151. + *
  89152. + */
  89153. +int pcd_init(dwc_bus_dev_t *_dev)
  89154. +{
  89155. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  89156. + int retval = 0;
  89157. +
  89158. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev=%p\n", __func__, _dev, otg_dev);
  89159. +
  89160. + otg_dev->pcd = dwc_otg_pcd_init(otg_dev->core_if);
  89161. +
  89162. + if (!otg_dev->pcd) {
  89163. + DWC_ERROR("dwc_otg_pcd_init failed\n");
  89164. + return -ENOMEM;
  89165. + }
  89166. +
  89167. + otg_dev->pcd->otg_dev = otg_dev;
  89168. + gadget_wrapper = alloc_wrapper(_dev);
  89169. +
  89170. + /*
  89171. + * Initialize EP structures
  89172. + */
  89173. + gadget_add_eps(gadget_wrapper);
  89174. + /*
  89175. + * Setup interupt handler
  89176. + */
  89177. +#ifdef PLATFORM_INTERFACE
  89178. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  89179. + platform_get_irq(_dev, 0));
  89180. + retval = request_irq(platform_get_irq(_dev, 0), dwc_otg_pcd_irq,
  89181. + IRQF_SHARED, gadget_wrapper->gadget.name,
  89182. + otg_dev->pcd);
  89183. + if (retval != 0) {
  89184. + DWC_ERROR("request of irq%d failed\n",
  89185. + platform_get_irq(_dev, 0));
  89186. + free_wrapper(gadget_wrapper);
  89187. + return -EBUSY;
  89188. + }
  89189. +#else
  89190. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  89191. + _dev->irq);
  89192. + retval = request_irq(_dev->irq, dwc_otg_pcd_irq,
  89193. + IRQF_SHARED | IRQF_DISABLED,
  89194. + gadget_wrapper->gadget.name, otg_dev->pcd);
  89195. + if (retval != 0) {
  89196. + DWC_ERROR("request of irq%d failed\n", _dev->irq);
  89197. + free_wrapper(gadget_wrapper);
  89198. + return -EBUSY;
  89199. + }
  89200. +#endif
  89201. +
  89202. + dwc_otg_pcd_start(gadget_wrapper->pcd, &fops);
  89203. +
  89204. + return retval;
  89205. +}
  89206. +
  89207. +/**
  89208. + * Cleanup the PCD.
  89209. + */
  89210. +void pcd_remove(dwc_bus_dev_t *_dev)
  89211. +{
  89212. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  89213. + dwc_otg_pcd_t *pcd = otg_dev->pcd;
  89214. +
  89215. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  89216. +
  89217. + /*
  89218. + * Free the IRQ
  89219. + */
  89220. +#ifdef PLATFORM_INTERFACE
  89221. + free_irq(platform_get_irq(_dev, 0), pcd);
  89222. +#else
  89223. + free_irq(_dev->irq, pcd);
  89224. +#endif
  89225. + dwc_otg_pcd_remove(otg_dev->pcd);
  89226. + free_wrapper(gadget_wrapper);
  89227. + otg_dev->pcd = 0;
  89228. +}
  89229. +
  89230. +/**
  89231. + * This function registers a gadget driver with the PCD.
  89232. + *
  89233. + * When a driver is successfully registered, it will receive control
  89234. + * requests including set_configuration(), which enables non-control
  89235. + * requests. then usb traffic follows until a disconnect is reported.
  89236. + * then a host may connect again, or the driver might get unbound.
  89237. + *
  89238. + * @param driver The driver being registered
  89239. + * @param bind The bind function of gadget driver
  89240. + */
  89241. +
  89242. +int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
  89243. +{
  89244. + int retval;
  89245. +
  89246. + DWC_DEBUGPL(DBG_PCD, "registering gadget driver '%s'\n",
  89247. + driver->driver.name);
  89248. +
  89249. + if (!driver || driver->max_speed == USB_SPEED_UNKNOWN ||
  89250. + !driver->bind ||
  89251. + !driver->unbind || !driver->disconnect || !driver->setup) {
  89252. + DWC_DEBUGPL(DBG_PCDV, "EINVAL\n");
  89253. + return -EINVAL;
  89254. + }
  89255. + if (gadget_wrapper == 0) {
  89256. + DWC_DEBUGPL(DBG_PCDV, "ENODEV\n");
  89257. + return -ENODEV;
  89258. + }
  89259. + if (gadget_wrapper->driver != 0) {
  89260. + DWC_DEBUGPL(DBG_PCDV, "EBUSY (%p)\n", gadget_wrapper->driver);
  89261. + return -EBUSY;
  89262. + }
  89263. +
  89264. + /* hook up the driver */
  89265. + gadget_wrapper->driver = driver;
  89266. + gadget_wrapper->gadget.dev.driver = &driver->driver;
  89267. +
  89268. + DWC_DEBUGPL(DBG_PCD, "bind to driver %s\n", driver->driver.name);
  89269. + retval = driver->bind(&gadget_wrapper->gadget, gadget_wrapper->driver);
  89270. + if (retval) {
  89271. + DWC_ERROR("bind to driver %s --> error %d\n",
  89272. + driver->driver.name, retval);
  89273. + gadget_wrapper->driver = 0;
  89274. + gadget_wrapper->gadget.dev.driver = 0;
  89275. + return retval;
  89276. + }
  89277. + DWC_DEBUGPL(DBG_ANY, "registered gadget driver '%s'\n",
  89278. + driver->driver.name);
  89279. + return 0;
  89280. +}
  89281. +EXPORT_SYMBOL(usb_gadget_probe_driver);
  89282. +
  89283. +/**
  89284. + * This function unregisters a gadget driver
  89285. + *
  89286. + * @param driver The driver being unregistered
  89287. + */
  89288. +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
  89289. +{
  89290. + //DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, _driver);
  89291. +
  89292. + if (gadget_wrapper == 0) {
  89293. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): s_pcd==0\n", __func__,
  89294. + -ENODEV);
  89295. + return -ENODEV;
  89296. + }
  89297. + if (driver == 0 || driver != gadget_wrapper->driver) {
  89298. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): driver?\n", __func__,
  89299. + -EINVAL);
  89300. + return -EINVAL;
  89301. + }
  89302. +
  89303. + driver->unbind(&gadget_wrapper->gadget);
  89304. + gadget_wrapper->driver = 0;
  89305. +
  89306. + DWC_DEBUGPL(DBG_ANY, "unregistered driver '%s'\n", driver->driver.name);
  89307. + return 0;
  89308. +}
  89309. +
  89310. +EXPORT_SYMBOL(usb_gadget_unregister_driver);
  89311. +
  89312. +#endif /* DWC_HOST_ONLY */
  89313. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_regs.h linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_regs.h
  89314. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/dwc_otg_regs.h 1970-01-01 01:00:00.000000000 +0100
  89315. +++ linux-3.12.11/drivers/usb/host/dwc_otg/dwc_otg_regs.h 2014-02-18 11:52:14.000000000 +0100
  89316. @@ -0,0 +1,2550 @@
  89317. +/* ==========================================================================
  89318. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_regs.h $
  89319. + * $Revision: #98 $
  89320. + * $Date: 2012/08/10 $
  89321. + * $Change: 2047372 $
  89322. + *
  89323. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  89324. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  89325. + * otherwise expressly agreed to in writing between Synopsys and you.
  89326. + *
  89327. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  89328. + * any End User Software License Agreement or Agreement for Licensed Product
  89329. + * with Synopsys or any supplement thereto. You are permitted to use and
  89330. + * redistribute this Software in source and binary forms, with or without
  89331. + * modification, provided that redistributions of source code must retain this
  89332. + * notice. You may not view, use, disclose, copy or distribute this file or
  89333. + * any information contained herein except pursuant to this license grant from
  89334. + * Synopsys. If you do not agree with this notice, including the disclaimer
  89335. + * below, then you are not authorized to use the Software.
  89336. + *
  89337. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  89338. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  89339. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  89340. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  89341. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  89342. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  89343. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  89344. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  89345. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  89346. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  89347. + * DAMAGE.
  89348. + * ========================================================================== */
  89349. +
  89350. +#ifndef __DWC_OTG_REGS_H__
  89351. +#define __DWC_OTG_REGS_H__
  89352. +
  89353. +#include "dwc_otg_core_if.h"
  89354. +
  89355. +/**
  89356. + * @file
  89357. + *
  89358. + * This file contains the data structures for accessing the DWC_otg core registers.
  89359. + *
  89360. + * The application interfaces with the HS OTG core by reading from and
  89361. + * writing to the Control and Status Register (CSR) space through the
  89362. + * AHB Slave interface. These registers are 32 bits wide, and the
  89363. + * addresses are 32-bit-block aligned.
  89364. + * CSRs are classified as follows:
  89365. + * - Core Global Registers
  89366. + * - Device Mode Registers
  89367. + * - Device Global Registers
  89368. + * - Device Endpoint Specific Registers
  89369. + * - Host Mode Registers
  89370. + * - Host Global Registers
  89371. + * - Host Port CSRs
  89372. + * - Host Channel Specific Registers
  89373. + *
  89374. + * Only the Core Global registers can be accessed in both Device and
  89375. + * Host modes. When the HS OTG core is operating in one mode, either
  89376. + * Device or Host, the application must not access registers from the
  89377. + * other mode. When the core switches from one mode to another, the
  89378. + * registers in the new mode of operation must be reprogrammed as they
  89379. + * would be after a power-on reset.
  89380. + */
  89381. +
  89382. +/****************************************************************************/
  89383. +/** DWC_otg Core registers .
  89384. + * The dwc_otg_core_global_regs structure defines the size
  89385. + * and relative field offsets for the Core Global registers.
  89386. + */
  89387. +typedef struct dwc_otg_core_global_regs {
  89388. + /** OTG Control and Status Register. <i>Offset: 000h</i> */
  89389. + volatile uint32_t gotgctl;
  89390. + /** OTG Interrupt Register. <i>Offset: 004h</i> */
  89391. + volatile uint32_t gotgint;
  89392. + /**Core AHB Configuration Register. <i>Offset: 008h</i> */
  89393. + volatile uint32_t gahbcfg;
  89394. +
  89395. +#define DWC_GLBINTRMASK 0x0001
  89396. +#define DWC_DMAENABLE 0x0020
  89397. +#define DWC_NPTXEMPTYLVL_EMPTY 0x0080
  89398. +#define DWC_NPTXEMPTYLVL_HALFEMPTY 0x0000
  89399. +#define DWC_PTXEMPTYLVL_EMPTY 0x0100
  89400. +#define DWC_PTXEMPTYLVL_HALFEMPTY 0x0000
  89401. +
  89402. + /**Core USB Configuration Register. <i>Offset: 00Ch</i> */
  89403. + volatile uint32_t gusbcfg;
  89404. + /**Core Reset Register. <i>Offset: 010h</i> */
  89405. + volatile uint32_t grstctl;
  89406. + /**Core Interrupt Register. <i>Offset: 014h</i> */
  89407. + volatile uint32_t gintsts;
  89408. + /**Core Interrupt Mask Register. <i>Offset: 018h</i> */
  89409. + volatile uint32_t gintmsk;
  89410. + /**Receive Status Queue Read Register (Read Only). <i>Offset: 01Ch</i> */
  89411. + volatile uint32_t grxstsr;
  89412. + /**Receive Status Queue Read & POP Register (Read Only). <i>Offset: 020h</i>*/
  89413. + volatile uint32_t grxstsp;
  89414. + /**Receive FIFO Size Register. <i>Offset: 024h</i> */
  89415. + volatile uint32_t grxfsiz;
  89416. + /**Non Periodic Transmit FIFO Size Register. <i>Offset: 028h</i> */
  89417. + volatile uint32_t gnptxfsiz;
  89418. + /**Non Periodic Transmit FIFO/Queue Status Register (Read
  89419. + * Only). <i>Offset: 02Ch</i> */
  89420. + volatile uint32_t gnptxsts;
  89421. + /**I2C Access Register. <i>Offset: 030h</i> */
  89422. + volatile uint32_t gi2cctl;
  89423. + /**PHY Vendor Control Register. <i>Offset: 034h</i> */
  89424. + volatile uint32_t gpvndctl;
  89425. + /**General Purpose Input/Output Register. <i>Offset: 038h</i> */
  89426. + volatile uint32_t ggpio;
  89427. + /**User ID Register. <i>Offset: 03Ch</i> */
  89428. + volatile uint32_t guid;
  89429. + /**Synopsys ID Register (Read Only). <i>Offset: 040h</i> */
  89430. + volatile uint32_t gsnpsid;
  89431. + /**User HW Config1 Register (Read Only). <i>Offset: 044h</i> */
  89432. + volatile uint32_t ghwcfg1;
  89433. + /**User HW Config2 Register (Read Only). <i>Offset: 048h</i> */
  89434. + volatile uint32_t ghwcfg2;
  89435. +#define DWC_SLAVE_ONLY_ARCH 0
  89436. +#define DWC_EXT_DMA_ARCH 1
  89437. +#define DWC_INT_DMA_ARCH 2
  89438. +
  89439. +#define DWC_MODE_HNP_SRP_CAPABLE 0
  89440. +#define DWC_MODE_SRP_ONLY_CAPABLE 1
  89441. +#define DWC_MODE_NO_HNP_SRP_CAPABLE 2
  89442. +#define DWC_MODE_SRP_CAPABLE_DEVICE 3
  89443. +#define DWC_MODE_NO_SRP_CAPABLE_DEVICE 4
  89444. +#define DWC_MODE_SRP_CAPABLE_HOST 5
  89445. +#define DWC_MODE_NO_SRP_CAPABLE_HOST 6
  89446. +
  89447. + /**User HW Config3 Register (Read Only). <i>Offset: 04Ch</i> */
  89448. + volatile uint32_t ghwcfg3;
  89449. + /**User HW Config4 Register (Read Only). <i>Offset: 050h</i>*/
  89450. + volatile uint32_t ghwcfg4;
  89451. + /** Core LPM Configuration register <i>Offset: 054h</i>*/
  89452. + volatile uint32_t glpmcfg;
  89453. + /** Global PowerDn Register <i>Offset: 058h</i> */
  89454. + volatile uint32_t gpwrdn;
  89455. + /** Global DFIFO SW Config Register <i>Offset: 05Ch</i> */
  89456. + volatile uint32_t gdfifocfg;
  89457. + /** ADP Control Register <i>Offset: 060h</i> */
  89458. + volatile uint32_t adpctl;
  89459. + /** Reserved <i>Offset: 064h-0FFh</i> */
  89460. + volatile uint32_t reserved39[39];
  89461. + /** Host Periodic Transmit FIFO Size Register. <i>Offset: 100h</i> */
  89462. + volatile uint32_t hptxfsiz;
  89463. + /** Device Periodic Transmit FIFO#n Register if dedicated fifos are disabled,
  89464. + otherwise Device Transmit FIFO#n Register.
  89465. + * <i>Offset: 104h + (FIFO_Number-1)*04h, 1 <= FIFO Number <= 15 (1<=n<=15).</i> */
  89466. + volatile uint32_t dtxfsiz[15];
  89467. +} dwc_otg_core_global_regs_t;
  89468. +
  89469. +/**
  89470. + * This union represents the bit fields of the Core OTG Control
  89471. + * and Status Register (GOTGCTL). Set the bits using the bit
  89472. + * fields then write the <i>d32</i> value to the register.
  89473. + */
  89474. +typedef union gotgctl_data {
  89475. + /** raw register data */
  89476. + uint32_t d32;
  89477. + /** register bits */
  89478. + struct {
  89479. + unsigned sesreqscs:1;
  89480. + unsigned sesreq:1;
  89481. + unsigned vbvalidoven:1;
  89482. + unsigned vbvalidovval:1;
  89483. + unsigned avalidoven:1;
  89484. + unsigned avalidovval:1;
  89485. + unsigned bvalidoven:1;
  89486. + unsigned bvalidovval:1;
  89487. + unsigned hstnegscs:1;
  89488. + unsigned hnpreq:1;
  89489. + unsigned hstsethnpen:1;
  89490. + unsigned devhnpen:1;
  89491. + unsigned reserved12_15:4;
  89492. + unsigned conidsts:1;
  89493. + unsigned dbnctime:1;
  89494. + unsigned asesvld:1;
  89495. + unsigned bsesvld:1;
  89496. + unsigned otgver:1;
  89497. + unsigned reserved1:1;
  89498. + unsigned multvalidbc:5;
  89499. + unsigned chirpen:1;
  89500. + unsigned reserved28_31:4;
  89501. + } b;
  89502. +} gotgctl_data_t;
  89503. +
  89504. +/**
  89505. + * This union represents the bit fields of the Core OTG Interrupt Register
  89506. + * (GOTGINT). Set/clear the bits using the bit fields then write the <i>d32</i>
  89507. + * value to the register.
  89508. + */
  89509. +typedef union gotgint_data {
  89510. + /** raw register data */
  89511. + uint32_t d32;
  89512. + /** register bits */
  89513. + struct {
  89514. + /** Current Mode */
  89515. + unsigned reserved0_1:2;
  89516. +
  89517. + /** Session End Detected */
  89518. + unsigned sesenddet:1;
  89519. +
  89520. + unsigned reserved3_7:5;
  89521. +
  89522. + /** Session Request Success Status Change */
  89523. + unsigned sesreqsucstschng:1;
  89524. + /** Host Negotiation Success Status Change */
  89525. + unsigned hstnegsucstschng:1;
  89526. +
  89527. + unsigned reserved10_16:7;
  89528. +
  89529. + /** Host Negotiation Detected */
  89530. + unsigned hstnegdet:1;
  89531. + /** A-Device Timeout Change */
  89532. + unsigned adevtoutchng:1;
  89533. + /** Debounce Done */
  89534. + unsigned debdone:1;
  89535. + /** Multi-Valued input changed */
  89536. + unsigned mvic:1;
  89537. +
  89538. + unsigned reserved31_21:11;
  89539. +
  89540. + } b;
  89541. +} gotgint_data_t;
  89542. +
  89543. +/**
  89544. + * This union represents the bit fields of the Core AHB Configuration
  89545. + * Register (GAHBCFG). Set/clear the bits using the bit fields then
  89546. + * write the <i>d32</i> value to the register.
  89547. + */
  89548. +typedef union gahbcfg_data {
  89549. + /** raw register data */
  89550. + uint32_t d32;
  89551. + /** register bits */
  89552. + struct {
  89553. + unsigned glblintrmsk:1;
  89554. +#define DWC_GAHBCFG_GLBINT_ENABLE 1
  89555. +
  89556. + unsigned hburstlen:4;
  89557. +#define DWC_GAHBCFG_INT_DMA_BURST_SINGLE 0
  89558. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR 1
  89559. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR4 3
  89560. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR8 5
  89561. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR16 7
  89562. +
  89563. + unsigned dmaenable:1;
  89564. +#define DWC_GAHBCFG_DMAENABLE 1
  89565. + unsigned reserved:1;
  89566. + unsigned nptxfemplvl_txfemplvl:1;
  89567. + unsigned ptxfemplvl:1;
  89568. +#define DWC_GAHBCFG_TXFEMPTYLVL_EMPTY 1
  89569. +#define DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
  89570. + unsigned reserved9_20:12;
  89571. + unsigned remmemsupp:1;
  89572. + unsigned notialldmawrit:1;
  89573. + unsigned ahbsingle:1;
  89574. + unsigned reserved24_31:8;
  89575. + } b;
  89576. +} gahbcfg_data_t;
  89577. +
  89578. +/**
  89579. + * This union represents the bit fields of the Core USB Configuration
  89580. + * Register (GUSBCFG). Set the bits using the bit fields then write
  89581. + * the <i>d32</i> value to the register.
  89582. + */
  89583. +typedef union gusbcfg_data {
  89584. + /** raw register data */
  89585. + uint32_t d32;
  89586. + /** register bits */
  89587. + struct {
  89588. + unsigned toutcal:3;
  89589. + unsigned phyif:1;
  89590. + unsigned ulpi_utmi_sel:1;
  89591. + unsigned fsintf:1;
  89592. + unsigned physel:1;
  89593. + unsigned ddrsel:1;
  89594. + unsigned srpcap:1;
  89595. + unsigned hnpcap:1;
  89596. + unsigned usbtrdtim:4;
  89597. + unsigned reserved1:1;
  89598. + unsigned phylpwrclksel:1;
  89599. + unsigned otgutmifssel:1;
  89600. + unsigned ulpi_fsls:1;
  89601. + unsigned ulpi_auto_res:1;
  89602. + unsigned ulpi_clk_sus_m:1;
  89603. + unsigned ulpi_ext_vbus_drv:1;
  89604. + unsigned ulpi_int_vbus_indicator:1;
  89605. + unsigned term_sel_dl_pulse:1;
  89606. + unsigned indicator_complement:1;
  89607. + unsigned indicator_pass_through:1;
  89608. + unsigned ulpi_int_prot_dis:1;
  89609. + unsigned ic_usb_cap:1;
  89610. + unsigned ic_traffic_pull_remove:1;
  89611. + unsigned tx_end_delay:1;
  89612. + unsigned force_host_mode:1;
  89613. + unsigned force_dev_mode:1;
  89614. + unsigned reserved31:1;
  89615. + } b;
  89616. +} gusbcfg_data_t;
  89617. +
  89618. +/**
  89619. + * This union represents the bit fields of the Core Reset Register
  89620. + * (GRSTCTL). Set/clear the bits using the bit fields then write the
  89621. + * <i>d32</i> value to the register.
  89622. + */
  89623. +typedef union grstctl_data {
  89624. + /** raw register data */
  89625. + uint32_t d32;
  89626. + /** register bits */
  89627. + struct {
  89628. + /** Core Soft Reset (CSftRst) (Device and Host)
  89629. + *
  89630. + * The application can flush the control logic in the
  89631. + * entire core using this bit. This bit resets the
  89632. + * pipelines in the AHB Clock domain as well as the
  89633. + * PHY Clock domain.
  89634. + *
  89635. + * The state machines are reset to an IDLE state, the
  89636. + * control bits in the CSRs are cleared, all the
  89637. + * transmit FIFOs and the receive FIFO are flushed.
  89638. + *
  89639. + * The status mask bits that control the generation of
  89640. + * the interrupt, are cleared, to clear the
  89641. + * interrupt. The interrupt status bits are not
  89642. + * cleared, so the application can get the status of
  89643. + * any events that occurred in the core after it has
  89644. + * set this bit.
  89645. + *
  89646. + * Any transactions on the AHB are terminated as soon
  89647. + * as possible following the protocol. Any
  89648. + * transactions on the USB are terminated immediately.
  89649. + *
  89650. + * The configuration settings in the CSRs are
  89651. + * unchanged, so the software doesn't have to
  89652. + * reprogram these registers (Device
  89653. + * Configuration/Host Configuration/Core System
  89654. + * Configuration/Core PHY Configuration).
  89655. + *
  89656. + * The application can write to this bit, any time it
  89657. + * wants to reset the core. This is a self clearing
  89658. + * bit and the core clears this bit after all the
  89659. + * necessary logic is reset in the core, which may
  89660. + * take several clocks, depending on the current state
  89661. + * of the core.
  89662. + */
  89663. + unsigned csftrst:1;
  89664. + /** Hclk Soft Reset
  89665. + *
  89666. + * The application uses this bit to reset the control logic in
  89667. + * the AHB clock domain. Only AHB clock domain pipelines are
  89668. + * reset.
  89669. + */
  89670. + unsigned hsftrst:1;
  89671. + /** Host Frame Counter Reset (Host Only)<br>
  89672. + *
  89673. + * The application can reset the (micro)frame number
  89674. + * counter inside the core, using this bit. When the
  89675. + * (micro)frame counter is reset, the subsequent SOF
  89676. + * sent out by the core, will have a (micro)frame
  89677. + * number of 0.
  89678. + */
  89679. + unsigned hstfrm:1;
  89680. + /** In Token Sequence Learning Queue Flush
  89681. + * (INTknQFlsh) (Device Only)
  89682. + */
  89683. + unsigned intknqflsh:1;
  89684. + /** RxFIFO Flush (RxFFlsh) (Device and Host)
  89685. + *
  89686. + * The application can flush the entire Receive FIFO
  89687. + * using this bit. The application must first
  89688. + * ensure that the core is not in the middle of a
  89689. + * transaction. The application should write into
  89690. + * this bit, only after making sure that neither the
  89691. + * DMA engine is reading from the RxFIFO nor the MAC
  89692. + * is writing the data in to the FIFO. The
  89693. + * application should wait until the bit is cleared
  89694. + * before performing any other operations. This bit
  89695. + * will takes 8 clocks (slowest of PHY or AHB clock)
  89696. + * to clear.
  89697. + */
  89698. + unsigned rxfflsh:1;
  89699. + /** TxFIFO Flush (TxFFlsh) (Device and Host).
  89700. + *
  89701. + * This bit is used to selectively flush a single or
  89702. + * all transmit FIFOs. The application must first
  89703. + * ensure that the core is not in the middle of a
  89704. + * transaction. The application should write into
  89705. + * this bit, only after making sure that neither the
  89706. + * DMA engine is writing into the TxFIFO nor the MAC
  89707. + * is reading the data out of the FIFO. The
  89708. + * application should wait until the core clears this
  89709. + * bit, before performing any operations. This bit
  89710. + * will takes 8 clocks (slowest of PHY or AHB clock)
  89711. + * to clear.
  89712. + */
  89713. + unsigned txfflsh:1;
  89714. +
  89715. + /** TxFIFO Number (TxFNum) (Device and Host).
  89716. + *
  89717. + * This is the FIFO number which needs to be flushed,
  89718. + * using the TxFIFO Flush bit. This field should not
  89719. + * be changed until the TxFIFO Flush bit is cleared by
  89720. + * the core.
  89721. + * - 0x0 : Non Periodic TxFIFO Flush
  89722. + * - 0x1 : Periodic TxFIFO #1 Flush in device mode
  89723. + * or Periodic TxFIFO in host mode
  89724. + * - 0x2 : Periodic TxFIFO #2 Flush in device mode.
  89725. + * - ...
  89726. + * - 0xF : Periodic TxFIFO #15 Flush in device mode
  89727. + * - 0x10: Flush all the Transmit NonPeriodic and
  89728. + * Transmit Periodic FIFOs in the core
  89729. + */
  89730. + unsigned txfnum:5;
  89731. + /** Reserved */
  89732. + unsigned reserved11_29:19;
  89733. + /** DMA Request Signal. Indicated DMA request is in
  89734. + * probress. Used for debug purpose. */
  89735. + unsigned dmareq:1;
  89736. + /** AHB Master Idle. Indicates the AHB Master State
  89737. + * Machine is in IDLE condition. */
  89738. + unsigned ahbidle:1;
  89739. + } b;
  89740. +} grstctl_t;
  89741. +
  89742. +/**
  89743. + * This union represents the bit fields of the Core Interrupt Mask
  89744. + * Register (GINTMSK). Set/clear the bits using the bit fields then
  89745. + * write the <i>d32</i> value to the register.
  89746. + */
  89747. +typedef union gintmsk_data {
  89748. + /** raw register data */
  89749. + uint32_t d32;
  89750. + /** register bits */
  89751. + struct {
  89752. + unsigned reserved0:1;
  89753. + unsigned modemismatch:1;
  89754. + unsigned otgintr:1;
  89755. + unsigned sofintr:1;
  89756. + unsigned rxstsqlvl:1;
  89757. + unsigned nptxfempty:1;
  89758. + unsigned ginnakeff:1;
  89759. + unsigned goutnakeff:1;
  89760. + unsigned ulpickint:1;
  89761. + unsigned i2cintr:1;
  89762. + unsigned erlysuspend:1;
  89763. + unsigned usbsuspend:1;
  89764. + unsigned usbreset:1;
  89765. + unsigned enumdone:1;
  89766. + unsigned isooutdrop:1;
  89767. + unsigned eopframe:1;
  89768. + unsigned restoredone:1;
  89769. + unsigned epmismatch:1;
  89770. + unsigned inepintr:1;
  89771. + unsigned outepintr:1;
  89772. + unsigned incomplisoin:1;
  89773. + unsigned incomplisoout:1;
  89774. + unsigned fetsusp:1;
  89775. + unsigned resetdet:1;
  89776. + unsigned portintr:1;
  89777. + unsigned hcintr:1;
  89778. + unsigned ptxfempty:1;
  89779. + unsigned lpmtranrcvd:1;
  89780. + unsigned conidstschng:1;
  89781. + unsigned disconnect:1;
  89782. + unsigned sessreqintr:1;
  89783. + unsigned wkupintr:1;
  89784. + } b;
  89785. +} gintmsk_data_t;
  89786. +/**
  89787. + * This union represents the bit fields of the Core Interrupt Register
  89788. + * (GINTSTS). Set/clear the bits using the bit fields then write the
  89789. + * <i>d32</i> value to the register.
  89790. + */
  89791. +typedef union gintsts_data {
  89792. + /** raw register data */
  89793. + uint32_t d32;
  89794. +#define DWC_SOF_INTR_MASK 0x0008
  89795. + /** register bits */
  89796. + struct {
  89797. +#define DWC_HOST_MODE 1
  89798. + unsigned curmode:1;
  89799. + unsigned modemismatch:1;
  89800. + unsigned otgintr:1;
  89801. + unsigned sofintr:1;
  89802. + unsigned rxstsqlvl:1;
  89803. + unsigned nptxfempty:1;
  89804. + unsigned ginnakeff:1;
  89805. + unsigned goutnakeff:1;
  89806. + unsigned ulpickint:1;
  89807. + unsigned i2cintr:1;
  89808. + unsigned erlysuspend:1;
  89809. + unsigned usbsuspend:1;
  89810. + unsigned usbreset:1;
  89811. + unsigned enumdone:1;
  89812. + unsigned isooutdrop:1;
  89813. + unsigned eopframe:1;
  89814. + unsigned restoredone:1;
  89815. + unsigned epmismatch:1;
  89816. + unsigned inepint:1;
  89817. + unsigned outepintr:1;
  89818. + unsigned incomplisoin:1;
  89819. + unsigned incomplisoout:1;
  89820. + unsigned fetsusp:1;
  89821. + unsigned resetdet:1;
  89822. + unsigned portintr:1;
  89823. + unsigned hcintr:1;
  89824. + unsigned ptxfempty:1;
  89825. + unsigned lpmtranrcvd:1;
  89826. + unsigned conidstschng:1;
  89827. + unsigned disconnect:1;
  89828. + unsigned sessreqintr:1;
  89829. + unsigned wkupintr:1;
  89830. + } b;
  89831. +} gintsts_data_t;
  89832. +
  89833. +/**
  89834. + * This union represents the bit fields in the Device Receive Status Read and
  89835. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  89836. + * element then read out the bits using the <i>b</i>it elements.
  89837. + */
  89838. +typedef union device_grxsts_data {
  89839. + /** raw register data */
  89840. + uint32_t d32;
  89841. + /** register bits */
  89842. + struct {
  89843. + unsigned epnum:4;
  89844. + unsigned bcnt:11;
  89845. + unsigned dpid:2;
  89846. +
  89847. +#define DWC_STS_DATA_UPDT 0x2 // OUT Data Packet
  89848. +#define DWC_STS_XFER_COMP 0x3 // OUT Data Transfer Complete
  89849. +
  89850. +#define DWC_DSTS_GOUT_NAK 0x1 // Global OUT NAK
  89851. +#define DWC_DSTS_SETUP_COMP 0x4 // Setup Phase Complete
  89852. +#define DWC_DSTS_SETUP_UPDT 0x6 // SETUP Packet
  89853. + unsigned pktsts:4;
  89854. + unsigned fn:4;
  89855. + unsigned reserved25_31:7;
  89856. + } b;
  89857. +} device_grxsts_data_t;
  89858. +
  89859. +/**
  89860. + * This union represents the bit fields in the Host Receive Status Read and
  89861. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  89862. + * element then read out the bits using the <i>b</i>it elements.
  89863. + */
  89864. +typedef union host_grxsts_data {
  89865. + /** raw register data */
  89866. + uint32_t d32;
  89867. + /** register bits */
  89868. + struct {
  89869. + unsigned chnum:4;
  89870. + unsigned bcnt:11;
  89871. + unsigned dpid:2;
  89872. +
  89873. + unsigned pktsts:4;
  89874. +#define DWC_GRXSTS_PKTSTS_IN 0x2
  89875. +#define DWC_GRXSTS_PKTSTS_IN_XFER_COMP 0x3
  89876. +#define DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR 0x5
  89877. +#define DWC_GRXSTS_PKTSTS_CH_HALTED 0x7
  89878. +
  89879. + unsigned reserved21_31:11;
  89880. + } b;
  89881. +} host_grxsts_data_t;
  89882. +
  89883. +/**
  89884. + * This union represents the bit fields in the FIFO Size Registers (HPTXFSIZ,
  89885. + * GNPTXFSIZ, DPTXFSIZn, DIEPTXFn). Read the register into the <i>d32</i> element
  89886. + * then read out the bits using the <i>b</i>it elements.
  89887. + */
  89888. +typedef union fifosize_data {
  89889. + /** raw register data */
  89890. + uint32_t d32;
  89891. + /** register bits */
  89892. + struct {
  89893. + unsigned startaddr:16;
  89894. + unsigned depth:16;
  89895. + } b;
  89896. +} fifosize_data_t;
  89897. +
  89898. +/**
  89899. + * This union represents the bit fields in the Non-Periodic Transmit
  89900. + * FIFO/Queue Status Register (GNPTXSTS). Read the register into the
  89901. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  89902. + * elements.
  89903. + */
  89904. +typedef union gnptxsts_data {
  89905. + /** raw register data */
  89906. + uint32_t d32;
  89907. + /** register bits */
  89908. + struct {
  89909. + unsigned nptxfspcavail:16;
  89910. + unsigned nptxqspcavail:8;
  89911. + /** Top of the Non-Periodic Transmit Request Queue
  89912. + * - bit 24 - Terminate (Last entry for the selected
  89913. + * channel/EP)
  89914. + * - bits 26:25 - Token Type
  89915. + * - 2'b00 - IN/OUT
  89916. + * - 2'b01 - Zero Length OUT
  89917. + * - 2'b10 - PING/Complete Split
  89918. + * - 2'b11 - Channel Halt
  89919. + * - bits 30:27 - Channel/EP Number
  89920. + */
  89921. + unsigned nptxqtop_terminate:1;
  89922. + unsigned nptxqtop_token:2;
  89923. + unsigned nptxqtop_chnep:4;
  89924. + unsigned reserved:1;
  89925. + } b;
  89926. +} gnptxsts_data_t;
  89927. +
  89928. +/**
  89929. + * This union represents the bit fields in the Transmit
  89930. + * FIFO Status Register (DTXFSTS). Read the register into the
  89931. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  89932. + * elements.
  89933. + */
  89934. +typedef union dtxfsts_data {
  89935. + /** raw register data */
  89936. + uint32_t d32;
  89937. + /** register bits */
  89938. + struct {
  89939. + unsigned txfspcavail:16;
  89940. + unsigned reserved:16;
  89941. + } b;
  89942. +} dtxfsts_data_t;
  89943. +
  89944. +/**
  89945. + * This union represents the bit fields in the I2C Control Register
  89946. + * (I2CCTL). Read the register into the <i>d32</i> element then read out the
  89947. + * bits using the <i>b</i>it elements.
  89948. + */
  89949. +typedef union gi2cctl_data {
  89950. + /** raw register data */
  89951. + uint32_t d32;
  89952. + /** register bits */
  89953. + struct {
  89954. + unsigned rwdata:8;
  89955. + unsigned regaddr:8;
  89956. + unsigned addr:7;
  89957. + unsigned i2cen:1;
  89958. + unsigned ack:1;
  89959. + unsigned i2csuspctl:1;
  89960. + unsigned i2cdevaddr:2;
  89961. + unsigned i2cdatse0:1;
  89962. + unsigned reserved:1;
  89963. + unsigned rw:1;
  89964. + unsigned bsydne:1;
  89965. + } b;
  89966. +} gi2cctl_data_t;
  89967. +
  89968. +/**
  89969. + * This union represents the bit fields in the PHY Vendor Control Register
  89970. + * (GPVNDCTL). Read the register into the <i>d32</i> element then read out the
  89971. + * bits using the <i>b</i>it elements.
  89972. + */
  89973. +typedef union gpvndctl_data {
  89974. + /** raw register data */
  89975. + uint32_t d32;
  89976. + /** register bits */
  89977. + struct {
  89978. + unsigned regdata:8;
  89979. + unsigned vctrl:8;
  89980. + unsigned regaddr16_21:6;
  89981. + unsigned regwr:1;
  89982. + unsigned reserved23_24:2;
  89983. + unsigned newregreq:1;
  89984. + unsigned vstsbsy:1;
  89985. + unsigned vstsdone:1;
  89986. + unsigned reserved28_30:3;
  89987. + unsigned disulpidrvr:1;
  89988. + } b;
  89989. +} gpvndctl_data_t;
  89990. +
  89991. +/**
  89992. + * This union represents the bit fields in the General Purpose
  89993. + * Input/Output Register (GGPIO).
  89994. + * Read the register into the <i>d32</i> element then read out the
  89995. + * bits using the <i>b</i>it elements.
  89996. + */
  89997. +typedef union ggpio_data {
  89998. + /** raw register data */
  89999. + uint32_t d32;
  90000. + /** register bits */
  90001. + struct {
  90002. + unsigned gpi:16;
  90003. + unsigned gpo:16;
  90004. + } b;
  90005. +} ggpio_data_t;
  90006. +
  90007. +/**
  90008. + * This union represents the bit fields in the User ID Register
  90009. + * (GUID). Read the register into the <i>d32</i> element then read out the
  90010. + * bits using the <i>b</i>it elements.
  90011. + */
  90012. +typedef union guid_data {
  90013. + /** raw register data */
  90014. + uint32_t d32;
  90015. + /** register bits */
  90016. + struct {
  90017. + unsigned rwdata:32;
  90018. + } b;
  90019. +} guid_data_t;
  90020. +
  90021. +/**
  90022. + * This union represents the bit fields in the Synopsys ID Register
  90023. + * (GSNPSID). Read the register into the <i>d32</i> element then read out the
  90024. + * bits using the <i>b</i>it elements.
  90025. + */
  90026. +typedef union gsnpsid_data {
  90027. + /** raw register data */
  90028. + uint32_t d32;
  90029. + /** register bits */
  90030. + struct {
  90031. + unsigned rwdata:32;
  90032. + } b;
  90033. +} gsnpsid_data_t;
  90034. +
  90035. +/**
  90036. + * This union represents the bit fields in the User HW Config1
  90037. + * Register. Read the register into the <i>d32</i> element then read
  90038. + * out the bits using the <i>b</i>it elements.
  90039. + */
  90040. +typedef union hwcfg1_data {
  90041. + /** raw register data */
  90042. + uint32_t d32;
  90043. + /** register bits */
  90044. + struct {
  90045. + unsigned ep_dir0:2;
  90046. + unsigned ep_dir1:2;
  90047. + unsigned ep_dir2:2;
  90048. + unsigned ep_dir3:2;
  90049. + unsigned ep_dir4:2;
  90050. + unsigned ep_dir5:2;
  90051. + unsigned ep_dir6:2;
  90052. + unsigned ep_dir7:2;
  90053. + unsigned ep_dir8:2;
  90054. + unsigned ep_dir9:2;
  90055. + unsigned ep_dir10:2;
  90056. + unsigned ep_dir11:2;
  90057. + unsigned ep_dir12:2;
  90058. + unsigned ep_dir13:2;
  90059. + unsigned ep_dir14:2;
  90060. + unsigned ep_dir15:2;
  90061. + } b;
  90062. +} hwcfg1_data_t;
  90063. +
  90064. +/**
  90065. + * This union represents the bit fields in the User HW Config2
  90066. + * Register. Read the register into the <i>d32</i> element then read
  90067. + * out the bits using the <i>b</i>it elements.
  90068. + */
  90069. +typedef union hwcfg2_data {
  90070. + /** raw register data */
  90071. + uint32_t d32;
  90072. + /** register bits */
  90073. + struct {
  90074. + /* GHWCFG2 */
  90075. + unsigned op_mode:3;
  90076. +#define DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG 0
  90077. +#define DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG 1
  90078. +#define DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG 2
  90079. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3
  90080. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4
  90081. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST 5
  90082. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6
  90083. +
  90084. + unsigned architecture:2;
  90085. + unsigned point2point:1;
  90086. + unsigned hs_phy_type:2;
  90087. +#define DWC_HWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
  90088. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI 1
  90089. +#define DWC_HWCFG2_HS_PHY_TYPE_ULPI 2
  90090. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI 3
  90091. +
  90092. + unsigned fs_phy_type:2;
  90093. + unsigned num_dev_ep:4;
  90094. + unsigned num_host_chan:4;
  90095. + unsigned perio_ep_supported:1;
  90096. + unsigned dynamic_fifo:1;
  90097. + unsigned multi_proc_int:1;
  90098. + unsigned reserved21:1;
  90099. + unsigned nonperio_tx_q_depth:2;
  90100. + unsigned host_perio_tx_q_depth:2;
  90101. + unsigned dev_token_q_depth:5;
  90102. + unsigned otg_enable_ic_usb:1;
  90103. + } b;
  90104. +} hwcfg2_data_t;
  90105. +
  90106. +/**
  90107. + * This union represents the bit fields in the User HW Config3
  90108. + * Register. Read the register into the <i>d32</i> element then read
  90109. + * out the bits using the <i>b</i>it elements.
  90110. + */
  90111. +typedef union hwcfg3_data {
  90112. + /** raw register data */
  90113. + uint32_t d32;
  90114. + /** register bits */
  90115. + struct {
  90116. + /* GHWCFG3 */
  90117. + unsigned xfer_size_cntr_width:4;
  90118. + unsigned packet_size_cntr_width:3;
  90119. + unsigned otg_func:1;
  90120. + unsigned i2c:1;
  90121. + unsigned vendor_ctrl_if:1;
  90122. + unsigned optional_features:1;
  90123. + unsigned synch_reset_type:1;
  90124. + unsigned adp_supp:1;
  90125. + unsigned otg_enable_hsic:1;
  90126. + unsigned bc_support:1;
  90127. + unsigned otg_lpm_en:1;
  90128. + unsigned dfifo_depth:16;
  90129. + } b;
  90130. +} hwcfg3_data_t;
  90131. +
  90132. +/**
  90133. + * This union represents the bit fields in the User HW Config4
  90134. + * Register. Read the register into the <i>d32</i> element then read
  90135. + * out the bits using the <i>b</i>it elements.
  90136. + */
  90137. +typedef union hwcfg4_data {
  90138. + /** raw register data */
  90139. + uint32_t d32;
  90140. + /** register bits */
  90141. + struct {
  90142. + unsigned num_dev_perio_in_ep:4;
  90143. + unsigned power_optimiz:1;
  90144. + unsigned min_ahb_freq:1;
  90145. + unsigned hiber:1;
  90146. + unsigned xhiber:1;
  90147. + unsigned reserved:6;
  90148. + unsigned utmi_phy_data_width:2;
  90149. + unsigned num_dev_mode_ctrl_ep:4;
  90150. + unsigned iddig_filt_en:1;
  90151. + unsigned vbus_valid_filt_en:1;
  90152. + unsigned a_valid_filt_en:1;
  90153. + unsigned b_valid_filt_en:1;
  90154. + unsigned session_end_filt_en:1;
  90155. + unsigned ded_fifo_en:1;
  90156. + unsigned num_in_eps:4;
  90157. + unsigned desc_dma:1;
  90158. + unsigned desc_dma_dyn:1;
  90159. + } b;
  90160. +} hwcfg4_data_t;
  90161. +
  90162. +/**
  90163. + * This union represents the bit fields of the Core LPM Configuration
  90164. + * Register (GLPMCFG). Set the bits using bit fields then write
  90165. + * the <i>d32</i> value to the register.
  90166. + */
  90167. +typedef union glpmctl_data {
  90168. + /** raw register data */
  90169. + uint32_t d32;
  90170. + /** register bits */
  90171. + struct {
  90172. + /** LPM-Capable (LPMCap) (Device and Host)
  90173. + * The application uses this bit to control
  90174. + * the DWC_otg core LPM capabilities.
  90175. + */
  90176. + unsigned lpm_cap_en:1;
  90177. + /** LPM response programmed by application (AppL1Res) (Device)
  90178. + * Handshake response to LPM token pre-programmed
  90179. + * by device application software.
  90180. + */
  90181. + unsigned appl_resp:1;
  90182. + /** Host Initiated Resume Duration (HIRD) (Device and Host)
  90183. + * In Host mode this field indicates the value of HIRD
  90184. + * to be sent in an LPM transaction.
  90185. + * In Device mode this field is updated with the
  90186. + * Received LPM Token HIRD bmAttribute
  90187. + * when an ACK/NYET/STALL response is sent
  90188. + * to an LPM transaction.
  90189. + */
  90190. + unsigned hird:4;
  90191. + /** RemoteWakeEnable (bRemoteWake) (Device and Host)
  90192. + * In Host mode this bit indicates the value of remote
  90193. + * wake up to be sent in wIndex field of LPM transaction.
  90194. + * In Device mode this field is updated with the
  90195. + * Received LPM Token bRemoteWake bmAttribute
  90196. + * when an ACK/NYET/STALL response is sent
  90197. + * to an LPM transaction.
  90198. + */
  90199. + unsigned rem_wkup_en:1;
  90200. + /** Enable utmi_sleep_n (EnblSlpM) (Device and Host)
  90201. + * The application uses this bit to control
  90202. + * the utmi_sleep_n assertion to the PHY when in L1 state.
  90203. + */
  90204. + unsigned en_utmi_sleep:1;
  90205. + /** HIRD Threshold (HIRD_Thres) (Device and Host)
  90206. + */
  90207. + unsigned hird_thres:5;
  90208. + /** LPM Response (CoreL1Res) (Device and Host)
  90209. + * In Host mode this bit contains handsake response to
  90210. + * LPM transaction.
  90211. + * In Device mode the response of the core to
  90212. + * LPM transaction received is reflected in these two bits.
  90213. + - 0x0 : ERROR (No handshake response)
  90214. + - 0x1 : STALL
  90215. + - 0x2 : NYET
  90216. + - 0x3 : ACK
  90217. + */
  90218. + unsigned lpm_resp:2;
  90219. + /** Port Sleep Status (SlpSts) (Device and Host)
  90220. + * This bit is set as long as a Sleep condition
  90221. + * is present on the USB bus.
  90222. + */
  90223. + unsigned prt_sleep_sts:1;
  90224. + /** Sleep State Resume OK (L1ResumeOK) (Device and Host)
  90225. + * Indicates that the application or host
  90226. + * can start resume from Sleep state.
  90227. + */
  90228. + unsigned sleep_state_resumeok:1;
  90229. + /** LPM channel Index (LPM_Chnl_Indx) (Host)
  90230. + * The channel number on which the LPM transaction
  90231. + * has to be applied while sending
  90232. + * an LPM transaction to the local device.
  90233. + */
  90234. + unsigned lpm_chan_index:4;
  90235. + /** LPM Retry Count (LPM_Retry_Cnt) (Host)
  90236. + * Number host retries that would be performed
  90237. + * if the device response was not valid response.
  90238. + */
  90239. + unsigned retry_count:3;
  90240. + /** Send LPM Transaction (SndLPM) (Host)
  90241. + * When set by application software,
  90242. + * an LPM transaction containing two tokens
  90243. + * is sent.
  90244. + */
  90245. + unsigned send_lpm:1;
  90246. + /** LPM Retry status (LPM_RetryCnt_Sts) (Host)
  90247. + * Number of LPM Host Retries still remaining
  90248. + * to be transmitted for the current LPM sequence
  90249. + */
  90250. + unsigned retry_count_sts:3;
  90251. + unsigned reserved28_29:2;
  90252. + /** In host mode once this bit is set, the host
  90253. + * configures to drive the HSIC Idle state on the bus.
  90254. + * It then waits for the device to initiate the Connect sequence.
  90255. + * In device mode once this bit is set, the device waits for
  90256. + * the HSIC Idle line state on the bus. Upon receving the Idle
  90257. + * line state, it initiates the HSIC Connect sequence.
  90258. + */
  90259. + unsigned hsic_connect:1;
  90260. + /** This bit overrides and functionally inverts
  90261. + * the if_select_hsic input port signal.
  90262. + */
  90263. + unsigned inv_sel_hsic:1;
  90264. + } b;
  90265. +} glpmcfg_data_t;
  90266. +
  90267. +/**
  90268. + * This union represents the bit fields of the Core ADP Timer, Control and
  90269. + * Status Register (ADPTIMCTLSTS). Set the bits using bit fields then write
  90270. + * the <i>d32</i> value to the register.
  90271. + */
  90272. +typedef union adpctl_data {
  90273. + /** raw register data */
  90274. + uint32_t d32;
  90275. + /** register bits */
  90276. + struct {
  90277. + /** Probe Discharge (PRB_DSCHG)
  90278. + * These bits set the times for TADP_DSCHG.
  90279. + * These bits are defined as follows:
  90280. + * 2'b00 - 4 msec
  90281. + * 2'b01 - 8 msec
  90282. + * 2'b10 - 16 msec
  90283. + * 2'b11 - 32 msec
  90284. + */
  90285. + unsigned prb_dschg:2;
  90286. + /** Probe Delta (PRB_DELTA)
  90287. + * These bits set the resolution for RTIM value.
  90288. + * The bits are defined in units of 32 kHz clock cycles as follows:
  90289. + * 2'b00 - 1 cycles
  90290. + * 2'b01 - 2 cycles
  90291. + * 2'b10 - 3 cycles
  90292. + * 2'b11 - 4 cycles
  90293. + * For example if this value is chosen to 2'b01, it means that RTIM
  90294. + * increments for every 3(three) 32Khz clock cycles.
  90295. + */
  90296. + unsigned prb_delta:2;
  90297. + /** Probe Period (PRB_PER)
  90298. + * These bits sets the TADP_PRD as shown in Figure 4 as follows:
  90299. + * 2'b00 - 0.625 to 0.925 sec (typical 0.775 sec)
  90300. + * 2'b01 - 1.25 to 1.85 sec (typical 1.55 sec)
  90301. + * 2'b10 - 1.9 to 2.6 sec (typical 2.275 sec)
  90302. + * 2'b11 - Reserved
  90303. + */
  90304. + unsigned prb_per:2;
  90305. + /** These bits capture the latest time it took for VBUS to ramp from
  90306. + * VADP_SINK to VADP_PRB.
  90307. + * 0x000 - 1 cycles
  90308. + * 0x001 - 2 cycles
  90309. + * 0x002 - 3 cycles
  90310. + * etc
  90311. + * 0x7FF - 2048 cycles
  90312. + * A time of 1024 cycles at 32 kHz corresponds to a time of 32 msec.
  90313. + */
  90314. + unsigned rtim:11;
  90315. + /** Enable Probe (EnaPrb)
  90316. + * When programmed to 1'b1, the core performs a probe operation.
  90317. + * This bit is valid only if OTG_Ver = 1'b1.
  90318. + */
  90319. + unsigned enaprb:1;
  90320. + /** Enable Sense (EnaSns)
  90321. + * When programmed to 1'b1, the core performs a Sense operation.
  90322. + * This bit is valid only if OTG_Ver = 1'b1.
  90323. + */
  90324. + unsigned enasns:1;
  90325. + /** ADP Reset (ADPRes)
  90326. + * When set, ADP controller is reset.
  90327. + * This bit is valid only if OTG_Ver = 1'b1.
  90328. + */
  90329. + unsigned adpres:1;
  90330. + /** ADP Enable (ADPEn)
  90331. + * When set, the core performs either ADP probing or sensing
  90332. + * based on EnaPrb or EnaSns.
  90333. + * This bit is valid only if OTG_Ver = 1'b1.
  90334. + */
  90335. + unsigned adpen:1;
  90336. + /** ADP Probe Interrupt (ADP_PRB_INT)
  90337. + * When this bit is set, it means that the VBUS
  90338. + * voltage is greater than VADP_PRB or VADP_PRB is reached.
  90339. + * This bit is valid only if OTG_Ver = 1'b1.
  90340. + */
  90341. + unsigned adp_prb_int:1;
  90342. + /**
  90343. + * ADP Sense Interrupt (ADP_SNS_INT)
  90344. + * When this bit is set, it means that the VBUS voltage is greater than
  90345. + * VADP_SNS value or VADP_SNS is reached.
  90346. + * This bit is valid only if OTG_Ver = 1'b1.
  90347. + */
  90348. + unsigned adp_sns_int:1;
  90349. + /** ADP Tomeout Interrupt (ADP_TMOUT_INT)
  90350. + * This bit is relevant only for an ADP probe.
  90351. + * When this bit is set, it means that the ramp time has
  90352. + * completed ie ADPCTL.RTIM has reached its terminal value
  90353. + * of 0x7FF. This is a debug feature that allows software
  90354. + * to read the ramp time after each cycle.
  90355. + * This bit is valid only if OTG_Ver = 1'b1.
  90356. + */
  90357. + unsigned adp_tmout_int:1;
  90358. + /** ADP Probe Interrupt Mask (ADP_PRB_INT_MSK)
  90359. + * When this bit is set, it unmasks the interrupt due to ADP_PRB_INT.
  90360. + * This bit is valid only if OTG_Ver = 1'b1.
  90361. + */
  90362. + unsigned adp_prb_int_msk:1;
  90363. + /** ADP Sense Interrupt Mask (ADP_SNS_INT_MSK)
  90364. + * When this bit is set, it unmasks the interrupt due to ADP_SNS_INT.
  90365. + * This bit is valid only if OTG_Ver = 1'b1.
  90366. + */
  90367. + unsigned adp_sns_int_msk:1;
  90368. + /** ADP Timoeout Interrupt Mask (ADP_TMOUT_MSK)
  90369. + * When this bit is set, it unmasks the interrupt due to ADP_TMOUT_INT.
  90370. + * This bit is valid only if OTG_Ver = 1'b1.
  90371. + */
  90372. + unsigned adp_tmout_int_msk:1;
  90373. + /** Access Request
  90374. + * 2'b00 - Read/Write Valid (updated by the core)
  90375. + * 2'b01 - Read
  90376. + * 2'b00 - Write
  90377. + * 2'b00 - Reserved
  90378. + */
  90379. + unsigned ar:2;
  90380. + /** Reserved */
  90381. + unsigned reserved29_31:3;
  90382. + } b;
  90383. +} adpctl_data_t;
  90384. +
  90385. +////////////////////////////////////////////
  90386. +// Device Registers
  90387. +/**
  90388. + * Device Global Registers. <i>Offsets 800h-BFFh</i>
  90389. + *
  90390. + * The following structures define the size and relative field offsets
  90391. + * for the Device Mode Registers.
  90392. + *
  90393. + * <i>These registers are visible only in Device mode and must not be
  90394. + * accessed in Host mode, as the results are unknown.</i>
  90395. + */
  90396. +typedef struct dwc_otg_dev_global_regs {
  90397. + /** Device Configuration Register. <i>Offset 800h</i> */
  90398. + volatile uint32_t dcfg;
  90399. + /** Device Control Register. <i>Offset: 804h</i> */
  90400. + volatile uint32_t dctl;
  90401. + /** Device Status Register (Read Only). <i>Offset: 808h</i> */
  90402. + volatile uint32_t dsts;
  90403. + /** Reserved. <i>Offset: 80Ch</i> */
  90404. + uint32_t unused;
  90405. + /** Device IN Endpoint Common Interrupt Mask
  90406. + * Register. <i>Offset: 810h</i> */
  90407. + volatile uint32_t diepmsk;
  90408. + /** Device OUT Endpoint Common Interrupt Mask
  90409. + * Register. <i>Offset: 814h</i> */
  90410. + volatile uint32_t doepmsk;
  90411. + /** Device All Endpoints Interrupt Register. <i>Offset: 818h</i> */
  90412. + volatile uint32_t daint;
  90413. + /** Device All Endpoints Interrupt Mask Register. <i>Offset:
  90414. + * 81Ch</i> */
  90415. + volatile uint32_t daintmsk;
  90416. + /** Device IN Token Queue Read Register-1 (Read Only).
  90417. + * <i>Offset: 820h</i> */
  90418. + volatile uint32_t dtknqr1;
  90419. + /** Device IN Token Queue Read Register-2 (Read Only).
  90420. + * <i>Offset: 824h</i> */
  90421. + volatile uint32_t dtknqr2;
  90422. + /** Device VBUS discharge Register. <i>Offset: 828h</i> */
  90423. + volatile uint32_t dvbusdis;
  90424. + /** Device VBUS Pulse Register. <i>Offset: 82Ch</i> */
  90425. + volatile uint32_t dvbuspulse;
  90426. + /** Device IN Token Queue Read Register-3 (Read Only). /
  90427. + * Device Thresholding control register (Read/Write)
  90428. + * <i>Offset: 830h</i> */
  90429. + volatile uint32_t dtknqr3_dthrctl;
  90430. + /** Device IN Token Queue Read Register-4 (Read Only). /
  90431. + * Device IN EPs empty Inr. Mask Register (Read/Write)
  90432. + * <i>Offset: 834h</i> */
  90433. + volatile uint32_t dtknqr4_fifoemptymsk;
  90434. + /** Device Each Endpoint Interrupt Register (Read Only). /
  90435. + * <i>Offset: 838h</i> */
  90436. + volatile uint32_t deachint;
  90437. + /** Device Each Endpoint Interrupt mask Register (Read/Write). /
  90438. + * <i>Offset: 83Ch</i> */
  90439. + volatile uint32_t deachintmsk;
  90440. + /** Device Each In Endpoint Interrupt mask Register (Read/Write). /
  90441. + * <i>Offset: 840h</i> */
  90442. + volatile uint32_t diepeachintmsk[MAX_EPS_CHANNELS];
  90443. + /** Device Each Out Endpoint Interrupt mask Register (Read/Write). /
  90444. + * <i>Offset: 880h</i> */
  90445. + volatile uint32_t doepeachintmsk[MAX_EPS_CHANNELS];
  90446. +} dwc_otg_device_global_regs_t;
  90447. +
  90448. +/**
  90449. + * This union represents the bit fields in the Device Configuration
  90450. + * Register. Read the register into the <i>d32</i> member then
  90451. + * set/clear the bits using the <i>b</i>it elements. Write the
  90452. + * <i>d32</i> member to the dcfg register.
  90453. + */
  90454. +typedef union dcfg_data {
  90455. + /** raw register data */
  90456. + uint32_t d32;
  90457. + /** register bits */
  90458. + struct {
  90459. + /** Device Speed */
  90460. + unsigned devspd:2;
  90461. + /** Non Zero Length Status OUT Handshake */
  90462. + unsigned nzstsouthshk:1;
  90463. +#define DWC_DCFG_SEND_STALL 1
  90464. +
  90465. + unsigned ena32khzs:1;
  90466. + /** Device Addresses */
  90467. + unsigned devaddr:7;
  90468. + /** Periodic Frame Interval */
  90469. + unsigned perfrint:2;
  90470. +#define DWC_DCFG_FRAME_INTERVAL_80 0
  90471. +#define DWC_DCFG_FRAME_INTERVAL_85 1
  90472. +#define DWC_DCFG_FRAME_INTERVAL_90 2
  90473. +#define DWC_DCFG_FRAME_INTERVAL_95 3
  90474. +
  90475. + /** Enable Device OUT NAK for bulk in DDMA mode */
  90476. + unsigned endevoutnak:1;
  90477. +
  90478. + unsigned reserved14_17:4;
  90479. + /** In Endpoint Mis-match count */
  90480. + unsigned epmscnt:5;
  90481. + /** Enable Descriptor DMA in Device mode */
  90482. + unsigned descdma:1;
  90483. + unsigned perschintvl:2;
  90484. + unsigned resvalid:6;
  90485. + } b;
  90486. +} dcfg_data_t;
  90487. +
  90488. +/**
  90489. + * This union represents the bit fields in the Device Control
  90490. + * Register. Read the register into the <i>d32</i> member then
  90491. + * set/clear the bits using the <i>b</i>it elements.
  90492. + */
  90493. +typedef union dctl_data {
  90494. + /** raw register data */
  90495. + uint32_t d32;
  90496. + /** register bits */
  90497. + struct {
  90498. + /** Remote Wakeup */
  90499. + unsigned rmtwkupsig:1;
  90500. + /** Soft Disconnect */
  90501. + unsigned sftdiscon:1;
  90502. + /** Global Non-Periodic IN NAK Status */
  90503. + unsigned gnpinnaksts:1;
  90504. + /** Global OUT NAK Status */
  90505. + unsigned goutnaksts:1;
  90506. + /** Test Control */
  90507. + unsigned tstctl:3;
  90508. + /** Set Global Non-Periodic IN NAK */
  90509. + unsigned sgnpinnak:1;
  90510. + /** Clear Global Non-Periodic IN NAK */
  90511. + unsigned cgnpinnak:1;
  90512. + /** Set Global OUT NAK */
  90513. + unsigned sgoutnak:1;
  90514. + /** Clear Global OUT NAK */
  90515. + unsigned cgoutnak:1;
  90516. + /** Power-On Programming Done */
  90517. + unsigned pwronprgdone:1;
  90518. + /** Reserved */
  90519. + unsigned reserved:1;
  90520. + /** Global Multi Count */
  90521. + unsigned gmc:2;
  90522. + /** Ignore Frame Number for ISOC EPs */
  90523. + unsigned ifrmnum:1;
  90524. + /** NAK on Babble */
  90525. + unsigned nakonbble:1;
  90526. + /** Enable Continue on BNA */
  90527. + unsigned encontonbna:1;
  90528. +
  90529. + unsigned reserved18_31:14;
  90530. + } b;
  90531. +} dctl_data_t;
  90532. +
  90533. +/**
  90534. + * This union represents the bit fields in the Device Status
  90535. + * Register. Read the register into the <i>d32</i> member then
  90536. + * set/clear the bits using the <i>b</i>it elements.
  90537. + */
  90538. +typedef union dsts_data {
  90539. + /** raw register data */
  90540. + uint32_t d32;
  90541. + /** register bits */
  90542. + struct {
  90543. + /** Suspend Status */
  90544. + unsigned suspsts:1;
  90545. + /** Enumerated Speed */
  90546. + unsigned enumspd:2;
  90547. +#define DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
  90548. +#define DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
  90549. +#define DWC_DSTS_ENUMSPD_LS_PHY_6MHZ 2
  90550. +#define DWC_DSTS_ENUMSPD_FS_PHY_48MHZ 3
  90551. + /** Erratic Error */
  90552. + unsigned errticerr:1;
  90553. + unsigned reserved4_7:4;
  90554. + /** Frame or Microframe Number of the received SOF */
  90555. + unsigned soffn:14;
  90556. + unsigned reserved22_31:10;
  90557. + } b;
  90558. +} dsts_data_t;
  90559. +
  90560. +/**
  90561. + * This union represents the bit fields in the Device IN EP Interrupt
  90562. + * Register and the Device IN EP Common Mask Register.
  90563. + *
  90564. + * - Read the register into the <i>d32</i> member then set/clear the
  90565. + * bits using the <i>b</i>it elements.
  90566. + */
  90567. +typedef union diepint_data {
  90568. + /** raw register data */
  90569. + uint32_t d32;
  90570. + /** register bits */
  90571. + struct {
  90572. + /** Transfer complete mask */
  90573. + unsigned xfercompl:1;
  90574. + /** Endpoint disable mask */
  90575. + unsigned epdisabled:1;
  90576. + /** AHB Error mask */
  90577. + unsigned ahberr:1;
  90578. + /** TimeOUT Handshake mask (non-ISOC EPs) */
  90579. + unsigned timeout:1;
  90580. + /** IN Token received with TxF Empty mask */
  90581. + unsigned intktxfemp:1;
  90582. + /** IN Token Received with EP mismatch mask */
  90583. + unsigned intknepmis:1;
  90584. + /** IN Endpoint NAK Effective mask */
  90585. + unsigned inepnakeff:1;
  90586. + /** Reserved */
  90587. + unsigned emptyintr:1;
  90588. +
  90589. + unsigned txfifoundrn:1;
  90590. +
  90591. + /** BNA Interrupt mask */
  90592. + unsigned bna:1;
  90593. +
  90594. + unsigned reserved10_12:3;
  90595. + /** BNA Interrupt mask */
  90596. + unsigned nak:1;
  90597. +
  90598. + unsigned reserved14_31:18;
  90599. + } b;
  90600. +} diepint_data_t;
  90601. +
  90602. +/**
  90603. + * This union represents the bit fields in the Device IN EP
  90604. + * Common/Dedicated Interrupt Mask Register.
  90605. + */
  90606. +typedef union diepint_data diepmsk_data_t;
  90607. +
  90608. +/**
  90609. + * This union represents the bit fields in the Device OUT EP Interrupt
  90610. + * Registerand Device OUT EP Common Interrupt Mask Register.
  90611. + *
  90612. + * - Read the register into the <i>d32</i> member then set/clear the
  90613. + * bits using the <i>b</i>it elements.
  90614. + */
  90615. +typedef union doepint_data {
  90616. + /** raw register data */
  90617. + uint32_t d32;
  90618. + /** register bits */
  90619. + struct {
  90620. + /** Transfer complete */
  90621. + unsigned xfercompl:1;
  90622. + /** Endpoint disable */
  90623. + unsigned epdisabled:1;
  90624. + /** AHB Error */
  90625. + unsigned ahberr:1;
  90626. + /** Setup Phase Done (contorl EPs) */
  90627. + unsigned setup:1;
  90628. + /** OUT Token Received when Endpoint Disabled */
  90629. + unsigned outtknepdis:1;
  90630. +
  90631. + unsigned stsphsercvd:1;
  90632. + /** Back-to-Back SETUP Packets Received */
  90633. + unsigned back2backsetup:1;
  90634. +
  90635. + unsigned reserved7:1;
  90636. + /** OUT packet Error */
  90637. + unsigned outpkterr:1;
  90638. + /** BNA Interrupt */
  90639. + unsigned bna:1;
  90640. +
  90641. + unsigned reserved10:1;
  90642. + /** Packet Drop Status */
  90643. + unsigned pktdrpsts:1;
  90644. + /** Babble Interrupt */
  90645. + unsigned babble:1;
  90646. + /** NAK Interrupt */
  90647. + unsigned nak:1;
  90648. + /** NYET Interrupt */
  90649. + unsigned nyet:1;
  90650. + /** Bit indicating setup packet received */
  90651. + unsigned sr:1;
  90652. +
  90653. + unsigned reserved16_31:16;
  90654. + } b;
  90655. +} doepint_data_t;
  90656. +
  90657. +/**
  90658. + * This union represents the bit fields in the Device OUT EP
  90659. + * Common/Dedicated Interrupt Mask Register.
  90660. + */
  90661. +typedef union doepint_data doepmsk_data_t;
  90662. +
  90663. +/**
  90664. + * This union represents the bit fields in the Device All EP Interrupt
  90665. + * and Mask Registers.
  90666. + * - Read the register into the <i>d32</i> member then set/clear the
  90667. + * bits using the <i>b</i>it elements.
  90668. + */
  90669. +typedef union daint_data {
  90670. + /** raw register data */
  90671. + uint32_t d32;
  90672. + /** register bits */
  90673. + struct {
  90674. + /** IN Endpoint bits */
  90675. + unsigned in:16;
  90676. + /** OUT Endpoint bits */
  90677. + unsigned out:16;
  90678. + } ep;
  90679. + struct {
  90680. + /** IN Endpoint bits */
  90681. + unsigned inep0:1;
  90682. + unsigned inep1:1;
  90683. + unsigned inep2:1;
  90684. + unsigned inep3:1;
  90685. + unsigned inep4:1;
  90686. + unsigned inep5:1;
  90687. + unsigned inep6:1;
  90688. + unsigned inep7:1;
  90689. + unsigned inep8:1;
  90690. + unsigned inep9:1;
  90691. + unsigned inep10:1;
  90692. + unsigned inep11:1;
  90693. + unsigned inep12:1;
  90694. + unsigned inep13:1;
  90695. + unsigned inep14:1;
  90696. + unsigned inep15:1;
  90697. + /** OUT Endpoint bits */
  90698. + unsigned outep0:1;
  90699. + unsigned outep1:1;
  90700. + unsigned outep2:1;
  90701. + unsigned outep3:1;
  90702. + unsigned outep4:1;
  90703. + unsigned outep5:1;
  90704. + unsigned outep6:1;
  90705. + unsigned outep7:1;
  90706. + unsigned outep8:1;
  90707. + unsigned outep9:1;
  90708. + unsigned outep10:1;
  90709. + unsigned outep11:1;
  90710. + unsigned outep12:1;
  90711. + unsigned outep13:1;
  90712. + unsigned outep14:1;
  90713. + unsigned outep15:1;
  90714. + } b;
  90715. +} daint_data_t;
  90716. +
  90717. +/**
  90718. + * This union represents the bit fields in the Device IN Token Queue
  90719. + * Read Registers.
  90720. + * - Read the register into the <i>d32</i> member.
  90721. + * - READ-ONLY Register
  90722. + */
  90723. +typedef union dtknq1_data {
  90724. + /** raw register data */
  90725. + uint32_t d32;
  90726. + /** register bits */
  90727. + struct {
  90728. + /** In Token Queue Write Pointer */
  90729. + unsigned intknwptr:5;
  90730. + /** Reserved */
  90731. + unsigned reserved05_06:2;
  90732. + /** write pointer has wrapped. */
  90733. + unsigned wrap_bit:1;
  90734. + /** EP Numbers of IN Tokens 0 ... 4 */
  90735. + unsigned epnums0_5:24;
  90736. + } b;
  90737. +} dtknq1_data_t;
  90738. +
  90739. +/**
  90740. + * This union represents Threshold control Register
  90741. + * - Read and write the register into the <i>d32</i> member.
  90742. + * - READ-WRITABLE Register
  90743. + */
  90744. +typedef union dthrctl_data {
  90745. + /** raw register data */
  90746. + uint32_t d32;
  90747. + /** register bits */
  90748. + struct {
  90749. + /** non ISO Tx Thr. Enable */
  90750. + unsigned non_iso_thr_en:1;
  90751. + /** ISO Tx Thr. Enable */
  90752. + unsigned iso_thr_en:1;
  90753. + /** Tx Thr. Length */
  90754. + unsigned tx_thr_len:9;
  90755. + /** AHB Threshold ratio */
  90756. + unsigned ahb_thr_ratio:2;
  90757. + /** Reserved */
  90758. + unsigned reserved13_15:3;
  90759. + /** Rx Thr. Enable */
  90760. + unsigned rx_thr_en:1;
  90761. + /** Rx Thr. Length */
  90762. + unsigned rx_thr_len:9;
  90763. + unsigned reserved26:1;
  90764. + /** Arbiter Parking Enable*/
  90765. + unsigned arbprken:1;
  90766. + /** Reserved */
  90767. + unsigned reserved28_31:4;
  90768. + } b;
  90769. +} dthrctl_data_t;
  90770. +
  90771. +/**
  90772. + * Device Logical IN Endpoint-Specific Registers. <i>Offsets
  90773. + * 900h-AFCh</i>
  90774. + *
  90775. + * There will be one set of endpoint registers per logical endpoint
  90776. + * implemented.
  90777. + *
  90778. + * <i>These registers are visible only in Device mode and must not be
  90779. + * accessed in Host mode, as the results are unknown.</i>
  90780. + */
  90781. +typedef struct dwc_otg_dev_in_ep_regs {
  90782. + /** Device IN Endpoint Control Register. <i>Offset:900h +
  90783. + * (ep_num * 20h) + 00h</i> */
  90784. + volatile uint32_t diepctl;
  90785. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 04h</i> */
  90786. + uint32_t reserved04;
  90787. + /** Device IN Endpoint Interrupt Register. <i>Offset:900h +
  90788. + * (ep_num * 20h) + 08h</i> */
  90789. + volatile uint32_t diepint;
  90790. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 0Ch</i> */
  90791. + uint32_t reserved0C;
  90792. + /** Device IN Endpoint Transfer Size
  90793. + * Register. <i>Offset:900h + (ep_num * 20h) + 10h</i> */
  90794. + volatile uint32_t dieptsiz;
  90795. + /** Device IN Endpoint DMA Address Register. <i>Offset:900h +
  90796. + * (ep_num * 20h) + 14h</i> */
  90797. + volatile uint32_t diepdma;
  90798. + /** Device IN Endpoint Transmit FIFO Status Register. <i>Offset:900h +
  90799. + * (ep_num * 20h) + 18h</i> */
  90800. + volatile uint32_t dtxfsts;
  90801. + /** Device IN Endpoint DMA Buffer Register. <i>Offset:900h +
  90802. + * (ep_num * 20h) + 1Ch</i> */
  90803. + volatile uint32_t diepdmab;
  90804. +} dwc_otg_dev_in_ep_regs_t;
  90805. +
  90806. +/**
  90807. + * Device Logical OUT Endpoint-Specific Registers. <i>Offsets:
  90808. + * B00h-CFCh</i>
  90809. + *
  90810. + * There will be one set of endpoint registers per logical endpoint
  90811. + * implemented.
  90812. + *
  90813. + * <i>These registers are visible only in Device mode and must not be
  90814. + * accessed in Host mode, as the results are unknown.</i>
  90815. + */
  90816. +typedef struct dwc_otg_dev_out_ep_regs {
  90817. + /** Device OUT Endpoint Control Register. <i>Offset:B00h +
  90818. + * (ep_num * 20h) + 00h</i> */
  90819. + volatile uint32_t doepctl;
  90820. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 04h</i> */
  90821. + uint32_t reserved04;
  90822. + /** Device OUT Endpoint Interrupt Register. <i>Offset:B00h +
  90823. + * (ep_num * 20h) + 08h</i> */
  90824. + volatile uint32_t doepint;
  90825. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 0Ch</i> */
  90826. + uint32_t reserved0C;
  90827. + /** Device OUT Endpoint Transfer Size Register. <i>Offset:
  90828. + * B00h + (ep_num * 20h) + 10h</i> */
  90829. + volatile uint32_t doeptsiz;
  90830. + /** Device OUT Endpoint DMA Address Register. <i>Offset:B00h
  90831. + * + (ep_num * 20h) + 14h</i> */
  90832. + volatile uint32_t doepdma;
  90833. + /** Reserved. <i>Offset:B00h + * (ep_num * 20h) + 18h</i> */
  90834. + uint32_t unused;
  90835. + /** Device OUT Endpoint DMA Buffer Register. <i>Offset:B00h
  90836. + * + (ep_num * 20h) + 1Ch</i> */
  90837. + uint32_t doepdmab;
  90838. +} dwc_otg_dev_out_ep_regs_t;
  90839. +
  90840. +/**
  90841. + * This union represents the bit fields in the Device EP Control
  90842. + * Register. Read the register into the <i>d32</i> member then
  90843. + * set/clear the bits using the <i>b</i>it elements.
  90844. + */
  90845. +typedef union depctl_data {
  90846. + /** raw register data */
  90847. + uint32_t d32;
  90848. + /** register bits */
  90849. + struct {
  90850. + /** Maximum Packet Size
  90851. + * IN/OUT EPn
  90852. + * IN/OUT EP0 - 2 bits
  90853. + * 2'b00: 64 Bytes
  90854. + * 2'b01: 32
  90855. + * 2'b10: 16
  90856. + * 2'b11: 8 */
  90857. + unsigned mps:11;
  90858. +#define DWC_DEP0CTL_MPS_64 0
  90859. +#define DWC_DEP0CTL_MPS_32 1
  90860. +#define DWC_DEP0CTL_MPS_16 2
  90861. +#define DWC_DEP0CTL_MPS_8 3
  90862. +
  90863. + /** Next Endpoint
  90864. + * IN EPn/IN EP0
  90865. + * OUT EPn/OUT EP0 - reserved */
  90866. + unsigned nextep:4;
  90867. +
  90868. + /** USB Active Endpoint */
  90869. + unsigned usbactep:1;
  90870. +
  90871. + /** Endpoint DPID (INTR/Bulk IN and OUT endpoints)
  90872. + * This field contains the PID of the packet going to
  90873. + * be received or transmitted on this endpoint. The
  90874. + * application should program the PID of the first
  90875. + * packet going to be received or transmitted on this
  90876. + * endpoint , after the endpoint is
  90877. + * activated. Application use the SetD1PID and
  90878. + * SetD0PID fields of this register to program either
  90879. + * D0 or D1 PID.
  90880. + *
  90881. + * The encoding for this field is
  90882. + * - 0: D0
  90883. + * - 1: D1
  90884. + */
  90885. + unsigned dpid:1;
  90886. +
  90887. + /** NAK Status */
  90888. + unsigned naksts:1;
  90889. +
  90890. + /** Endpoint Type
  90891. + * 2'b00: Control
  90892. + * 2'b01: Isochronous
  90893. + * 2'b10: Bulk
  90894. + * 2'b11: Interrupt */
  90895. + unsigned eptype:2;
  90896. +
  90897. + /** Snoop Mode
  90898. + * OUT EPn/OUT EP0
  90899. + * IN EPn/IN EP0 - reserved */
  90900. + unsigned snp:1;
  90901. +
  90902. + /** Stall Handshake */
  90903. + unsigned stall:1;
  90904. +
  90905. + /** Tx Fifo Number
  90906. + * IN EPn/IN EP0
  90907. + * OUT EPn/OUT EP0 - reserved */
  90908. + unsigned txfnum:4;
  90909. +
  90910. + /** Clear NAK */
  90911. + unsigned cnak:1;
  90912. + /** Set NAK */
  90913. + unsigned snak:1;
  90914. + /** Set DATA0 PID (INTR/Bulk IN and OUT endpoints)
  90915. + * Writing to this field sets the Endpoint DPID (DPID)
  90916. + * field in this register to DATA0. Set Even
  90917. + * (micro)frame (SetEvenFr) (ISO IN and OUT Endpoints)
  90918. + * Writing to this field sets the Even/Odd
  90919. + * (micro)frame (EO_FrNum) field to even (micro)
  90920. + * frame.
  90921. + */
  90922. + unsigned setd0pid:1;
  90923. + /** Set DATA1 PID (INTR/Bulk IN and OUT endpoints)
  90924. + * Writing to this field sets the Endpoint DPID (DPID)
  90925. + * field in this register to DATA1 Set Odd
  90926. + * (micro)frame (SetOddFr) (ISO IN and OUT Endpoints)
  90927. + * Writing to this field sets the Even/Odd
  90928. + * (micro)frame (EO_FrNum) field to odd (micro) frame.
  90929. + */
  90930. + unsigned setd1pid:1;
  90931. +
  90932. + /** Endpoint Disable */
  90933. + unsigned epdis:1;
  90934. + /** Endpoint Enable */
  90935. + unsigned epena:1;
  90936. + } b;
  90937. +} depctl_data_t;
  90938. +
  90939. +/**
  90940. + * This union represents the bit fields in the Device EP Transfer
  90941. + * Size Register. Read the register into the <i>d32</i> member then
  90942. + * set/clear the bits using the <i>b</i>it elements.
  90943. + */
  90944. +typedef union deptsiz_data {
  90945. + /** raw register data */
  90946. + uint32_t d32;
  90947. + /** register bits */
  90948. + struct {
  90949. + /** Transfer size */
  90950. + unsigned xfersize:19;
  90951. +/** Max packet count for EP (pow(2,10)-1) */
  90952. +#define MAX_PKT_CNT 1023
  90953. + /** Packet Count */
  90954. + unsigned pktcnt:10;
  90955. + /** Multi Count - Periodic IN endpoints */
  90956. + unsigned mc:2;
  90957. + unsigned reserved:1;
  90958. + } b;
  90959. +} deptsiz_data_t;
  90960. +
  90961. +/**
  90962. + * This union represents the bit fields in the Device EP 0 Transfer
  90963. + * Size Register. Read the register into the <i>d32</i> member then
  90964. + * set/clear the bits using the <i>b</i>it elements.
  90965. + */
  90966. +typedef union deptsiz0_data {
  90967. + /** raw register data */
  90968. + uint32_t d32;
  90969. + /** register bits */
  90970. + struct {
  90971. + /** Transfer size */
  90972. + unsigned xfersize:7;
  90973. + /** Reserved */
  90974. + unsigned reserved7_18:12;
  90975. + /** Packet Count */
  90976. + unsigned pktcnt:2;
  90977. + /** Reserved */
  90978. + unsigned reserved21_28:8;
  90979. + /**Setup Packet Count (DOEPTSIZ0 Only) */
  90980. + unsigned supcnt:2;
  90981. + unsigned reserved31;
  90982. + } b;
  90983. +} deptsiz0_data_t;
  90984. +
  90985. +/////////////////////////////////////////////////
  90986. +// DMA Descriptor Specific Structures
  90987. +//
  90988. +
  90989. +/** Buffer status definitions */
  90990. +
  90991. +#define BS_HOST_READY 0x0
  90992. +#define BS_DMA_BUSY 0x1
  90993. +#define BS_DMA_DONE 0x2
  90994. +#define BS_HOST_BUSY 0x3
  90995. +
  90996. +/** Receive/Transmit status definitions */
  90997. +
  90998. +#define RTS_SUCCESS 0x0
  90999. +#define RTS_BUFFLUSH 0x1
  91000. +#define RTS_RESERVED 0x2
  91001. +#define RTS_BUFERR 0x3
  91002. +
  91003. +/**
  91004. + * This union represents the bit fields in the DMA Descriptor
  91005. + * status quadlet. Read the quadlet into the <i>d32</i> member then
  91006. + * set/clear the bits using the <i>b</i>it, <i>b_iso_out</i> and
  91007. + * <i>b_iso_in</i> elements.
  91008. + */
  91009. +typedef union dev_dma_desc_sts {
  91010. + /** raw register data */
  91011. + uint32_t d32;
  91012. + /** quadlet bits */
  91013. + struct {
  91014. + /** Received number of bytes */
  91015. + unsigned bytes:16;
  91016. + /** NAK bit - only for OUT EPs */
  91017. + unsigned nak:1;
  91018. + unsigned reserved17_22:6;
  91019. + /** Multiple Transfer - only for OUT EPs */
  91020. + unsigned mtrf:1;
  91021. + /** Setup Packet received - only for OUT EPs */
  91022. + unsigned sr:1;
  91023. + /** Interrupt On Complete */
  91024. + unsigned ioc:1;
  91025. + /** Short Packet */
  91026. + unsigned sp:1;
  91027. + /** Last */
  91028. + unsigned l:1;
  91029. + /** Receive Status */
  91030. + unsigned sts:2;
  91031. + /** Buffer Status */
  91032. + unsigned bs:2;
  91033. + } b;
  91034. +
  91035. +//#ifdef DWC_EN_ISOC
  91036. + /** iso out quadlet bits */
  91037. + struct {
  91038. + /** Received number of bytes */
  91039. + unsigned rxbytes:11;
  91040. +
  91041. + unsigned reserved11:1;
  91042. + /** Frame Number */
  91043. + unsigned framenum:11;
  91044. + /** Received ISO Data PID */
  91045. + unsigned pid:2;
  91046. + /** Interrupt On Complete */
  91047. + unsigned ioc:1;
  91048. + /** Short Packet */
  91049. + unsigned sp:1;
  91050. + /** Last */
  91051. + unsigned l:1;
  91052. + /** Receive Status */
  91053. + unsigned rxsts:2;
  91054. + /** Buffer Status */
  91055. + unsigned bs:2;
  91056. + } b_iso_out;
  91057. +
  91058. + /** iso in quadlet bits */
  91059. + struct {
  91060. + /** Transmited number of bytes */
  91061. + unsigned txbytes:12;
  91062. + /** Frame Number */
  91063. + unsigned framenum:11;
  91064. + /** Transmited ISO Data PID */
  91065. + unsigned pid:2;
  91066. + /** Interrupt On Complete */
  91067. + unsigned ioc:1;
  91068. + /** Short Packet */
  91069. + unsigned sp:1;
  91070. + /** Last */
  91071. + unsigned l:1;
  91072. + /** Transmit Status */
  91073. + unsigned txsts:2;
  91074. + /** Buffer Status */
  91075. + unsigned bs:2;
  91076. + } b_iso_in;
  91077. +//#endif /* DWC_EN_ISOC */
  91078. +} dev_dma_desc_sts_t;
  91079. +
  91080. +/**
  91081. + * DMA Descriptor structure
  91082. + *
  91083. + * DMA Descriptor structure contains two quadlets:
  91084. + * Status quadlet and Data buffer pointer.
  91085. + */
  91086. +typedef struct dwc_otg_dev_dma_desc {
  91087. + /** DMA Descriptor status quadlet */
  91088. + dev_dma_desc_sts_t status;
  91089. + /** DMA Descriptor data buffer pointer */
  91090. + uint32_t buf;
  91091. +} dwc_otg_dev_dma_desc_t;
  91092. +
  91093. +/**
  91094. + * The dwc_otg_dev_if structure contains information needed to manage
  91095. + * the DWC_otg controller acting in device mode. It represents the
  91096. + * programming view of the device-specific aspects of the controller.
  91097. + */
  91098. +typedef struct dwc_otg_dev_if {
  91099. + /** Pointer to device Global registers.
  91100. + * Device Global Registers starting at offset 800h
  91101. + */
  91102. + dwc_otg_device_global_regs_t *dev_global_regs;
  91103. +#define DWC_DEV_GLOBAL_REG_OFFSET 0x800
  91104. +
  91105. + /**
  91106. + * Device Logical IN Endpoint-Specific Registers 900h-AFCh
  91107. + */
  91108. + dwc_otg_dev_in_ep_regs_t *in_ep_regs[MAX_EPS_CHANNELS];
  91109. +#define DWC_DEV_IN_EP_REG_OFFSET 0x900
  91110. +#define DWC_EP_REG_OFFSET 0x20
  91111. +
  91112. + /** Device Logical OUT Endpoint-Specific Registers B00h-CFCh */
  91113. + dwc_otg_dev_out_ep_regs_t *out_ep_regs[MAX_EPS_CHANNELS];
  91114. +#define DWC_DEV_OUT_EP_REG_OFFSET 0xB00
  91115. +
  91116. + /* Device configuration information */
  91117. + uint8_t speed; /**< Device Speed 0: Unknown, 1: LS, 2:FS, 3: HS */
  91118. + uint8_t num_in_eps; /**< Number # of Tx EP range: 0-15 exept ep0 */
  91119. + uint8_t num_out_eps; /**< Number # of Rx EP range: 0-15 exept ep 0*/
  91120. +
  91121. + /** Size of periodic FIFOs (Bytes) */
  91122. + uint16_t perio_tx_fifo_size[MAX_PERIO_FIFOS];
  91123. +
  91124. + /** Size of Tx FIFOs (Bytes) */
  91125. + uint16_t tx_fifo_size[MAX_TX_FIFOS];
  91126. +
  91127. + /** Thresholding enable flags and length varaiables **/
  91128. + uint16_t rx_thr_en;
  91129. + uint16_t iso_tx_thr_en;
  91130. + uint16_t non_iso_tx_thr_en;
  91131. +
  91132. + uint16_t rx_thr_length;
  91133. + uint16_t tx_thr_length;
  91134. +
  91135. + /**
  91136. + * Pointers to the DMA Descriptors for EP0 Control
  91137. + * transfers (virtual and physical)
  91138. + */
  91139. +
  91140. + /** 2 descriptors for SETUP packets */
  91141. + dwc_dma_t dma_setup_desc_addr[2];
  91142. + dwc_otg_dev_dma_desc_t *setup_desc_addr[2];
  91143. +
  91144. + /** Pointer to Descriptor with latest SETUP packet */
  91145. + dwc_otg_dev_dma_desc_t *psetup;
  91146. +
  91147. + /** Index of current SETUP handler descriptor */
  91148. + uint32_t setup_desc_index;
  91149. +
  91150. + /** Descriptor for Data In or Status In phases */
  91151. + dwc_dma_t dma_in_desc_addr;
  91152. + dwc_otg_dev_dma_desc_t *in_desc_addr;
  91153. +
  91154. + /** Descriptor for Data Out or Status Out phases */
  91155. + dwc_dma_t dma_out_desc_addr;
  91156. + dwc_otg_dev_dma_desc_t *out_desc_addr;
  91157. +
  91158. + /** Setup Packet Detected - if set clear NAK when queueing */
  91159. + uint32_t spd;
  91160. + /** Isoc ep pointer on which incomplete happens */
  91161. + void *isoc_ep;
  91162. +
  91163. +} dwc_otg_dev_if_t;
  91164. +
  91165. +/////////////////////////////////////////////////
  91166. +// Host Mode Register Structures
  91167. +//
  91168. +/**
  91169. + * The Host Global Registers structure defines the size and relative
  91170. + * field offsets for the Host Mode Global Registers. Host Global
  91171. + * Registers offsets 400h-7FFh.
  91172. +*/
  91173. +typedef struct dwc_otg_host_global_regs {
  91174. + /** Host Configuration Register. <i>Offset: 400h</i> */
  91175. + volatile uint32_t hcfg;
  91176. + /** Host Frame Interval Register. <i>Offset: 404h</i> */
  91177. + volatile uint32_t hfir;
  91178. + /** Host Frame Number / Frame Remaining Register. <i>Offset: 408h</i> */
  91179. + volatile uint32_t hfnum;
  91180. + /** Reserved. <i>Offset: 40Ch</i> */
  91181. + uint32_t reserved40C;
  91182. + /** Host Periodic Transmit FIFO/ Queue Status Register. <i>Offset: 410h</i> */
  91183. + volatile uint32_t hptxsts;
  91184. + /** Host All Channels Interrupt Register. <i>Offset: 414h</i> */
  91185. + volatile uint32_t haint;
  91186. + /** Host All Channels Interrupt Mask Register. <i>Offset: 418h</i> */
  91187. + volatile uint32_t haintmsk;
  91188. + /** Host Frame List Base Address Register . <i>Offset: 41Ch</i> */
  91189. + volatile uint32_t hflbaddr;
  91190. +} dwc_otg_host_global_regs_t;
  91191. +
  91192. +/**
  91193. + * This union represents the bit fields in the Host Configuration Register.
  91194. + * Read the register into the <i>d32</i> member then set/clear the bits using
  91195. + * the <i>b</i>it elements. Write the <i>d32</i> member to the hcfg register.
  91196. + */
  91197. +typedef union hcfg_data {
  91198. + /** raw register data */
  91199. + uint32_t d32;
  91200. +
  91201. + /** register bits */
  91202. + struct {
  91203. + /** FS/LS Phy Clock Select */
  91204. + unsigned fslspclksel:2;
  91205. +#define DWC_HCFG_30_60_MHZ 0
  91206. +#define DWC_HCFG_48_MHZ 1
  91207. +#define DWC_HCFG_6_MHZ 2
  91208. +
  91209. + /** FS/LS Only Support */
  91210. + unsigned fslssupp:1;
  91211. + unsigned reserved3_6:4;
  91212. + /** Enable 32-KHz Suspend Mode */
  91213. + unsigned ena32khzs:1;
  91214. + /** Resume Validation Periiod */
  91215. + unsigned resvalid:8;
  91216. + unsigned reserved16_22:7;
  91217. + /** Enable Scatter/gather DMA in Host mode */
  91218. + unsigned descdma:1;
  91219. + /** Frame List Entries */
  91220. + unsigned frlisten:2;
  91221. + /** Enable Periodic Scheduling */
  91222. + unsigned perschedena:1;
  91223. + unsigned reserved27_30:4;
  91224. + unsigned modechtimen:1;
  91225. + } b;
  91226. +} hcfg_data_t;
  91227. +
  91228. +/**
  91229. + * This union represents the bit fields in the Host Frame Remaing/Number
  91230. + * Register.
  91231. + */
  91232. +typedef union hfir_data {
  91233. + /** raw register data */
  91234. + uint32_t d32;
  91235. +
  91236. + /** register bits */
  91237. + struct {
  91238. + unsigned frint:16;
  91239. + unsigned hfirrldctrl:1;
  91240. + unsigned reserved:15;
  91241. + } b;
  91242. +} hfir_data_t;
  91243. +
  91244. +/**
  91245. + * This union represents the bit fields in the Host Frame Remaing/Number
  91246. + * Register.
  91247. + */
  91248. +typedef union hfnum_data {
  91249. + /** raw register data */
  91250. + uint32_t d32;
  91251. +
  91252. + /** register bits */
  91253. + struct {
  91254. + unsigned frnum:16;
  91255. +#define DWC_HFNUM_MAX_FRNUM 0x3FFF
  91256. + unsigned frrem:16;
  91257. + } b;
  91258. +} hfnum_data_t;
  91259. +
  91260. +typedef union hptxsts_data {
  91261. + /** raw register data */
  91262. + uint32_t d32;
  91263. +
  91264. + /** register bits */
  91265. + struct {
  91266. + unsigned ptxfspcavail:16;
  91267. + unsigned ptxqspcavail:8;
  91268. + /** Top of the Periodic Transmit Request Queue
  91269. + * - bit 24 - Terminate (last entry for the selected channel)
  91270. + * - bits 26:25 - Token Type
  91271. + * - 2'b00 - Zero length
  91272. + * - 2'b01 - Ping
  91273. + * - 2'b10 - Disable
  91274. + * - bits 30:27 - Channel Number
  91275. + * - bit 31 - Odd/even microframe
  91276. + */
  91277. + unsigned ptxqtop_terminate:1;
  91278. + unsigned ptxqtop_token:2;
  91279. + unsigned ptxqtop_chnum:4;
  91280. + unsigned ptxqtop_odd:1;
  91281. + } b;
  91282. +} hptxsts_data_t;
  91283. +
  91284. +/**
  91285. + * This union represents the bit fields in the Host Port Control and Status
  91286. + * Register. Read the register into the <i>d32</i> member then set/clear the
  91287. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  91288. + * hprt0 register.
  91289. + */
  91290. +typedef union hprt0_data {
  91291. + /** raw register data */
  91292. + uint32_t d32;
  91293. + /** register bits */
  91294. + struct {
  91295. + unsigned prtconnsts:1;
  91296. + unsigned prtconndet:1;
  91297. + unsigned prtena:1;
  91298. + unsigned prtenchng:1;
  91299. + unsigned prtovrcurract:1;
  91300. + unsigned prtovrcurrchng:1;
  91301. + unsigned prtres:1;
  91302. + unsigned prtsusp:1;
  91303. + unsigned prtrst:1;
  91304. + unsigned reserved9:1;
  91305. + unsigned prtlnsts:2;
  91306. + unsigned prtpwr:1;
  91307. + unsigned prttstctl:4;
  91308. + unsigned prtspd:2;
  91309. +#define DWC_HPRT0_PRTSPD_HIGH_SPEED 0
  91310. +#define DWC_HPRT0_PRTSPD_FULL_SPEED 1
  91311. +#define DWC_HPRT0_PRTSPD_LOW_SPEED 2
  91312. + unsigned reserved19_31:13;
  91313. + } b;
  91314. +} hprt0_data_t;
  91315. +
  91316. +/**
  91317. + * This union represents the bit fields in the Host All Interrupt
  91318. + * Register.
  91319. + */
  91320. +typedef union haint_data {
  91321. + /** raw register data */
  91322. + uint32_t d32;
  91323. + /** register bits */
  91324. + struct {
  91325. + unsigned ch0:1;
  91326. + unsigned ch1:1;
  91327. + unsigned ch2:1;
  91328. + unsigned ch3:1;
  91329. + unsigned ch4:1;
  91330. + unsigned ch5:1;
  91331. + unsigned ch6:1;
  91332. + unsigned ch7:1;
  91333. + unsigned ch8:1;
  91334. + unsigned ch9:1;
  91335. + unsigned ch10:1;
  91336. + unsigned ch11:1;
  91337. + unsigned ch12:1;
  91338. + unsigned ch13:1;
  91339. + unsigned ch14:1;
  91340. + unsigned ch15:1;
  91341. + unsigned reserved:16;
  91342. + } b;
  91343. +
  91344. + struct {
  91345. + unsigned chint:16;
  91346. + unsigned reserved:16;
  91347. + } b2;
  91348. +} haint_data_t;
  91349. +
  91350. +/**
  91351. + * This union represents the bit fields in the Host All Interrupt
  91352. + * Register.
  91353. + */
  91354. +typedef union haintmsk_data {
  91355. + /** raw register data */
  91356. + uint32_t d32;
  91357. + /** register bits */
  91358. + struct {
  91359. + unsigned ch0:1;
  91360. + unsigned ch1:1;
  91361. + unsigned ch2:1;
  91362. + unsigned ch3:1;
  91363. + unsigned ch4:1;
  91364. + unsigned ch5:1;
  91365. + unsigned ch6:1;
  91366. + unsigned ch7:1;
  91367. + unsigned ch8:1;
  91368. + unsigned ch9:1;
  91369. + unsigned ch10:1;
  91370. + unsigned ch11:1;
  91371. + unsigned ch12:1;
  91372. + unsigned ch13:1;
  91373. + unsigned ch14:1;
  91374. + unsigned ch15:1;
  91375. + unsigned reserved:16;
  91376. + } b;
  91377. +
  91378. + struct {
  91379. + unsigned chint:16;
  91380. + unsigned reserved:16;
  91381. + } b2;
  91382. +} haintmsk_data_t;
  91383. +
  91384. +/**
  91385. + * Host Channel Specific Registers. <i>500h-5FCh</i>
  91386. + */
  91387. +typedef struct dwc_otg_hc_regs {
  91388. + /** Host Channel 0 Characteristic Register. <i>Offset: 500h + (chan_num * 20h) + 00h</i> */
  91389. + volatile uint32_t hcchar;
  91390. + /** Host Channel 0 Split Control Register. <i>Offset: 500h + (chan_num * 20h) + 04h</i> */
  91391. + volatile uint32_t hcsplt;
  91392. + /** Host Channel 0 Interrupt Register. <i>Offset: 500h + (chan_num * 20h) + 08h</i> */
  91393. + volatile uint32_t hcint;
  91394. + /** Host Channel 0 Interrupt Mask Register. <i>Offset: 500h + (chan_num * 20h) + 0Ch</i> */
  91395. + volatile uint32_t hcintmsk;
  91396. + /** Host Channel 0 Transfer Size Register. <i>Offset: 500h + (chan_num * 20h) + 10h</i> */
  91397. + volatile uint32_t hctsiz;
  91398. + /** Host Channel 0 DMA Address Register. <i>Offset: 500h + (chan_num * 20h) + 14h</i> */
  91399. + volatile uint32_t hcdma;
  91400. + volatile uint32_t reserved;
  91401. + /** Host Channel 0 DMA Buffer Address Register. <i>Offset: 500h + (chan_num * 20h) + 1Ch</i> */
  91402. + volatile uint32_t hcdmab;
  91403. +} dwc_otg_hc_regs_t;
  91404. +
  91405. +/**
  91406. + * This union represents the bit fields in the Host Channel Characteristics
  91407. + * Register. Read the register into the <i>d32</i> member then set/clear the
  91408. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  91409. + * hcchar register.
  91410. + */
  91411. +typedef union hcchar_data {
  91412. + /** raw register data */
  91413. + uint32_t d32;
  91414. +
  91415. + /** register bits */
  91416. + struct {
  91417. + /** Maximum packet size in bytes */
  91418. + unsigned mps:11;
  91419. +
  91420. + /** Endpoint number */
  91421. + unsigned epnum:4;
  91422. +
  91423. + /** 0: OUT, 1: IN */
  91424. + unsigned epdir:1;
  91425. +
  91426. + unsigned reserved:1;
  91427. +
  91428. + /** 0: Full/high speed device, 1: Low speed device */
  91429. + unsigned lspddev:1;
  91430. +
  91431. + /** 0: Control, 1: Isoc, 2: Bulk, 3: Intr */
  91432. + unsigned eptype:2;
  91433. +
  91434. + /** Packets per frame for periodic transfers. 0 is reserved. */
  91435. + unsigned multicnt:2;
  91436. +
  91437. + /** Device address */
  91438. + unsigned devaddr:7;
  91439. +
  91440. + /**
  91441. + * Frame to transmit periodic transaction.
  91442. + * 0: even, 1: odd
  91443. + */
  91444. + unsigned oddfrm:1;
  91445. +
  91446. + /** Channel disable */
  91447. + unsigned chdis:1;
  91448. +
  91449. + /** Channel enable */
  91450. + unsigned chen:1;
  91451. + } b;
  91452. +} hcchar_data_t;
  91453. +
  91454. +typedef union hcsplt_data {
  91455. + /** raw register data */
  91456. + uint32_t d32;
  91457. +
  91458. + /** register bits */
  91459. + struct {
  91460. + /** Port Address */
  91461. + unsigned prtaddr:7;
  91462. +
  91463. + /** Hub Address */
  91464. + unsigned hubaddr:7;
  91465. +
  91466. + /** Transaction Position */
  91467. + unsigned xactpos:2;
  91468. +#define DWC_HCSPLIT_XACTPOS_MID 0
  91469. +#define DWC_HCSPLIT_XACTPOS_END 1
  91470. +#define DWC_HCSPLIT_XACTPOS_BEGIN 2
  91471. +#define DWC_HCSPLIT_XACTPOS_ALL 3
  91472. +
  91473. + /** Do Complete Split */
  91474. + unsigned compsplt:1;
  91475. +
  91476. + /** Reserved */
  91477. + unsigned reserved:14;
  91478. +
  91479. + /** Split Enble */
  91480. + unsigned spltena:1;
  91481. + } b;
  91482. +} hcsplt_data_t;
  91483. +
  91484. +/**
  91485. + * This union represents the bit fields in the Host All Interrupt
  91486. + * Register.
  91487. + */
  91488. +typedef union hcint_data {
  91489. + /** raw register data */
  91490. + uint32_t d32;
  91491. + /** register bits */
  91492. + struct {
  91493. + /** Transfer Complete */
  91494. + unsigned xfercomp:1;
  91495. + /** Channel Halted */
  91496. + unsigned chhltd:1;
  91497. + /** AHB Error */
  91498. + unsigned ahberr:1;
  91499. + /** STALL Response Received */
  91500. + unsigned stall:1;
  91501. + /** NAK Response Received */
  91502. + unsigned nak:1;
  91503. + /** ACK Response Received */
  91504. + unsigned ack:1;
  91505. + /** NYET Response Received */
  91506. + unsigned nyet:1;
  91507. + /** Transaction Err */
  91508. + unsigned xacterr:1;
  91509. + /** Babble Error */
  91510. + unsigned bblerr:1;
  91511. + /** Frame Overrun */
  91512. + unsigned frmovrun:1;
  91513. + /** Data Toggle Error */
  91514. + unsigned datatglerr:1;
  91515. + /** Buffer Not Available (only for DDMA mode) */
  91516. + unsigned bna:1;
  91517. + /** Exessive transaction error (only for DDMA mode) */
  91518. + unsigned xcs_xact:1;
  91519. + /** Frame List Rollover interrupt */
  91520. + unsigned frm_list_roll:1;
  91521. + /** Reserved */
  91522. + unsigned reserved14_31:18;
  91523. + } b;
  91524. +} hcint_data_t;
  91525. +
  91526. +/**
  91527. + * This union represents the bit fields in the Host Channel Interrupt Mask
  91528. + * Register. Read the register into the <i>d32</i> member then set/clear the
  91529. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  91530. + * hcintmsk register.
  91531. + */
  91532. +typedef union hcintmsk_data {
  91533. + /** raw register data */
  91534. + uint32_t d32;
  91535. +
  91536. + /** register bits */
  91537. + struct {
  91538. + unsigned xfercompl:1;
  91539. + unsigned chhltd:1;
  91540. + unsigned ahberr:1;
  91541. + unsigned stall:1;
  91542. + unsigned nak:1;
  91543. + unsigned ack:1;
  91544. + unsigned nyet:1;
  91545. + unsigned xacterr:1;
  91546. + unsigned bblerr:1;
  91547. + unsigned frmovrun:1;
  91548. + unsigned datatglerr:1;
  91549. + unsigned bna:1;
  91550. + unsigned xcs_xact:1;
  91551. + unsigned frm_list_roll:1;
  91552. + unsigned reserved14_31:18;
  91553. + } b;
  91554. +} hcintmsk_data_t;
  91555. +
  91556. +/**
  91557. + * This union represents the bit fields in the Host Channel Transfer Size
  91558. + * Register. Read the register into the <i>d32</i> member then set/clear the
  91559. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  91560. + * hcchar register.
  91561. + */
  91562. +
  91563. +typedef union hctsiz_data {
  91564. + /** raw register data */
  91565. + uint32_t d32;
  91566. +
  91567. + /** register bits */
  91568. + struct {
  91569. + /** Total transfer size in bytes */
  91570. + unsigned xfersize:19;
  91571. +
  91572. + /** Data packets to transfer */
  91573. + unsigned pktcnt:10;
  91574. +
  91575. + /**
  91576. + * Packet ID for next data packet
  91577. + * 0: DATA0
  91578. + * 1: DATA2
  91579. + * 2: DATA1
  91580. + * 3: MDATA (non-Control), SETUP (Control)
  91581. + */
  91582. + unsigned pid:2;
  91583. +#define DWC_HCTSIZ_DATA0 0
  91584. +#define DWC_HCTSIZ_DATA1 2
  91585. +#define DWC_HCTSIZ_DATA2 1
  91586. +#define DWC_HCTSIZ_MDATA 3
  91587. +#define DWC_HCTSIZ_SETUP 3
  91588. +
  91589. + /** Do PING protocol when 1 */
  91590. + unsigned dopng:1;
  91591. + } b;
  91592. +
  91593. + /** register bits */
  91594. + struct {
  91595. + /** Scheduling information */
  91596. + unsigned schinfo:8;
  91597. +
  91598. + /** Number of transfer descriptors.
  91599. + * Max value:
  91600. + * 64 in general,
  91601. + * 256 only for HS isochronous endpoint.
  91602. + */
  91603. + unsigned ntd:8;
  91604. +
  91605. + /** Data packets to transfer */
  91606. + unsigned reserved16_28:13;
  91607. +
  91608. + /**
  91609. + * Packet ID for next data packet
  91610. + * 0: DATA0
  91611. + * 1: DATA2
  91612. + * 2: DATA1
  91613. + * 3: MDATA (non-Control)
  91614. + */
  91615. + unsigned pid:2;
  91616. +
  91617. + /** Do PING protocol when 1 */
  91618. + unsigned dopng:1;
  91619. + } b_ddma;
  91620. +} hctsiz_data_t;
  91621. +
  91622. +/**
  91623. + * This union represents the bit fields in the Host DMA Address
  91624. + * Register used in Descriptor DMA mode.
  91625. + */
  91626. +typedef union hcdma_data {
  91627. + /** raw register data */
  91628. + uint32_t d32;
  91629. + /** register bits */
  91630. + struct {
  91631. + unsigned reserved0_2:3;
  91632. + /** Current Transfer Descriptor. Not used for ISOC */
  91633. + unsigned ctd:8;
  91634. + /** Start Address of Descriptor List */
  91635. + unsigned dma_addr:21;
  91636. + } b;
  91637. +} hcdma_data_t;
  91638. +
  91639. +/**
  91640. + * This union represents the bit fields in the DMA Descriptor
  91641. + * status quadlet for host mode. Read the quadlet into the <i>d32</i> member then
  91642. + * set/clear the bits using the <i>b</i>it elements.
  91643. + */
  91644. +typedef union host_dma_desc_sts {
  91645. + /** raw register data */
  91646. + uint32_t d32;
  91647. + /** quadlet bits */
  91648. +
  91649. + /* for non-isochronous */
  91650. + struct {
  91651. + /** Number of bytes */
  91652. + unsigned n_bytes:17;
  91653. + /** QTD offset to jump when Short Packet received - only for IN EPs */
  91654. + unsigned qtd_offset:6;
  91655. + /**
  91656. + * Set to request the core to jump to alternate QTD if
  91657. + * Short Packet received - only for IN EPs
  91658. + */
  91659. + unsigned a_qtd:1;
  91660. + /**
  91661. + * Setup Packet bit. When set indicates that buffer contains
  91662. + * setup packet.
  91663. + */
  91664. + unsigned sup:1;
  91665. + /** Interrupt On Complete */
  91666. + unsigned ioc:1;
  91667. + /** End of List */
  91668. + unsigned eol:1;
  91669. + unsigned reserved27:1;
  91670. + /** Rx/Tx Status */
  91671. + unsigned sts:2;
  91672. +#define DMA_DESC_STS_PKTERR 1
  91673. + unsigned reserved30:1;
  91674. + /** Active Bit */
  91675. + unsigned a:1;
  91676. + } b;
  91677. + /* for isochronous */
  91678. + struct {
  91679. + /** Number of bytes */
  91680. + unsigned n_bytes:12;
  91681. + unsigned reserved12_24:13;
  91682. + /** Interrupt On Complete */
  91683. + unsigned ioc:1;
  91684. + unsigned reserved26_27:2;
  91685. + /** Rx/Tx Status */
  91686. + unsigned sts:2;
  91687. + unsigned reserved30:1;
  91688. + /** Active Bit */
  91689. + unsigned a:1;
  91690. + } b_isoc;
  91691. +} host_dma_desc_sts_t;
  91692. +
  91693. +#define MAX_DMA_DESC_SIZE 131071
  91694. +#define MAX_DMA_DESC_NUM_GENERIC 64
  91695. +#define MAX_DMA_DESC_NUM_HS_ISOC 256
  91696. +#define MAX_FRLIST_EN_NUM 64
  91697. +/**
  91698. + * Host-mode DMA Descriptor structure
  91699. + *
  91700. + * DMA Descriptor structure contains two quadlets:
  91701. + * Status quadlet and Data buffer pointer.
  91702. + */
  91703. +typedef struct dwc_otg_host_dma_desc {
  91704. + /** DMA Descriptor status quadlet */
  91705. + host_dma_desc_sts_t status;
  91706. + /** DMA Descriptor data buffer pointer */
  91707. + uint32_t buf;
  91708. +} dwc_otg_host_dma_desc_t;
  91709. +
  91710. +/** OTG Host Interface Structure.
  91711. + *
  91712. + * The OTG Host Interface Structure structure contains information
  91713. + * needed to manage the DWC_otg controller acting in host mode. It
  91714. + * represents the programming view of the host-specific aspects of the
  91715. + * controller.
  91716. + */
  91717. +typedef struct dwc_otg_host_if {
  91718. + /** Host Global Registers starting at offset 400h.*/
  91719. + dwc_otg_host_global_regs_t *host_global_regs;
  91720. +#define DWC_OTG_HOST_GLOBAL_REG_OFFSET 0x400
  91721. +
  91722. + /** Host Port 0 Control and Status Register */
  91723. + volatile uint32_t *hprt0;
  91724. +#define DWC_OTG_HOST_PORT_REGS_OFFSET 0x440
  91725. +
  91726. + /** Host Channel Specific Registers at offsets 500h-5FCh. */
  91727. + dwc_otg_hc_regs_t *hc_regs[MAX_EPS_CHANNELS];
  91728. +#define DWC_OTG_HOST_CHAN_REGS_OFFSET 0x500
  91729. +#define DWC_OTG_CHAN_REGS_OFFSET 0x20
  91730. +
  91731. + /* Host configuration information */
  91732. + /** Number of Host Channels (range: 1-16) */
  91733. + uint8_t num_host_channels;
  91734. + /** Periodic EPs supported (0: no, 1: yes) */
  91735. + uint8_t perio_eps_supported;
  91736. + /** Periodic Tx FIFO Size (Only 1 host periodic Tx FIFO) */
  91737. + uint16_t perio_tx_fifo_size;
  91738. +
  91739. +} dwc_otg_host_if_t;
  91740. +
  91741. +/**
  91742. + * This union represents the bit fields in the Power and Clock Gating Control
  91743. + * Register. Read the register into the <i>d32</i> member then set/clear the
  91744. + * bits using the <i>b</i>it elements.
  91745. + */
  91746. +typedef union pcgcctl_data {
  91747. + /** raw register data */
  91748. + uint32_t d32;
  91749. +
  91750. + /** register bits */
  91751. + struct {
  91752. + /** Stop Pclk */
  91753. + unsigned stoppclk:1;
  91754. + /** Gate Hclk */
  91755. + unsigned gatehclk:1;
  91756. + /** Power Clamp */
  91757. + unsigned pwrclmp:1;
  91758. + /** Reset Power Down Modules */
  91759. + unsigned rstpdwnmodule:1;
  91760. + /** Reserved */
  91761. + unsigned reserved:1;
  91762. + /** Enable Sleep Clock Gating (Enbl_L1Gating) */
  91763. + unsigned enbl_sleep_gating:1;
  91764. + /** PHY In Sleep (PhySleep) */
  91765. + unsigned phy_in_sleep:1;
  91766. + /** Deep Sleep*/
  91767. + unsigned deep_sleep:1;
  91768. + unsigned resetaftsusp:1;
  91769. + unsigned restoremode:1;
  91770. + unsigned enbl_extnd_hiber:1;
  91771. + unsigned extnd_hiber_pwrclmp:1;
  91772. + unsigned extnd_hiber_switch:1;
  91773. + unsigned ess_reg_restored:1;
  91774. + unsigned prt_clk_sel:2;
  91775. + unsigned port_power:1;
  91776. + unsigned max_xcvrselect:2;
  91777. + unsigned max_termsel:1;
  91778. + unsigned mac_dev_addr:7;
  91779. + unsigned p2hd_dev_enum_spd:2;
  91780. + unsigned p2hd_prt_spd:2;
  91781. + unsigned if_dev_mode:1;
  91782. + } b;
  91783. +} pcgcctl_data_t;
  91784. +
  91785. +/**
  91786. + * This union represents the bit fields in the Global Data FIFO Software
  91787. + * Configuration Register. Read the register into the <i>d32</i> member then
  91788. + * set/clear the bits using the <i>b</i>it elements.
  91789. + */
  91790. +typedef union gdfifocfg_data {
  91791. + /* raw register data */
  91792. + uint32_t d32;
  91793. + /** register bits */
  91794. + struct {
  91795. + /** OTG Data FIFO depth */
  91796. + unsigned gdfifocfg:16;
  91797. + /** Start address of EP info controller */
  91798. + unsigned epinfobase:16;
  91799. + } b;
  91800. +} gdfifocfg_data_t;
  91801. +
  91802. +/**
  91803. + * This union represents the bit fields in the Global Power Down Register
  91804. + * Register. Read the register into the <i>d32</i> member then set/clear the
  91805. + * bits using the <i>b</i>it elements.
  91806. + */
  91807. +typedef union gpwrdn_data {
  91808. + /* raw register data */
  91809. + uint32_t d32;
  91810. +
  91811. + /** register bits */
  91812. + struct {
  91813. + /** PMU Interrupt Select */
  91814. + unsigned pmuintsel:1;
  91815. + /** PMU Active */
  91816. + unsigned pmuactv:1;
  91817. + /** Restore */
  91818. + unsigned restore:1;
  91819. + /** Power Down Clamp */
  91820. + unsigned pwrdnclmp:1;
  91821. + /** Power Down Reset */
  91822. + unsigned pwrdnrstn:1;
  91823. + /** Power Down Switch */
  91824. + unsigned pwrdnswtch:1;
  91825. + /** Disable VBUS */
  91826. + unsigned dis_vbus:1;
  91827. + /** Line State Change */
  91828. + unsigned lnstschng:1;
  91829. + /** Line state change mask */
  91830. + unsigned lnstchng_msk:1;
  91831. + /** Reset Detected */
  91832. + unsigned rst_det:1;
  91833. + /** Reset Detect mask */
  91834. + unsigned rst_det_msk:1;
  91835. + /** Disconnect Detected */
  91836. + unsigned disconn_det:1;
  91837. + /** Disconnect Detect mask */
  91838. + unsigned disconn_det_msk:1;
  91839. + /** Connect Detected*/
  91840. + unsigned connect_det:1;
  91841. + /** Connect Detected Mask*/
  91842. + unsigned connect_det_msk:1;
  91843. + /** SRP Detected */
  91844. + unsigned srp_det:1;
  91845. + /** SRP Detect mask */
  91846. + unsigned srp_det_msk:1;
  91847. + /** Status Change Interrupt */
  91848. + unsigned sts_chngint:1;
  91849. + /** Status Change Interrupt Mask */
  91850. + unsigned sts_chngint_msk:1;
  91851. + /** Line State */
  91852. + unsigned linestate:2;
  91853. + /** Indicates current mode(status of IDDIG signal) */
  91854. + unsigned idsts:1;
  91855. + /** B Session Valid signal status*/
  91856. + unsigned bsessvld:1;
  91857. + /** ADP Event Detected */
  91858. + unsigned adp_int:1;
  91859. + /** Multi Valued ID pin */
  91860. + unsigned mult_val_id_bc:5;
  91861. + /** Reserved 24_31 */
  91862. + unsigned reserved29_31:3;
  91863. + } b;
  91864. +} gpwrdn_data_t;
  91865. +
  91866. +#endif
  91867. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/Makefile linux-3.12.11/drivers/usb/host/dwc_otg/Makefile
  91868. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/Makefile 1970-01-01 01:00:00.000000000 +0100
  91869. +++ linux-3.12.11/drivers/usb/host/dwc_otg/Makefile 2014-02-18 11:52:14.000000000 +0100
  91870. @@ -0,0 +1,81 @@
  91871. +#
  91872. +# Makefile for DWC_otg Highspeed USB controller driver
  91873. +#
  91874. +
  91875. +ifneq ($(KERNELRELEASE),)
  91876. +
  91877. +# Use the BUS_INTERFACE variable to compile the software for either
  91878. +# PCI(PCI_INTERFACE) or LM(LM_INTERFACE) bus.
  91879. +ifeq ($(BUS_INTERFACE),)
  91880. +# BUS_INTERFACE = -DPCI_INTERFACE
  91881. +# BUS_INTERFACE = -DLM_INTERFACE
  91882. + BUS_INTERFACE = -DPLATFORM_INTERFACE
  91883. +endif
  91884. +
  91885. +#EXTRA_CFLAGS += -DDEBUG
  91886. +#EXTRA_CFLAGS += -DDWC_OTG_DEBUGLEV=1 # reduce common debug msgs
  91887. +
  91888. +# Use one of the following flags to compile the software in host-only or
  91889. +# device-only mode.
  91890. +#EXTRA_CFLAGS += -DDWC_HOST_ONLY
  91891. +#EXTRA_CFLAGS += -DDWC_DEVICE_ONLY
  91892. +
  91893. +EXTRA_CFLAGS += -Dlinux -DDWC_HS_ELECT_TST
  91894. +#EXTRA_CFLAGS += -DDWC_EN_ISOC
  91895. +EXTRA_CFLAGS += -I$(obj)/../dwc_common_port
  91896. +#EXTRA_CFLAGS += -I$(PORTLIB)
  91897. +EXTRA_CFLAGS += -DDWC_LINUX
  91898. +EXTRA_CFLAGS += $(CFI)
  91899. +EXTRA_CFLAGS += $(BUS_INTERFACE)
  91900. +#EXTRA_CFLAGS += -DDWC_DEV_SRPCAP
  91901. +
  91902. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg.o
  91903. +
  91904. +dwc_otg-objs := dwc_otg_driver.o dwc_otg_attr.o
  91905. +dwc_otg-objs += dwc_otg_cil.o dwc_otg_cil_intr.o
  91906. +dwc_otg-objs += dwc_otg_pcd_linux.o dwc_otg_pcd.o dwc_otg_pcd_intr.o
  91907. +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
  91908. +dwc_otg-objs += dwc_otg_adp.o
  91909. +dwc_otg-objs += dwc_otg_mphi_fix.o
  91910. +ifneq ($(CFI),)
  91911. +dwc_otg-objs += dwc_otg_cfi.o
  91912. +endif
  91913. +
  91914. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  91915. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  91916. +
  91917. +ifneq ($(kernrel3),2.6.20)
  91918. +EXTRA_CFLAGS += $(CPPFLAGS)
  91919. +endif
  91920. +
  91921. +else
  91922. +
  91923. +PWD := $(shell pwd)
  91924. +PORTLIB := $(PWD)/../dwc_common_port
  91925. +
  91926. +# Command paths
  91927. +CTAGS := $(CTAGS)
  91928. +DOXYGEN := $(DOXYGEN)
  91929. +
  91930. +default: portlib
  91931. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  91932. +
  91933. +install: default
  91934. + $(MAKE) -C$(KDIR) M=$(PORTLIB) modules_install
  91935. + $(MAKE) -C$(KDIR) M=$(PWD) modules_install
  91936. +
  91937. +portlib:
  91938. + $(MAKE) -C$(KDIR) M=$(PORTLIB) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  91939. + cp $(PORTLIB)/Module.symvers $(PWD)/
  91940. +
  91941. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  91942. + $(DOXYGEN) doc/doxygen.cfg
  91943. +
  91944. +tags: $(wildcard *.[hc])
  91945. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  91946. +
  91947. +
  91948. +clean:
  91949. + rm -rf *.o *.ko .*cmd *.mod.c .tmp_versions Module.symvers
  91950. +
  91951. +endif
  91952. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm linux-3.12.11/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm
  91953. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 1970-01-01 01:00:00.000000000 +0100
  91954. +++ linux-3.12.11/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 2014-02-18 11:52:14.000000000 +0100
  91955. @@ -0,0 +1,337 @@
  91956. +package dwc_otg_test;
  91957. +
  91958. +use strict;
  91959. +use Exporter ();
  91960. +
  91961. +use vars qw(@ISA @EXPORT
  91962. +$sysfsdir $paramdir $errors $params
  91963. +);
  91964. +
  91965. +@ISA = qw(Exporter);
  91966. +
  91967. +#
  91968. +# Globals
  91969. +#
  91970. +$sysfsdir = "/sys/devices/lm0";
  91971. +$paramdir = "/sys/module/dwc_otg";
  91972. +$errors = 0;
  91973. +
  91974. +$params = [
  91975. + {
  91976. + NAME => "otg_cap",
  91977. + DEFAULT => 0,
  91978. + ENUM => [],
  91979. + LOW => 0,
  91980. + HIGH => 2
  91981. + },
  91982. + {
  91983. + NAME => "dma_enable",
  91984. + DEFAULT => 0,
  91985. + ENUM => [],
  91986. + LOW => 0,
  91987. + HIGH => 1
  91988. + },
  91989. + {
  91990. + NAME => "dma_burst_size",
  91991. + DEFAULT => 32,
  91992. + ENUM => [1, 4, 8, 16, 32, 64, 128, 256],
  91993. + LOW => 1,
  91994. + HIGH => 256
  91995. + },
  91996. + {
  91997. + NAME => "host_speed",
  91998. + DEFAULT => 0,
  91999. + ENUM => [],
  92000. + LOW => 0,
  92001. + HIGH => 1
  92002. + },
  92003. + {
  92004. + NAME => "host_support_fs_ls_low_power",
  92005. + DEFAULT => 0,
  92006. + ENUM => [],
  92007. + LOW => 0,
  92008. + HIGH => 1
  92009. + },
  92010. + {
  92011. + NAME => "host_ls_low_power_phy_clk",
  92012. + DEFAULT => 0,
  92013. + ENUM => [],
  92014. + LOW => 0,
  92015. + HIGH => 1
  92016. + },
  92017. + {
  92018. + NAME => "dev_speed",
  92019. + DEFAULT => 0,
  92020. + ENUM => [],
  92021. + LOW => 0,
  92022. + HIGH => 1
  92023. + },
  92024. + {
  92025. + NAME => "enable_dynamic_fifo",
  92026. + DEFAULT => 1,
  92027. + ENUM => [],
  92028. + LOW => 0,
  92029. + HIGH => 1
  92030. + },
  92031. + {
  92032. + NAME => "data_fifo_size",
  92033. + DEFAULT => 8192,
  92034. + ENUM => [],
  92035. + LOW => 32,
  92036. + HIGH => 32768
  92037. + },
  92038. + {
  92039. + NAME => "dev_rx_fifo_size",
  92040. + DEFAULT => 1064,
  92041. + ENUM => [],
  92042. + LOW => 16,
  92043. + HIGH => 32768
  92044. + },
  92045. + {
  92046. + NAME => "dev_nperio_tx_fifo_size",
  92047. + DEFAULT => 1024,
  92048. + ENUM => [],
  92049. + LOW => 16,
  92050. + HIGH => 32768
  92051. + },
  92052. + {
  92053. + NAME => "dev_perio_tx_fifo_size_1",
  92054. + DEFAULT => 256,
  92055. + ENUM => [],
  92056. + LOW => 4,
  92057. + HIGH => 768
  92058. + },
  92059. + {
  92060. + NAME => "dev_perio_tx_fifo_size_2",
  92061. + DEFAULT => 256,
  92062. + ENUM => [],
  92063. + LOW => 4,
  92064. + HIGH => 768
  92065. + },
  92066. + {
  92067. + NAME => "dev_perio_tx_fifo_size_3",
  92068. + DEFAULT => 256,
  92069. + ENUM => [],
  92070. + LOW => 4,
  92071. + HIGH => 768
  92072. + },
  92073. + {
  92074. + NAME => "dev_perio_tx_fifo_size_4",
  92075. + DEFAULT => 256,
  92076. + ENUM => [],
  92077. + LOW => 4,
  92078. + HIGH => 768
  92079. + },
  92080. + {
  92081. + NAME => "dev_perio_tx_fifo_size_5",
  92082. + DEFAULT => 256,
  92083. + ENUM => [],
  92084. + LOW => 4,
  92085. + HIGH => 768
  92086. + },
  92087. + {
  92088. + NAME => "dev_perio_tx_fifo_size_6",
  92089. + DEFAULT => 256,
  92090. + ENUM => [],
  92091. + LOW => 4,
  92092. + HIGH => 768
  92093. + },
  92094. + {
  92095. + NAME => "dev_perio_tx_fifo_size_7",
  92096. + DEFAULT => 256,
  92097. + ENUM => [],
  92098. + LOW => 4,
  92099. + HIGH => 768
  92100. + },
  92101. + {
  92102. + NAME => "dev_perio_tx_fifo_size_8",
  92103. + DEFAULT => 256,
  92104. + ENUM => [],
  92105. + LOW => 4,
  92106. + HIGH => 768
  92107. + },
  92108. + {
  92109. + NAME => "dev_perio_tx_fifo_size_9",
  92110. + DEFAULT => 256,
  92111. + ENUM => [],
  92112. + LOW => 4,
  92113. + HIGH => 768
  92114. + },
  92115. + {
  92116. + NAME => "dev_perio_tx_fifo_size_10",
  92117. + DEFAULT => 256,
  92118. + ENUM => [],
  92119. + LOW => 4,
  92120. + HIGH => 768
  92121. + },
  92122. + {
  92123. + NAME => "dev_perio_tx_fifo_size_11",
  92124. + DEFAULT => 256,
  92125. + ENUM => [],
  92126. + LOW => 4,
  92127. + HIGH => 768
  92128. + },
  92129. + {
  92130. + NAME => "dev_perio_tx_fifo_size_12",
  92131. + DEFAULT => 256,
  92132. + ENUM => [],
  92133. + LOW => 4,
  92134. + HIGH => 768
  92135. + },
  92136. + {
  92137. + NAME => "dev_perio_tx_fifo_size_13",
  92138. + DEFAULT => 256,
  92139. + ENUM => [],
  92140. + LOW => 4,
  92141. + HIGH => 768
  92142. + },
  92143. + {
  92144. + NAME => "dev_perio_tx_fifo_size_14",
  92145. + DEFAULT => 256,
  92146. + ENUM => [],
  92147. + LOW => 4,
  92148. + HIGH => 768
  92149. + },
  92150. + {
  92151. + NAME => "dev_perio_tx_fifo_size_15",
  92152. + DEFAULT => 256,
  92153. + ENUM => [],
  92154. + LOW => 4,
  92155. + HIGH => 768
  92156. + },
  92157. + {
  92158. + NAME => "host_rx_fifo_size",
  92159. + DEFAULT => 1024,
  92160. + ENUM => [],
  92161. + LOW => 16,
  92162. + HIGH => 32768
  92163. + },
  92164. + {
  92165. + NAME => "host_nperio_tx_fifo_size",
  92166. + DEFAULT => 1024,
  92167. + ENUM => [],
  92168. + LOW => 16,
  92169. + HIGH => 32768
  92170. + },
  92171. + {
  92172. + NAME => "host_perio_tx_fifo_size",
  92173. + DEFAULT => 1024,
  92174. + ENUM => [],
  92175. + LOW => 16,
  92176. + HIGH => 32768
  92177. + },
  92178. + {
  92179. + NAME => "max_transfer_size",
  92180. + DEFAULT => 65535,
  92181. + ENUM => [],
  92182. + LOW => 2047,
  92183. + HIGH => 65535
  92184. + },
  92185. + {
  92186. + NAME => "max_packet_count",
  92187. + DEFAULT => 511,
  92188. + ENUM => [],
  92189. + LOW => 15,
  92190. + HIGH => 511
  92191. + },
  92192. + {
  92193. + NAME => "host_channels",
  92194. + DEFAULT => 12,
  92195. + ENUM => [],
  92196. + LOW => 1,
  92197. + HIGH => 16
  92198. + },
  92199. + {
  92200. + NAME => "dev_endpoints",
  92201. + DEFAULT => 6,
  92202. + ENUM => [],
  92203. + LOW => 1,
  92204. + HIGH => 15
  92205. + },
  92206. + {
  92207. + NAME => "phy_type",
  92208. + DEFAULT => 1,
  92209. + ENUM => [],
  92210. + LOW => 0,
  92211. + HIGH => 2
  92212. + },
  92213. + {
  92214. + NAME => "phy_utmi_width",
  92215. + DEFAULT => 16,
  92216. + ENUM => [8, 16],
  92217. + LOW => 8,
  92218. + HIGH => 16
  92219. + },
  92220. + {
  92221. + NAME => "phy_ulpi_ddr",
  92222. + DEFAULT => 0,
  92223. + ENUM => [],
  92224. + LOW => 0,
  92225. + HIGH => 1
  92226. + },
  92227. + ];
  92228. +
  92229. +
  92230. +#
  92231. +#
  92232. +sub check_arch {
  92233. + $_ = `uname -m`;
  92234. + chomp;
  92235. + unless (m/armv4tl/) {
  92236. + warn "# \n# Can't execute on $_. Run on integrator platform.\n# \n";
  92237. + return 0;
  92238. + }
  92239. + return 1;
  92240. +}
  92241. +
  92242. +#
  92243. +#
  92244. +sub load_module {
  92245. + my $params = shift;
  92246. + print "\nRemoving Module\n";
  92247. + system "rmmod dwc_otg";
  92248. + print "Loading Module\n";
  92249. + if ($params ne "") {
  92250. + print "Module Parameters: $params\n";
  92251. + }
  92252. + if (system("modprobe dwc_otg $params")) {
  92253. + warn "Unable to load module\n";
  92254. + return 0;
  92255. + }
  92256. + return 1;
  92257. +}
  92258. +
  92259. +#
  92260. +#
  92261. +sub test_status {
  92262. + my $arg = shift;
  92263. +
  92264. + print "\n";
  92265. +
  92266. + if (defined $arg) {
  92267. + warn "WARNING: $arg\n";
  92268. + }
  92269. +
  92270. + if ($errors > 0) {
  92271. + warn "TEST FAILED with $errors errors\n";
  92272. + return 0;
  92273. + } else {
  92274. + print "TEST PASSED\n";
  92275. + return 0 if (defined $arg);
  92276. + }
  92277. + return 1;
  92278. +}
  92279. +
  92280. +#
  92281. +#
  92282. +@EXPORT = qw(
  92283. +$sysfsdir
  92284. +$paramdir
  92285. +$params
  92286. +$errors
  92287. +check_arch
  92288. +load_module
  92289. +test_status
  92290. +);
  92291. +
  92292. +1;
  92293. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/test/Makefile linux-3.12.11/drivers/usb/host/dwc_otg/test/Makefile
  92294. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/test/Makefile 1970-01-01 01:00:00.000000000 +0100
  92295. +++ linux-3.12.11/drivers/usb/host/dwc_otg/test/Makefile 2014-02-18 11:52:14.000000000 +0100
  92296. @@ -0,0 +1,16 @@
  92297. +
  92298. +PERL=/usr/bin/perl
  92299. +PL_TESTS=test_sysfs.pl test_mod_param.pl
  92300. +
  92301. +.PHONY : test
  92302. +test : perl_tests
  92303. +
  92304. +perl_tests :
  92305. + @echo
  92306. + @echo Running perl tests
  92307. + @for test in $(PL_TESTS); do \
  92308. + if $(PERL) ./$$test ; then \
  92309. + echo "=======> $$test, PASSED" ; \
  92310. + else echo "=======> $$test, FAILED" ; \
  92311. + fi \
  92312. + done
  92313. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/test/test_mod_param.pl linux-3.12.11/drivers/usb/host/dwc_otg/test/test_mod_param.pl
  92314. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/test/test_mod_param.pl 1970-01-01 01:00:00.000000000 +0100
  92315. +++ linux-3.12.11/drivers/usb/host/dwc_otg/test/test_mod_param.pl 2014-02-18 11:52:14.000000000 +0100
  92316. @@ -0,0 +1,133 @@
  92317. +#!/usr/bin/perl -w
  92318. +#
  92319. +# Run this program on the integrator.
  92320. +#
  92321. +# - Tests module parameter default values.
  92322. +# - Tests setting of valid module parameter values via modprobe.
  92323. +# - Tests invalid module parameter values.
  92324. +# -----------------------------------------------------------------------------
  92325. +use strict;
  92326. +use dwc_otg_test;
  92327. +
  92328. +check_arch() or die;
  92329. +
  92330. +#
  92331. +#
  92332. +sub test {
  92333. + my ($param,$expected) = @_;
  92334. + my $value = get($param);
  92335. +
  92336. + if ($value == $expected) {
  92337. + print "$param = $value, okay\n";
  92338. + }
  92339. +
  92340. + else {
  92341. + warn "ERROR: value of $param != $expected, $value\n";
  92342. + $errors ++;
  92343. + }
  92344. +}
  92345. +
  92346. +#
  92347. +#
  92348. +sub get {
  92349. + my $param = shift;
  92350. + my $tmp = `cat $paramdir/$param`;
  92351. + chomp $tmp;
  92352. + return $tmp;
  92353. +}
  92354. +
  92355. +#
  92356. +#
  92357. +sub test_main {
  92358. +
  92359. + print "\nTesting Module Parameters\n";
  92360. +
  92361. + load_module("") or die;
  92362. +
  92363. + # Test initial values
  92364. + print "\nTesting Default Values\n";
  92365. + foreach (@{$params}) {
  92366. + test ($_->{NAME}, $_->{DEFAULT});
  92367. + }
  92368. +
  92369. + # Test low value
  92370. + print "\nTesting Low Value\n";
  92371. + my $cmd_params = "";
  92372. + foreach (@{$params}) {
  92373. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{LOW} ";
  92374. + }
  92375. + load_module($cmd_params) or die;
  92376. +
  92377. + foreach (@{$params}) {
  92378. + test ($_->{NAME}, $_->{LOW});
  92379. + }
  92380. +
  92381. + # Test high value
  92382. + print "\nTesting High Value\n";
  92383. + $cmd_params = "";
  92384. + foreach (@{$params}) {
  92385. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{HIGH} ";
  92386. + }
  92387. + load_module($cmd_params) or die;
  92388. +
  92389. + foreach (@{$params}) {
  92390. + test ($_->{NAME}, $_->{HIGH});
  92391. + }
  92392. +
  92393. + # Test Enum
  92394. + print "\nTesting Enumerated\n";
  92395. + foreach (@{$params}) {
  92396. + if (defined $_->{ENUM}) {
  92397. + my $value;
  92398. + foreach $value (@{$_->{ENUM}}) {
  92399. + $cmd_params = "$_->{NAME}=$value";
  92400. + load_module($cmd_params) or die;
  92401. + test ($_->{NAME}, $value);
  92402. + }
  92403. + }
  92404. + }
  92405. +
  92406. + # Test Invalid Values
  92407. + print "\nTesting Invalid Values\n";
  92408. + $cmd_params = "";
  92409. + foreach (@{$params}) {
  92410. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{LOW}-1;
  92411. + }
  92412. + load_module($cmd_params) or die;
  92413. +
  92414. + foreach (@{$params}) {
  92415. + test ($_->{NAME}, $_->{DEFAULT});
  92416. + }
  92417. +
  92418. + $cmd_params = "";
  92419. + foreach (@{$params}) {
  92420. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{HIGH}+1;
  92421. + }
  92422. + load_module($cmd_params) or die;
  92423. +
  92424. + foreach (@{$params}) {
  92425. + test ($_->{NAME}, $_->{DEFAULT});
  92426. + }
  92427. +
  92428. + print "\nTesting Enumerated\n";
  92429. + foreach (@{$params}) {
  92430. + if (defined $_->{ENUM}) {
  92431. + my $value;
  92432. + foreach $value (@{$_->{ENUM}}) {
  92433. + $value = $value + 1;
  92434. + $cmd_params = "$_->{NAME}=$value";
  92435. + load_module($cmd_params) or die;
  92436. + test ($_->{NAME}, $_->{DEFAULT});
  92437. + $value = $value - 2;
  92438. + $cmd_params = "$_->{NAME}=$value";
  92439. + load_module($cmd_params) or die;
  92440. + test ($_->{NAME}, $_->{DEFAULT});
  92441. + }
  92442. + }
  92443. + }
  92444. +
  92445. + test_status() or die;
  92446. +}
  92447. +
  92448. +test_main();
  92449. +0;
  92450. diff -Nur linux-3.12.11.orig/drivers/usb/host/dwc_otg/test/test_sysfs.pl linux-3.12.11/drivers/usb/host/dwc_otg/test/test_sysfs.pl
  92451. --- linux-3.12.11.orig/drivers/usb/host/dwc_otg/test/test_sysfs.pl 1970-01-01 01:00:00.000000000 +0100
  92452. +++ linux-3.12.11/drivers/usb/host/dwc_otg/test/test_sysfs.pl 2014-02-18 11:52:14.000000000 +0100
  92453. @@ -0,0 +1,193 @@
  92454. +#!/usr/bin/perl -w
  92455. +#
  92456. +# Run this program on the integrator
  92457. +# - Tests select sysfs attributes.
  92458. +# - Todo ... test more attributes, hnp/srp, buspower/bussuspend, etc.
  92459. +# -----------------------------------------------------------------------------
  92460. +use strict;
  92461. +use dwc_otg_test;
  92462. +
  92463. +check_arch() or die;
  92464. +
  92465. +#
  92466. +#
  92467. +sub test {
  92468. + my ($attr,$expected) = @_;
  92469. + my $string = get($attr);
  92470. +
  92471. + if ($string eq $expected) {
  92472. + printf("$attr = $string, okay\n");
  92473. + }
  92474. + else {
  92475. + warn "ERROR: value of $attr != $expected, $string\n";
  92476. + $errors ++;
  92477. + }
  92478. +}
  92479. +
  92480. +#
  92481. +#
  92482. +sub set {
  92483. + my ($reg, $value) = @_;
  92484. + system "echo $value > $sysfsdir/$reg";
  92485. +}
  92486. +
  92487. +#
  92488. +#
  92489. +sub get {
  92490. + my $attr = shift;
  92491. + my $string = `cat $sysfsdir/$attr`;
  92492. + chomp $string;
  92493. + if ($string =~ m/\s\=\s/) {
  92494. + my $tmp;
  92495. + ($tmp, $string) = split /\s=\s/, $string;
  92496. + }
  92497. + return $string;
  92498. +}
  92499. +
  92500. +#
  92501. +#
  92502. +sub test_main {
  92503. + print("\nTesting Sysfs Attributes\n");
  92504. +
  92505. + load_module("") or die;
  92506. +
  92507. + # Test initial values of regoffset/regvalue/guid/gsnpsid
  92508. + print("\nTesting Default Values\n");
  92509. +
  92510. + test("regoffset", "0xffffffff");
  92511. + test("regvalue", "invalid offset");
  92512. + test("guid", "0x12345678"); # this will fail if it has been changed
  92513. + test("gsnpsid", "0x4f54200a");
  92514. +
  92515. + # Test operation of regoffset/regvalue
  92516. + print("\nTesting regoffset\n");
  92517. + set('regoffset', '5a5a5a5a');
  92518. + test("regoffset", "0xffffffff");
  92519. +
  92520. + set('regoffset', '0');
  92521. + test("regoffset", "0x00000000");
  92522. +
  92523. + set('regoffset', '40000');
  92524. + test("regoffset", "0x00000000");
  92525. +
  92526. + set('regoffset', '3ffff');
  92527. + test("regoffset", "0x0003ffff");
  92528. +
  92529. + set('regoffset', '1');
  92530. + test("regoffset", "0x00000001");
  92531. +
  92532. + print("\nTesting regvalue\n");
  92533. + set('regoffset', '3c');
  92534. + test("regvalue", "0x12345678");
  92535. + set('regvalue', '5a5a5a5a');
  92536. + test("regvalue", "0x5a5a5a5a");
  92537. + set('regvalue','a5a5a5a5');
  92538. + test("regvalue", "0xa5a5a5a5");
  92539. + set('guid','12345678');
  92540. +
  92541. + # Test HNP Capable
  92542. + print("\nTesting HNP Capable bit\n");
  92543. + set('hnpcapable', '1');
  92544. + test("hnpcapable", "0x1");
  92545. + set('hnpcapable','0');
  92546. + test("hnpcapable", "0x0");
  92547. +
  92548. + set('regoffset','0c');
  92549. +
  92550. + my $old = get('gusbcfg');
  92551. + print("setting hnpcapable\n");
  92552. + set('hnpcapable', '1');
  92553. + test("hnpcapable", "0x1");
  92554. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<9)));
  92555. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<9)));
  92556. +
  92557. + $old = get('gusbcfg');
  92558. + print("clearing hnpcapable\n");
  92559. + set('hnpcapable', '0');
  92560. + test("hnpcapable", "0x0");
  92561. + test ('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  92562. + test ('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  92563. +
  92564. + # Test SRP Capable
  92565. + print("\nTesting SRP Capable bit\n");
  92566. + set('srpcapable', '1');
  92567. + test("srpcapable", "0x1");
  92568. + set('srpcapable','0');
  92569. + test("srpcapable", "0x0");
  92570. +
  92571. + set('regoffset','0c');
  92572. +
  92573. + $old = get('gusbcfg');
  92574. + print("setting srpcapable\n");
  92575. + set('srpcapable', '1');
  92576. + test("srpcapable", "0x1");
  92577. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<8)));
  92578. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<8)));
  92579. +
  92580. + $old = get('gusbcfg');
  92581. + print("clearing srpcapable\n");
  92582. + set('srpcapable', '0');
  92583. + test("srpcapable", "0x0");
  92584. + test('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  92585. + test('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  92586. +
  92587. + # Test GGPIO
  92588. + print("\nTesting GGPIO\n");
  92589. + set('ggpio','5a5a5a5a');
  92590. + test('ggpio','0x5a5a0000');
  92591. + set('ggpio','a5a5a5a5');
  92592. + test('ggpio','0xa5a50000');
  92593. + set('ggpio','11110000');
  92594. + test('ggpio','0x11110000');
  92595. + set('ggpio','00001111');
  92596. + test('ggpio','0x00000000');
  92597. +
  92598. + # Test DEVSPEED
  92599. + print("\nTesting DEVSPEED\n");
  92600. + set('regoffset','800');
  92601. + $old = get('regvalue');
  92602. + set('devspeed','0');
  92603. + test('devspeed','0x0');
  92604. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  92605. + set('devspeed','1');
  92606. + test('devspeed','0x1');
  92607. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  92608. + set('devspeed','2');
  92609. + test('devspeed','0x2');
  92610. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 2));
  92611. + set('devspeed','3');
  92612. + test('devspeed','0x3');
  92613. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 3));
  92614. + set('devspeed','4');
  92615. + test('devspeed','0x0');
  92616. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  92617. + set('devspeed','5');
  92618. + test('devspeed','0x1');
  92619. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  92620. +
  92621. +
  92622. + # mode Returns the current mode:0 for device mode1 for host mode Read
  92623. + # hnp Initiate the Host Negotiation Protocol. Read returns the status. Read/Write
  92624. + # srp Initiate the Session Request Protocol. Read returns the status. Read/Write
  92625. + # buspower Get or Set the Power State of the bus (0 - Off or 1 - On) Read/Write
  92626. + # bussuspend Suspend the USB bus. Read/Write
  92627. + # busconnected Get the connection status of the bus Read
  92628. +
  92629. + # gotgctl Get or set the Core Control Status Register. Read/Write
  92630. + ## gusbcfg Get or set the Core USB Configuration Register Read/Write
  92631. + # grxfsiz Get or set the Receive FIFO Size Register Read/Write
  92632. + # gnptxfsiz Get or set the non-periodic Transmit Size Register Read/Write
  92633. + # gpvndctl Get or set the PHY Vendor Control Register Read/Write
  92634. + ## ggpio Get the value in the lower 16-bits of the General Purpose IO Register or Set the upper 16 bits. Read/Write
  92635. + ## guid Get or set the value of the User ID Register Read/Write
  92636. + ## gsnpsid Get the value of the Synopsys ID Regester Read
  92637. + ## devspeed Get or set the device speed setting in the DCFG register Read/Write
  92638. + # enumspeed Gets the device enumeration Speed. Read
  92639. + # hptxfsiz Get the value of the Host Periodic Transmit FIFO Read
  92640. + # hprt0 Get or Set the value in the Host Port Control and Status Register Read/Write
  92641. +
  92642. + test_status("TEST NYI") or die;
  92643. +}
  92644. +
  92645. +test_main();
  92646. +0;
  92647. diff -Nur linux-3.12.11.orig/drivers/usb/host/Kconfig linux-3.12.11/drivers/usb/host/Kconfig
  92648. --- linux-3.12.11.orig/drivers/usb/host/Kconfig 2014-02-13 22:51:06.000000000 +0100
  92649. +++ linux-3.12.11/drivers/usb/host/Kconfig 2014-02-18 11:52:14.000000000 +0100
  92650. @@ -650,6 +650,19 @@
  92651. To compile this driver a module, choose M here: the module
  92652. will be called "hwa-hc".
  92653. +config USB_DWCOTG
  92654. + tristate "Synopsis DWC host support"
  92655. + depends on USB
  92656. + help
  92657. + The Synopsis DWC controller is a dual-role
  92658. + host/peripheral/OTG ("On The Go") USB controllers.
  92659. +
  92660. + Enable this option to support this IP in host controller mode.
  92661. + If unsure, say N.
  92662. +
  92663. + To compile this driver as a module, choose M here: the
  92664. + modules built will be called dwc_otg and dwc_common_port.
  92665. +
  92666. config USB_IMX21_HCD
  92667. tristate "i.MX21 HCD support"
  92668. depends on ARM && ARCH_MXC
  92669. diff -Nur linux-3.12.11.orig/drivers/usb/host/Makefile linux-3.12.11/drivers/usb/host/Makefile
  92670. --- linux-3.12.11.orig/drivers/usb/host/Makefile 2014-02-13 22:51:06.000000000 +0100
  92671. +++ linux-3.12.11/drivers/usb/host/Makefile 2014-02-18 11:52:14.000000000 +0100
  92672. @@ -56,6 +56,8 @@
  92673. obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o
  92674. obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o
  92675. obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o
  92676. +
  92677. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg/ dwc_common_port/
  92678. obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o
  92679. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o
  92680. obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o
  92681. diff -Nur linux-3.12.11.orig/drivers/usb/Makefile linux-3.12.11/drivers/usb/Makefile
  92682. --- linux-3.12.11.orig/drivers/usb/Makefile 2014-02-13 22:51:06.000000000 +0100
  92683. +++ linux-3.12.11/drivers/usb/Makefile 2014-02-18 11:52:14.000000000 +0100
  92684. @@ -23,6 +23,7 @@
  92685. obj-$(CONFIG_USB_R8A66597_HCD) += host/
  92686. obj-$(CONFIG_USB_HWA_HCD) += host/
  92687. obj-$(CONFIG_USB_ISP1760_HCD) += host/
  92688. +obj-$(CONFIG_USB_DWCOTG) += host/
  92689. obj-$(CONFIG_USB_IMX21_HCD) += host/
  92690. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += host/
  92691. obj-$(CONFIG_USB_FUSBH200_HCD) += host/
  92692. diff -Nur linux-3.12.11.orig/drivers/video/bcm2708_fb.c linux-3.12.11/drivers/video/bcm2708_fb.c
  92693. --- linux-3.12.11.orig/drivers/video/bcm2708_fb.c 1970-01-01 01:00:00.000000000 +0100
  92694. +++ linux-3.12.11/drivers/video/bcm2708_fb.c 2014-02-18 11:52:14.000000000 +0100
  92695. @@ -0,0 +1,647 @@
  92696. +/*
  92697. + * linux/drivers/video/bcm2708_fb.c
  92698. + *
  92699. + * Copyright (C) 2010 Broadcom
  92700. + *
  92701. + * This file is subject to the terms and conditions of the GNU General Public
  92702. + * License. See the file COPYING in the main directory of this archive
  92703. + * for more details.
  92704. + *
  92705. + * Broadcom simple framebuffer driver
  92706. + *
  92707. + * This file is derived from cirrusfb.c
  92708. + * Copyright 1999-2001 Jeff Garzik <jgarzik@pobox.com>
  92709. + *
  92710. + */
  92711. +#include <linux/module.h>
  92712. +#include <linux/kernel.h>
  92713. +#include <linux/errno.h>
  92714. +#include <linux/string.h>
  92715. +#include <linux/slab.h>
  92716. +#include <linux/mm.h>
  92717. +#include <linux/fb.h>
  92718. +#include <linux/init.h>
  92719. +#include <linux/ioport.h>
  92720. +#include <linux/list.h>
  92721. +#include <linux/platform_device.h>
  92722. +#include <linux/clk.h>
  92723. +#include <linux/printk.h>
  92724. +#include <linux/console.h>
  92725. +
  92726. +#include <mach/dma.h>
  92727. +#include <mach/platform.h>
  92728. +#include <mach/vcio.h>
  92729. +
  92730. +#include <asm/sizes.h>
  92731. +#include <linux/io.h>
  92732. +#include <linux/dma-mapping.h>
  92733. +
  92734. +#ifdef BCM2708_FB_DEBUG
  92735. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  92736. +#else
  92737. +#define print_debug(fmt,...)
  92738. +#endif
  92739. +
  92740. +/* This is limited to 16 characters when displayed by X startup */
  92741. +static const char *bcm2708_name = "BCM2708 FB";
  92742. +
  92743. +#define DRIVER_NAME "bcm2708_fb"
  92744. +
  92745. +/* this data structure describes each frame buffer device we find */
  92746. +
  92747. +struct fbinfo_s {
  92748. + u32 xres, yres, xres_virtual, yres_virtual;
  92749. + u32 pitch, bpp;
  92750. + u32 xoffset, yoffset;
  92751. + u32 base;
  92752. + u32 screen_size;
  92753. + u16 cmap[256];
  92754. +};
  92755. +
  92756. +struct bcm2708_fb {
  92757. + struct fb_info fb;
  92758. + struct platform_device *dev;
  92759. + struct fbinfo_s *info;
  92760. + dma_addr_t dma;
  92761. + u32 cmap[16];
  92762. + int dma_chan;
  92763. + int dma_irq;
  92764. + void __iomem *dma_chan_base;
  92765. + void *cb_base; /* DMA control blocks */
  92766. + dma_addr_t cb_handle;
  92767. +};
  92768. +
  92769. +#define to_bcm2708(info) container_of(info, struct bcm2708_fb, fb)
  92770. +
  92771. +static int bcm2708_fb_set_bitfields(struct fb_var_screeninfo *var)
  92772. +{
  92773. + int ret = 0;
  92774. +
  92775. + memset(&var->transp, 0, sizeof(var->transp));
  92776. +
  92777. + var->red.msb_right = 0;
  92778. + var->green.msb_right = 0;
  92779. + var->blue.msb_right = 0;
  92780. +
  92781. + switch (var->bits_per_pixel) {
  92782. + case 1:
  92783. + case 2:
  92784. + case 4:
  92785. + case 8:
  92786. + var->red.length = var->bits_per_pixel;
  92787. + var->red.offset = 0;
  92788. + var->green.length = var->bits_per_pixel;
  92789. + var->green.offset = 0;
  92790. + var->blue.length = var->bits_per_pixel;
  92791. + var->blue.offset = 0;
  92792. + break;
  92793. + case 16:
  92794. + var->red.length = 5;
  92795. + var->blue.length = 5;
  92796. + /*
  92797. + * Green length can be 5 or 6 depending whether
  92798. + * we're operating in RGB555 or RGB565 mode.
  92799. + */
  92800. + if (var->green.length != 5 && var->green.length != 6)
  92801. + var->green.length = 6;
  92802. + break;
  92803. + case 24:
  92804. + var->red.length = 8;
  92805. + var->blue.length = 8;
  92806. + var->green.length = 8;
  92807. + break;
  92808. + case 32:
  92809. + var->red.length = 8;
  92810. + var->green.length = 8;
  92811. + var->blue.length = 8;
  92812. + var->transp.length = 8;
  92813. + break;
  92814. + default:
  92815. + ret = -EINVAL;
  92816. + break;
  92817. + }
  92818. +
  92819. + /*
  92820. + * >= 16bpp displays have separate colour component bitfields
  92821. + * encoded in the pixel data. Calculate their position from
  92822. + * the bitfield length defined above.
  92823. + */
  92824. + if (ret == 0 && var->bits_per_pixel >= 24) {
  92825. + var->red.offset = 0;
  92826. + var->green.offset = var->red.offset + var->red.length;
  92827. + var->blue.offset = var->green.offset + var->green.length;
  92828. + var->transp.offset = var->blue.offset + var->blue.length;
  92829. + } else if (ret == 0 && var->bits_per_pixel >= 16) {
  92830. + var->blue.offset = 0;
  92831. + var->green.offset = var->blue.offset + var->blue.length;
  92832. + var->red.offset = var->green.offset + var->green.length;
  92833. + var->transp.offset = var->red.offset + var->red.length;
  92834. + }
  92835. +
  92836. + return ret;
  92837. +}
  92838. +
  92839. +static int bcm2708_fb_check_var(struct fb_var_screeninfo *var,
  92840. + struct fb_info *info)
  92841. +{
  92842. + /* info input, var output */
  92843. + int yres;
  92844. +
  92845. + /* info input, var output */
  92846. + print_debug("bcm2708_fb_check_var info(%p) %dx%d (%dx%d), %d, %d\n", info,
  92847. + info->var.xres, info->var.yres, info->var.xres_virtual,
  92848. + info->var.yres_virtual, (int)info->screen_size,
  92849. + info->var.bits_per_pixel);
  92850. + print_debug("bcm2708_fb_check_var var(%p) %dx%d (%dx%d), %d\n", var,
  92851. + var->xres, var->yres, var->xres_virtual, var->yres_virtual,
  92852. + var->bits_per_pixel);
  92853. +
  92854. + if (!var->bits_per_pixel)
  92855. + var->bits_per_pixel = 16;
  92856. +
  92857. + if (bcm2708_fb_set_bitfields(var) != 0) {
  92858. + pr_err("bcm2708_fb_check_var: invalid bits_per_pixel %d\n",
  92859. + var->bits_per_pixel);
  92860. + return -EINVAL;
  92861. + }
  92862. +
  92863. +
  92864. + if (var->xres_virtual < var->xres)
  92865. + var->xres_virtual = var->xres;
  92866. + /* use highest possible virtual resolution */
  92867. + if (var->yres_virtual == -1) {
  92868. + var->yres_virtual = 480;
  92869. +
  92870. + pr_err
  92871. + ("bcm2708_fb_check_var: virtual resolution set to maximum of %dx%d\n",
  92872. + var->xres_virtual, var->yres_virtual);
  92873. + }
  92874. + if (var->yres_virtual < var->yres)
  92875. + var->yres_virtual = var->yres;
  92876. +
  92877. + if (var->xoffset < 0)
  92878. + var->xoffset = 0;
  92879. + if (var->yoffset < 0)
  92880. + var->yoffset = 0;
  92881. +
  92882. + /* truncate xoffset and yoffset to maximum if too high */
  92883. + if (var->xoffset > var->xres_virtual - var->xres)
  92884. + var->xoffset = var->xres_virtual - var->xres - 1;
  92885. + if (var->yoffset > var->yres_virtual - var->yres)
  92886. + var->yoffset = var->yres_virtual - var->yres - 1;
  92887. +
  92888. + yres = var->yres;
  92889. + if (var->vmode & FB_VMODE_DOUBLE)
  92890. + yres *= 2;
  92891. + else if (var->vmode & FB_VMODE_INTERLACED)
  92892. + yres = (yres + 1) / 2;
  92893. +
  92894. + if (yres > 1200) {
  92895. + pr_err("bcm2708_fb_check_var: ERROR: VerticalTotal >= 1200; "
  92896. + "special treatment required! (TODO)\n");
  92897. + return -EINVAL;
  92898. + }
  92899. +
  92900. + return 0;
  92901. +}
  92902. +
  92903. +static int bcm2708_fb_set_par(struct fb_info *info)
  92904. +{
  92905. + uint32_t val = 0;
  92906. + struct bcm2708_fb *fb = to_bcm2708(info);
  92907. + volatile struct fbinfo_s *fbinfo = fb->info;
  92908. + fbinfo->xres = info->var.xres;
  92909. + fbinfo->yres = info->var.yres;
  92910. + fbinfo->xres_virtual = info->var.xres_virtual;
  92911. + fbinfo->yres_virtual = info->var.yres_virtual;
  92912. + fbinfo->bpp = info->var.bits_per_pixel;
  92913. + fbinfo->xoffset = info->var.xoffset;
  92914. + fbinfo->yoffset = info->var.yoffset;
  92915. + fbinfo->base = 0; /* filled in by VC */
  92916. + fbinfo->pitch = 0; /* filled in by VC */
  92917. +
  92918. + print_debug("bcm2708_fb_set_par info(%p) %dx%d (%dx%d), %d, %d\n", info,
  92919. + info->var.xres, info->var.yres, info->var.xres_virtual,
  92920. + info->var.yres_virtual, (int)info->screen_size,
  92921. + info->var.bits_per_pixel);
  92922. +
  92923. + /* ensure last write to fbinfo is visible to GPU */
  92924. + wmb();
  92925. +
  92926. + /* inform vc about new framebuffer */
  92927. + bcm_mailbox_write(MBOX_CHAN_FB, fb->dma);
  92928. +
  92929. + /* TODO: replace fb driver with vchiq version */
  92930. + /* wait for response */
  92931. + bcm_mailbox_read(MBOX_CHAN_FB, &val);
  92932. +
  92933. + /* ensure GPU writes are visible to us */
  92934. + rmb();
  92935. +
  92936. + if (val == 0) {
  92937. + fb->fb.fix.line_length = fbinfo->pitch;
  92938. +
  92939. + if (info->var.bits_per_pixel <= 8)
  92940. + fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  92941. + else
  92942. + fb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  92943. +
  92944. + fb->fb.fix.smem_start = fbinfo->base;
  92945. + fb->fb.fix.smem_len = fbinfo->pitch * fbinfo->yres_virtual;
  92946. + fb->fb.screen_size = fbinfo->screen_size;
  92947. + if (fb->fb.screen_base)
  92948. + iounmap(fb->fb.screen_base);
  92949. + fb->fb.screen_base =
  92950. + (void *)ioremap_wc(fb->fb.fix.smem_start, fb->fb.screen_size);
  92951. + if (!fb->fb.screen_base) {
  92952. + /* the console may currently be locked */
  92953. + console_trylock();
  92954. + console_unlock();
  92955. +
  92956. + BUG(); /* what can we do here */
  92957. + }
  92958. + }
  92959. + print_debug
  92960. + ("BCM2708FB: start = %p,%p width=%d, height=%d, bpp=%d, pitch=%d size=%d success=%d\n",
  92961. + (void *)fb->fb.screen_base, (void *)fb->fb.fix.smem_start,
  92962. + fbinfo->xres, fbinfo->yres, fbinfo->bpp,
  92963. + fbinfo->pitch, (int)fb->fb.screen_size, val);
  92964. +
  92965. + return val;
  92966. +}
  92967. +
  92968. +static inline u32 convert_bitfield(int val, struct fb_bitfield *bf)
  92969. +{
  92970. + unsigned int mask = (1 << bf->length) - 1;
  92971. +
  92972. + return (val >> (16 - bf->length) & mask) << bf->offset;
  92973. +}
  92974. +
  92975. +
  92976. +static int bcm2708_fb_setcolreg(unsigned int regno, unsigned int red,
  92977. + unsigned int green, unsigned int blue,
  92978. + unsigned int transp, struct fb_info *info)
  92979. +{
  92980. + struct bcm2708_fb *fb = to_bcm2708(info);
  92981. +
  92982. + /*print_debug("BCM2708FB: setcolreg %d:(%02x,%02x,%02x,%02x) %x\n", regno, red, green, blue, transp, fb->fb.fix.visual);*/
  92983. + if (fb->fb.var.bits_per_pixel <= 8) {
  92984. + if (regno < 256) {
  92985. + /* blue [0:4], green [5:10], red [11:15] */
  92986. + fb->info->cmap[regno] = ((red >> (16-5)) & 0x1f) << 11 |
  92987. + ((green >> (16-6)) & 0x3f) << 5 |
  92988. + ((blue >> (16-5)) & 0x1f) << 0;
  92989. + }
  92990. + /* 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 */
  92991. + /* So just call it for what looks like the last colour in a list for now. */
  92992. + if (regno == 15 || regno == 255)
  92993. + bcm2708_fb_set_par(info);
  92994. + } else if (regno < 16) {
  92995. + fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) |
  92996. + convert_bitfield(blue, &fb->fb.var.blue) |
  92997. + convert_bitfield(green, &fb->fb.var.green) |
  92998. + convert_bitfield(red, &fb->fb.var.red);
  92999. + }
  93000. + return regno > 255;
  93001. +}
  93002. +
  93003. +static int bcm2708_fb_blank(int blank_mode, struct fb_info *info)
  93004. +{
  93005. + /*print_debug("bcm2708_fb_blank\n"); */
  93006. + return -1;
  93007. +}
  93008. +
  93009. +static void bcm2708_fb_fillrect(struct fb_info *info,
  93010. + const struct fb_fillrect *rect)
  93011. +{
  93012. + /* (is called) print_debug("bcm2708_fb_fillrect\n"); */
  93013. + cfb_fillrect(info, rect);
  93014. +}
  93015. +
  93016. +/* A helper function for configuring dma control block */
  93017. +static void set_dma_cb(struct bcm2708_dma_cb *cb,
  93018. + int burst_size,
  93019. + dma_addr_t dst,
  93020. + int dst_stride,
  93021. + dma_addr_t src,
  93022. + int src_stride,
  93023. + int w,
  93024. + int h)
  93025. +{
  93026. + cb->info = BCM2708_DMA_BURST(burst_size) | BCM2708_DMA_S_WIDTH |
  93027. + BCM2708_DMA_S_INC | BCM2708_DMA_D_WIDTH |
  93028. + BCM2708_DMA_D_INC | BCM2708_DMA_TDMODE;
  93029. + cb->dst = dst;
  93030. + cb->src = src;
  93031. + /*
  93032. + * This is not really obvious from the DMA documentation,
  93033. + * but the top 16 bits must be programmmed to "height -1"
  93034. + * and not "height" in 2D mode.
  93035. + */
  93036. + cb->length = ((h - 1) << 16) | w;
  93037. + cb->stride = ((dst_stride - w) << 16) | (u16)(src_stride - w);
  93038. + cb->pad[0] = 0;
  93039. + cb->pad[1] = 0;
  93040. +}
  93041. +
  93042. +static void bcm2708_fb_copyarea(struct fb_info *info,
  93043. + const struct fb_copyarea *region)
  93044. +{
  93045. + struct bcm2708_fb *fb = to_bcm2708(info);
  93046. + struct bcm2708_dma_cb *cb = fb->cb_base;
  93047. + int bytes_per_pixel = (info->var.bits_per_pixel + 7) >> 3;
  93048. + /* Channel 0 supports larger bursts and is a bit faster */
  93049. + int burst_size = (fb->dma_chan == 0) ? 8 : 2;
  93050. +
  93051. + /* Fallback to cfb_copyarea() if we don't like something */
  93052. + if (bytes_per_pixel > 4 ||
  93053. + info->var.xres > 1920 || info->var.yres > 1200 ||
  93054. + region->width <= 0 || region->width > info->var.xres ||
  93055. + region->height <= 0 || region->height > info->var.yres ||
  93056. + region->sx < 0 || region->sx >= info->var.xres ||
  93057. + region->sy < 0 || region->sy >= info->var.yres ||
  93058. + region->dx < 0 || region->dx >= info->var.xres ||
  93059. + region->dy < 0 || region->dy >= info->var.yres ||
  93060. + region->sx + region->width > info->var.xres ||
  93061. + region->dx + region->width > info->var.xres ||
  93062. + region->sy + region->height > info->var.yres ||
  93063. + region->dy + region->height > info->var.yres) {
  93064. + cfb_copyarea(info, region);
  93065. + return;
  93066. + }
  93067. +
  93068. + if (region->dy == region->sy && region->dx > region->sx) {
  93069. + /*
  93070. + * A difficult case of overlapped copy. Because DMA can't
  93071. + * copy individual scanlines in backwards direction, we need
  93072. + * two-pass processing. We do it by programming a chain of dma
  93073. + * control blocks in the first 16K part of the buffer and use
  93074. + * the remaining 48K as the intermediate temporary scratch
  93075. + * buffer. The buffer size is sufficient to handle up to
  93076. + * 1920x1200 resolution at 32bpp pixel depth.
  93077. + */
  93078. + int y;
  93079. + dma_addr_t control_block_pa = fb->cb_handle;
  93080. + dma_addr_t scratchbuf = fb->cb_handle + 16 * 1024;
  93081. + int scanline_size = bytes_per_pixel * region->width;
  93082. + int scanlines_per_cb = (64 * 1024 - 16 * 1024) / scanline_size;
  93083. +
  93084. + for (y = 0; y < region->height; y += scanlines_per_cb) {
  93085. + dma_addr_t src =
  93086. + fb->fb.fix.smem_start +
  93087. + bytes_per_pixel * region->sx +
  93088. + (region->sy + y) * fb->fb.fix.line_length;
  93089. + dma_addr_t dst =
  93090. + fb->fb.fix.smem_start +
  93091. + bytes_per_pixel * region->dx +
  93092. + (region->dy + y) * fb->fb.fix.line_length;
  93093. +
  93094. + if (region->height - y < scanlines_per_cb)
  93095. + scanlines_per_cb = region->height - y;
  93096. +
  93097. + set_dma_cb(cb, burst_size, scratchbuf, scanline_size,
  93098. + src, fb->fb.fix.line_length,
  93099. + scanline_size, scanlines_per_cb);
  93100. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  93101. + cb->next = control_block_pa;
  93102. + cb++;
  93103. +
  93104. + set_dma_cb(cb, burst_size, dst, fb->fb.fix.line_length,
  93105. + scratchbuf, scanline_size,
  93106. + scanline_size, scanlines_per_cb);
  93107. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  93108. + cb->next = control_block_pa;
  93109. + cb++;
  93110. + }
  93111. + /* move the pointer back to the last dma control block */
  93112. + cb--;
  93113. + } else {
  93114. + /* A single dma control block is enough. */
  93115. + int sy, dy, stride;
  93116. + if (region->dy <= region->sy) {
  93117. + /* processing from top to bottom */
  93118. + dy = region->dy;
  93119. + sy = region->sy;
  93120. + stride = fb->fb.fix.line_length;
  93121. + } else {
  93122. + /* processing from bottom to top */
  93123. + dy = region->dy + region->height - 1;
  93124. + sy = region->sy + region->height - 1;
  93125. + stride = -fb->fb.fix.line_length;
  93126. + }
  93127. + set_dma_cb(cb, burst_size,
  93128. + fb->fb.fix.smem_start + dy * fb->fb.fix.line_length +
  93129. + bytes_per_pixel * region->dx,
  93130. + stride,
  93131. + fb->fb.fix.smem_start + sy * fb->fb.fix.line_length +
  93132. + bytes_per_pixel * region->sx,
  93133. + stride,
  93134. + region->width * bytes_per_pixel,
  93135. + region->height);
  93136. + }
  93137. +
  93138. + /* end of dma control blocks chain */
  93139. + cb->next = 0;
  93140. +
  93141. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  93142. + bcm_dma_wait_idle(fb->dma_chan_base);
  93143. +}
  93144. +
  93145. +static void bcm2708_fb_imageblit(struct fb_info *info,
  93146. + const struct fb_image *image)
  93147. +{
  93148. + /* (is called) print_debug("bcm2708_fb_imageblit\n"); */
  93149. + cfb_imageblit(info, image);
  93150. +}
  93151. +
  93152. +static struct fb_ops bcm2708_fb_ops = {
  93153. + .owner = THIS_MODULE,
  93154. + .fb_check_var = bcm2708_fb_check_var,
  93155. + .fb_set_par = bcm2708_fb_set_par,
  93156. + .fb_setcolreg = bcm2708_fb_setcolreg,
  93157. + .fb_blank = bcm2708_fb_blank,
  93158. + .fb_fillrect = bcm2708_fb_fillrect,
  93159. + .fb_copyarea = bcm2708_fb_copyarea,
  93160. + .fb_imageblit = bcm2708_fb_imageblit,
  93161. +};
  93162. +
  93163. +static int fbwidth = 800; /* module parameter */
  93164. +static int fbheight = 480; /* module parameter */
  93165. +static int fbdepth = 16; /* module parameter */
  93166. +
  93167. +static int bcm2708_fb_register(struct bcm2708_fb *fb)
  93168. +{
  93169. + int ret;
  93170. + dma_addr_t dma;
  93171. + void *mem;
  93172. +
  93173. + mem =
  93174. + dma_alloc_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), &dma,
  93175. + GFP_KERNEL);
  93176. +
  93177. + if (NULL == mem) {
  93178. + pr_err(": unable to allocate fbinfo buffer\n");
  93179. + ret = -ENOMEM;
  93180. + } else {
  93181. + fb->info = (struct fbinfo_s *)mem;
  93182. + fb->dma = dma;
  93183. + }
  93184. + fb->fb.fbops = &bcm2708_fb_ops;
  93185. + fb->fb.flags = FBINFO_FLAG_DEFAULT | FBINFO_HWACCEL_COPYAREA;
  93186. + fb->fb.pseudo_palette = fb->cmap;
  93187. +
  93188. + strncpy(fb->fb.fix.id, bcm2708_name, sizeof(fb->fb.fix.id));
  93189. + fb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  93190. + fb->fb.fix.type_aux = 0;
  93191. + fb->fb.fix.xpanstep = 0;
  93192. + fb->fb.fix.ypanstep = 0;
  93193. + fb->fb.fix.ywrapstep = 0;
  93194. + fb->fb.fix.accel = FB_ACCEL_NONE;
  93195. +
  93196. + fb->fb.var.xres = fbwidth;
  93197. + fb->fb.var.yres = fbheight;
  93198. + fb->fb.var.xres_virtual = fbwidth;
  93199. + fb->fb.var.yres_virtual = fbheight;
  93200. + fb->fb.var.bits_per_pixel = fbdepth;
  93201. + fb->fb.var.vmode = FB_VMODE_NONINTERLACED;
  93202. + fb->fb.var.activate = FB_ACTIVATE_NOW;
  93203. + fb->fb.var.nonstd = 0;
  93204. + fb->fb.var.height = -1; /* height of picture in mm */
  93205. + fb->fb.var.width = -1; /* width of picture in mm */
  93206. + fb->fb.var.accel_flags = 0;
  93207. +
  93208. + fb->fb.monspecs.hfmin = 0;
  93209. + fb->fb.monspecs.hfmax = 100000;
  93210. + fb->fb.monspecs.vfmin = 0;
  93211. + fb->fb.monspecs.vfmax = 400;
  93212. + fb->fb.monspecs.dclkmin = 1000000;
  93213. + fb->fb.monspecs.dclkmax = 100000000;
  93214. +
  93215. + bcm2708_fb_set_bitfields(&fb->fb.var);
  93216. +
  93217. + /*
  93218. + * Allocate colourmap.
  93219. + */
  93220. +
  93221. + fb_set_var(&fb->fb, &fb->fb.var);
  93222. +
  93223. + print_debug("BCM2708FB: registering framebuffer (%dx%d@%d)\n", fbwidth,
  93224. + fbheight, fbdepth);
  93225. +
  93226. + ret = register_framebuffer(&fb->fb);
  93227. + print_debug("BCM2708FB: register framebuffer (%d)\n", ret);
  93228. + if (ret == 0)
  93229. + goto out;
  93230. +
  93231. + print_debug("BCM2708FB: cannot register framebuffer (%d)\n", ret);
  93232. +out:
  93233. + return ret;
  93234. +}
  93235. +
  93236. +static int bcm2708_fb_probe(struct platform_device *dev)
  93237. +{
  93238. + struct bcm2708_fb *fb;
  93239. + int ret;
  93240. +
  93241. + fb = kmalloc(sizeof(struct bcm2708_fb), GFP_KERNEL);
  93242. + if (!fb) {
  93243. + dev_err(&dev->dev,
  93244. + "could not allocate new bcm2708_fb struct\n");
  93245. + ret = -ENOMEM;
  93246. + goto free_region;
  93247. + }
  93248. + memset(fb, 0, sizeof(struct bcm2708_fb));
  93249. +
  93250. + fb->cb_base = dma_alloc_writecombine(&dev->dev, SZ_64K,
  93251. + &fb->cb_handle, GFP_KERNEL);
  93252. + if (!fb->cb_base) {
  93253. + dev_err(&dev->dev, "cannot allocate DMA CBs\n");
  93254. + ret = -ENOMEM;
  93255. + goto free_fb;
  93256. + }
  93257. +
  93258. + pr_info("BCM2708FB: allocated DMA memory %08x\n",
  93259. + fb->cb_handle);
  93260. +
  93261. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_BULK,
  93262. + &fb->dma_chan_base, &fb->dma_irq);
  93263. + if (ret < 0) {
  93264. + dev_err(&dev->dev, "couldn't allocate a DMA channel\n");
  93265. + goto free_cb;
  93266. + }
  93267. + fb->dma_chan = ret;
  93268. +
  93269. + pr_info("BCM2708FB: allocated DMA channel %d @ %p\n",
  93270. + fb->dma_chan, fb->dma_chan_base);
  93271. +
  93272. + fb->dev = dev;
  93273. +
  93274. + ret = bcm2708_fb_register(fb);
  93275. + if (ret == 0) {
  93276. + platform_set_drvdata(dev, fb);
  93277. + goto out;
  93278. + }
  93279. +
  93280. +free_cb:
  93281. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  93282. +free_fb:
  93283. + kfree(fb);
  93284. +free_region:
  93285. + dev_err(&dev->dev, "probe failed, err %d\n", ret);
  93286. +out:
  93287. + return ret;
  93288. +}
  93289. +
  93290. +static int bcm2708_fb_remove(struct platform_device *dev)
  93291. +{
  93292. + struct bcm2708_fb *fb = platform_get_drvdata(dev);
  93293. +
  93294. + platform_set_drvdata(dev, NULL);
  93295. +
  93296. + if (fb->fb.screen_base)
  93297. + iounmap(fb->fb.screen_base);
  93298. + unregister_framebuffer(&fb->fb);
  93299. +
  93300. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  93301. + bcm_dma_chan_free(fb->dma_chan);
  93302. +
  93303. + dma_free_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), (void *)fb->info,
  93304. + fb->dma);
  93305. + kfree(fb);
  93306. +
  93307. + return 0;
  93308. +}
  93309. +
  93310. +static struct platform_driver bcm2708_fb_driver = {
  93311. + .probe = bcm2708_fb_probe,
  93312. + .remove = bcm2708_fb_remove,
  93313. + .driver = {
  93314. + .name = DRIVER_NAME,
  93315. + .owner = THIS_MODULE,
  93316. + },
  93317. +};
  93318. +
  93319. +static int __init bcm2708_fb_init(void)
  93320. +{
  93321. + return platform_driver_register(&bcm2708_fb_driver);
  93322. +}
  93323. +
  93324. +module_init(bcm2708_fb_init);
  93325. +
  93326. +static void __exit bcm2708_fb_exit(void)
  93327. +{
  93328. + platform_driver_unregister(&bcm2708_fb_driver);
  93329. +}
  93330. +
  93331. +module_exit(bcm2708_fb_exit);
  93332. +
  93333. +module_param(fbwidth, int, 0644);
  93334. +module_param(fbheight, int, 0644);
  93335. +module_param(fbdepth, int, 0644);
  93336. +
  93337. +MODULE_DESCRIPTION("BCM2708 framebuffer driver");
  93338. +MODULE_LICENSE("GPL");
  93339. +
  93340. +MODULE_PARM_DESC(fbwidth, "Width of ARM Framebuffer");
  93341. +MODULE_PARM_DESC(fbheight, "Height of ARM Framebuffer");
  93342. +MODULE_PARM_DESC(fbdepth, "Bit depth of ARM Framebuffer");
  93343. diff -Nur linux-3.12.11.orig/drivers/video/cfbimgblt.c linux-3.12.11/drivers/video/cfbimgblt.c
  93344. --- linux-3.12.11.orig/drivers/video/cfbimgblt.c 2014-02-13 22:51:06.000000000 +0100
  93345. +++ linux-3.12.11/drivers/video/cfbimgblt.c 2014-02-18 11:52:14.000000000 +0100
  93346. @@ -28,6 +28,11 @@
  93347. *
  93348. * Also need to add code to deal with cards endians that are different than
  93349. * the native cpu endians. I also need to deal with MSB position in the word.
  93350. + * Modified by Harm Hanemaaijer (fgenfb@yahoo.com) 2013:
  93351. + * - Provide optimized versions of fast_imageblit for 16 and 32bpp that are
  93352. + * significantly faster than the previous implementation.
  93353. + * - Simplify the fast/slow_imageblit selection code, avoiding integer
  93354. + * divides.
  93355. */
  93356. #include <linux/module.h>
  93357. #include <linux/string.h>
  93358. @@ -262,6 +267,133 @@
  93359. }
  93360. }
  93361. +/*
  93362. + * Optimized fast_imageblit for bpp == 16. ppw = 2, bit_mask = 3 folded
  93363. + * into the code, main loop unrolled.
  93364. + */
  93365. +
  93366. +static inline void fast_imageblit16(const struct fb_image *image,
  93367. + struct fb_info *p, u8 __iomem * dst1,
  93368. + u32 fgcolor, u32 bgcolor)
  93369. +{
  93370. + u32 fgx = fgcolor, bgx = bgcolor;
  93371. + u32 spitch = (image->width + 7) / 8;
  93372. + u32 end_mask, eorx;
  93373. + const char *s = image->data, *src;
  93374. + u32 __iomem *dst;
  93375. + const u32 *tab = NULL;
  93376. + int i, j, k;
  93377. +
  93378. + tab = fb_be_math(p) ? cfb_tab16_be : cfb_tab16_le;
  93379. +
  93380. + fgx <<= 16;
  93381. + bgx <<= 16;
  93382. + fgx |= fgcolor;
  93383. + bgx |= bgcolor;
  93384. +
  93385. + eorx = fgx ^ bgx;
  93386. + k = image->width / 2;
  93387. +
  93388. + for (i = image->height; i--;) {
  93389. + dst = (u32 __iomem *) dst1;
  93390. + src = s;
  93391. +
  93392. + j = k;
  93393. + while (j >= 4) {
  93394. + u8 bits = *src;
  93395. + end_mask = tab[(bits >> 6) & 3];
  93396. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93397. + end_mask = tab[(bits >> 4) & 3];
  93398. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93399. + end_mask = tab[(bits >> 2) & 3];
  93400. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93401. + end_mask = tab[bits & 3];
  93402. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93403. + src++;
  93404. + j -= 4;
  93405. + }
  93406. + if (j != 0) {
  93407. + u8 bits = *src;
  93408. + end_mask = tab[(bits >> 6) & 3];
  93409. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93410. + if (j >= 2) {
  93411. + end_mask = tab[(bits >> 4) & 3];
  93412. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93413. + if (j == 3) {
  93414. + end_mask = tab[(bits >> 2) & 3];
  93415. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  93416. + }
  93417. + }
  93418. + }
  93419. + dst1 += p->fix.line_length;
  93420. + s += spitch;
  93421. + }
  93422. +}
  93423. +
  93424. +/*
  93425. + * Optimized fast_imageblit for bpp == 32. ppw = 1, bit_mask = 1 folded
  93426. + * into the code, main loop unrolled.
  93427. + */
  93428. +
  93429. +static inline void fast_imageblit32(const struct fb_image *image,
  93430. + struct fb_info *p, u8 __iomem * dst1,
  93431. + u32 fgcolor, u32 bgcolor)
  93432. +{
  93433. + u32 fgx = fgcolor, bgx = bgcolor;
  93434. + u32 spitch = (image->width + 7) / 8;
  93435. + u32 end_mask, eorx;
  93436. + const char *s = image->data, *src;
  93437. + u32 __iomem *dst;
  93438. + const u32 *tab = NULL;
  93439. + int i, j, k;
  93440. +
  93441. + tab = cfb_tab32;
  93442. +
  93443. + eorx = fgx ^ bgx;
  93444. + k = image->width;
  93445. +
  93446. + for (i = image->height; i--;) {
  93447. + dst = (u32 __iomem *) dst1;
  93448. + src = s;
  93449. +
  93450. + j = k;
  93451. + while (j >= 8) {
  93452. + u8 bits = *src;
  93453. + end_mask = tab[(bits >> 7) & 1];
  93454. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93455. + end_mask = tab[(bits >> 6) & 1];
  93456. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93457. + end_mask = tab[(bits >> 5) & 1];
  93458. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93459. + end_mask = tab[(bits >> 4) & 1];
  93460. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93461. + end_mask = tab[(bits >> 3) & 1];
  93462. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93463. + end_mask = tab[(bits >> 2) & 1];
  93464. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93465. + end_mask = tab[(bits >> 1) & 1];
  93466. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93467. + end_mask = tab[bits & 1];
  93468. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93469. + src++;
  93470. + j -= 8;
  93471. + }
  93472. + if (j != 0) {
  93473. + u32 bits = (u32) * src;
  93474. + while (j > 1) {
  93475. + end_mask = tab[(bits >> 7) & 1];
  93476. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93477. + bits <<= 1;
  93478. + j--;
  93479. + }
  93480. + end_mask = tab[(bits >> 7) & 1];
  93481. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  93482. + }
  93483. + dst1 += p->fix.line_length;
  93484. + s += spitch;
  93485. + }
  93486. +}
  93487. +
  93488. void cfb_imageblit(struct fb_info *p, const struct fb_image *image)
  93489. {
  93490. u32 fgcolor, bgcolor, start_index, bitstart, pitch_index = 0;
  93491. @@ -294,11 +426,21 @@
  93492. bgcolor = image->bg_color;
  93493. }
  93494. - if (32 % bpp == 0 && !start_index && !pitch_index &&
  93495. - ((width & (32/bpp-1)) == 0) &&
  93496. - bpp >= 8 && bpp <= 32)
  93497. - fast_imageblit(image, p, dst1, fgcolor, bgcolor);
  93498. - else
  93499. + if (!start_index && !pitch_index) {
  93500. + if (bpp == 32)
  93501. + fast_imageblit32(image, p, dst1, fgcolor,
  93502. + bgcolor);
  93503. + else if (bpp == 16 && (width & 1) == 0)
  93504. + fast_imageblit16(image, p, dst1, fgcolor,
  93505. + bgcolor);
  93506. + else if (bpp == 8 && (width & 3) == 0)
  93507. + fast_imageblit(image, p, dst1, fgcolor,
  93508. + bgcolor);
  93509. + else
  93510. + slow_imageblit(image, p, dst1, fgcolor,
  93511. + bgcolor,
  93512. + start_index, pitch_index);
  93513. + } else
  93514. slow_imageblit(image, p, dst1, fgcolor, bgcolor,
  93515. start_index, pitch_index);
  93516. } else
  93517. diff -Nur linux-3.12.11.orig/drivers/video/fbmem.c linux-3.12.11/drivers/video/fbmem.c
  93518. --- linux-3.12.11.orig/drivers/video/fbmem.c 2014-02-13 22:51:06.000000000 +0100
  93519. +++ linux-3.12.11/drivers/video/fbmem.c 2014-02-18 11:52:14.000000000 +0100
  93520. @@ -1083,6 +1083,25 @@
  93521. }
  93522. EXPORT_SYMBOL(fb_blank);
  93523. +static int fb_copyarea_user(struct fb_info *info,
  93524. + struct fb_copyarea *copy)
  93525. +{
  93526. + int ret = 0;
  93527. + if (!lock_fb_info(info))
  93528. + return -ENODEV;
  93529. + if (copy->dx + copy->width > info->var.xres ||
  93530. + copy->sx + copy->width > info->var.xres ||
  93531. + copy->dy + copy->height > info->var.yres ||
  93532. + copy->sy + copy->height > info->var.yres) {
  93533. + ret = -EINVAL;
  93534. + goto out;
  93535. + }
  93536. + info->fbops->fb_copyarea(info, copy);
  93537. +out:
  93538. + unlock_fb_info(info);
  93539. + return ret;
  93540. +}
  93541. +
  93542. static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
  93543. unsigned long arg)
  93544. {
  93545. @@ -1093,6 +1112,7 @@
  93546. struct fb_cmap cmap_from;
  93547. struct fb_cmap_user cmap;
  93548. struct fb_event event;
  93549. + struct fb_copyarea copy;
  93550. void __user *argp = (void __user *)arg;
  93551. long ret = 0;
  93552. @@ -1202,6 +1222,15 @@
  93553. console_unlock();
  93554. unlock_fb_info(info);
  93555. break;
  93556. + case FBIOCOPYAREA:
  93557. + if (info->flags & FBINFO_HWACCEL_COPYAREA) {
  93558. + /* only provide this ioctl if it is accelerated */
  93559. + if (copy_from_user(&copy, argp, sizeof(copy)))
  93560. + return -EFAULT;
  93561. + ret = fb_copyarea_user(info, &copy);
  93562. + break;
  93563. + }
  93564. + /* fall through */
  93565. default:
  93566. if (!lock_fb_info(info))
  93567. return -ENODEV;
  93568. @@ -1356,6 +1385,7 @@
  93569. case FBIOPAN_DISPLAY:
  93570. case FBIOGET_CON2FBMAP:
  93571. case FBIOPUT_CON2FBMAP:
  93572. + case FBIOCOPYAREA:
  93573. arg = (unsigned long) compat_ptr(arg);
  93574. case FBIOBLANK:
  93575. ret = do_fb_ioctl(info, cmd, arg);
  93576. diff -Nur linux-3.12.11.orig/drivers/video/Kconfig linux-3.12.11/drivers/video/Kconfig
  93577. --- linux-3.12.11.orig/drivers/video/Kconfig 2014-02-13 22:51:06.000000000 +0100
  93578. +++ linux-3.12.11/drivers/video/Kconfig 2014-02-18 11:52:14.000000000 +0100
  93579. @@ -310,6 +310,20 @@
  93580. help
  93581. Support the Permedia2 FIFO disconnect feature.
  93582. +config FB_BCM2708
  93583. + tristate "BCM2708 framebuffer support"
  93584. + depends on FB && ARM
  93585. + select FB_CFB_FILLRECT
  93586. + select FB_CFB_COPYAREA
  93587. + select FB_CFB_IMAGEBLIT
  93588. + help
  93589. + This framebuffer device driver is for the BCM2708 framebuffer.
  93590. +
  93591. + If you want to compile this as a module (=code which can be
  93592. + inserted into and removed from the running kernel), say M
  93593. + here and read <file:Documentation/kbuild/modules.txt>. The module
  93594. + will be called bcm2708_fb.
  93595. +
  93596. config FB_ARMCLCD
  93597. tristate "ARM PrimeCell PL110 support"
  93598. depends on FB && ARM && ARM_AMBA
  93599. diff -Nur linux-3.12.11.orig/drivers/video/logo/logo_linux_clut224.ppm linux-3.12.11/drivers/video/logo/logo_linux_clut224.ppm
  93600. --- linux-3.12.11.orig/drivers/video/logo/logo_linux_clut224.ppm 2014-02-13 22:51:06.000000000 +0100
  93601. +++ linux-3.12.11/drivers/video/logo/logo_linux_clut224.ppm 2014-02-18 11:52:14.000000000 +0100
  93602. @@ -1,1604 +1,883 @@
  93603. P3
  93604. -# Standard 224-color Linux logo
  93605. -80 80
  93606. +63 80
  93607. 255
  93608. - 0 0 0 0 0 0 0 0 0 0 0 0
  93609. - 0 0 0 0 0 0 0 0 0 0 0 0
  93610. - 0 0 0 0 0 0 0 0 0 0 0 0
  93611. - 0 0 0 0 0 0 0 0 0 0 0 0
  93612. - 0 0 0 0 0 0 0 0 0 0 0 0
  93613. - 0 0 0 0 0 0 0 0 0 0 0 0
  93614. - 0 0 0 0 0 0 0 0 0 0 0 0
  93615. - 0 0 0 0 0 0 0 0 0 0 0 0
  93616. - 0 0 0 0 0 0 0 0 0 0 0 0
  93617. - 6 6 6 6 6 6 10 10 10 10 10 10
  93618. - 10 10 10 6 6 6 6 6 6 6 6 6
  93619. - 0 0 0 0 0 0 0 0 0 0 0 0
  93620. - 0 0 0 0 0 0 0 0 0 0 0 0
  93621. - 0 0 0 0 0 0 0 0 0 0 0 0
  93622. - 0 0 0 0 0 0 0 0 0 0 0 0
  93623. - 0 0 0 0 0 0 0 0 0 0 0 0
  93624. - 0 0 0 0 0 0 0 0 0 0 0 0
  93625. - 0 0 0 0 0 0 0 0 0 0 0 0
  93626. - 0 0 0 0 0 0 0 0 0 0 0 0
  93627. - 0 0 0 0 0 0 0 0 0 0 0 0
  93628. - 0 0 0 0 0 0 0 0 0 0 0 0
  93629. - 0 0 0 0 0 0 0 0 0 0 0 0
  93630. - 0 0 0 0 0 0 0 0 0 0 0 0
  93631. - 0 0 0 0 0 0 0 0 0 0 0 0
  93632. - 0 0 0 0 0 0 0 0 0 0 0 0
  93633. - 0 0 0 0 0 0 0 0 0 0 0 0
  93634. - 0 0 0 0 0 0 0 0 0 0 0 0
  93635. - 0 0 0 0 0 0 0 0 0 0 0 0
  93636. - 0 0 0 6 6 6 10 10 10 14 14 14
  93637. - 22 22 22 26 26 26 30 30 30 34 34 34
  93638. - 30 30 30 30 30 30 26 26 26 18 18 18
  93639. - 14 14 14 10 10 10 6 6 6 0 0 0
  93640. - 0 0 0 0 0 0 0 0 0 0 0 0
  93641. - 0 0 0 0 0 0 0 0 0 0 0 0
  93642. - 0 0 0 0 0 0 0 0 0 0 0 0
  93643. - 0 0 0 0 0 0 0 0 0 0 0 0
  93644. - 0 0 0 0 0 0 0 0 0 0 0 0
  93645. - 0 0 0 0 0 0 0 0 0 0 0 0
  93646. - 0 0 0 0 0 0 0 0 0 0 0 0
  93647. - 0 0 0 0 0 0 0 0 0 0 0 0
  93648. - 0 0 0 0 0 0 0 0 0 0 0 0
  93649. - 0 0 0 0 0 1 0 0 1 0 0 0
  93650. - 0 0 0 0 0 0 0 0 0 0 0 0
  93651. - 0 0 0 0 0 0 0 0 0 0 0 0
  93652. - 0 0 0 0 0 0 0 0 0 0 0 0
  93653. - 0 0 0 0 0 0 0 0 0 0 0 0
  93654. - 0 0 0 0 0 0 0 0 0 0 0 0
  93655. - 0 0 0 0 0 0 0 0 0 0 0 0
  93656. - 6 6 6 14 14 14 26 26 26 42 42 42
  93657. - 54 54 54 66 66 66 78 78 78 78 78 78
  93658. - 78 78 78 74 74 74 66 66 66 54 54 54
  93659. - 42 42 42 26 26 26 18 18 18 10 10 10
  93660. - 6 6 6 0 0 0 0 0 0 0 0 0
  93661. - 0 0 0 0 0 0 0 0 0 0 0 0
  93662. - 0 0 0 0 0 0 0 0 0 0 0 0
  93663. - 0 0 0 0 0 0 0 0 0 0 0 0
  93664. - 0 0 0 0 0 0 0 0 0 0 0 0
  93665. - 0 0 0 0 0 0 0 0 0 0 0 0
  93666. - 0 0 0 0 0 0 0 0 0 0 0 0
  93667. - 0 0 0 0 0 0 0 0 0 0 0 0
  93668. - 0 0 0 0 0 0 0 0 0 0 0 0
  93669. - 0 0 1 0 0 0 0 0 0 0 0 0
  93670. - 0 0 0 0 0 0 0 0 0 0 0 0
  93671. - 0 0 0 0 0 0 0 0 0 0 0 0
  93672. - 0 0 0 0 0 0 0 0 0 0 0 0
  93673. - 0 0 0 0 0 0 0 0 0 0 0 0
  93674. - 0 0 0 0 0 0 0 0 0 0 0 0
  93675. - 0 0 0 0 0 0 0 0 0 10 10 10
  93676. - 22 22 22 42 42 42 66 66 66 86 86 86
  93677. - 66 66 66 38 38 38 38 38 38 22 22 22
  93678. - 26 26 26 34 34 34 54 54 54 66 66 66
  93679. - 86 86 86 70 70 70 46 46 46 26 26 26
  93680. - 14 14 14 6 6 6 0 0 0 0 0 0
  93681. - 0 0 0 0 0 0 0 0 0 0 0 0
  93682. - 0 0 0 0 0 0 0 0 0 0 0 0
  93683. - 0 0 0 0 0 0 0 0 0 0 0 0
  93684. - 0 0 0 0 0 0 0 0 0 0 0 0
  93685. - 0 0 0 0 0 0 0 0 0 0 0 0
  93686. - 0 0 0 0 0 0 0 0 0 0 0 0
  93687. - 0 0 0 0 0 0 0 0 0 0 0 0
  93688. - 0 0 0 0 0 0 0 0 0 0 0 0
  93689. - 0 0 1 0 0 1 0 0 1 0 0 0
  93690. - 0 0 0 0 0 0 0 0 0 0 0 0
  93691. - 0 0 0 0 0 0 0 0 0 0 0 0
  93692. - 0 0 0 0 0 0 0 0 0 0 0 0
  93693. - 0 0 0 0 0 0 0 0 0 0 0 0
  93694. - 0 0 0 0 0 0 0 0 0 0 0 0
  93695. - 0 0 0 0 0 0 10 10 10 26 26 26
  93696. - 50 50 50 82 82 82 58 58 58 6 6 6
  93697. - 2 2 6 2 2 6 2 2 6 2 2 6
  93698. - 2 2 6 2 2 6 2 2 6 2 2 6
  93699. - 6 6 6 54 54 54 86 86 86 66 66 66
  93700. - 38 38 38 18 18 18 6 6 6 0 0 0
  93701. - 0 0 0 0 0 0 0 0 0 0 0 0
  93702. - 0 0 0 0 0 0 0 0 0 0 0 0
  93703. - 0 0 0 0 0 0 0 0 0 0 0 0
  93704. - 0 0 0 0 0 0 0 0 0 0 0 0
  93705. - 0 0 0 0 0 0 0 0 0 0 0 0
  93706. - 0 0 0 0 0 0 0 0 0 0 0 0
  93707. - 0 0 0 0 0 0 0 0 0 0 0 0
  93708. - 0 0 0 0 0 0 0 0 0 0 0 0
  93709. - 0 0 0 0 0 0 0 0 0 0 0 0
  93710. - 0 0 0 0 0 0 0 0 0 0 0 0
  93711. - 0 0 0 0 0 0 0 0 0 0 0 0
  93712. - 0 0 0 0 0 0 0 0 0 0 0 0
  93713. - 0 0 0 0 0 0 0 0 0 0 0 0
  93714. - 0 0 0 0 0 0 0 0 0 0 0 0
  93715. - 0 0 0 6 6 6 22 22 22 50 50 50
  93716. - 78 78 78 34 34 34 2 2 6 2 2 6
  93717. - 2 2 6 2 2 6 2 2 6 2 2 6
  93718. - 2 2 6 2 2 6 2 2 6 2 2 6
  93719. - 2 2 6 2 2 6 6 6 6 70 70 70
  93720. - 78 78 78 46 46 46 22 22 22 6 6 6
  93721. - 0 0 0 0 0 0 0 0 0 0 0 0
  93722. - 0 0 0 0 0 0 0 0 0 0 0 0
  93723. - 0 0 0 0 0 0 0 0 0 0 0 0
  93724. - 0 0 0 0 0 0 0 0 0 0 0 0
  93725. - 0 0 0 0 0 0 0 0 0 0 0 0
  93726. - 0 0 0 0 0 0 0 0 0 0 0 0
  93727. - 0 0 0 0 0 0 0 0 0 0 0 0
  93728. - 0 0 0 0 0 0 0 0 0 0 0 0
  93729. - 0 0 1 0 0 1 0 0 1 0 0 0
  93730. - 0 0 0 0 0 0 0 0 0 0 0 0
  93731. - 0 0 0 0 0 0 0 0 0 0 0 0
  93732. - 0 0 0 0 0 0 0 0 0 0 0 0
  93733. - 0 0 0 0 0 0 0 0 0 0 0 0
  93734. - 0 0 0 0 0 0 0 0 0 0 0 0
  93735. - 6 6 6 18 18 18 42 42 42 82 82 82
  93736. - 26 26 26 2 2 6 2 2 6 2 2 6
  93737. - 2 2 6 2 2 6 2 2 6 2 2 6
  93738. - 2 2 6 2 2 6 2 2 6 14 14 14
  93739. - 46 46 46 34 34 34 6 6 6 2 2 6
  93740. - 42 42 42 78 78 78 42 42 42 18 18 18
  93741. - 6 6 6 0 0 0 0 0 0 0 0 0
  93742. - 0 0 0 0 0 0 0 0 0 0 0 0
  93743. - 0 0 0 0 0 0 0 0 0 0 0 0
  93744. - 0 0 0 0 0 0 0 0 0 0 0 0
  93745. - 0 0 0 0 0 0 0 0 0 0 0 0
  93746. - 0 0 0 0 0 0 0 0 0 0 0 0
  93747. - 0 0 0 0 0 0 0 0 0 0 0 0
  93748. - 0 0 0 0 0 0 0 0 0 0 0 0
  93749. - 0 0 1 0 0 0 0 0 1 0 0 0
  93750. - 0 0 0 0 0 0 0 0 0 0 0 0
  93751. - 0 0 0 0 0 0 0 0 0 0 0 0
  93752. - 0 0 0 0 0 0 0 0 0 0 0 0
  93753. - 0 0 0 0 0 0 0 0 0 0 0 0
  93754. - 0 0 0 0 0 0 0 0 0 0 0 0
  93755. - 10 10 10 30 30 30 66 66 66 58 58 58
  93756. - 2 2 6 2 2 6 2 2 6 2 2 6
  93757. - 2 2 6 2 2 6 2 2 6 2 2 6
  93758. - 2 2 6 2 2 6 2 2 6 26 26 26
  93759. - 86 86 86 101 101 101 46 46 46 10 10 10
  93760. - 2 2 6 58 58 58 70 70 70 34 34 34
  93761. - 10 10 10 0 0 0 0 0 0 0 0 0
  93762. - 0 0 0 0 0 0 0 0 0 0 0 0
  93763. - 0 0 0 0 0 0 0 0 0 0 0 0
  93764. - 0 0 0 0 0 0 0 0 0 0 0 0
  93765. - 0 0 0 0 0 0 0 0 0 0 0 0
  93766. - 0 0 0 0 0 0 0 0 0 0 0 0
  93767. - 0 0 0 0 0 0 0 0 0 0 0 0
  93768. - 0 0 0 0 0 0 0 0 0 0 0 0
  93769. - 0 0 1 0 0 1 0 0 1 0 0 0
  93770. - 0 0 0 0 0 0 0 0 0 0 0 0
  93771. - 0 0 0 0 0 0 0 0 0 0 0 0
  93772. - 0 0 0 0 0 0 0 0 0 0 0 0
  93773. - 0 0 0 0 0 0 0 0 0 0 0 0
  93774. - 0 0 0 0 0 0 0 0 0 0 0 0
  93775. - 14 14 14 42 42 42 86 86 86 10 10 10
  93776. - 2 2 6 2 2 6 2 2 6 2 2 6
  93777. - 2 2 6 2 2 6 2 2 6 2 2 6
  93778. - 2 2 6 2 2 6 2 2 6 30 30 30
  93779. - 94 94 94 94 94 94 58 58 58 26 26 26
  93780. - 2 2 6 6 6 6 78 78 78 54 54 54
  93781. - 22 22 22 6 6 6 0 0 0 0 0 0
  93782. - 0 0 0 0 0 0 0 0 0 0 0 0
  93783. - 0 0 0 0 0 0 0 0 0 0 0 0
  93784. - 0 0 0 0 0 0 0 0 0 0 0 0
  93785. - 0 0 0 0 0 0 0 0 0 0 0 0
  93786. - 0 0 0 0 0 0 0 0 0 0 0 0
  93787. - 0 0 0 0 0 0 0 0 0 0 0 0
  93788. - 0 0 0 0 0 0 0 0 0 0 0 0
  93789. - 0 0 0 0 0 0 0 0 0 0 0 0
  93790. - 0 0 0 0 0 0 0 0 0 0 0 0
  93791. - 0 0 0 0 0 0 0 0 0 0 0 0
  93792. - 0 0 0 0 0 0 0 0 0 0 0 0
  93793. - 0 0 0 0 0 0 0 0 0 0 0 0
  93794. - 0 0 0 0 0 0 0 0 0 6 6 6
  93795. - 22 22 22 62 62 62 62 62 62 2 2 6
  93796. - 2 2 6 2 2 6 2 2 6 2 2 6
  93797. - 2 2 6 2 2 6 2 2 6 2 2 6
  93798. - 2 2 6 2 2 6 2 2 6 26 26 26
  93799. - 54 54 54 38 38 38 18 18 18 10 10 10
  93800. - 2 2 6 2 2 6 34 34 34 82 82 82
  93801. - 38 38 38 14 14 14 0 0 0 0 0 0
  93802. - 0 0 0 0 0 0 0 0 0 0 0 0
  93803. - 0 0 0 0 0 0 0 0 0 0 0 0
  93804. - 0 0 0 0 0 0 0 0 0 0 0 0
  93805. - 0 0 0 0 0 0 0 0 0 0 0 0
  93806. - 0 0 0 0 0 0 0 0 0 0 0 0
  93807. - 0 0 0 0 0 0 0 0 0 0 0 0
  93808. - 0 0 0 0 0 0 0 0 0 0 0 0
  93809. - 0 0 0 0 0 1 0 0 1 0 0 0
  93810. - 0 0 0 0 0 0 0 0 0 0 0 0
  93811. - 0 0 0 0 0 0 0 0 0 0 0 0
  93812. - 0 0 0 0 0 0 0 0 0 0 0 0
  93813. - 0 0 0 0 0 0 0 0 0 0 0 0
  93814. - 0 0 0 0 0 0 0 0 0 6 6 6
  93815. - 30 30 30 78 78 78 30 30 30 2 2 6
  93816. - 2 2 6 2 2 6 2 2 6 2 2 6
  93817. - 2 2 6 2 2 6 2 2 6 2 2 6
  93818. - 2 2 6 2 2 6 2 2 6 10 10 10
  93819. - 10 10 10 2 2 6 2 2 6 2 2 6
  93820. - 2 2 6 2 2 6 2 2 6 78 78 78
  93821. - 50 50 50 18 18 18 6 6 6 0 0 0
  93822. - 0 0 0 0 0 0 0 0 0 0 0 0
  93823. - 0 0 0 0 0 0 0 0 0 0 0 0
  93824. - 0 0 0 0 0 0 0 0 0 0 0 0
  93825. - 0 0 0 0 0 0 0 0 0 0 0 0
  93826. - 0 0 0 0 0 0 0 0 0 0 0 0
  93827. - 0 0 0 0 0 0 0 0 0 0 0 0
  93828. - 0 0 0 0 0 0 0 0 0 0 0 0
  93829. - 0 0 1 0 0 0 0 0 0 0 0 0
  93830. - 0 0 0 0 0 0 0 0 0 0 0 0
  93831. - 0 0 0 0 0 0 0 0 0 0 0 0
  93832. - 0 0 0 0 0 0 0 0 0 0 0 0
  93833. - 0 0 0 0 0 0 0 0 0 0 0 0
  93834. - 0 0 0 0 0 0 0 0 0 10 10 10
  93835. - 38 38 38 86 86 86 14 14 14 2 2 6
  93836. - 2 2 6 2 2 6 2 2 6 2 2 6
  93837. - 2 2 6 2 2 6 2 2 6 2 2 6
  93838. - 2 2 6 2 2 6 2 2 6 2 2 6
  93839. - 2 2 6 2 2 6 2 2 6 2 2 6
  93840. - 2 2 6 2 2 6 2 2 6 54 54 54
  93841. - 66 66 66 26 26 26 6 6 6 0 0 0
  93842. - 0 0 0 0 0 0 0 0 0 0 0 0
  93843. - 0 0 0 0 0 0 0 0 0 0 0 0
  93844. - 0 0 0 0 0 0 0 0 0 0 0 0
  93845. - 0 0 0 0 0 0 0 0 0 0 0 0
  93846. - 0 0 0 0 0 0 0 0 0 0 0 0
  93847. - 0 0 0 0 0 0 0 0 0 0 0 0
  93848. - 0 0 0 0 0 0 0 0 0 0 0 0
  93849. - 0 0 0 0 0 1 0 0 1 0 0 0
  93850. - 0 0 0 0 0 0 0 0 0 0 0 0
  93851. - 0 0 0 0 0 0 0 0 0 0 0 0
  93852. - 0 0 0 0 0 0 0 0 0 0 0 0
  93853. - 0 0 0 0 0 0 0 0 0 0 0 0
  93854. - 0 0 0 0 0 0 0 0 0 14 14 14
  93855. - 42 42 42 82 82 82 2 2 6 2 2 6
  93856. - 2 2 6 6 6 6 10 10 10 2 2 6
  93857. - 2 2 6 2 2 6 2 2 6 2 2 6
  93858. - 2 2 6 2 2 6 2 2 6 6 6 6
  93859. - 14 14 14 10 10 10 2 2 6 2 2 6
  93860. - 2 2 6 2 2 6 2 2 6 18 18 18
  93861. - 82 82 82 34 34 34 10 10 10 0 0 0
  93862. - 0 0 0 0 0 0 0 0 0 0 0 0
  93863. - 0 0 0 0 0 0 0 0 0 0 0 0
  93864. - 0 0 0 0 0 0 0 0 0 0 0 0
  93865. - 0 0 0 0 0 0 0 0 0 0 0 0
  93866. - 0 0 0 0 0 0 0 0 0 0 0 0
  93867. - 0 0 0 0 0 0 0 0 0 0 0 0
  93868. - 0 0 0 0 0 0 0 0 0 0 0 0
  93869. - 0 0 1 0 0 0 0 0 0 0 0 0
  93870. - 0 0 0 0 0 0 0 0 0 0 0 0
  93871. - 0 0 0 0 0 0 0 0 0 0 0 0
  93872. - 0 0 0 0 0 0 0 0 0 0 0 0
  93873. - 0 0 0 0 0 0 0 0 0 0 0 0
  93874. - 0 0 0 0 0 0 0 0 0 14 14 14
  93875. - 46 46 46 86 86 86 2 2 6 2 2 6
  93876. - 6 6 6 6 6 6 22 22 22 34 34 34
  93877. - 6 6 6 2 2 6 2 2 6 2 2 6
  93878. - 2 2 6 2 2 6 18 18 18 34 34 34
  93879. - 10 10 10 50 50 50 22 22 22 2 2 6
  93880. - 2 2 6 2 2 6 2 2 6 10 10 10
  93881. - 86 86 86 42 42 42 14 14 14 0 0 0
  93882. - 0 0 0 0 0 0 0 0 0 0 0 0
  93883. - 0 0 0 0 0 0 0 0 0 0 0 0
  93884. - 0 0 0 0 0 0 0 0 0 0 0 0
  93885. - 0 0 0 0 0 0 0 0 0 0 0 0
  93886. - 0 0 0 0 0 0 0 0 0 0 0 0
  93887. - 0 0 0 0 0 0 0 0 0 0 0 0
  93888. - 0 0 0 0 0 0 0 0 0 0 0 0
  93889. - 0 0 1 0 0 1 0 0 1 0 0 0
  93890. - 0 0 0 0 0 0 0 0 0 0 0 0
  93891. - 0 0 0 0 0 0 0 0 0 0 0 0
  93892. - 0 0 0 0 0 0 0 0 0 0 0 0
  93893. - 0 0 0 0 0 0 0 0 0 0 0 0
  93894. - 0 0 0 0 0 0 0 0 0 14 14 14
  93895. - 46 46 46 86 86 86 2 2 6 2 2 6
  93896. - 38 38 38 116 116 116 94 94 94 22 22 22
  93897. - 22 22 22 2 2 6 2 2 6 2 2 6
  93898. - 14 14 14 86 86 86 138 138 138 162 162 162
  93899. -154 154 154 38 38 38 26 26 26 6 6 6
  93900. - 2 2 6 2 2 6 2 2 6 2 2 6
  93901. - 86 86 86 46 46 46 14 14 14 0 0 0
  93902. - 0 0 0 0 0 0 0 0 0 0 0 0
  93903. - 0 0 0 0 0 0 0 0 0 0 0 0
  93904. - 0 0 0 0 0 0 0 0 0 0 0 0
  93905. - 0 0 0 0 0 0 0 0 0 0 0 0
  93906. - 0 0 0 0 0 0 0 0 0 0 0 0
  93907. - 0 0 0 0 0 0 0 0 0 0 0 0
  93908. - 0 0 0 0 0 0 0 0 0 0 0 0
  93909. - 0 0 0 0 0 0 0 0 0 0 0 0
  93910. - 0 0 0 0 0 0 0 0 0 0 0 0
  93911. - 0 0 0 0 0 0 0 0 0 0 0 0
  93912. - 0 0 0 0 0 0 0 0 0 0 0 0
  93913. - 0 0 0 0 0 0 0 0 0 0 0 0
  93914. - 0 0 0 0 0 0 0 0 0 14 14 14
  93915. - 46 46 46 86 86 86 2 2 6 14 14 14
  93916. -134 134 134 198 198 198 195 195 195 116 116 116
  93917. - 10 10 10 2 2 6 2 2 6 6 6 6
  93918. -101 98 89 187 187 187 210 210 210 218 218 218
  93919. -214 214 214 134 134 134 14 14 14 6 6 6
  93920. - 2 2 6 2 2 6 2 2 6 2 2 6
  93921. - 86 86 86 50 50 50 18 18 18 6 6 6
  93922. - 0 0 0 0 0 0 0 0 0 0 0 0
  93923. - 0 0 0 0 0 0 0 0 0 0 0 0
  93924. - 0 0 0 0 0 0 0 0 0 0 0 0
  93925. - 0 0 0 0 0 0 0 0 0 0 0 0
  93926. - 0 0 0 0 0 0 0 0 0 0 0 0
  93927. - 0 0 0 0 0 0 0 0 0 0 0 0
  93928. - 0 0 0 0 0 0 0 0 1 0 0 0
  93929. - 0 0 1 0 0 1 0 0 1 0 0 0
  93930. - 0 0 0 0 0 0 0 0 0 0 0 0
  93931. - 0 0 0 0 0 0 0 0 0 0 0 0
  93932. - 0 0 0 0 0 0 0 0 0 0 0 0
  93933. - 0 0 0 0 0 0 0 0 0 0 0 0
  93934. - 0 0 0 0 0 0 0 0 0 14 14 14
  93935. - 46 46 46 86 86 86 2 2 6 54 54 54
  93936. -218 218 218 195 195 195 226 226 226 246 246 246
  93937. - 58 58 58 2 2 6 2 2 6 30 30 30
  93938. -210 210 210 253 253 253 174 174 174 123 123 123
  93939. -221 221 221 234 234 234 74 74 74 2 2 6
  93940. - 2 2 6 2 2 6 2 2 6 2 2 6
  93941. - 70 70 70 58 58 58 22 22 22 6 6 6
  93942. - 0 0 0 0 0 0 0 0 0 0 0 0
  93943. - 0 0 0 0 0 0 0 0 0 0 0 0
  93944. - 0 0 0 0 0 0 0 0 0 0 0 0
  93945. - 0 0 0 0 0 0 0 0 0 0 0 0
  93946. - 0 0 0 0 0 0 0 0 0 0 0 0
  93947. - 0 0 0 0 0 0 0 0 0 0 0 0
  93948. - 0 0 0 0 0 0 0 0 0 0 0 0
  93949. - 0 0 0 0 0 0 0 0 0 0 0 0
  93950. - 0 0 0 0 0 0 0 0 0 0 0 0
  93951. - 0 0 0 0 0 0 0 0 0 0 0 0
  93952. - 0 0 0 0 0 0 0 0 0 0 0 0
  93953. - 0 0 0 0 0 0 0 0 0 0 0 0
  93954. - 0 0 0 0 0 0 0 0 0 14 14 14
  93955. - 46 46 46 82 82 82 2 2 6 106 106 106
  93956. -170 170 170 26 26 26 86 86 86 226 226 226
  93957. -123 123 123 10 10 10 14 14 14 46 46 46
  93958. -231 231 231 190 190 190 6 6 6 70 70 70
  93959. - 90 90 90 238 238 238 158 158 158 2 2 6
  93960. - 2 2 6 2 2 6 2 2 6 2 2 6
  93961. - 70 70 70 58 58 58 22 22 22 6 6 6
  93962. - 0 0 0 0 0 0 0 0 0 0 0 0
  93963. - 0 0 0 0 0 0 0 0 0 0 0 0
  93964. - 0 0 0 0 0 0 0 0 0 0 0 0
  93965. - 0 0 0 0 0 0 0 0 0 0 0 0
  93966. - 0 0 0 0 0 0 0 0 0 0 0 0
  93967. - 0 0 0 0 0 0 0 0 0 0 0 0
  93968. - 0 0 0 0 0 0 0 0 1 0 0 0
  93969. - 0 0 1 0 0 1 0 0 1 0 0 0
  93970. - 0 0 0 0 0 0 0 0 0 0 0 0
  93971. - 0 0 0 0 0 0 0 0 0 0 0 0
  93972. - 0 0 0 0 0 0 0 0 0 0 0 0
  93973. - 0 0 0 0 0 0 0 0 0 0 0 0
  93974. - 0 0 0 0 0 0 0 0 0 14 14 14
  93975. - 42 42 42 86 86 86 6 6 6 116 116 116
  93976. -106 106 106 6 6 6 70 70 70 149 149 149
  93977. -128 128 128 18 18 18 38 38 38 54 54 54
  93978. -221 221 221 106 106 106 2 2 6 14 14 14
  93979. - 46 46 46 190 190 190 198 198 198 2 2 6
  93980. - 2 2 6 2 2 6 2 2 6 2 2 6
  93981. - 74 74 74 62 62 62 22 22 22 6 6 6
  93982. - 0 0 0 0 0 0 0 0 0 0 0 0
  93983. - 0 0 0 0 0 0 0 0 0 0 0 0
  93984. - 0 0 0 0 0 0 0 0 0 0 0 0
  93985. - 0 0 0 0 0 0 0 0 0 0 0 0
  93986. - 0 0 0 0 0 0 0 0 0 0 0 0
  93987. - 0 0 0 0 0 0 0 0 0 0 0 0
  93988. - 0 0 0 0 0 0 0 0 1 0 0 0
  93989. - 0 0 1 0 0 0 0 0 1 0 0 0
  93990. - 0 0 0 0 0 0 0 0 0 0 0 0
  93991. - 0 0 0 0 0 0 0 0 0 0 0 0
  93992. - 0 0 0 0 0 0 0 0 0 0 0 0
  93993. - 0 0 0 0 0 0 0 0 0 0 0 0
  93994. - 0 0 0 0 0 0 0 0 0 14 14 14
  93995. - 42 42 42 94 94 94 14 14 14 101 101 101
  93996. -128 128 128 2 2 6 18 18 18 116 116 116
  93997. -118 98 46 121 92 8 121 92 8 98 78 10
  93998. -162 162 162 106 106 106 2 2 6 2 2 6
  93999. - 2 2 6 195 195 195 195 195 195 6 6 6
  94000. - 2 2 6 2 2 6 2 2 6 2 2 6
  94001. - 74 74 74 62 62 62 22 22 22 6 6 6
  94002. - 0 0 0 0 0 0 0 0 0 0 0 0
  94003. - 0 0 0 0 0 0 0 0 0 0 0 0
  94004. - 0 0 0 0 0 0 0 0 0 0 0 0
  94005. - 0 0 0 0 0 0 0 0 0 0 0 0
  94006. - 0 0 0 0 0 0 0 0 0 0 0 0
  94007. - 0 0 0 0 0 0 0 0 0 0 0 0
  94008. - 0 0 0 0 0 0 0 0 1 0 0 1
  94009. - 0 0 1 0 0 0 0 0 1 0 0 0
  94010. - 0 0 0 0 0 0 0 0 0 0 0 0
  94011. - 0 0 0 0 0 0 0 0 0 0 0 0
  94012. - 0 0 0 0 0 0 0 0 0 0 0 0
  94013. - 0 0 0 0 0 0 0 0 0 0 0 0
  94014. - 0 0 0 0 0 0 0 0 0 10 10 10
  94015. - 38 38 38 90 90 90 14 14 14 58 58 58
  94016. -210 210 210 26 26 26 54 38 6 154 114 10
  94017. -226 170 11 236 186 11 225 175 15 184 144 12
  94018. -215 174 15 175 146 61 37 26 9 2 2 6
  94019. - 70 70 70 246 246 246 138 138 138 2 2 6
  94020. - 2 2 6 2 2 6 2 2 6 2 2 6
  94021. - 70 70 70 66 66 66 26 26 26 6 6 6
  94022. - 0 0 0 0 0 0 0 0 0 0 0 0
  94023. - 0 0 0 0 0 0 0 0 0 0 0 0
  94024. - 0 0 0 0 0 0 0 0 0 0 0 0
  94025. - 0 0 0 0 0 0 0 0 0 0 0 0
  94026. - 0 0 0 0 0 0 0 0 0 0 0 0
  94027. - 0 0 0 0 0 0 0 0 0 0 0 0
  94028. - 0 0 0 0 0 0 0 0 0 0 0 0
  94029. - 0 0 0 0 0 0 0 0 0 0 0 0
  94030. - 0 0 0 0 0 0 0 0 0 0 0 0
  94031. - 0 0 0 0 0 0 0 0 0 0 0 0
  94032. - 0 0 0 0 0 0 0 0 0 0 0 0
  94033. - 0 0 0 0 0 0 0 0 0 0 0 0
  94034. - 0 0 0 0 0 0 0 0 0 10 10 10
  94035. - 38 38 38 86 86 86 14 14 14 10 10 10
  94036. -195 195 195 188 164 115 192 133 9 225 175 15
  94037. -239 182 13 234 190 10 232 195 16 232 200 30
  94038. -245 207 45 241 208 19 232 195 16 184 144 12
  94039. -218 194 134 211 206 186 42 42 42 2 2 6
  94040. - 2 2 6 2 2 6 2 2 6 2 2 6
  94041. - 50 50 50 74 74 74 30 30 30 6 6 6
  94042. - 0 0 0 0 0 0 0 0 0 0 0 0
  94043. - 0 0 0 0 0 0 0 0 0 0 0 0
  94044. - 0 0 0 0 0 0 0 0 0 0 0 0
  94045. - 0 0 0 0 0 0 0 0 0 0 0 0
  94046. - 0 0 0 0 0 0 0 0 0 0 0 0
  94047. - 0 0 0 0 0 0 0 0 0 0 0 0
  94048. - 0 0 0 0 0 0 0 0 0 0 0 0
  94049. - 0 0 0 0 0 0 0 0 0 0 0 0
  94050. - 0 0 0 0 0 0 0 0 0 0 0 0
  94051. - 0 0 0 0 0 0 0 0 0 0 0 0
  94052. - 0 0 0 0 0 0 0 0 0 0 0 0
  94053. - 0 0 0 0 0 0 0 0 0 0 0 0
  94054. - 0 0 0 0 0 0 0 0 0 10 10 10
  94055. - 34 34 34 86 86 86 14 14 14 2 2 6
  94056. -121 87 25 192 133 9 219 162 10 239 182 13
  94057. -236 186 11 232 195 16 241 208 19 244 214 54
  94058. -246 218 60 246 218 38 246 215 20 241 208 19
  94059. -241 208 19 226 184 13 121 87 25 2 2 6
  94060. - 2 2 6 2 2 6 2 2 6 2 2 6
  94061. - 50 50 50 82 82 82 34 34 34 10 10 10
  94062. - 0 0 0 0 0 0 0 0 0 0 0 0
  94063. - 0 0 0 0 0 0 0 0 0 0 0 0
  94064. - 0 0 0 0 0 0 0 0 0 0 0 0
  94065. - 0 0 0 0 0 0 0 0 0 0 0 0
  94066. - 0 0 0 0 0 0 0 0 0 0 0 0
  94067. - 0 0 0 0 0 0 0 0 0 0 0 0
  94068. - 0 0 0 0 0 0 0 0 0 0 0 0
  94069. - 0 0 0 0 0 0 0 0 0 0 0 0
  94070. - 0 0 0 0 0 0 0 0 0 0 0 0
  94071. - 0 0 0 0 0 0 0 0 0 0 0 0
  94072. - 0 0 0 0 0 0 0 0 0 0 0 0
  94073. - 0 0 0 0 0 0 0 0 0 0 0 0
  94074. - 0 0 0 0 0 0 0 0 0 10 10 10
  94075. - 34 34 34 82 82 82 30 30 30 61 42 6
  94076. -180 123 7 206 145 10 230 174 11 239 182 13
  94077. -234 190 10 238 202 15 241 208 19 246 218 74
  94078. -246 218 38 246 215 20 246 215 20 246 215 20
  94079. -226 184 13 215 174 15 184 144 12 6 6 6
  94080. - 2 2 6 2 2 6 2 2 6 2 2 6
  94081. - 26 26 26 94 94 94 42 42 42 14 14 14
  94082. - 0 0 0 0 0 0 0 0 0 0 0 0
  94083. - 0 0 0 0 0 0 0 0 0 0 0 0
  94084. - 0 0 0 0 0 0 0 0 0 0 0 0
  94085. - 0 0 0 0 0 0 0 0 0 0 0 0
  94086. - 0 0 0 0 0 0 0 0 0 0 0 0
  94087. - 0 0 0 0 0 0 0 0 0 0 0 0
  94088. - 0 0 0 0 0 0 0 0 0 0 0 0
  94089. - 0 0 0 0 0 0 0 0 0 0 0 0
  94090. - 0 0 0 0 0 0 0 0 0 0 0 0
  94091. - 0 0 0 0 0 0 0 0 0 0 0 0
  94092. - 0 0 0 0 0 0 0 0 0 0 0 0
  94093. - 0 0 0 0 0 0 0 0 0 0 0 0
  94094. - 0 0 0 0 0 0 0 0 0 10 10 10
  94095. - 30 30 30 78 78 78 50 50 50 104 69 6
  94096. -192 133 9 216 158 10 236 178 12 236 186 11
  94097. -232 195 16 241 208 19 244 214 54 245 215 43
  94098. -246 215 20 246 215 20 241 208 19 198 155 10
  94099. -200 144 11 216 158 10 156 118 10 2 2 6
  94100. - 2 2 6 2 2 6 2 2 6 2 2 6
  94101. - 6 6 6 90 90 90 54 54 54 18 18 18
  94102. - 6 6 6 0 0 0 0 0 0 0 0 0
  94103. - 0 0 0 0 0 0 0 0 0 0 0 0
  94104. - 0 0 0 0 0 0 0 0 0 0 0 0
  94105. - 0 0 0 0 0 0 0 0 0 0 0 0
  94106. - 0 0 0 0 0 0 0 0 0 0 0 0
  94107. - 0 0 0 0 0 0 0 0 0 0 0 0
  94108. - 0 0 0 0 0 0 0 0 0 0 0 0
  94109. - 0 0 0 0 0 0 0 0 0 0 0 0
  94110. - 0 0 0 0 0 0 0 0 0 0 0 0
  94111. - 0 0 0 0 0 0 0 0 0 0 0 0
  94112. - 0 0 0 0 0 0 0 0 0 0 0 0
  94113. - 0 0 0 0 0 0 0 0 0 0 0 0
  94114. - 0 0 0 0 0 0 0 0 0 10 10 10
  94115. - 30 30 30 78 78 78 46 46 46 22 22 22
  94116. -137 92 6 210 162 10 239 182 13 238 190 10
  94117. -238 202 15 241 208 19 246 215 20 246 215 20
  94118. -241 208 19 203 166 17 185 133 11 210 150 10
  94119. -216 158 10 210 150 10 102 78 10 2 2 6
  94120. - 6 6 6 54 54 54 14 14 14 2 2 6
  94121. - 2 2 6 62 62 62 74 74 74 30 30 30
  94122. - 10 10 10 0 0 0 0 0 0 0 0 0
  94123. - 0 0 0 0 0 0 0 0 0 0 0 0
  94124. - 0 0 0 0 0 0 0 0 0 0 0 0
  94125. - 0 0 0 0 0 0 0 0 0 0 0 0
  94126. - 0 0 0 0 0 0 0 0 0 0 0 0
  94127. - 0 0 0 0 0 0 0 0 0 0 0 0
  94128. - 0 0 0 0 0 0 0 0 0 0 0 0
  94129. - 0 0 0 0 0 0 0 0 0 0 0 0
  94130. - 0 0 0 0 0 0 0 0 0 0 0 0
  94131. - 0 0 0 0 0 0 0 0 0 0 0 0
  94132. - 0 0 0 0 0 0 0 0 0 0 0 0
  94133. - 0 0 0 0 0 0 0 0 0 0 0 0
  94134. - 0 0 0 0 0 0 0 0 0 10 10 10
  94135. - 34 34 34 78 78 78 50 50 50 6 6 6
  94136. - 94 70 30 139 102 15 190 146 13 226 184 13
  94137. -232 200 30 232 195 16 215 174 15 190 146 13
  94138. -168 122 10 192 133 9 210 150 10 213 154 11
  94139. -202 150 34 182 157 106 101 98 89 2 2 6
  94140. - 2 2 6 78 78 78 116 116 116 58 58 58
  94141. - 2 2 6 22 22 22 90 90 90 46 46 46
  94142. - 18 18 18 6 6 6 0 0 0 0 0 0
  94143. - 0 0 0 0 0 0 0 0 0 0 0 0
  94144. - 0 0 0 0 0 0 0 0 0 0 0 0
  94145. - 0 0 0 0 0 0 0 0 0 0 0 0
  94146. - 0 0 0 0 0 0 0 0 0 0 0 0
  94147. - 0 0 0 0 0 0 0 0 0 0 0 0
  94148. - 0 0 0 0 0 0 0 0 0 0 0 0
  94149. - 0 0 0 0 0 0 0 0 0 0 0 0
  94150. - 0 0 0 0 0 0 0 0 0 0 0 0
  94151. - 0 0 0 0 0 0 0 0 0 0 0 0
  94152. - 0 0 0 0 0 0 0 0 0 0 0 0
  94153. - 0 0 0 0 0 0 0 0 0 0 0 0
  94154. - 0 0 0 0 0 0 0 0 0 10 10 10
  94155. - 38 38 38 86 86 86 50 50 50 6 6 6
  94156. -128 128 128 174 154 114 156 107 11 168 122 10
  94157. -198 155 10 184 144 12 197 138 11 200 144 11
  94158. -206 145 10 206 145 10 197 138 11 188 164 115
  94159. -195 195 195 198 198 198 174 174 174 14 14 14
  94160. - 2 2 6 22 22 22 116 116 116 116 116 116
  94161. - 22 22 22 2 2 6 74 74 74 70 70 70
  94162. - 30 30 30 10 10 10 0 0 0 0 0 0
  94163. - 0 0 0 0 0 0 0 0 0 0 0 0
  94164. - 0 0 0 0 0 0 0 0 0 0 0 0
  94165. - 0 0 0 0 0 0 0 0 0 0 0 0
  94166. - 0 0 0 0 0 0 0 0 0 0 0 0
  94167. - 0 0 0 0 0 0 0 0 0 0 0 0
  94168. - 0 0 0 0 0 0 0 0 0 0 0 0
  94169. - 0 0 0 0 0 0 0 0 0 0 0 0
  94170. - 0 0 0 0 0 0 0 0 0 0 0 0
  94171. - 0 0 0 0 0 0 0 0 0 0 0 0
  94172. - 0 0 0 0 0 0 0 0 0 0 0 0
  94173. - 0 0 0 0 0 0 0 0 0 0 0 0
  94174. - 0 0 0 0 0 0 6 6 6 18 18 18
  94175. - 50 50 50 101 101 101 26 26 26 10 10 10
  94176. -138 138 138 190 190 190 174 154 114 156 107 11
  94177. -197 138 11 200 144 11 197 138 11 192 133 9
  94178. -180 123 7 190 142 34 190 178 144 187 187 187
  94179. -202 202 202 221 221 221 214 214 214 66 66 66
  94180. - 2 2 6 2 2 6 50 50 50 62 62 62
  94181. - 6 6 6 2 2 6 10 10 10 90 90 90
  94182. - 50 50 50 18 18 18 6 6 6 0 0 0
  94183. - 0 0 0 0 0 0 0 0 0 0 0 0
  94184. - 0 0 0 0 0 0 0 0 0 0 0 0
  94185. - 0 0 0 0 0 0 0 0 0 0 0 0
  94186. - 0 0 0 0 0 0 0 0 0 0 0 0
  94187. - 0 0 0 0 0 0 0 0 0 0 0 0
  94188. - 0 0 0 0 0 0 0 0 0 0 0 0
  94189. - 0 0 0 0 0 0 0 0 0 0 0 0
  94190. - 0 0 0 0 0 0 0 0 0 0 0 0
  94191. - 0 0 0 0 0 0 0 0 0 0 0 0
  94192. - 0 0 0 0 0 0 0 0 0 0 0 0
  94193. - 0 0 0 0 0 0 0 0 0 0 0 0
  94194. - 0 0 0 0 0 0 10 10 10 34 34 34
  94195. - 74 74 74 74 74 74 2 2 6 6 6 6
  94196. -144 144 144 198 198 198 190 190 190 178 166 146
  94197. -154 121 60 156 107 11 156 107 11 168 124 44
  94198. -174 154 114 187 187 187 190 190 190 210 210 210
  94199. -246 246 246 253 253 253 253 253 253 182 182 182
  94200. - 6 6 6 2 2 6 2 2 6 2 2 6
  94201. - 2 2 6 2 2 6 2 2 6 62 62 62
  94202. - 74 74 74 34 34 34 14 14 14 0 0 0
  94203. - 0 0 0 0 0 0 0 0 0 0 0 0
  94204. - 0 0 0 0 0 0 0 0 0 0 0 0
  94205. - 0 0 0 0 0 0 0 0 0 0 0 0
  94206. - 0 0 0 0 0 0 0 0 0 0 0 0
  94207. - 0 0 0 0 0 0 0 0 0 0 0 0
  94208. - 0 0 0 0 0 0 0 0 0 0 0 0
  94209. - 0 0 0 0 0 0 0 0 0 0 0 0
  94210. - 0 0 0 0 0 0 0 0 0 0 0 0
  94211. - 0 0 0 0 0 0 0 0 0 0 0 0
  94212. - 0 0 0 0 0 0 0 0 0 0 0 0
  94213. - 0 0 0 0 0 0 0 0 0 0 0 0
  94214. - 0 0 0 10 10 10 22 22 22 54 54 54
  94215. - 94 94 94 18 18 18 2 2 6 46 46 46
  94216. -234 234 234 221 221 221 190 190 190 190 190 190
  94217. -190 190 190 187 187 187 187 187 187 190 190 190
  94218. -190 190 190 195 195 195 214 214 214 242 242 242
  94219. -253 253 253 253 253 253 253 253 253 253 253 253
  94220. - 82 82 82 2 2 6 2 2 6 2 2 6
  94221. - 2 2 6 2 2 6 2 2 6 14 14 14
  94222. - 86 86 86 54 54 54 22 22 22 6 6 6
  94223. - 0 0 0 0 0 0 0 0 0 0 0 0
  94224. - 0 0 0 0 0 0 0 0 0 0 0 0
  94225. - 0 0 0 0 0 0 0 0 0 0 0 0
  94226. - 0 0 0 0 0 0 0 0 0 0 0 0
  94227. - 0 0 0 0 0 0 0 0 0 0 0 0
  94228. - 0 0 0 0 0 0 0 0 0 0 0 0
  94229. - 0 0 0 0 0 0 0 0 0 0 0 0
  94230. - 0 0 0 0 0 0 0 0 0 0 0 0
  94231. - 0 0 0 0 0 0 0 0 0 0 0 0
  94232. - 0 0 0 0 0 0 0 0 0 0 0 0
  94233. - 0 0 0 0 0 0 0 0 0 0 0 0
  94234. - 6 6 6 18 18 18 46 46 46 90 90 90
  94235. - 46 46 46 18 18 18 6 6 6 182 182 182
  94236. -253 253 253 246 246 246 206 206 206 190 190 190
  94237. -190 190 190 190 190 190 190 190 190 190 190 190
  94238. -206 206 206 231 231 231 250 250 250 253 253 253
  94239. -253 253 253 253 253 253 253 253 253 253 253 253
  94240. -202 202 202 14 14 14 2 2 6 2 2 6
  94241. - 2 2 6 2 2 6 2 2 6 2 2 6
  94242. - 42 42 42 86 86 86 42 42 42 18 18 18
  94243. - 6 6 6 0 0 0 0 0 0 0 0 0
  94244. - 0 0 0 0 0 0 0 0 0 0 0 0
  94245. - 0 0 0 0 0 0 0 0 0 0 0 0
  94246. - 0 0 0 0 0 0 0 0 0 0 0 0
  94247. - 0 0 0 0 0 0 0 0 0 0 0 0
  94248. - 0 0 0 0 0 0 0 0 0 0 0 0
  94249. - 0 0 0 0 0 0 0 0 0 0 0 0
  94250. - 0 0 0 0 0 0 0 0 0 0 0 0
  94251. - 0 0 0 0 0 0 0 0 0 0 0 0
  94252. - 0 0 0 0 0 0 0 0 0 0 0 0
  94253. - 0 0 0 0 0 0 0 0 0 6 6 6
  94254. - 14 14 14 38 38 38 74 74 74 66 66 66
  94255. - 2 2 6 6 6 6 90 90 90 250 250 250
  94256. -253 253 253 253 253 253 238 238 238 198 198 198
  94257. -190 190 190 190 190 190 195 195 195 221 221 221
  94258. -246 246 246 253 253 253 253 253 253 253 253 253
  94259. -253 253 253 253 253 253 253 253 253 253 253 253
  94260. -253 253 253 82 82 82 2 2 6 2 2 6
  94261. - 2 2 6 2 2 6 2 2 6 2 2 6
  94262. - 2 2 6 78 78 78 70 70 70 34 34 34
  94263. - 14 14 14 6 6 6 0 0 0 0 0 0
  94264. - 0 0 0 0 0 0 0 0 0 0 0 0
  94265. - 0 0 0 0 0 0 0 0 0 0 0 0
  94266. - 0 0 0 0 0 0 0 0 0 0 0 0
  94267. - 0 0 0 0 0 0 0 0 0 0 0 0
  94268. - 0 0 0 0 0 0 0 0 0 0 0 0
  94269. - 0 0 0 0 0 0 0 0 0 0 0 0
  94270. - 0 0 0 0 0 0 0 0 0 0 0 0
  94271. - 0 0 0 0 0 0 0 0 0 0 0 0
  94272. - 0 0 0 0 0 0 0 0 0 0 0 0
  94273. - 0 0 0 0 0 0 0 0 0 14 14 14
  94274. - 34 34 34 66 66 66 78 78 78 6 6 6
  94275. - 2 2 6 18 18 18 218 218 218 253 253 253
  94276. -253 253 253 253 253 253 253 253 253 246 246 246
  94277. -226 226 226 231 231 231 246 246 246 253 253 253
  94278. -253 253 253 253 253 253 253 253 253 253 253 253
  94279. -253 253 253 253 253 253 253 253 253 253 253 253
  94280. -253 253 253 178 178 178 2 2 6 2 2 6
  94281. - 2 2 6 2 2 6 2 2 6 2 2 6
  94282. - 2 2 6 18 18 18 90 90 90 62 62 62
  94283. - 30 30 30 10 10 10 0 0 0 0 0 0
  94284. - 0 0 0 0 0 0 0 0 0 0 0 0
  94285. - 0 0 0 0 0 0 0 0 0 0 0 0
  94286. - 0 0 0 0 0 0 0 0 0 0 0 0
  94287. - 0 0 0 0 0 0 0 0 0 0 0 0
  94288. - 0 0 0 0 0 0 0 0 0 0 0 0
  94289. - 0 0 0 0 0 0 0 0 0 0 0 0
  94290. - 0 0 0 0 0 0 0 0 0 0 0 0
  94291. - 0 0 0 0 0 0 0 0 0 0 0 0
  94292. - 0 0 0 0 0 0 0 0 0 0 0 0
  94293. - 0 0 0 0 0 0 10 10 10 26 26 26
  94294. - 58 58 58 90 90 90 18 18 18 2 2 6
  94295. - 2 2 6 110 110 110 253 253 253 253 253 253
  94296. -253 253 253 253 253 253 253 253 253 253 253 253
  94297. -250 250 250 253 253 253 253 253 253 253 253 253
  94298. -253 253 253 253 253 253 253 253 253 253 253 253
  94299. -253 253 253 253 253 253 253 253 253 253 253 253
  94300. -253 253 253 231 231 231 18 18 18 2 2 6
  94301. - 2 2 6 2 2 6 2 2 6 2 2 6
  94302. - 2 2 6 2 2 6 18 18 18 94 94 94
  94303. - 54 54 54 26 26 26 10 10 10 0 0 0
  94304. - 0 0 0 0 0 0 0 0 0 0 0 0
  94305. - 0 0 0 0 0 0 0 0 0 0 0 0
  94306. - 0 0 0 0 0 0 0 0 0 0 0 0
  94307. - 0 0 0 0 0 0 0 0 0 0 0 0
  94308. - 0 0 0 0 0 0 0 0 0 0 0 0
  94309. - 0 0 0 0 0 0 0 0 0 0 0 0
  94310. - 0 0 0 0 0 0 0 0 0 0 0 0
  94311. - 0 0 0 0 0 0 0 0 0 0 0 0
  94312. - 0 0 0 0 0 0 0 0 0 0 0 0
  94313. - 0 0 0 6 6 6 22 22 22 50 50 50
  94314. - 90 90 90 26 26 26 2 2 6 2 2 6
  94315. - 14 14 14 195 195 195 250 250 250 253 253 253
  94316. -253 253 253 253 253 253 253 253 253 253 253 253
  94317. -253 253 253 253 253 253 253 253 253 253 253 253
  94318. -253 253 253 253 253 253 253 253 253 253 253 253
  94319. -253 253 253 253 253 253 253 253 253 253 253 253
  94320. -250 250 250 242 242 242 54 54 54 2 2 6
  94321. - 2 2 6 2 2 6 2 2 6 2 2 6
  94322. - 2 2 6 2 2 6 2 2 6 38 38 38
  94323. - 86 86 86 50 50 50 22 22 22 6 6 6
  94324. - 0 0 0 0 0 0 0 0 0 0 0 0
  94325. - 0 0 0 0 0 0 0 0 0 0 0 0
  94326. - 0 0 0 0 0 0 0 0 0 0 0 0
  94327. - 0 0 0 0 0 0 0 0 0 0 0 0
  94328. - 0 0 0 0 0 0 0 0 0 0 0 0
  94329. - 0 0 0 0 0 0 0 0 0 0 0 0
  94330. - 0 0 0 0 0 0 0 0 0 0 0 0
  94331. - 0 0 0 0 0 0 0 0 0 0 0 0
  94332. - 0 0 0 0 0 0 0 0 0 0 0 0
  94333. - 6 6 6 14 14 14 38 38 38 82 82 82
  94334. - 34 34 34 2 2 6 2 2 6 2 2 6
  94335. - 42 42 42 195 195 195 246 246 246 253 253 253
  94336. -253 253 253 253 253 253 253 253 253 250 250 250
  94337. -242 242 242 242 242 242 250 250 250 253 253 253
  94338. -253 253 253 253 253 253 253 253 253 253 253 253
  94339. -253 253 253 250 250 250 246 246 246 238 238 238
  94340. -226 226 226 231 231 231 101 101 101 6 6 6
  94341. - 2 2 6 2 2 6 2 2 6 2 2 6
  94342. - 2 2 6 2 2 6 2 2 6 2 2 6
  94343. - 38 38 38 82 82 82 42 42 42 14 14 14
  94344. - 6 6 6 0 0 0 0 0 0 0 0 0
  94345. - 0 0 0 0 0 0 0 0 0 0 0 0
  94346. - 0 0 0 0 0 0 0 0 0 0 0 0
  94347. - 0 0 0 0 0 0 0 0 0 0 0 0
  94348. - 0 0 0 0 0 0 0 0 0 0 0 0
  94349. - 0 0 0 0 0 0 0 0 0 0 0 0
  94350. - 0 0 0 0 0 0 0 0 0 0 0 0
  94351. - 0 0 0 0 0 0 0 0 0 0 0 0
  94352. - 0 0 0 0 0 0 0 0 0 0 0 0
  94353. - 10 10 10 26 26 26 62 62 62 66 66 66
  94354. - 2 2 6 2 2 6 2 2 6 6 6 6
  94355. - 70 70 70 170 170 170 206 206 206 234 234 234
  94356. -246 246 246 250 250 250 250 250 250 238 238 238
  94357. -226 226 226 231 231 231 238 238 238 250 250 250
  94358. -250 250 250 250 250 250 246 246 246 231 231 231
  94359. -214 214 214 206 206 206 202 202 202 202 202 202
  94360. -198 198 198 202 202 202 182 182 182 18 18 18
  94361. - 2 2 6 2 2 6 2 2 6 2 2 6
  94362. - 2 2 6 2 2 6 2 2 6 2 2 6
  94363. - 2 2 6 62 62 62 66 66 66 30 30 30
  94364. - 10 10 10 0 0 0 0 0 0 0 0 0
  94365. - 0 0 0 0 0 0 0 0 0 0 0 0
  94366. - 0 0 0 0 0 0 0 0 0 0 0 0
  94367. - 0 0 0 0 0 0 0 0 0 0 0 0
  94368. - 0 0 0 0 0 0 0 0 0 0 0 0
  94369. - 0 0 0 0 0 0 0 0 0 0 0 0
  94370. - 0 0 0 0 0 0 0 0 0 0 0 0
  94371. - 0 0 0 0 0 0 0 0 0 0 0 0
  94372. - 0 0 0 0 0 0 0 0 0 0 0 0
  94373. - 14 14 14 42 42 42 82 82 82 18 18 18
  94374. - 2 2 6 2 2 6 2 2 6 10 10 10
  94375. - 94 94 94 182 182 182 218 218 218 242 242 242
  94376. -250 250 250 253 253 253 253 253 253 250 250 250
  94377. -234 234 234 253 253 253 253 253 253 253 253 253
  94378. -253 253 253 253 253 253 253 253 253 246 246 246
  94379. -238 238 238 226 226 226 210 210 210 202 202 202
  94380. -195 195 195 195 195 195 210 210 210 158 158 158
  94381. - 6 6 6 14 14 14 50 50 50 14 14 14
  94382. - 2 2 6 2 2 6 2 2 6 2 2 6
  94383. - 2 2 6 6 6 6 86 86 86 46 46 46
  94384. - 18 18 18 6 6 6 0 0 0 0 0 0
  94385. - 0 0 0 0 0 0 0 0 0 0 0 0
  94386. - 0 0 0 0 0 0 0 0 0 0 0 0
  94387. - 0 0 0 0 0 0 0 0 0 0 0 0
  94388. - 0 0 0 0 0 0 0 0 0 0 0 0
  94389. - 0 0 0 0 0 0 0 0 0 0 0 0
  94390. - 0 0 0 0 0 0 0 0 0 0 0 0
  94391. - 0 0 0 0 0 0 0 0 0 0 0 0
  94392. - 0 0 0 0 0 0 0 0 0 6 6 6
  94393. - 22 22 22 54 54 54 70 70 70 2 2 6
  94394. - 2 2 6 10 10 10 2 2 6 22 22 22
  94395. -166 166 166 231 231 231 250 250 250 253 253 253
  94396. -253 253 253 253 253 253 253 253 253 250 250 250
  94397. -242 242 242 253 253 253 253 253 253 253 253 253
  94398. -253 253 253 253 253 253 253 253 253 253 253 253
  94399. -253 253 253 253 253 253 253 253 253 246 246 246
  94400. -231 231 231 206 206 206 198 198 198 226 226 226
  94401. - 94 94 94 2 2 6 6 6 6 38 38 38
  94402. - 30 30 30 2 2 6 2 2 6 2 2 6
  94403. - 2 2 6 2 2 6 62 62 62 66 66 66
  94404. - 26 26 26 10 10 10 0 0 0 0 0 0
  94405. - 0 0 0 0 0 0 0 0 0 0 0 0
  94406. - 0 0 0 0 0 0 0 0 0 0 0 0
  94407. - 0 0 0 0 0 0 0 0 0 0 0 0
  94408. - 0 0 0 0 0 0 0 0 0 0 0 0
  94409. - 0 0 0 0 0 0 0 0 0 0 0 0
  94410. - 0 0 0 0 0 0 0 0 0 0 0 0
  94411. - 0 0 0 0 0 0 0 0 0 0 0 0
  94412. - 0 0 0 0 0 0 0 0 0 10 10 10
  94413. - 30 30 30 74 74 74 50 50 50 2 2 6
  94414. - 26 26 26 26 26 26 2 2 6 106 106 106
  94415. -238 238 238 253 253 253 253 253 253 253 253 253
  94416. -253 253 253 253 253 253 253 253 253 253 253 253
  94417. -253 253 253 253 253 253 253 253 253 253 253 253
  94418. -253 253 253 253 253 253 253 253 253 253 253 253
  94419. -253 253 253 253 253 253 253 253 253 253 253 253
  94420. -253 253 253 246 246 246 218 218 218 202 202 202
  94421. -210 210 210 14 14 14 2 2 6 2 2 6
  94422. - 30 30 30 22 22 22 2 2 6 2 2 6
  94423. - 2 2 6 2 2 6 18 18 18 86 86 86
  94424. - 42 42 42 14 14 14 0 0 0 0 0 0
  94425. - 0 0 0 0 0 0 0 0 0 0 0 0
  94426. - 0 0 0 0 0 0 0 0 0 0 0 0
  94427. - 0 0 0 0 0 0 0 0 0 0 0 0
  94428. - 0 0 0 0 0 0 0 0 0 0 0 0
  94429. - 0 0 0 0 0 0 0 0 0 0 0 0
  94430. - 0 0 0 0 0 0 0 0 0 0 0 0
  94431. - 0 0 0 0 0 0 0 0 0 0 0 0
  94432. - 0 0 0 0 0 0 0 0 0 14 14 14
  94433. - 42 42 42 90 90 90 22 22 22 2 2 6
  94434. - 42 42 42 2 2 6 18 18 18 218 218 218
  94435. -253 253 253 253 253 253 253 253 253 253 253 253
  94436. -253 253 253 253 253 253 253 253 253 253 253 253
  94437. -253 253 253 253 253 253 253 253 253 253 253 253
  94438. -253 253 253 253 253 253 253 253 253 253 253 253
  94439. -253 253 253 253 253 253 253 253 253 253 253 253
  94440. -253 253 253 253 253 253 250 250 250 221 221 221
  94441. -218 218 218 101 101 101 2 2 6 14 14 14
  94442. - 18 18 18 38 38 38 10 10 10 2 2 6
  94443. - 2 2 6 2 2 6 2 2 6 78 78 78
  94444. - 58 58 58 22 22 22 6 6 6 0 0 0
  94445. - 0 0 0 0 0 0 0 0 0 0 0 0
  94446. - 0 0 0 0 0 0 0 0 0 0 0 0
  94447. - 0 0 0 0 0 0 0 0 0 0 0 0
  94448. - 0 0 0 0 0 0 0 0 0 0 0 0
  94449. - 0 0 0 0 0 0 0 0 0 0 0 0
  94450. - 0 0 0 0 0 0 0 0 0 0 0 0
  94451. - 0 0 0 0 0 0 0 0 0 0 0 0
  94452. - 0 0 0 0 0 0 6 6 6 18 18 18
  94453. - 54 54 54 82 82 82 2 2 6 26 26 26
  94454. - 22 22 22 2 2 6 123 123 123 253 253 253
  94455. -253 253 253 253 253 253 253 253 253 253 253 253
  94456. -253 253 253 253 253 253 253 253 253 253 253 253
  94457. -253 253 253 253 253 253 253 253 253 253 253 253
  94458. -253 253 253 253 253 253 253 253 253 253 253 253
  94459. -253 253 253 253 253 253 253 253 253 253 253 253
  94460. -253 253 253 253 253 253 253 253 253 250 250 250
  94461. -238 238 238 198 198 198 6 6 6 38 38 38
  94462. - 58 58 58 26 26 26 38 38 38 2 2 6
  94463. - 2 2 6 2 2 6 2 2 6 46 46 46
  94464. - 78 78 78 30 30 30 10 10 10 0 0 0
  94465. - 0 0 0 0 0 0 0 0 0 0 0 0
  94466. - 0 0 0 0 0 0 0 0 0 0 0 0
  94467. - 0 0 0 0 0 0 0 0 0 0 0 0
  94468. - 0 0 0 0 0 0 0 0 0 0 0 0
  94469. - 0 0 0 0 0 0 0 0 0 0 0 0
  94470. - 0 0 0 0 0 0 0 0 0 0 0 0
  94471. - 0 0 0 0 0 0 0 0 0 0 0 0
  94472. - 0 0 0 0 0 0 10 10 10 30 30 30
  94473. - 74 74 74 58 58 58 2 2 6 42 42 42
  94474. - 2 2 6 22 22 22 231 231 231 253 253 253
  94475. -253 253 253 253 253 253 253 253 253 253 253 253
  94476. -253 253 253 253 253 253 253 253 253 250 250 250
  94477. -253 253 253 253 253 253 253 253 253 253 253 253
  94478. -253 253 253 253 253 253 253 253 253 253 253 253
  94479. -253 253 253 253 253 253 253 253 253 253 253 253
  94480. -253 253 253 253 253 253 253 253 253 253 253 253
  94481. -253 253 253 246 246 246 46 46 46 38 38 38
  94482. - 42 42 42 14 14 14 38 38 38 14 14 14
  94483. - 2 2 6 2 2 6 2 2 6 6 6 6
  94484. - 86 86 86 46 46 46 14 14 14 0 0 0
  94485. - 0 0 0 0 0 0 0 0 0 0 0 0
  94486. - 0 0 0 0 0 0 0 0 0 0 0 0
  94487. - 0 0 0 0 0 0 0 0 0 0 0 0
  94488. - 0 0 0 0 0 0 0 0 0 0 0 0
  94489. - 0 0 0 0 0 0 0 0 0 0 0 0
  94490. - 0 0 0 0 0 0 0 0 0 0 0 0
  94491. - 0 0 0 0 0 0 0 0 0 0 0 0
  94492. - 0 0 0 6 6 6 14 14 14 42 42 42
  94493. - 90 90 90 18 18 18 18 18 18 26 26 26
  94494. - 2 2 6 116 116 116 253 253 253 253 253 253
  94495. -253 253 253 253 253 253 253 253 253 253 253 253
  94496. -253 253 253 253 253 253 250 250 250 238 238 238
  94497. -253 253 253 253 253 253 253 253 253 253 253 253
  94498. -253 253 253 253 253 253 253 253 253 253 253 253
  94499. -253 253 253 253 253 253 253 253 253 253 253 253
  94500. -253 253 253 253 253 253 253 253 253 253 253 253
  94501. -253 253 253 253 253 253 94 94 94 6 6 6
  94502. - 2 2 6 2 2 6 10 10 10 34 34 34
  94503. - 2 2 6 2 2 6 2 2 6 2 2 6
  94504. - 74 74 74 58 58 58 22 22 22 6 6 6
  94505. - 0 0 0 0 0 0 0 0 0 0 0 0
  94506. - 0 0 0 0 0 0 0 0 0 0 0 0
  94507. - 0 0 0 0 0 0 0 0 0 0 0 0
  94508. - 0 0 0 0 0 0 0 0 0 0 0 0
  94509. - 0 0 0 0 0 0 0 0 0 0 0 0
  94510. - 0 0 0 0 0 0 0 0 0 0 0 0
  94511. - 0 0 0 0 0 0 0 0 0 0 0 0
  94512. - 0 0 0 10 10 10 26 26 26 66 66 66
  94513. - 82 82 82 2 2 6 38 38 38 6 6 6
  94514. - 14 14 14 210 210 210 253 253 253 253 253 253
  94515. -253 253 253 253 253 253 253 253 253 253 253 253
  94516. -253 253 253 253 253 253 246 246 246 242 242 242
  94517. -253 253 253 253 253 253 253 253 253 253 253 253
  94518. -253 253 253 253 253 253 253 253 253 253 253 253
  94519. -253 253 253 253 253 253 253 253 253 253 253 253
  94520. -253 253 253 253 253 253 253 253 253 253 253 253
  94521. -253 253 253 253 253 253 144 144 144 2 2 6
  94522. - 2 2 6 2 2 6 2 2 6 46 46 46
  94523. - 2 2 6 2 2 6 2 2 6 2 2 6
  94524. - 42 42 42 74 74 74 30 30 30 10 10 10
  94525. - 0 0 0 0 0 0 0 0 0 0 0 0
  94526. - 0 0 0 0 0 0 0 0 0 0 0 0
  94527. - 0 0 0 0 0 0 0 0 0 0 0 0
  94528. - 0 0 0 0 0 0 0 0 0 0 0 0
  94529. - 0 0 0 0 0 0 0 0 0 0 0 0
  94530. - 0 0 0 0 0 0 0 0 0 0 0 0
  94531. - 0 0 0 0 0 0 0 0 0 0 0 0
  94532. - 6 6 6 14 14 14 42 42 42 90 90 90
  94533. - 26 26 26 6 6 6 42 42 42 2 2 6
  94534. - 74 74 74 250 250 250 253 253 253 253 253 253
  94535. -253 253 253 253 253 253 253 253 253 253 253 253
  94536. -253 253 253 253 253 253 242 242 242 242 242 242
  94537. -253 253 253 253 253 253 253 253 253 253 253 253
  94538. -253 253 253 253 253 253 253 253 253 253 253 253
  94539. -253 253 253 253 253 253 253 253 253 253 253 253
  94540. -253 253 253 253 253 253 253 253 253 253 253 253
  94541. -253 253 253 253 253 253 182 182 182 2 2 6
  94542. - 2 2 6 2 2 6 2 2 6 46 46 46
  94543. - 2 2 6 2 2 6 2 2 6 2 2 6
  94544. - 10 10 10 86 86 86 38 38 38 10 10 10
  94545. - 0 0 0 0 0 0 0 0 0 0 0 0
  94546. - 0 0 0 0 0 0 0 0 0 0 0 0
  94547. - 0 0 0 0 0 0 0 0 0 0 0 0
  94548. - 0 0 0 0 0 0 0 0 0 0 0 0
  94549. - 0 0 0 0 0 0 0 0 0 0 0 0
  94550. - 0 0 0 0 0 0 0 0 0 0 0 0
  94551. - 0 0 0 0 0 0 0 0 0 0 0 0
  94552. - 10 10 10 26 26 26 66 66 66 82 82 82
  94553. - 2 2 6 22 22 22 18 18 18 2 2 6
  94554. -149 149 149 253 253 253 253 253 253 253 253 253
  94555. -253 253 253 253 253 253 253 253 253 253 253 253
  94556. -253 253 253 253 253 253 234 234 234 242 242 242
  94557. -253 253 253 253 253 253 253 253 253 253 253 253
  94558. -253 253 253 253 253 253 253 253 253 253 253 253
  94559. -253 253 253 253 253 253 253 253 253 253 253 253
  94560. -253 253 253 253 253 253 253 253 253 253 253 253
  94561. -253 253 253 253 253 253 206 206 206 2 2 6
  94562. - 2 2 6 2 2 6 2 2 6 38 38 38
  94563. - 2 2 6 2 2 6 2 2 6 2 2 6
  94564. - 6 6 6 86 86 86 46 46 46 14 14 14
  94565. - 0 0 0 0 0 0 0 0 0 0 0 0
  94566. - 0 0 0 0 0 0 0 0 0 0 0 0
  94567. - 0 0 0 0 0 0 0 0 0 0 0 0
  94568. - 0 0 0 0 0 0 0 0 0 0 0 0
  94569. - 0 0 0 0 0 0 0 0 0 0 0 0
  94570. - 0 0 0 0 0 0 0 0 0 0 0 0
  94571. - 0 0 0 0 0 0 0 0 0 6 6 6
  94572. - 18 18 18 46 46 46 86 86 86 18 18 18
  94573. - 2 2 6 34 34 34 10 10 10 6 6 6
  94574. -210 210 210 253 253 253 253 253 253 253 253 253
  94575. -253 253 253 253 253 253 253 253 253 253 253 253
  94576. -253 253 253 253 253 253 234 234 234 242 242 242
  94577. -253 253 253 253 253 253 253 253 253 253 253 253
  94578. -253 253 253 253 253 253 253 253 253 253 253 253
  94579. -253 253 253 253 253 253 253 253 253 253 253 253
  94580. -253 253 253 253 253 253 253 253 253 253 253 253
  94581. -253 253 253 253 253 253 221 221 221 6 6 6
  94582. - 2 2 6 2 2 6 6 6 6 30 30 30
  94583. - 2 2 6 2 2 6 2 2 6 2 2 6
  94584. - 2 2 6 82 82 82 54 54 54 18 18 18
  94585. - 6 6 6 0 0 0 0 0 0 0 0 0
  94586. - 0 0 0 0 0 0 0 0 0 0 0 0
  94587. - 0 0 0 0 0 0 0 0 0 0 0 0
  94588. - 0 0 0 0 0 0 0 0 0 0 0 0
  94589. - 0 0 0 0 0 0 0 0 0 0 0 0
  94590. - 0 0 0 0 0 0 0 0 0 0 0 0
  94591. - 0 0 0 0 0 0 0 0 0 10 10 10
  94592. - 26 26 26 66 66 66 62 62 62 2 2 6
  94593. - 2 2 6 38 38 38 10 10 10 26 26 26
  94594. -238 238 238 253 253 253 253 253 253 253 253 253
  94595. -253 253 253 253 253 253 253 253 253 253 253 253
  94596. -253 253 253 253 253 253 231 231 231 238 238 238
  94597. -253 253 253 253 253 253 253 253 253 253 253 253
  94598. -253 253 253 253 253 253 253 253 253 253 253 253
  94599. -253 253 253 253 253 253 253 253 253 253 253 253
  94600. -253 253 253 253 253 253 253 253 253 253 253 253
  94601. -253 253 253 253 253 253 231 231 231 6 6 6
  94602. - 2 2 6 2 2 6 10 10 10 30 30 30
  94603. - 2 2 6 2 2 6 2 2 6 2 2 6
  94604. - 2 2 6 66 66 66 58 58 58 22 22 22
  94605. - 6 6 6 0 0 0 0 0 0 0 0 0
  94606. - 0 0 0 0 0 0 0 0 0 0 0 0
  94607. - 0 0 0 0 0 0 0 0 0 0 0 0
  94608. - 0 0 0 0 0 0 0 0 0 0 0 0
  94609. - 0 0 0 0 0 0 0 0 0 0 0 0
  94610. - 0 0 0 0 0 0 0 0 0 0 0 0
  94611. - 0 0 0 0 0 0 0 0 0 10 10 10
  94612. - 38 38 38 78 78 78 6 6 6 2 2 6
  94613. - 2 2 6 46 46 46 14 14 14 42 42 42
  94614. -246 246 246 253 253 253 253 253 253 253 253 253
  94615. -253 253 253 253 253 253 253 253 253 253 253 253
  94616. -253 253 253 253 253 253 231 231 231 242 242 242
  94617. -253 253 253 253 253 253 253 253 253 253 253 253
  94618. -253 253 253 253 253 253 253 253 253 253 253 253
  94619. -253 253 253 253 253 253 253 253 253 253 253 253
  94620. -253 253 253 253 253 253 253 253 253 253 253 253
  94621. -253 253 253 253 253 253 234 234 234 10 10 10
  94622. - 2 2 6 2 2 6 22 22 22 14 14 14
  94623. - 2 2 6 2 2 6 2 2 6 2 2 6
  94624. - 2 2 6 66 66 66 62 62 62 22 22 22
  94625. - 6 6 6 0 0 0 0 0 0 0 0 0
  94626. - 0 0 0 0 0 0 0 0 0 0 0 0
  94627. - 0 0 0 0 0 0 0 0 0 0 0 0
  94628. - 0 0 0 0 0 0 0 0 0 0 0 0
  94629. - 0 0 0 0 0 0 0 0 0 0 0 0
  94630. - 0 0 0 0 0 0 0 0 0 0 0 0
  94631. - 0 0 0 0 0 0 6 6 6 18 18 18
  94632. - 50 50 50 74 74 74 2 2 6 2 2 6
  94633. - 14 14 14 70 70 70 34 34 34 62 62 62
  94634. -250 250 250 253 253 253 253 253 253 253 253 253
  94635. -253 253 253 253 253 253 253 253 253 253 253 253
  94636. -253 253 253 253 253 253 231 231 231 246 246 246
  94637. -253 253 253 253 253 253 253 253 253 253 253 253
  94638. -253 253 253 253 253 253 253 253 253 253 253 253
  94639. -253 253 253 253 253 253 253 253 253 253 253 253
  94640. -253 253 253 253 253 253 253 253 253 253 253 253
  94641. -253 253 253 253 253 253 234 234 234 14 14 14
  94642. - 2 2 6 2 2 6 30 30 30 2 2 6
  94643. - 2 2 6 2 2 6 2 2 6 2 2 6
  94644. - 2 2 6 66 66 66 62 62 62 22 22 22
  94645. - 6 6 6 0 0 0 0 0 0 0 0 0
  94646. - 0 0 0 0 0 0 0 0 0 0 0 0
  94647. - 0 0 0 0 0 0 0 0 0 0 0 0
  94648. - 0 0 0 0 0 0 0 0 0 0 0 0
  94649. - 0 0 0 0 0 0 0 0 0 0 0 0
  94650. - 0 0 0 0 0 0 0 0 0 0 0 0
  94651. - 0 0 0 0 0 0 6 6 6 18 18 18
  94652. - 54 54 54 62 62 62 2 2 6 2 2 6
  94653. - 2 2 6 30 30 30 46 46 46 70 70 70
  94654. -250 250 250 253 253 253 253 253 253 253 253 253
  94655. -253 253 253 253 253 253 253 253 253 253 253 253
  94656. -253 253 253 253 253 253 231 231 231 246 246 246
  94657. -253 253 253 253 253 253 253 253 253 253 253 253
  94658. -253 253 253 253 253 253 253 253 253 253 253 253
  94659. -253 253 253 253 253 253 253 253 253 253 253 253
  94660. -253 253 253 253 253 253 253 253 253 253 253 253
  94661. -253 253 253 253 253 253 226 226 226 10 10 10
  94662. - 2 2 6 6 6 6 30 30 30 2 2 6
  94663. - 2 2 6 2 2 6 2 2 6 2 2 6
  94664. - 2 2 6 66 66 66 58 58 58 22 22 22
  94665. - 6 6 6 0 0 0 0 0 0 0 0 0
  94666. - 0 0 0 0 0 0 0 0 0 0 0 0
  94667. - 0 0 0 0 0 0 0 0 0 0 0 0
  94668. - 0 0 0 0 0 0 0 0 0 0 0 0
  94669. - 0 0 0 0 0 0 0 0 0 0 0 0
  94670. - 0 0 0 0 0 0 0 0 0 0 0 0
  94671. - 0 0 0 0 0 0 6 6 6 22 22 22
  94672. - 58 58 58 62 62 62 2 2 6 2 2 6
  94673. - 2 2 6 2 2 6 30 30 30 78 78 78
  94674. -250 250 250 253 253 253 253 253 253 253 253 253
  94675. -253 253 253 253 253 253 253 253 253 253 253 253
  94676. -253 253 253 253 253 253 231 231 231 246 246 246
  94677. -253 253 253 253 253 253 253 253 253 253 253 253
  94678. -253 253 253 253 253 253 253 253 253 253 253 253
  94679. -253 253 253 253 253 253 253 253 253 253 253 253
  94680. -253 253 253 253 253 253 253 253 253 253 253 253
  94681. -253 253 253 253 253 253 206 206 206 2 2 6
  94682. - 22 22 22 34 34 34 18 14 6 22 22 22
  94683. - 26 26 26 18 18 18 6 6 6 2 2 6
  94684. - 2 2 6 82 82 82 54 54 54 18 18 18
  94685. - 6 6 6 0 0 0 0 0 0 0 0 0
  94686. - 0 0 0 0 0 0 0 0 0 0 0 0
  94687. - 0 0 0 0 0 0 0 0 0 0 0 0
  94688. - 0 0 0 0 0 0 0 0 0 0 0 0
  94689. - 0 0 0 0 0 0 0 0 0 0 0 0
  94690. - 0 0 0 0 0 0 0 0 0 0 0 0
  94691. - 0 0 0 0 0 0 6 6 6 26 26 26
  94692. - 62 62 62 106 106 106 74 54 14 185 133 11
  94693. -210 162 10 121 92 8 6 6 6 62 62 62
  94694. -238 238 238 253 253 253 253 253 253 253 253 253
  94695. -253 253 253 253 253 253 253 253 253 253 253 253
  94696. -253 253 253 253 253 253 231 231 231 246 246 246
  94697. -253 253 253 253 253 253 253 253 253 253 253 253
  94698. -253 253 253 253 253 253 253 253 253 253 253 253
  94699. -253 253 253 253 253 253 253 253 253 253 253 253
  94700. -253 253 253 253 253 253 253 253 253 253 253 253
  94701. -253 253 253 253 253 253 158 158 158 18 18 18
  94702. - 14 14 14 2 2 6 2 2 6 2 2 6
  94703. - 6 6 6 18 18 18 66 66 66 38 38 38
  94704. - 6 6 6 94 94 94 50 50 50 18 18 18
  94705. - 6 6 6 0 0 0 0 0 0 0 0 0
  94706. - 0 0 0 0 0 0 0 0 0 0 0 0
  94707. - 0 0 0 0 0 0 0 0 0 0 0 0
  94708. - 0 0 0 0 0 0 0 0 0 0 0 0
  94709. - 0 0 0 0 0 0 0 0 0 0 0 0
  94710. - 0 0 0 0 0 0 0 0 0 6 6 6
  94711. - 10 10 10 10 10 10 18 18 18 38 38 38
  94712. - 78 78 78 142 134 106 216 158 10 242 186 14
  94713. -246 190 14 246 190 14 156 118 10 10 10 10
  94714. - 90 90 90 238 238 238 253 253 253 253 253 253
  94715. -253 253 253 253 253 253 253 253 253 253 253 253
  94716. -253 253 253 253 253 253 231 231 231 250 250 250
  94717. -253 253 253 253 253 253 253 253 253 253 253 253
  94718. -253 253 253 253 253 253 253 253 253 253 253 253
  94719. -253 253 253 253 253 253 253 253 253 253 253 253
  94720. -253 253 253 253 253 253 253 253 253 246 230 190
  94721. -238 204 91 238 204 91 181 142 44 37 26 9
  94722. - 2 2 6 2 2 6 2 2 6 2 2 6
  94723. - 2 2 6 2 2 6 38 38 38 46 46 46
  94724. - 26 26 26 106 106 106 54 54 54 18 18 18
  94725. - 6 6 6 0 0 0 0 0 0 0 0 0
  94726. - 0 0 0 0 0 0 0 0 0 0 0 0
  94727. - 0 0 0 0 0 0 0 0 0 0 0 0
  94728. - 0 0 0 0 0 0 0 0 0 0 0 0
  94729. - 0 0 0 0 0 0 0 0 0 0 0 0
  94730. - 0 0 0 6 6 6 14 14 14 22 22 22
  94731. - 30 30 30 38 38 38 50 50 50 70 70 70
  94732. -106 106 106 190 142 34 226 170 11 242 186 14
  94733. -246 190 14 246 190 14 246 190 14 154 114 10
  94734. - 6 6 6 74 74 74 226 226 226 253 253 253
  94735. -253 253 253 253 253 253 253 253 253 253 253 253
  94736. -253 253 253 253 253 253 231 231 231 250 250 250
  94737. -253 253 253 253 253 253 253 253 253 253 253 253
  94738. -253 253 253 253 253 253 253 253 253 253 253 253
  94739. -253 253 253 253 253 253 253 253 253 253 253 253
  94740. -253 253 253 253 253 253 253 253 253 228 184 62
  94741. -241 196 14 241 208 19 232 195 16 38 30 10
  94742. - 2 2 6 2 2 6 2 2 6 2 2 6
  94743. - 2 2 6 6 6 6 30 30 30 26 26 26
  94744. -203 166 17 154 142 90 66 66 66 26 26 26
  94745. - 6 6 6 0 0 0 0 0 0 0 0 0
  94746. - 0 0 0 0 0 0 0 0 0 0 0 0
  94747. - 0 0 0 0 0 0 0 0 0 0 0 0
  94748. - 0 0 0 0 0 0 0 0 0 0 0 0
  94749. - 0 0 0 0 0 0 0 0 0 0 0 0
  94750. - 6 6 6 18 18 18 38 38 38 58 58 58
  94751. - 78 78 78 86 86 86 101 101 101 123 123 123
  94752. -175 146 61 210 150 10 234 174 13 246 186 14
  94753. -246 190 14 246 190 14 246 190 14 238 190 10
  94754. -102 78 10 2 2 6 46 46 46 198 198 198
  94755. -253 253 253 253 253 253 253 253 253 253 253 253
  94756. -253 253 253 253 253 253 234 234 234 242 242 242
  94757. -253 253 253 253 253 253 253 253 253 253 253 253
  94758. -253 253 253 253 253 253 253 253 253 253 253 253
  94759. -253 253 253 253 253 253 253 253 253 253 253 253
  94760. -253 253 253 253 253 253 253 253 253 224 178 62
  94761. -242 186 14 241 196 14 210 166 10 22 18 6
  94762. - 2 2 6 2 2 6 2 2 6 2 2 6
  94763. - 2 2 6 2 2 6 6 6 6 121 92 8
  94764. -238 202 15 232 195 16 82 82 82 34 34 34
  94765. - 10 10 10 0 0 0 0 0 0 0 0 0
  94766. - 0 0 0 0 0 0 0 0 0 0 0 0
  94767. - 0 0 0 0 0 0 0 0 0 0 0 0
  94768. - 0 0 0 0 0 0 0 0 0 0 0 0
  94769. - 0 0 0 0 0 0 0 0 0 0 0 0
  94770. - 14 14 14 38 38 38 70 70 70 154 122 46
  94771. -190 142 34 200 144 11 197 138 11 197 138 11
  94772. -213 154 11 226 170 11 242 186 14 246 190 14
  94773. -246 190 14 246 190 14 246 190 14 246 190 14
  94774. -225 175 15 46 32 6 2 2 6 22 22 22
  94775. -158 158 158 250 250 250 253 253 253 253 253 253
  94776. -253 253 253 253 253 253 253 253 253 253 253 253
  94777. -253 253 253 253 253 253 253 253 253 253 253 253
  94778. -253 253 253 253 253 253 253 253 253 253 253 253
  94779. -253 253 253 253 253 253 253 253 253 253 253 253
  94780. -253 253 253 250 250 250 242 242 242 224 178 62
  94781. -239 182 13 236 186 11 213 154 11 46 32 6
  94782. - 2 2 6 2 2 6 2 2 6 2 2 6
  94783. - 2 2 6 2 2 6 61 42 6 225 175 15
  94784. -238 190 10 236 186 11 112 100 78 42 42 42
  94785. - 14 14 14 0 0 0 0 0 0 0 0 0
  94786. - 0 0 0 0 0 0 0 0 0 0 0 0
  94787. - 0 0 0 0 0 0 0 0 0 0 0 0
  94788. - 0 0 0 0 0 0 0 0 0 0 0 0
  94789. - 0 0 0 0 0 0 0 0 0 6 6 6
  94790. - 22 22 22 54 54 54 154 122 46 213 154 11
  94791. -226 170 11 230 174 11 226 170 11 226 170 11
  94792. -236 178 12 242 186 14 246 190 14 246 190 14
  94793. -246 190 14 246 190 14 246 190 14 246 190 14
  94794. -241 196 14 184 144 12 10 10 10 2 2 6
  94795. - 6 6 6 116 116 116 242 242 242 253 253 253
  94796. -253 253 253 253 253 253 253 253 253 253 253 253
  94797. -253 253 253 253 253 253 253 253 253 253 253 253
  94798. -253 253 253 253 253 253 253 253 253 253 253 253
  94799. -253 253 253 253 253 253 253 253 253 253 253 253
  94800. -253 253 253 231 231 231 198 198 198 214 170 54
  94801. -236 178 12 236 178 12 210 150 10 137 92 6
  94802. - 18 14 6 2 2 6 2 2 6 2 2 6
  94803. - 6 6 6 70 47 6 200 144 11 236 178 12
  94804. -239 182 13 239 182 13 124 112 88 58 58 58
  94805. - 22 22 22 6 6 6 0 0 0 0 0 0
  94806. - 0 0 0 0 0 0 0 0 0 0 0 0
  94807. - 0 0 0 0 0 0 0 0 0 0 0 0
  94808. - 0 0 0 0 0 0 0 0 0 0 0 0
  94809. - 0 0 0 0 0 0 0 0 0 10 10 10
  94810. - 30 30 30 70 70 70 180 133 36 226 170 11
  94811. -239 182 13 242 186 14 242 186 14 246 186 14
  94812. -246 190 14 246 190 14 246 190 14 246 190 14
  94813. -246 190 14 246 190 14 246 190 14 246 190 14
  94814. -246 190 14 232 195 16 98 70 6 2 2 6
  94815. - 2 2 6 2 2 6 66 66 66 221 221 221
  94816. -253 253 253 253 253 253 253 253 253 253 253 253
  94817. -253 253 253 253 253 253 253 253 253 253 253 253
  94818. -253 253 253 253 253 253 253 253 253 253 253 253
  94819. -253 253 253 253 253 253 253 253 253 253 253 253
  94820. -253 253 253 206 206 206 198 198 198 214 166 58
  94821. -230 174 11 230 174 11 216 158 10 192 133 9
  94822. -163 110 8 116 81 8 102 78 10 116 81 8
  94823. -167 114 7 197 138 11 226 170 11 239 182 13
  94824. -242 186 14 242 186 14 162 146 94 78 78 78
  94825. - 34 34 34 14 14 14 6 6 6 0 0 0
  94826. - 0 0 0 0 0 0 0 0 0 0 0 0
  94827. - 0 0 0 0 0 0 0 0 0 0 0 0
  94828. - 0 0 0 0 0 0 0 0 0 0 0 0
  94829. - 0 0 0 0 0 0 0 0 0 6 6 6
  94830. - 30 30 30 78 78 78 190 142 34 226 170 11
  94831. -239 182 13 246 190 14 246 190 14 246 190 14
  94832. -246 190 14 246 190 14 246 190 14 246 190 14
  94833. -246 190 14 246 190 14 246 190 14 246 190 14
  94834. -246 190 14 241 196 14 203 166 17 22 18 6
  94835. - 2 2 6 2 2 6 2 2 6 38 38 38
  94836. -218 218 218 253 253 253 253 253 253 253 253 253
  94837. -253 253 253 253 253 253 253 253 253 253 253 253
  94838. -253 253 253 253 253 253 253 253 253 253 253 253
  94839. -253 253 253 253 253 253 253 253 253 253 253 253
  94840. -250 250 250 206 206 206 198 198 198 202 162 69
  94841. -226 170 11 236 178 12 224 166 10 210 150 10
  94842. -200 144 11 197 138 11 192 133 9 197 138 11
  94843. -210 150 10 226 170 11 242 186 14 246 190 14
  94844. -246 190 14 246 186 14 225 175 15 124 112 88
  94845. - 62 62 62 30 30 30 14 14 14 6 6 6
  94846. - 0 0 0 0 0 0 0 0 0 0 0 0
  94847. - 0 0 0 0 0 0 0 0 0 0 0 0
  94848. - 0 0 0 0 0 0 0 0 0 0 0 0
  94849. - 0 0 0 0 0 0 0 0 0 10 10 10
  94850. - 30 30 30 78 78 78 174 135 50 224 166 10
  94851. -239 182 13 246 190 14 246 190 14 246 190 14
  94852. -246 190 14 246 190 14 246 190 14 246 190 14
  94853. -246 190 14 246 190 14 246 190 14 246 190 14
  94854. -246 190 14 246 190 14 241 196 14 139 102 15
  94855. - 2 2 6 2 2 6 2 2 6 2 2 6
  94856. - 78 78 78 250 250 250 253 253 253 253 253 253
  94857. -253 253 253 253 253 253 253 253 253 253 253 253
  94858. -253 253 253 253 253 253 253 253 253 253 253 253
  94859. -253 253 253 253 253 253 253 253 253 253 253 253
  94860. -250 250 250 214 214 214 198 198 198 190 150 46
  94861. -219 162 10 236 178 12 234 174 13 224 166 10
  94862. -216 158 10 213 154 11 213 154 11 216 158 10
  94863. -226 170 11 239 182 13 246 190 14 246 190 14
  94864. -246 190 14 246 190 14 242 186 14 206 162 42
  94865. -101 101 101 58 58 58 30 30 30 14 14 14
  94866. - 6 6 6 0 0 0 0 0 0 0 0 0
  94867. - 0 0 0 0 0 0 0 0 0 0 0 0
  94868. - 0 0 0 0 0 0 0 0 0 0 0 0
  94869. - 0 0 0 0 0 0 0 0 0 10 10 10
  94870. - 30 30 30 74 74 74 174 135 50 216 158 10
  94871. -236 178 12 246 190 14 246 190 14 246 190 14
  94872. -246 190 14 246 190 14 246 190 14 246 190 14
  94873. -246 190 14 246 190 14 246 190 14 246 190 14
  94874. -246 190 14 246 190 14 241 196 14 226 184 13
  94875. - 61 42 6 2 2 6 2 2 6 2 2 6
  94876. - 22 22 22 238 238 238 253 253 253 253 253 253
  94877. -253 253 253 253 253 253 253 253 253 253 253 253
  94878. -253 253 253 253 253 253 253 253 253 253 253 253
  94879. -253 253 253 253 253 253 253 253 253 253 253 253
  94880. -253 253 253 226 226 226 187 187 187 180 133 36
  94881. -216 158 10 236 178 12 239 182 13 236 178 12
  94882. -230 174 11 226 170 11 226 170 11 230 174 11
  94883. -236 178 12 242 186 14 246 190 14 246 190 14
  94884. -246 190 14 246 190 14 246 186 14 239 182 13
  94885. -206 162 42 106 106 106 66 66 66 34 34 34
  94886. - 14 14 14 6 6 6 0 0 0 0 0 0
  94887. - 0 0 0 0 0 0 0 0 0 0 0 0
  94888. - 0 0 0 0 0 0 0 0 0 0 0 0
  94889. - 0 0 0 0 0 0 0 0 0 6 6 6
  94890. - 26 26 26 70 70 70 163 133 67 213 154 11
  94891. -236 178 12 246 190 14 246 190 14 246 190 14
  94892. -246 190 14 246 190 14 246 190 14 246 190 14
  94893. -246 190 14 246 190 14 246 190 14 246 190 14
  94894. -246 190 14 246 190 14 246 190 14 241 196 14
  94895. -190 146 13 18 14 6 2 2 6 2 2 6
  94896. - 46 46 46 246 246 246 253 253 253 253 253 253
  94897. -253 253 253 253 253 253 253 253 253 253 253 253
  94898. -253 253 253 253 253 253 253 253 253 253 253 253
  94899. -253 253 253 253 253 253 253 253 253 253 253 253
  94900. -253 253 253 221 221 221 86 86 86 156 107 11
  94901. -216 158 10 236 178 12 242 186 14 246 186 14
  94902. -242 186 14 239 182 13 239 182 13 242 186 14
  94903. -242 186 14 246 186 14 246 190 14 246 190 14
  94904. -246 190 14 246 190 14 246 190 14 246 190 14
  94905. -242 186 14 225 175 15 142 122 72 66 66 66
  94906. - 30 30 30 10 10 10 0 0 0 0 0 0
  94907. - 0 0 0 0 0 0 0 0 0 0 0 0
  94908. - 0 0 0 0 0 0 0 0 0 0 0 0
  94909. - 0 0 0 0 0 0 0 0 0 6 6 6
  94910. - 26 26 26 70 70 70 163 133 67 210 150 10
  94911. -236 178 12 246 190 14 246 190 14 246 190 14
  94912. -246 190 14 246 190 14 246 190 14 246 190 14
  94913. -246 190 14 246 190 14 246 190 14 246 190 14
  94914. -246 190 14 246 190 14 246 190 14 246 190 14
  94915. -232 195 16 121 92 8 34 34 34 106 106 106
  94916. -221 221 221 253 253 253 253 253 253 253 253 253
  94917. -253 253 253 253 253 253 253 253 253 253 253 253
  94918. -253 253 253 253 253 253 253 253 253 253 253 253
  94919. -253 253 253 253 253 253 253 253 253 253 253 253
  94920. -242 242 242 82 82 82 18 14 6 163 110 8
  94921. -216 158 10 236 178 12 242 186 14 246 190 14
  94922. -246 190 14 246 190 14 246 190 14 246 190 14
  94923. -246 190 14 246 190 14 246 190 14 246 190 14
  94924. -246 190 14 246 190 14 246 190 14 246 190 14
  94925. -246 190 14 246 190 14 242 186 14 163 133 67
  94926. - 46 46 46 18 18 18 6 6 6 0 0 0
  94927. - 0 0 0 0 0 0 0 0 0 0 0 0
  94928. - 0 0 0 0 0 0 0 0 0 0 0 0
  94929. - 0 0 0 0 0 0 0 0 0 10 10 10
  94930. - 30 30 30 78 78 78 163 133 67 210 150 10
  94931. -236 178 12 246 186 14 246 190 14 246 190 14
  94932. -246 190 14 246 190 14 246 190 14 246 190 14
  94933. -246 190 14 246 190 14 246 190 14 246 190 14
  94934. -246 190 14 246 190 14 246 190 14 246 190 14
  94935. -241 196 14 215 174 15 190 178 144 253 253 253
  94936. -253 253 253 253 253 253 253 253 253 253 253 253
  94937. -253 253 253 253 253 253 253 253 253 253 253 253
  94938. -253 253 253 253 253 253 253 253 253 253 253 253
  94939. -253 253 253 253 253 253 253 253 253 218 218 218
  94940. - 58 58 58 2 2 6 22 18 6 167 114 7
  94941. -216 158 10 236 178 12 246 186 14 246 190 14
  94942. -246 190 14 246 190 14 246 190 14 246 190 14
  94943. -246 190 14 246 190 14 246 190 14 246 190 14
  94944. -246 190 14 246 190 14 246 190 14 246 190 14
  94945. -246 190 14 246 186 14 242 186 14 190 150 46
  94946. - 54 54 54 22 22 22 6 6 6 0 0 0
  94947. - 0 0 0 0 0 0 0 0 0 0 0 0
  94948. - 0 0 0 0 0 0 0 0 0 0 0 0
  94949. - 0 0 0 0 0 0 0 0 0 14 14 14
  94950. - 38 38 38 86 86 86 180 133 36 213 154 11
  94951. -236 178 12 246 186 14 246 190 14 246 190 14
  94952. -246 190 14 246 190 14 246 190 14 246 190 14
  94953. -246 190 14 246 190 14 246 190 14 246 190 14
  94954. -246 190 14 246 190 14 246 190 14 246 190 14
  94955. -246 190 14 232 195 16 190 146 13 214 214 214
  94956. -253 253 253 253 253 253 253 253 253 253 253 253
  94957. -253 253 253 253 253 253 253 253 253 253 253 253
  94958. -253 253 253 253 253 253 253 253 253 253 253 253
  94959. -253 253 253 250 250 250 170 170 170 26 26 26
  94960. - 2 2 6 2 2 6 37 26 9 163 110 8
  94961. -219 162 10 239 182 13 246 186 14 246 190 14
  94962. -246 190 14 246 190 14 246 190 14 246 190 14
  94963. -246 190 14 246 190 14 246 190 14 246 190 14
  94964. -246 190 14 246 190 14 246 190 14 246 190 14
  94965. -246 186 14 236 178 12 224 166 10 142 122 72
  94966. - 46 46 46 18 18 18 6 6 6 0 0 0
  94967. - 0 0 0 0 0 0 0 0 0 0 0 0
  94968. - 0 0 0 0 0 0 0 0 0 0 0 0
  94969. - 0 0 0 0 0 0 6 6 6 18 18 18
  94970. - 50 50 50 109 106 95 192 133 9 224 166 10
  94971. -242 186 14 246 190 14 246 190 14 246 190 14
  94972. -246 190 14 246 190 14 246 190 14 246 190 14
  94973. -246 190 14 246 190 14 246 190 14 246 190 14
  94974. -246 190 14 246 190 14 246 190 14 246 190 14
  94975. -242 186 14 226 184 13 210 162 10 142 110 46
  94976. -226 226 226 253 253 253 253 253 253 253 253 253
  94977. -253 253 253 253 253 253 253 253 253 253 253 253
  94978. -253 253 253 253 253 253 253 253 253 253 253 253
  94979. -198 198 198 66 66 66 2 2 6 2 2 6
  94980. - 2 2 6 2 2 6 50 34 6 156 107 11
  94981. -219 162 10 239 182 13 246 186 14 246 190 14
  94982. -246 190 14 246 190 14 246 190 14 246 190 14
  94983. -246 190 14 246 190 14 246 190 14 246 190 14
  94984. -246 190 14 246 190 14 246 190 14 242 186 14
  94985. -234 174 13 213 154 11 154 122 46 66 66 66
  94986. - 30 30 30 10 10 10 0 0 0 0 0 0
  94987. - 0 0 0 0 0 0 0 0 0 0 0 0
  94988. - 0 0 0 0 0 0 0 0 0 0 0 0
  94989. - 0 0 0 0 0 0 6 6 6 22 22 22
  94990. - 58 58 58 154 121 60 206 145 10 234 174 13
  94991. -242 186 14 246 186 14 246 190 14 246 190 14
  94992. -246 190 14 246 190 14 246 190 14 246 190 14
  94993. -246 190 14 246 190 14 246 190 14 246 190 14
  94994. -246 190 14 246 190 14 246 190 14 246 190 14
  94995. -246 186 14 236 178 12 210 162 10 163 110 8
  94996. - 61 42 6 138 138 138 218 218 218 250 250 250
  94997. -253 253 253 253 253 253 253 253 253 250 250 250
  94998. -242 242 242 210 210 210 144 144 144 66 66 66
  94999. - 6 6 6 2 2 6 2 2 6 2 2 6
  95000. - 2 2 6 2 2 6 61 42 6 163 110 8
  95001. -216 158 10 236 178 12 246 190 14 246 190 14
  95002. -246 190 14 246 190 14 246 190 14 246 190 14
  95003. -246 190 14 246 190 14 246 190 14 246 190 14
  95004. -246 190 14 239 182 13 230 174 11 216 158 10
  95005. -190 142 34 124 112 88 70 70 70 38 38 38
  95006. - 18 18 18 6 6 6 0 0 0 0 0 0
  95007. - 0 0 0 0 0 0 0 0 0 0 0 0
  95008. - 0 0 0 0 0 0 0 0 0 0 0 0
  95009. - 0 0 0 0 0 0 6 6 6 22 22 22
  95010. - 62 62 62 168 124 44 206 145 10 224 166 10
  95011. -236 178 12 239 182 13 242 186 14 242 186 14
  95012. -246 186 14 246 190 14 246 190 14 246 190 14
  95013. -246 190 14 246 190 14 246 190 14 246 190 14
  95014. -246 190 14 246 190 14 246 190 14 246 190 14
  95015. -246 190 14 236 178 12 216 158 10 175 118 6
  95016. - 80 54 7 2 2 6 6 6 6 30 30 30
  95017. - 54 54 54 62 62 62 50 50 50 38 38 38
  95018. - 14 14 14 2 2 6 2 2 6 2 2 6
  95019. - 2 2 6 2 2 6 2 2 6 2 2 6
  95020. - 2 2 6 6 6 6 80 54 7 167 114 7
  95021. -213 154 11 236 178 12 246 190 14 246 190 14
  95022. -246 190 14 246 190 14 246 190 14 246 190 14
  95023. -246 190 14 242 186 14 239 182 13 239 182 13
  95024. -230 174 11 210 150 10 174 135 50 124 112 88
  95025. - 82 82 82 54 54 54 34 34 34 18 18 18
  95026. - 6 6 6 0 0 0 0 0 0 0 0 0
  95027. - 0 0 0 0 0 0 0 0 0 0 0 0
  95028. - 0 0 0 0 0 0 0 0 0 0 0 0
  95029. - 0 0 0 0 0 0 6 6 6 18 18 18
  95030. - 50 50 50 158 118 36 192 133 9 200 144 11
  95031. -216 158 10 219 162 10 224 166 10 226 170 11
  95032. -230 174 11 236 178 12 239 182 13 239 182 13
  95033. -242 186 14 246 186 14 246 190 14 246 190 14
  95034. -246 190 14 246 190 14 246 190 14 246 190 14
  95035. -246 186 14 230 174 11 210 150 10 163 110 8
  95036. -104 69 6 10 10 10 2 2 6 2 2 6
  95037. - 2 2 6 2 2 6 2 2 6 2 2 6
  95038. - 2 2 6 2 2 6 2 2 6 2 2 6
  95039. - 2 2 6 2 2 6 2 2 6 2 2 6
  95040. - 2 2 6 6 6 6 91 60 6 167 114 7
  95041. -206 145 10 230 174 11 242 186 14 246 190 14
  95042. -246 190 14 246 190 14 246 186 14 242 186 14
  95043. -239 182 13 230 174 11 224 166 10 213 154 11
  95044. -180 133 36 124 112 88 86 86 86 58 58 58
  95045. - 38 38 38 22 22 22 10 10 10 6 6 6
  95046. - 0 0 0 0 0 0 0 0 0 0 0 0
  95047. - 0 0 0 0 0 0 0 0 0 0 0 0
  95048. - 0 0 0 0 0 0 0 0 0 0 0 0
  95049. - 0 0 0 0 0 0 0 0 0 14 14 14
  95050. - 34 34 34 70 70 70 138 110 50 158 118 36
  95051. -167 114 7 180 123 7 192 133 9 197 138 11
  95052. -200 144 11 206 145 10 213 154 11 219 162 10
  95053. -224 166 10 230 174 11 239 182 13 242 186 14
  95054. -246 186 14 246 186 14 246 186 14 246 186 14
  95055. -239 182 13 216 158 10 185 133 11 152 99 6
  95056. -104 69 6 18 14 6 2 2 6 2 2 6
  95057. - 2 2 6 2 2 6 2 2 6 2 2 6
  95058. - 2 2 6 2 2 6 2 2 6 2 2 6
  95059. - 2 2 6 2 2 6 2 2 6 2 2 6
  95060. - 2 2 6 6 6 6 80 54 7 152 99 6
  95061. -192 133 9 219 162 10 236 178 12 239 182 13
  95062. -246 186 14 242 186 14 239 182 13 236 178 12
  95063. -224 166 10 206 145 10 192 133 9 154 121 60
  95064. - 94 94 94 62 62 62 42 42 42 22 22 22
  95065. - 14 14 14 6 6 6 0 0 0 0 0 0
  95066. - 0 0 0 0 0 0 0 0 0 0 0 0
  95067. - 0 0 0 0 0 0 0 0 0 0 0 0
  95068. - 0 0 0 0 0 0 0 0 0 0 0 0
  95069. - 0 0 0 0 0 0 0 0 0 6 6 6
  95070. - 18 18 18 34 34 34 58 58 58 78 78 78
  95071. -101 98 89 124 112 88 142 110 46 156 107 11
  95072. -163 110 8 167 114 7 175 118 6 180 123 7
  95073. -185 133 11 197 138 11 210 150 10 219 162 10
  95074. -226 170 11 236 178 12 236 178 12 234 174 13
  95075. -219 162 10 197 138 11 163 110 8 130 83 6
  95076. - 91 60 6 10 10 10 2 2 6 2 2 6
  95077. - 18 18 18 38 38 38 38 38 38 38 38 38
  95078. - 38 38 38 38 38 38 38 38 38 38 38 38
  95079. - 38 38 38 38 38 38 26 26 26 2 2 6
  95080. - 2 2 6 6 6 6 70 47 6 137 92 6
  95081. -175 118 6 200 144 11 219 162 10 230 174 11
  95082. -234 174 13 230 174 11 219 162 10 210 150 10
  95083. -192 133 9 163 110 8 124 112 88 82 82 82
  95084. - 50 50 50 30 30 30 14 14 14 6 6 6
  95085. - 0 0 0 0 0 0 0 0 0 0 0 0
  95086. - 0 0 0 0 0 0 0 0 0 0 0 0
  95087. - 0 0 0 0 0 0 0 0 0 0 0 0
  95088. - 0 0 0 0 0 0 0 0 0 0 0 0
  95089. - 0 0 0 0 0 0 0 0 0 0 0 0
  95090. - 6 6 6 14 14 14 22 22 22 34 34 34
  95091. - 42 42 42 58 58 58 74 74 74 86 86 86
  95092. -101 98 89 122 102 70 130 98 46 121 87 25
  95093. -137 92 6 152 99 6 163 110 8 180 123 7
  95094. -185 133 11 197 138 11 206 145 10 200 144 11
  95095. -180 123 7 156 107 11 130 83 6 104 69 6
  95096. - 50 34 6 54 54 54 110 110 110 101 98 89
  95097. - 86 86 86 82 82 82 78 78 78 78 78 78
  95098. - 78 78 78 78 78 78 78 78 78 78 78 78
  95099. - 78 78 78 82 82 82 86 86 86 94 94 94
  95100. -106 106 106 101 101 101 86 66 34 124 80 6
  95101. -156 107 11 180 123 7 192 133 9 200 144 11
  95102. -206 145 10 200 144 11 192 133 9 175 118 6
  95103. -139 102 15 109 106 95 70 70 70 42 42 42
  95104. - 22 22 22 10 10 10 0 0 0 0 0 0
  95105. - 0 0 0 0 0 0 0 0 0 0 0 0
  95106. - 0 0 0 0 0 0 0 0 0 0 0 0
  95107. - 0 0 0 0 0 0 0 0 0 0 0 0
  95108. - 0 0 0 0 0 0 0 0 0 0 0 0
  95109. - 0 0 0 0 0 0 0 0 0 0 0 0
  95110. - 0 0 0 0 0 0 6 6 6 10 10 10
  95111. - 14 14 14 22 22 22 30 30 30 38 38 38
  95112. - 50 50 50 62 62 62 74 74 74 90 90 90
  95113. -101 98 89 112 100 78 121 87 25 124 80 6
  95114. -137 92 6 152 99 6 152 99 6 152 99 6
  95115. -138 86 6 124 80 6 98 70 6 86 66 30
  95116. -101 98 89 82 82 82 58 58 58 46 46 46
  95117. - 38 38 38 34 34 34 34 34 34 34 34 34
  95118. - 34 34 34 34 34 34 34 34 34 34 34 34
  95119. - 34 34 34 34 34 34 38 38 38 42 42 42
  95120. - 54 54 54 82 82 82 94 86 76 91 60 6
  95121. -134 86 6 156 107 11 167 114 7 175 118 6
  95122. -175 118 6 167 114 7 152 99 6 121 87 25
  95123. -101 98 89 62 62 62 34 34 34 18 18 18
  95124. - 6 6 6 0 0 0 0 0 0 0 0 0
  95125. - 0 0 0 0 0 0 0 0 0 0 0 0
  95126. - 0 0 0 0 0 0 0 0 0 0 0 0
  95127. - 0 0 0 0 0 0 0 0 0 0 0 0
  95128. - 0 0 0 0 0 0 0 0 0 0 0 0
  95129. - 0 0 0 0 0 0 0 0 0 0 0 0
  95130. - 0 0 0 0 0 0 0 0 0 0 0 0
  95131. - 0 0 0 6 6 6 6 6 6 10 10 10
  95132. - 18 18 18 22 22 22 30 30 30 42 42 42
  95133. - 50 50 50 66 66 66 86 86 86 101 98 89
  95134. -106 86 58 98 70 6 104 69 6 104 69 6
  95135. -104 69 6 91 60 6 82 62 34 90 90 90
  95136. - 62 62 62 38 38 38 22 22 22 14 14 14
  95137. - 10 10 10 10 10 10 10 10 10 10 10 10
  95138. - 10 10 10 10 10 10 6 6 6 10 10 10
  95139. - 10 10 10 10 10 10 10 10 10 14 14 14
  95140. - 22 22 22 42 42 42 70 70 70 89 81 66
  95141. - 80 54 7 104 69 6 124 80 6 137 92 6
  95142. -134 86 6 116 81 8 100 82 52 86 86 86
  95143. - 58 58 58 30 30 30 14 14 14 6 6 6
  95144. - 0 0 0 0 0 0 0 0 0 0 0 0
  95145. - 0 0 0 0 0 0 0 0 0 0 0 0
  95146. - 0 0 0 0 0 0 0 0 0 0 0 0
  95147. - 0 0 0 0 0 0 0 0 0 0 0 0
  95148. - 0 0 0 0 0 0 0 0 0 0 0 0
  95149. - 0 0 0 0 0 0 0 0 0 0 0 0
  95150. - 0 0 0 0 0 0 0 0 0 0 0 0
  95151. - 0 0 0 0 0 0 0 0 0 0 0 0
  95152. - 0 0 0 6 6 6 10 10 10 14 14 14
  95153. - 18 18 18 26 26 26 38 38 38 54 54 54
  95154. - 70 70 70 86 86 86 94 86 76 89 81 66
  95155. - 89 81 66 86 86 86 74 74 74 50 50 50
  95156. - 30 30 30 14 14 14 6 6 6 0 0 0
  95157. - 0 0 0 0 0 0 0 0 0 0 0 0
  95158. - 0 0 0 0 0 0 0 0 0 0 0 0
  95159. - 0 0 0 0 0 0 0 0 0 0 0 0
  95160. - 6 6 6 18 18 18 34 34 34 58 58 58
  95161. - 82 82 82 89 81 66 89 81 66 89 81 66
  95162. - 94 86 66 94 86 76 74 74 74 50 50 50
  95163. - 26 26 26 14 14 14 6 6 6 0 0 0
  95164. - 0 0 0 0 0 0 0 0 0 0 0 0
  95165. - 0 0 0 0 0 0 0 0 0 0 0 0
  95166. - 0 0 0 0 0 0 0 0 0 0 0 0
  95167. - 0 0 0 0 0 0 0 0 0 0 0 0
  95168. - 0 0 0 0 0 0 0 0 0 0 0 0
  95169. - 0 0 0 0 0 0 0 0 0 0 0 0
  95170. - 0 0 0 0 0 0 0 0 0 0 0 0
  95171. - 0 0 0 0 0 0 0 0 0 0 0 0
  95172. - 0 0 0 0 0 0 0 0 0 0 0 0
  95173. - 6 6 6 6 6 6 14 14 14 18 18 18
  95174. - 30 30 30 38 38 38 46 46 46 54 54 54
  95175. - 50 50 50 42 42 42 30 30 30 18 18 18
  95176. - 10 10 10 0 0 0 0 0 0 0 0 0
  95177. - 0 0 0 0 0 0 0 0 0 0 0 0
  95178. - 0 0 0 0 0 0 0 0 0 0 0 0
  95179. - 0 0 0 0 0 0 0 0 0 0 0 0
  95180. - 0 0 0 6 6 6 14 14 14 26 26 26
  95181. - 38 38 38 50 50 50 58 58 58 58 58 58
  95182. - 54 54 54 42 42 42 30 30 30 18 18 18
  95183. - 10 10 10 0 0 0 0 0 0 0 0 0
  95184. - 0 0 0 0 0 0 0 0 0 0 0 0
  95185. - 0 0 0 0 0 0 0 0 0 0 0 0
  95186. - 0 0 0 0 0 0 0 0 0 0 0 0
  95187. - 0 0 0 0 0 0 0 0 0 0 0 0
  95188. - 0 0 0 0 0 0 0 0 0 0 0 0
  95189. - 0 0 0 0 0 0 0 0 0 0 0 0
  95190. - 0 0 0 0 0 0 0 0 0 0 0 0
  95191. - 0 0 0 0 0 0 0 0 0 0 0 0
  95192. - 0 0 0 0 0 0 0 0 0 0 0 0
  95193. - 0 0 0 0 0 0 0 0 0 6 6 6
  95194. - 6 6 6 10 10 10 14 14 14 18 18 18
  95195. - 18 18 18 14 14 14 10 10 10 6 6 6
  95196. - 0 0 0 0 0 0 0 0 0 0 0 0
  95197. - 0 0 0 0 0 0 0 0 0 0 0 0
  95198. - 0 0 0 0 0 0 0 0 0 0 0 0
  95199. - 0 0 0 0 0 0 0 0 0 0 0 0
  95200. - 0 0 0 0 0 0 0 0 0 6 6 6
  95201. - 14 14 14 18 18 18 22 22 22 22 22 22
  95202. - 18 18 18 14 14 14 10 10 10 6 6 6
  95203. - 0 0 0 0 0 0 0 0 0 0 0 0
  95204. - 0 0 0 0 0 0 0 0 0 0 0 0
  95205. - 0 0 0 0 0 0 0 0 0 0 0 0
  95206. - 0 0 0 0 0 0 0 0 0 0 0 0
  95207. - 0 0 0 0 0 0 0 0 0 0 0 0
  95208. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95209. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95210. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95211. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95212. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95213. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95214. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95215. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95216. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95217. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95218. +0 0 0 0 0 0 0 0 0
  95219. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95220. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95221. +0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0
  95222. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95223. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95224. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95225. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95226. +0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0
  95227. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95228. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95229. +0 0 0 0 0 0 0 0 0
  95230. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95231. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  95232. +10 15 3 2 3 1 12 18 4 42 61 14 19 27 6 11 16 4
  95233. +38 55 13 10 15 3 3 4 1 10 15 3 0 0 0 0 0 0
  95234. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95235. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95236. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 1
  95237. +12 18 4 1 1 0 23 34 8 31 45 11 10 15 3 32 47 11
  95238. +34 49 12 3 4 1 3 4 1 3 4 1 0 0 0 0 0 0
  95239. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95240. +0 0 0 0 0 0 0 0 0
  95241. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95242. +0 0 0 0 0 0 10 15 3 29 42 10 26 37 9 12 18 4
  95243. +55 80 19 81 118 28 55 80 19 92 132 31 106 153 36 69 100 23
  95244. +100 144 34 80 116 27 42 61 14 81 118 28 23 34 8 27 40 9
  95245. +15 21 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95246. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95247. +0 0 0 0 0 0 1 1 0 29 42 10 15 21 5 50 72 17
  95248. +74 107 25 45 64 15 102 148 35 80 116 27 84 121 28 111 160 38
  95249. +69 100 23 65 94 22 81 118 28 29 42 10 17 25 6 29 42 10
  95250. +23 34 8 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  95251. +0 0 0 0 0 0 0 0 0
  95252. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  95253. +15 21 5 15 21 5 34 49 12 101 146 34 111 161 38 97 141 33
  95254. +97 141 33 119 172 41 117 170 40 116 167 40 118 170 40 118 171 40
  95255. +117 169 40 118 170 40 111 160 38 118 170 40 96 138 32 89 128 30
  95256. +81 118 28 11 16 4 10 15 3 1 1 0 0 0 0 0 0 0
  95257. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95258. +3 4 1 3 4 1 34 49 12 101 146 34 79 115 27 111 160 38
  95259. +114 165 39 113 163 39 118 170 40 117 169 40 118 171 40 117 169 40
  95260. +116 167 40 119 172 41 113 163 39 92 132 31 105 151 36 113 163 39
  95261. +75 109 26 19 27 6 16 23 5 11 16 4 0 1 0 0 0 0
  95262. +0 0 0 0 0 0 0 0 0
  95263. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  95264. +80 116 27 106 153 36 105 151 36 114 165 39 118 170 40 118 171 40
  95265. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95266. +117 169 40 117 169 40 117 170 40 117 169 40 118 170 40 118 170 40
  95267. +117 170 40 75 109 26 75 109 26 34 49 12 0 0 0 0 0 0
  95268. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  95269. +64 92 22 65 94 22 100 144 34 118 171 40 118 170 40 117 169 40
  95270. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95271. +117 169 40 117 169 40 117 169 40 118 171 41 118 170 40 117 169 40
  95272. +109 158 37 105 151 36 104 150 35 47 69 16 0 0 0 0 0 0
  95273. +0 0 0 0 0 0 0 0 0
  95274. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95275. +42 61 14 115 167 39 118 170 40 117 169 40 117 169 40 117 169 40
  95276. +117 170 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  95277. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95278. +117 169 40 117 169 40 118 170 40 96 138 32 17 25 6 0 0 0
  95279. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 47 69 16
  95280. +114 165 39 117 168 40 117 170 40 117 169 40 117 169 40 117 169 40
  95281. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95282. +117 169 40 117 169 40 118 170 40 117 169 40 117 169 40 117 169 40
  95283. +117 170 40 119 172 41 96 138 32 12 18 4 0 0 0 0 0 0
  95284. +0 0 0 0 0 0 0 0 0
  95285. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  95286. +32 47 11 105 151 36 118 170 40 117 169 40 117 169 40 116 168 40
  95287. +109 157 37 111 160 38 117 169 40 118 171 40 117 169 40 117 169 40
  95288. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95289. +117 169 40 117 169 40 117 169 40 118 171 40 69 100 23 2 3 1
  95290. +0 0 0 0 0 0 0 0 0 0 0 0 19 27 6 101 146 34
  95291. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95292. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 170 40
  95293. +118 171 40 115 166 39 107 154 36 111 161 38 117 169 40 117 169 40
  95294. +117 169 40 118 171 40 75 109 26 19 27 6 2 3 1 0 0 0
  95295. +0 0 0 0 0 0 0 0 0
  95296. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 23 5
  95297. +89 128 30 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95298. +111 160 38 92 132 31 79 115 27 96 138 32 115 166 39 119 171 41
  95299. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95300. +117 169 40 117 169 40 117 169 40 118 170 40 109 157 37 26 37 9
  95301. +0 0 0 0 0 0 0 0 0 0 0 0 64 92 22 118 171 40
  95302. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95303. +117 169 40 117 169 40 117 169 40 118 170 40 118 171 40 109 157 37
  95304. +89 128 30 81 118 28 100 144 34 115 166 39 117 169 40 117 169 40
  95305. +117 169 40 117 170 40 113 163 39 60 86 20 1 1 0 0 0 0
  95306. +0 0 0 0 0 0 0 0 0
  95307. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95308. +27 40 9 96 138 32 118 170 40 117 169 40 117 169 40 117 169 40
  95309. +117 170 40 117 169 40 101 146 34 67 96 23 55 80 19 84 121 28
  95310. +113 163 39 119 171 41 117 169 40 117 169 40 117 169 40 117 169 40
  95311. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 65 94 22
  95312. +0 0 0 0 0 0 0 0 0 15 21 5 101 146 34 118 171 40
  95313. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95314. +117 169 40 118 170 40 118 171 40 104 150 35 69 100 23 53 76 18
  95315. +81 118 28 111 160 38 118 170 40 117 169 40 117 169 40 117 169 40
  95316. +117 169 40 114 165 39 69 100 23 10 15 3 0 0 0 0 0 0
  95317. +0 0 0 0 0 0 0 0 0
  95318. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  95319. +31 45 11 77 111 26 117 169 40 117 169 40 117 169 40 117 169 40
  95320. +117 169 40 117 169 40 118 170 40 116 168 40 92 132 31 47 69 16
  95321. +38 55 13 81 118 28 113 163 39 119 171 41 117 169 40 117 169 40
  95322. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 41 92 132 31
  95323. +10 15 3 0 0 0 0 0 0 36 52 12 115 166 39 117 169 40
  95324. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  95325. +118 171 40 102 148 35 64 92 22 34 49 12 65 94 22 106 153 36
  95326. +118 171 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  95327. +118 170 40 107 154 36 55 80 19 15 21 5 0 0 0 0 0 0
  95328. +0 0 0 0 0 0 0 0 0
  95329. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95330. +29 42 10 101 146 34 118 171 40 117 169 40 117 169 40 117 169 40
  95331. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 113 163 39
  95332. +75 109 26 27 40 9 36 52 12 89 128 30 116 167 40 118 171 40
  95333. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 104 150 35
  95334. +16 23 5 0 0 0 0 0 0 53 76 18 118 171 40 117 169 40
  95335. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 109 157 37
  95336. +67 96 23 23 34 8 42 61 14 96 138 32 118 170 40 118 170 40
  95337. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95338. +117 169 40 117 169 40 74 107 25 10 15 3 0 0 0 0 0 0
  95339. +0 0 0 0 0 0 0 0 0
  95340. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95341. +0 0 0 31 45 11 101 146 34 118 170 40 117 169 40 117 169 40
  95342. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95343. +119 171 41 102 148 35 47 69 16 14 20 5 50 72 17 102 148 35
  95344. +118 171 40 117 169 40 117 169 40 117 169 40 118 170 40 102 148 35
  95345. +15 21 5 0 0 0 0 0 0 50 72 17 118 170 40 117 169 40
  95346. +117 169 40 117 169 40 118 170 40 116 167 40 84 121 28 27 40 9
  95347. +19 27 6 74 107 25 114 165 39 118 171 40 117 169 40 117 169 40
  95348. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95349. +117 169 40 75 109 26 10 15 4 0 0 0 0 0 0 0 0 0
  95350. +0 0 0 0 0 0 0 0 0
  95351. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95352. +0 0 0 38 55 13 102 148 35 118 171 40 117 169 40 117 169 40
  95353. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95354. +117 169 40 118 170 40 115 167 39 77 111 26 17 25 6 19 27 6
  95355. +77 111 26 115 166 39 118 170 40 117 169 40 119 172 41 81 118 28
  95356. +3 4 1 0 0 0 0 0 0 27 40 9 111 160 38 118 170 40
  95357. +117 169 40 118 171 40 105 151 36 50 72 17 10 15 3 38 55 13
  95358. +100 144 34 118 171 40 117 169 40 117 169 40 117 169 40 117 169 40
  95359. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95360. +117 169 40 79 115 27 15 21 5 0 0 0 0 0 0 0 0 0
  95361. +0 0 0 0 0 0 0 0 0
  95362. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95363. +0 0 0 10 15 3 64 92 22 111 160 38 117 169 40 117 169 40
  95364. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95365. +117 169 40 117 169 40 117 169 40 118 171 40 96 138 32 32 47 11
  95366. +3 4 1 50 72 17 107 154 36 120 173 41 105 151 36 31 45 11
  95367. +0 0 0 0 0 0 0 0 0 3 4 1 65 94 22 117 169 40
  95368. +118 170 40 89 128 30 26 37 9 3 4 1 60 86 20 111 161 38
  95369. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95370. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95371. +97 141 33 36 52 12 1 1 0 0 0 0 0 0 0 0 0 0
  95372. +0 0 0 0 0 0 0 0 0
  95373. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95374. +0 0 0 0 0 0 14 20 5 75 109 26 117 168 40 117 169 40
  95375. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95376. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 107 154 36
  95377. +45 64 15 2 3 1 31 45 11 75 109 26 32 47 11 0 1 0
  95378. +0 0 0 0 0 0 0 0 0 0 0 0 10 15 3 55 80 19
  95379. +65 94 22 11 16 4 11 16 4 75 109 26 116 168 40 118 170 40
  95380. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95381. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 107 154 36
  95382. +47 69 16 3 4 1 0 0 0 0 0 0 0 0 0 0 0 0
  95383. +0 0 0 0 0 0 0 0 0
  95384. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95385. +0 0 0 0 0 0 12 18 4 69 100 23 111 161 38 118 171 40
  95386. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95387. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  95388. +111 160 38 50 72 17 2 3 1 2 3 1 0 0 0 0 0 0
  95389. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  95390. +1 1 0 12 18 4 81 118 28 118 170 40 117 169 40 117 169 40
  95391. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95392. +117 169 40 117 169 40 117 169 40 117 170 40 118 171 40 101 146 34
  95393. +42 61 14 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  95394. +0 0 0 0 0 0 0 0 0
  95395. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95396. +0 0 0 0 0 0 0 0 0 3 4 1 36 52 12 89 128 30
  95397. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95398. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95399. +118 171 41 101 146 34 14 20 5 0 0 0 0 0 0 0 0 0
  95400. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95401. +0 0 0 47 69 16 118 170 40 117 169 40 117 169 40 117 169 40
  95402. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95403. +117 169 40 117 169 40 117 170 40 111 160 38 69 100 23 19 27 6
  95404. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95405. +0 0 0 0 0 0 0 0 0
  95406. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95407. +0 0 0 0 0 0 0 0 0 0 0 0 11 16 4 69 100 23
  95408. +115 167 39 119 172 41 117 169 40 117 169 40 117 169 40 117 169 40
  95409. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95410. +119 172 41 75 109 26 3 4 1 0 0 0 0 0 0 0 0 0
  95411. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95412. +0 0 0 23 34 8 106 153 36 118 170 40 117 169 40 117 169 40
  95413. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95414. +117 169 40 118 170 40 119 172 41 105 151 36 42 61 14 2 3 1
  95415. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95416. +0 0 0 0 0 0 0 0 0
  95417. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95418. +0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 15 21 5
  95419. +45 64 15 80 116 27 114 165 39 118 170 40 117 169 40 117 169 40
  95420. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 119 172 41
  95421. +97 141 33 20 30 7 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 0 0 0 0 0 0
  95423. +0 0 0 1 1 0 53 76 18 114 165 39 118 171 40 117 169 40
  95424. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  95425. +118 171 40 104 150 35 64 92 22 31 45 11 10 15 3 0 0 0
  95426. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95427. +0 0 0 0 0 0 0 0 0
  95428. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95429. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95430. +0 0 0 36 52 12 97 141 33 109 158 37 113 163 39 116 168 40
  95431. +117 169 40 117 170 40 118 170 40 119 172 41 115 167 39 84 121 28
  95432. +23 34 8 0 0 0 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 0 0 0 0 0 0
  95434. +0 0 0 0 0 0 3 4 1 50 72 17 102 148 35 118 171 40
  95435. +119 171 41 118 170 40 117 169 40 117 169 40 115 166 39 111 161 38
  95436. +109 157 37 79 115 27 12 18 4 0 0 0 0 0 0 0 0 0
  95437. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95438. +0 0 0 0 0 0 0 0 0
  95439. +0 0 0 0 0 0 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 0 0 0 0 0 0
  95441. +0 0 0 3 4 1 15 21 5 23 34 8 45 64 15 106 153 36
  95442. +116 167 40 111 160 38 101 146 34 79 115 27 42 61 14 10 15 3
  95443. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95444. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95445. +0 0 0 0 0 0 0 0 0 1 1 0 20 30 7 60 86 20
  95446. +89 128 30 106 153 36 113 163 39 117 169 40 84 121 28 29 42 10
  95447. +19 27 6 10 15 3 2 3 1 0 0 0 0 0 0 0 0 0
  95448. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95449. +0 0 0 0 0 0 0 0 0
  95450. +0 0 0 0 0 0 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 0 0 0 0 0 0
  95452. +0 0 0 0 0 0 0 0 0 0 0 0 16 23 5 38 55 13
  95453. +36 52 12 26 37 9 12 18 4 2 3 1 0 0 0 0 0 0
  95454. +0 0 0 0 0 0 0 0 0 1 0 0 19 2 7 52 5 18
  95455. +78 7 27 88 8 31 81 7 29 56 5 19 25 2 9 3 0 1
  95456. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95457. +3 4 1 19 27 6 31 45 11 38 55 13 32 47 11 3 4 1
  95458. +0 0 0 0 0 0 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 0 0 0 0 0 0
  95460. +0 0 0 0 0 0 0 0 0
  95461. +0 0 0 0 0 0 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 0 0 0 0 0 0
  95463. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  95464. +9 0 3 12 1 4 9 0 3 4 0 1 0 0 0 0 0 0
  95465. +0 0 0 0 0 0 28 3 10 99 9 35 156 14 55 182 16 64
  95466. +189 17 66 190 17 67 189 17 66 184 17 65 166 15 58 118 13 41
  95467. +45 4 16 3 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  95468. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95469. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95470. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95471. +0 0 0 0 0 0 0 0 0
  95472. +0 0 0 0 0 0 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 0 0 0 0 0 0
  95474. +0 0 0 0 0 0 11 1 4 52 5 18 101 9 35 134 12 47
  95475. +151 14 53 154 14 54 151 14 53 113 10 40 11 1 4 0 0 0
  95476. +3 0 1 67 6 24 159 14 56 190 17 67 190 17 67 188 17 66
  95477. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 191 17 67
  95478. +174 16 61 101 9 35 14 1 5 0 0 0 35 3 12 108 10 38
  95479. +122 11 43 122 11 43 112 10 39 87 8 30 50 5 17 13 1 5
  95480. +0 0 0 0 0 0 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 0 0 0 0 0 0
  95482. +0 0 0 0 0 0 0 0 0
  95483. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95484. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95485. +3 0 1 56 5 19 141 13 49 182 16 64 191 17 67 191 17 67
  95486. +190 17 67 190 17 67 191 17 67 113 10 40 3 0 1 1 0 0
  95487. +79 7 28 180 16 63 190 17 67 188 17 66 188 17 66 188 17 66
  95488. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95489. +189 17 66 188 17 66 122 11 43 11 1 4 41 4 14 176 16 62
  95490. +191 17 67 191 17 67 191 17 67 190 17 67 181 16 63 146 13 51
  95491. +75 7 26 10 1 4 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 0 0 0 0 0 0
  95493. +0 0 0 0 0 0 0 0 0
  95494. +0 0 0 0 0 0 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 0 0 0 7 1 2
  95496. +90 8 32 178 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  95497. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 41 4 14
  95498. +173 16 61 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  95499. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95500. +188 17 66 188 17 66 188 17 66 88 8 31 1 0 0 89 8 31
  95501. +185 17 65 189 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  95502. +186 17 65 124 11 43 25 2 9 0 0 0 0 0 0 0 0 0
  95503. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95504. +0 0 0 0 0 0 0 0 0
  95505. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95506. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 89 8 31
  95507. +184 17 65 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95508. +190 17 67 151 14 53 34 3 12 0 0 0 0 0 0 79 7 28
  95509. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95510. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95511. +188 17 66 188 17 66 191 17 67 146 13 51 9 1 3 7 1 2
  95512. +108 10 38 187 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  95513. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 0 0 0
  95514. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95515. +0 0 0 0 0 0 0 0 0
  95516. +0 0 0 0 0 0 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 52 5 18 176 16 62
  95518. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  95519. +151 14 53 38 3 13 0 0 0 0 0 0 0 0 0 50 5 17
  95520. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95521. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95522. +188 17 66 188 17 66 191 17 67 141 13 49 7 1 3 0 0 0
  95523. +11 1 4 112 10 39 187 17 66 189 17 66 188 17 66 188 17 66
  95524. +188 17 66 188 17 66 190 17 67 113 10 40 5 0 2 0 0 0
  95525. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95526. +0 0 0 0 0 0 0 0 0
  95527. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95528. +0 0 0 0 0 0 0 0 0 7 1 3 132 12 46 191 17 67
  95529. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 146 13 51
  95530. +35 3 12 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  95531. +101 9 35 185 17 65 190 17 67 188 17 66 188 17 66 188 17 66
  95532. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95533. +188 17 66 190 17 67 180 16 63 67 6 24 0 0 0 0 0 0
  95534. +0 0 0 11 1 4 108 10 38 186 17 65 189 17 66 188 17 66
  95535. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  95536. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95537. +0 0 0 0 0 0 0 0 0
  95538. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95539. +0 0 0 0 0 0 0 0 0 44 4 15 177 16 62 189 17 66
  95540. +188 17 66 188 17 66 189 17 66 189 17 66 134 12 47 28 3 10
  95541. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95542. +8 1 3 79 7 28 159 14 56 188 17 66 191 17 67 190 17 67
  95543. +189 17 66 189 17 66 189 17 66 189 17 66 190 17 67 191 17 67
  95544. +188 17 66 158 14 55 72 7 25 4 0 1 0 0 0 0 0 0
  95545. +0 0 0 0 0 0 8 1 3 95 9 33 182 16 64 189 17 67
  95546. +188 17 66 188 17 66 188 17 66 191 17 67 122 11 43 3 0 1
  95547. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95548. +0 0 0 0 0 0 0 0 0
  95549. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95550. +0 0 0 0 0 0 0 0 0 88 8 31 190 17 67 188 17 66
  95551. +188 17 66 189 17 66 185 17 65 113 10 40 18 2 6 0 0 0
  95552. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95553. +0 0 0 1 0 0 24 2 8 77 7 27 124 11 43 154 14 54
  95554. +168 15 59 173 16 61 173 16 61 168 15 59 154 14 54 124 11 43
  95555. +77 7 27 22 2 8 0 0 0 0 0 0 0 0 0 0 0 0
  95556. +0 0 0 0 0 0 0 0 0 5 0 2 77 7 27 173 16 61
  95557. +190 17 67 188 17 66 188 17 66 190 17 67 164 15 57 23 2 8
  95558. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95559. +0 0 0 0 0 0 0 0 0
  95560. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95561. +0 0 0 0 0 0 1 0 0 118 13 41 191 17 67 188 17 66
  95562. +190 17 67 174 16 61 87 8 30 8 1 3 0 0 0 0 0 0
  95563. +0 0 0 0 0 0 10 1 4 29 3 10 40 4 14 36 3 13
  95564. +18 2 6 2 0 1 0 0 0 0 0 0 3 0 1 14 1 5
  95565. +26 2 9 33 3 11 32 3 11 25 2 9 13 1 5 3 0 1
  95566. +0 0 0 14 1 5 56 5 19 95 9 33 109 10 38 101 9 35
  95567. +77 7 27 35 3 12 5 0 2 0 0 0 1 0 0 56 5 19
  95568. +156 14 55 190 17 67 188 17 66 188 17 66 182 16 64 50 5 17
  95569. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95570. +0 0 0 0 0 0 0 0 0
  95571. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95572. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 189 17 66
  95573. +151 14 53 52 5 18 2 0 1 0 0 0 0 0 0 1 0 0
  95574. +28 3 10 90 8 32 146 13 51 170 15 60 178 16 62 174 16 61
  95575. +158 14 55 112 10 39 40 4 14 1 0 0 0 0 0 0 0 0
  95576. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  95577. +56 5 19 146 13 51 183 17 64 191 17 67 191 17 67 191 17 67
  95578. +188 17 66 173 16 61 122 11 43 41 4 14 1 0 0 0 0 0
  95579. +30 3 10 124 11 43 185 17 65 190 17 67 187 17 66 67 6 24
  95580. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95581. +0 0 0 0 0 0 0 0 0
  95582. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95583. +0 0 0 0 0 0 6 1 2 134 12 47 168 15 59 99 9 35
  95584. +21 2 7 0 0 0 0 0 0 0 0 0 6 1 2 77 7 27
  95585. +162 15 57 190 17 67 191 17 67 189 17 66 189 17 66 189 17 66
  95586. +190 17 67 191 17 67 169 15 59 75 7 26 3 0 1 0 0 0
  95587. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 79 7 28
  95588. +178 16 62 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  95589. +188 17 66 189 17 66 191 17 67 170 15 60 79 7 28 5 0 2
  95590. +0 0 0 10 1 3 78 7 27 159 14 56 188 17 66 75 7 26
  95591. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95592. +0 0 0 0 0 0 0 0 0
  95593. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95594. +0 0 0 0 0 0 1 0 0 35 3 12 29 3 10 2 0 1
  95595. +0 0 0 0 0 0 0 0 0 9 1 3 101 9 35 183 17 64
  95596. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95597. +188 17 66 188 17 66 190 17 67 178 16 63 67 6 23 0 0 0
  95598. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 174 16 61
  95599. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95600. +188 17 66 188 17 66 188 17 66 190 17 67 182 16 64 89 8 31
  95601. +4 0 1 0 0 0 0 0 0 25 2 9 73 7 26 31 3 11
  95602. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95603. +0 0 0 0 0 0 0 0 0
  95604. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95605. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95606. +0 0 0 0 0 0 4 0 1 98 9 34 187 17 66 189 17 66
  95607. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95608. +188 17 66 188 17 66 188 17 66 190 17 67 158 14 55 25 2 9
  95609. +0 0 0 0 0 0 0 0 0 8 1 3 134 12 47 191 17 67
  95610. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95611. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 180 16 63
  95612. +68 6 24 0 0 0 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 0 0 0 0 0 0
  95614. +0 0 0 0 0 0 0 0 0
  95615. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95616. +0 0 0 6 1 2 19 2 7 3 0 1 0 0 0 0 0 0
  95617. +0 0 0 0 0 0 65 6 23 180 16 63 189 17 66 188 17 66
  95618. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95619. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 83 8 29
  95620. +0 0 0 0 0 0 0 0 0 41 4 14 177 16 62 189 17 66
  95621. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95622. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  95623. +159 14 56 28 3 10 0 0 0 0 0 0 0 0 0 23 2 8
  95624. +41 4 14 5 0 2 0 0 0 0 0 0 0 0 0 0 0 0
  95625. +0 0 0 0 0 0 0 0 0
  95626. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95627. +23 2 8 113 10 40 159 14 56 65 6 23 0 0 0 0 0 0
  95628. +0 0 0 16 1 6 146 13 51 191 17 67 188 17 66 188 17 66
  95629. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95630. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 132 12 46
  95631. +5 0 2 0 0 0 0 0 0 77 7 27 189 17 66 188 17 66
  95632. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95633. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95634. +190 17 67 98 9 34 0 0 0 0 0 0 12 1 4 134 12 47
  95635. +178 16 63 108 10 38 16 1 6 0 0 0 0 0 0 0 0 0
  95636. +0 0 0 0 0 0 0 0 0
  95637. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30 3 10
  95638. +141 13 49 190 17 67 191 17 67 134 12 47 6 1 2 0 0 0
  95639. +0 0 0 68 6 24 186 17 65 188 17 66 188 17 66 188 17 66
  95640. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95641. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 156 14 55
  95642. +14 1 5 0 0 0 0 0 0 98 9 34 191 17 67 188 17 66
  95643. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95644. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95645. +190 17 67 156 14 55 19 2 7 0 0 0 47 4 16 181 16 63
  95646. +190 17 67 189 17 66 126 14 44 17 2 6 0 0 0 0 0 0
  95647. +0 0 0 0 0 0 0 0 0
  95648. +0 0 0 0 0 0 0 0 0 0 0 0 16 1 6 134 12 47
  95649. +191 17 67 188 17 66 190 17 67 162 15 57 19 2 7 0 0 0
  95650. +3 0 1 123 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  95651. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95652. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 163 15 57
  95653. +20 2 7 0 0 0 0 0 0 101 9 35 191 17 67 188 17 66
  95654. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95655. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95656. +188 17 66 182 16 64 52 5 18 0 0 0 73 7 26 188 17 66
  95657. +188 17 66 188 17 66 189 17 66 109 10 38 5 0 2 0 0 0
  95658. +0 0 0 0 0 0 0 0 0
  95659. +0 0 0 0 0 0 0 0 0 0 0 0 95 9 33 189 17 66
  95660. +188 17 66 188 17 66 189 17 66 171 15 60 29 3 10 0 0 0
  95661. +16 1 6 156 14 55 190 17 67 188 17 66 188 17 66 188 17 66
  95662. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95663. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 158 14 55
  95664. +17 2 6 0 0 0 0 0 0 85 8 30 190 17 67 188 17 66
  95665. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95666. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95667. +188 17 66 189 17 66 81 7 29 0 0 0 85 8 30 190 17 67
  95668. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  95669. +0 0 0 0 0 0 0 0 0
  95670. +0 0 0 0 0 0 0 0 0 25 2 9 162 15 57 190 17 67
  95671. +188 17 66 188 17 66 189 17 66 173 16 61 31 3 11 0 0 0
  95672. +30 3 10 171 15 60 189 17 66 188 17 66 188 17 66 188 17 66
  95673. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95674. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 141 13 49
  95675. +7 1 2 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  95676. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95677. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95678. +188 17 66 191 17 67 98 9 34 0 0 0 88 8 31 190 17 67
  95679. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 5 0 2
  95680. +0 0 0 0 0 0 0 0 0
  95681. +0 0 0 0 0 0 0 0 0 68 6 24 187 17 66 188 17 66
  95682. +188 17 66 188 17 66 189 17 66 170 15 60 28 3 10 0 0 0
  95683. +34 3 12 174 16 61 189 17 66 188 17 66 188 17 66 188 17 66
  95684. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95685. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 101 9 35
  95686. +0 0 0 0 0 0 0 0 0 21 2 7 159 14 56 190 17 67
  95687. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95688. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95689. +188 17 66 191 17 67 98 9 34 0 0 0 81 7 29 189 17 66
  95690. +188 17 66 188 17 66 188 17 66 189 17 66 168 15 59 28 3 10
  95691. +0 0 0 0 0 0 0 0 0
  95692. +0 0 0 0 0 0 0 0 0 109 10 38 191 17 67 188 17 66
  95693. +188 17 66 188 17 66 190 17 67 163 15 57 21 2 7 0 0 0
  95694. +26 2 9 168 15 59 189 17 66 188 17 66 188 17 66 188 17 66
  95695. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95696. +188 17 66 188 17 66 188 17 66 189 17 66 180 16 63 47 4 16
  95697. +0 0 0 0 0 0 0 0 0 0 0 0 108 10 38 190 17 67
  95698. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95699. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95700. +188 17 66 189 17 66 78 7 27 0 0 0 68 6 24 187 17 66
  95701. +188 17 66 188 17 66 188 17 66 188 17 66 183 17 64 56 5 19
  95702. +0 0 0 0 0 0 0 0 0
  95703. +0 0 0 0 0 0 3 0 1 131 12 46 191 17 67 188 17 66
  95704. +188 17 66 188 17 66 190 17 67 151 14 53 12 1 4 0 0 0
  95705. +11 1 4 146 13 51 190 17 67 188 17 66 188 17 66 188 17 66
  95706. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95707. +188 17 66 188 17 66 188 17 66 191 17 67 126 14 44 7 1 2
  95708. +0 0 0 0 0 0 0 0 0 0 0 0 32 3 11 164 15 58
  95709. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95710. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95711. +189 17 66 178 16 62 44 4 15 0 0 0 50 5 17 182 16 64
  95712. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  95713. +0 0 0 0 0 0 0 0 0
  95714. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 188 17 66
  95715. +188 17 66 188 17 66 191 17 67 131 12 46 3 0 1 0 0 0
  95716. +0 0 0 101 9 35 190 17 67 188 17 66 188 17 66 188 17 66
  95717. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95718. +188 17 66 188 17 66 190 17 67 170 15 60 44 4 15 0 0 0
  95719. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 77 7 27
  95720. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95721. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95722. +191 17 67 134 12 47 9 1 3 0 0 0 31 3 11 171 15 60
  95723. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  95724. +0 0 0 0 0 0 0 0 0
  95725. +0 0 0 0 0 0 2 0 1 124 11 43 191 17 67 188 17 66
  95726. +188 17 66 188 17 66 191 17 67 101 9 35 0 0 0 0 0 0
  95727. +0 0 0 35 3 12 168 15 59 190 17 67 188 17 66 188 17 66
  95728. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95729. +188 17 66 189 17 66 182 16 64 77 7 27 0 0 0 0 0 0
  95730. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 1 2
  95731. +99 9 35 185 17 65 189 17 66 188 17 66 188 17 66 188 17 66
  95732. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  95733. +177 16 62 56 5 19 0 0 0 0 0 0 13 1 5 151 14 53
  95734. +190 17 67 188 17 66 188 17 66 188 17 66 185 17 65 56 5 19
  95735. +0 0 0 0 0 0 0 0 0
  95736. +0 0 0 0 0 0 0 0 0 99 9 35 191 17 67 188 17 66
  95737. +188 17 66 188 17 66 186 17 65 65 6 23 0 0 0 0 0 0
  95738. +0 0 0 0 0 0 79 7 28 182 16 64 190 17 67 188 17 66
  95739. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95740. +191 17 67 177 16 62 83 8 29 4 0 1 0 0 0 0 0 0
  95741. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95742. +8 1 3 89 8 31 175 16 62 191 17 67 189 17 66 188 17 66
  95743. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 181 16 63
  95744. +85 8 30 3 0 1 0 0 0 0 0 0 1 0 0 118 13 41
  95745. +191 17 67 188 17 66 188 17 66 189 17 66 173 16 61 34 3 12
  95746. +0 0 0 0 0 0 0 0 0
  95747. +0 0 0 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  95748. +188 17 66 189 17 66 169 15 59 30 3 10 0 0 0 0 0 0
  95749. +0 0 0 0 0 0 5 0 2 83 8 29 173 16 61 191 17 67
  95750. +190 17 67 189 17 66 189 17 66 190 17 67 191 17 67 187 17 66
  95751. +151 14 53 56 5 19 3 0 1 0 0 0 16 1 6 50 5 17
  95752. +79 7 28 95 9 33 95 9 33 75 7 26 41 4 14 10 1 4
  95753. +0 0 0 2 0 1 50 5 17 132 12 46 178 16 62 190 17 67
  95754. +191 17 67 191 17 67 191 17 67 186 17 65 154 14 54 68 6 24
  95755. +4 0 1 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  95756. +187 17 66 188 17 66 188 17 66 191 17 67 141 13 49 9 1 3
  95757. +0 0 0 0 0 0 0 0 0
  95758. +0 0 0 0 0 0 0 0 0 14 1 5 151 14 53 190 17 67
  95759. +188 17 66 191 17 67 131 12 46 5 0 2 0 0 0 0 0 0
  95760. +0 0 0 0 0 0 0 0 0 2 0 1 44 4 15 113 10 40
  95761. +156 14 55 173 16 61 174 16 61 164 15 58 134 12 47 77 7 27
  95762. +18 2 6 0 0 0 16 1 6 85 8 30 151 14 53 182 16 64
  95763. +189 17 66 191 17 67 190 17 67 188 17 66 177 16 62 141 13 49
  95764. +68 6 24 8 1 3 0 0 0 8 1 3 44 4 15 88 8 31
  95765. +113 10 40 122 11 43 108 10 38 67 6 24 20 2 7 0 0 0
  95766. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 28 3 10
  95767. +166 15 58 190 17 67 188 17 66 187 17 66 79 7 28 0 0 0
  95768. +0 0 0 0 0 0 0 0 0
  95769. +0 0 0 0 0 0 0 0 0 0 0 0 73 7 26 185 17 65
  95770. +189 17 66 184 17 65 65 6 23 0 0 0 0 0 0 0 0 0
  95771. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 1
  95772. +17 2 6 32 3 11 34 3 12 22 2 8 6 1 2 0 0 0
  95773. +0 0 0 38 3 13 141 13 49 188 17 66 190 17 67 188 17 66
  95774. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  95775. +184 17 65 122 11 43 21 2 7 0 0 0 0 0 0 0 0 0
  95776. +0 0 0 1 0 0 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 0 0 0 1 0 0
  95778. +108 10 38 191 17 67 191 17 67 141 13 49 16 1 6 0 0 0
  95779. +0 0 0 0 0 0 0 0 0
  95780. +0 0 0 0 0 0 0 0 0 0 0 0 8 1 3 112 10 39
  95781. +186 17 65 124 11 43 10 1 4 0 0 0 0 0 0 0 0 0
  95782. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95783. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95784. +36 3 13 156 14 55 191 17 67 188 17 66 188 17 66 188 17 66
  95785. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95786. +189 17 66 190 17 67 134 12 47 18 2 6 0 0 0 0 0 0
  95787. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95788. +0 0 0 7 1 2 41 4 14 75 7 26 66 5 23 19 2 7
  95789. +26 2 9 144 13 50 154 14 54 40 4 14 0 0 0 0 0 0
  95790. +0 0 0 0 0 0 0 0 0
  95791. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  95792. +56 5 19 19 2 7 0 0 0 7 1 2 29 3 10 35 3 12
  95793. +19 2 7 2 0 1 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 0 0 0 13 1 5
  95795. +134 12 47 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  95796. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95797. +188 17 66 188 17 66 189 17 67 108 10 38 3 0 1 0 0 0
  95798. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  95799. +40 4 14 124 11 43 177 16 62 188 17 66 187 17 66 144 13 50
  95800. +24 2 8 17 2 6 22 2 8 0 0 0 0 0 0 0 0 0
  95801. +0 0 0 0 0 0 0 0 0
  95802. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95803. +0 0 0 0 0 0 19 2 7 122 11 43 171 15 60 175 16 62
  95804. +159 14 56 112 10 39 40 4 14 2 0 1 0 0 0 0 0 0
  95805. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  95806. +186 17 65 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95807. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95808. +188 17 66 188 17 66 189 17 66 174 16 61 41 4 14 0 0 0
  95809. +0 0 0 0 0 0 0 0 0 0 0 0 3 0 1 72 7 25
  95810. +168 15 59 191 17 67 189 17 66 188 17 66 188 17 66 190 17 67
  95811. +95 9 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95812. +0 0 0 0 0 0 0 0 0
  95813. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95814. +0 0 0 0 0 0 95 9 33 191 17 67 189 17 66 189 17 66
  95815. +190 17 67 191 17 67 171 15 60 90 8 32 12 1 4 0 0 0
  95816. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 132 12 46
  95817. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95818. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95819. +188 17 66 188 17 66 188 17 66 190 17 67 98 9 34 0 0 0
  95820. +0 0 0 0 0 0 0 0 0 5 0 2 88 8 31 180 16 63
  95821. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 191 17 67
  95822. +146 13 51 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  95823. +0 0 0 0 0 0 0 0 0
  95824. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95825. +0 0 0 9 1 3 144 13 50 191 17 67 188 17 66 188 17 66
  95826. +188 17 66 188 17 66 189 17 66 187 17 66 123 11 43 20 2 7
  95827. +0 0 0 0 0 0 0 0 0 0 0 0 21 2 7 163 15 57
  95828. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95829. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95830. +188 17 66 188 17 66 188 17 66 191 17 67 134 12 47 5 0 2
  95831. +0 0 0 0 0 0 3 0 1 88 8 31 182 16 64 189 17 66
  95832. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  95833. +171 15 60 31 3 11 0 0 0 0 0 0 0 0 0 0 0 0
  95834. +0 0 0 0 0 0 0 0 0
  95835. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95836. +0 0 0 20 2 7 162 15 57 190 17 67 188 17 66 188 17 66
  95837. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 132 12 46
  95838. +20 2 7 0 0 0 0 0 0 0 0 0 32 3 11 173 16 61
  95839. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95840. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95841. +188 17 66 188 17 66 188 17 66 190 17 67 151 14 53 12 1 4
  95842. +0 0 0 0 0 0 72 7 25 180 16 63 189 17 66 188 17 66
  95843. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95844. +181 16 63 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  95845. +0 0 0 0 0 0 0 0 0
  95846. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95847. +0 0 0 21 2 7 163 15 57 190 17 67 188 17 66 188 17 66
  95848. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  95849. +122 11 43 9 1 3 0 0 0 0 0 0 30 3 10 171 15 60
  95850. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95851. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95852. +188 17 66 188 17 66 188 17 66 190 17 67 146 13 51 10 1 4
  95853. +0 0 0 38 3 13 166 15 58 190 17 67 188 17 66 188 17 66
  95854. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95855. +183 17 64 52 5 18 0 0 0 0 0 0 0 0 0 0 0 0
  95856. +0 0 0 0 0 0 0 0 0
  95857. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95858. +0 0 0 13 1 5 154 14 54 190 17 67 188 17 66 188 17 66
  95859. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95860. +186 17 65 79 7 28 0 0 0 0 0 0 14 1 5 156 14 54
  95861. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95862. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95863. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 2 0 1
  95864. +5 0 2 122 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  95865. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95866. +182 16 64 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  95867. +0 0 0 0 0 0 0 0 0
  95868. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95869. +0 0 0 3 0 1 126 14 44 191 17 67 188 17 66 188 17 66
  95870. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95871. +190 17 67 158 14 55 23 2 8 0 0 0 1 0 0 113 10 40
  95872. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95873. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95874. +188 17 66 188 17 66 188 17 66 188 17 66 78 7 27 0 0 0
  95875. +47 4 16 177 16 62 189 17 66 188 17 66 188 17 66 188 17 66
  95876. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  95877. +173 16 61 34 3 12 0 0 0 0 0 0 0 0 0 0 0 0
  95878. +0 0 0 0 0 0 0 0 0
  95879. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95880. +0 0 0 0 0 0 85 8 30 189 17 66 188 17 66 188 17 66
  95881. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95882. +188 17 66 188 17 66 79 7 28 0 0 0 0 0 0 47 4 16
  95883. +175 16 62 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95884. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95885. +188 17 66 188 17 66 190 17 67 156 14 55 22 2 8 0 0 0
  95886. +109 10 38 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  95887. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  95888. +151 14 53 13 1 5 0 0 0 0 0 0 0 0 0 0 0 0
  95889. +0 0 0 0 0 0 0 0 0
  95890. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95891. +0 0 0 0 0 0 35 3 12 173 16 61 189 17 66 188 17 66
  95892. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95893. +188 17 66 191 17 67 134 12 47 7 1 2 0 0 0 3 0 1
  95894. +99 9 35 188 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  95895. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95896. +188 17 66 189 17 66 181 16 63 68 6 24 0 0 0 18 2 6
  95897. +156 14 55 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  95898. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  95899. +101 9 35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95900. +0 0 0 0 0 0 0 0 0
  95901. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95902. +0 0 0 0 0 0 3 0 1 118 13 41 191 17 67 188 17 66
  95903. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95904. +188 17 66 189 17 66 168 15 59 28 3 10 0 0 0 0 0 0
  95905. +12 1 4 113 10 40 187 17 66 189 17 67 188 17 66 188 17 66
  95906. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95907. +190 17 67 180 16 63 88 8 31 4 0 1 0 0 0 47 4 16
  95908. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95909. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 168 15 59
  95910. +36 3 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95911. +0 0 0 0 0 0 0 0 0
  95912. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95913. +0 0 0 0 0 0 0 0 0 38 3 13 164 15 58 190 17 67
  95914. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95915. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  95916. +0 0 0 11 1 4 90 8 32 169 15 59 190 17 67 190 17 67
  95917. +189 17 66 189 17 66 189 17 66 189 17 66 191 17 67 189 17 66
  95918. +158 14 55 68 6 24 4 0 1 0 0 0 0 0 0 73 7 26
  95919. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95920. +188 17 66 188 17 66 188 17 66 189 17 66 185 17 65 83 8 29
  95921. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95922. +0 0 0 0 0 0 0 0 0
  95923. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95924. +0 0 0 0 0 0 0 0 0 0 0 0 65 6 23 174 16 61
  95925. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95926. +188 17 66 188 17 66 185 17 65 56 5 19 0 0 0 0 0 0
  95927. +0 0 0 0 0 0 2 0 1 35 3 12 99 9 35 146 13 51
  95928. +170 15 60 177 16 62 177 16 62 166 15 58 141 13 49 85 8 30
  95929. +24 2 8 0 0 0 0 0 0 0 0 0 0 0 0 85 8 30
  95930. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95931. +188 17 66 188 17 66 188 17 66 189 17 66 112 10 39 8 1 3
  95932. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95933. +0 0 0 0 0 0 0 0 0
  95934. +0 0 0 0 0 0 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 1 0 0 68 6 24
  95936. +170 15 60 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  95937. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  95938. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 11 1 4
  95939. +28 3 10 40 4 14 38 3 13 25 2 9 8 1 3 0 0 0
  95940. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 78 7 27
  95941. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95942. +188 17 66 189 17 66 187 17 66 113 10 40 14 1 5 0 0 0
  95943. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95944. +0 0 0 0 0 0 0 0 0
  95945. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95946. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  95947. +47 4 16 141 13 49 186 17 65 191 17 67 190 17 67 189 17 66
  95948. +189 17 66 191 17 67 156 14 55 20 2 7 0 0 0 0 0 0
  95949. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95950. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95951. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 44 4 15
  95952. +178 16 62 190 17 67 188 17 66 188 17 66 188 17 66 190 17 67
  95953. +191 17 67 173 16 61 90 8 32 10 1 4 0 0 0 0 0 0
  95954. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95955. +0 0 0 0 0 0 0 0 0
  95956. +0 0 0 0 0 0 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 0 0 0 0 0 0
  95958. +0 0 0 14 1 5 68 6 24 131 12 46 162 15 57 174 16 61
  95959. +171 15 60 146 13 51 56 5 19 0 0 0 0 0 0 0 0 0
  95960. +0 0 0 0 0 0 0 0 0 3 0 1 14 1 5 29 3 10
  95961. +41 4 14 47 4 16 50 5 17 45 4 16 34 3 12 18 2 6
  95962. +5 0 2 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  95963. +90 8 32 169 15 59 185 17 65 187 17 66 182 16 64 163 15 57
  95964. +113 10 40 41 4 14 2 0 1 0 0 0 0 0 0 0 0 0
  95965. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95966. +0 0 0 0 0 0 0 0 0
  95967. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95968. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95969. +0 0 0 0 0 0 0 0 0 5 0 2 21 2 7 34 3 12
  95970. +29 3 10 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  95971. +3 0 1 32 3 11 79 7 28 124 11 43 154 14 54 171 15 60
  95972. +180 16 63 182 16 64 182 16 64 180 16 63 174 16 61 159 14 56
  95973. +132 12 46 88 8 31 34 3 12 3 0 1 0 0 0 0 0 0
  95974. +3 0 1 29 3 10 56 5 19 65 6 23 50 5 17 23 2 8
  95975. +3 0 1 0 0 0 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 0 0 0 0 0 0
  95977. +0 0 0 0 0 0 0 0 0
  95978. +0 0 0 0 0 0 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 0 0 0 0 0 0
  95980. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95981. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 2 9
  95982. +109 10 38 169 15 59 189 17 66 191 17 67 190 17 67 189 17 66
  95983. +189 17 66 188 17 66 188 17 66 188 17 66 189 17 66 190 17 67
  95984. +191 17 67 190 17 67 171 15 60 98 9 34 10 1 3 0 0 0
  95985. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95986. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95987. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95988. +0 0 0 0 0 0 0 0 0
  95989. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95990. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95991. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95992. +0 0 0 0 0 0 0 0 0 0 0 0 14 1 5 141 13 49
  95993. +191 17 67 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95994. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  95995. +188 17 66 188 17 66 189 17 67 186 17 65 65 6 23 0 0 0
  95996. +0 0 0 0 0 0 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 0 0 0 0 0 0
  95998. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  95999. +0 0 0 0 0 0 0 0 0
  96000. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96001. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96002. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96003. +0 0 0 0 0 0 0 0 0 0 0 0 23 2 8 166 15 58
  96004. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96005. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96006. +188 17 66 188 17 66 189 17 66 176 16 62 45 4 16 0 0 0
  96007. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96008. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96009. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96010. +0 0 0 0 0 0 0 0 0
  96011. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96012. +0 0 0 0 0 0 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 0 0 0 0 0 0
  96014. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 83 8 29
  96015. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96016. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96017. +188 17 66 189 17 66 185 17 65 95 9 33 3 0 1 0 0 0
  96018. +0 0 0 0 0 0 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 0 0 0 0 0 0
  96020. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96021. +0 0 0 0 0 0 0 0 0
  96022. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96023. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96024. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96025. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  96026. +85 8 30 176 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  96027. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  96028. +191 17 67 180 16 63 95 9 33 7 1 3 0 0 0 0 0 0
  96029. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96030. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96031. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96032. +0 0 0 0 0 0 0 0 0
  96033. +0 0 0 0 0 0 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 0 0 0 0 0 0
  96035. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96036. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96037. +2 0 1 52 5 18 141 13 49 185 17 65 191 17 67 189 17 67
  96038. +189 17 66 188 17 66 188 17 66 189 17 66 191 17 67 187 17 66
  96039. +146 13 51 56 5 19 4 0 1 0 0 0 0 0 0 0 0 0
  96040. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96041. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96042. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96043. +0 0 0 0 0 0 0 0 0
  96044. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96045. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96046. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96047. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96048. +0 0 0 0 0 0 14 1 5 68 6 24 131 12 46 166 15 58
  96049. +180 16 63 183 17 64 180 16 63 168 15 59 134 12 47 75 7 26
  96050. +17 2 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96051. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96052. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96053. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96054. +0 0 0 0 0 0 0 0 0
  96055. +0 0 0 0 0 0 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 0 0 0 0 0 0
  96057. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96058. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96059. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 24 2 8
  96060. +44 4 15 52 5 18 45 4 16 26 2 9 6 1 2 0 0 0
  96061. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96062. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96063. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96064. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96065. +0 0 0 0 0 0 0 0 0
  96066. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96067. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96068. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96069. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96070. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96071. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96072. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96073. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96074. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96075. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96076. +0 0 0 0 0 0 0 0 0
  96077. +0 0 0 0 0 0 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 0 0 0 0 0 0
  96079. +0 0 0 0 0 0 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 0 0 0 0 0 0
  96081. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96082. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96083. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96084. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96085. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96086. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96087. +0 0 0 0 0 0 0 0 0
  96088. diff -Nur linux-3.12.11.orig/drivers/video/Makefile linux-3.12.11/drivers/video/Makefile
  96089. --- linux-3.12.11.orig/drivers/video/Makefile 2014-02-13 22:51:06.000000000 +0100
  96090. +++ linux-3.12.11/drivers/video/Makefile 2014-02-18 11:52:14.000000000 +0100
  96091. @@ -100,6 +100,7 @@
  96092. obj-$(CONFIG_FB_VOODOO1) += sstfb.o
  96093. obj-$(CONFIG_FB_ARMCLCD) += amba-clcd.o
  96094. obj-$(CONFIG_FB_GOLDFISH) += goldfishfb.o
  96095. +obj-$(CONFIG_FB_BCM2708) += bcm2708_fb.o
  96096. obj-$(CONFIG_FB_68328) += 68328fb.o
  96097. obj-$(CONFIG_FB_GBE) += gbefb.o
  96098. obj-$(CONFIG_FB_CIRRUS) += cirrusfb.o
  96099. diff -Nur linux-3.12.11.orig/drivers/w1/masters/w1-gpio.c linux-3.12.11/drivers/w1/masters/w1-gpio.c
  96100. --- linux-3.12.11.orig/drivers/w1/masters/w1-gpio.c 2014-02-13 22:51:06.000000000 +0100
  96101. +++ linux-3.12.11/drivers/w1/masters/w1-gpio.c 2014-02-18 11:52:14.000000000 +0100
  96102. @@ -22,6 +22,9 @@
  96103. #include "../w1.h"
  96104. #include "../w1_int.h"
  96105. +static int w1_gpio_pullup = 0;
  96106. +module_param_named(pullup, w1_gpio_pullup, int, 0);
  96107. +
  96108. static void w1_gpio_write_bit_dir(void *data, u8 bit)
  96109. {
  96110. struct w1_gpio_platform_data *pdata = data;
  96111. @@ -46,6 +49,16 @@
  96112. return gpio_get_value(pdata->pin) ? 1 : 0;
  96113. }
  96114. +static void w1_gpio_bitbang_pullup(void *data, u8 on)
  96115. +{
  96116. + struct w1_gpio_platform_data *pdata = data;
  96117. +
  96118. + if (on)
  96119. + gpio_direction_output(pdata->pin, 1);
  96120. + else
  96121. + gpio_direction_input(pdata->pin);
  96122. +}
  96123. +
  96124. #if defined(CONFIG_OF)
  96125. static struct of_device_id w1_gpio_dt_ids[] = {
  96126. { .compatible = "w1-gpio" },
  96127. @@ -127,6 +140,13 @@
  96128. master->write_bit = w1_gpio_write_bit_dir;
  96129. }
  96130. + if (w1_gpio_pullup)
  96131. + if (pdata->is_open_drain)
  96132. + printk(KERN_ERR "w1-gpio 'pullup' option "
  96133. + "doesn't work with open drain GPIO\n");
  96134. + else
  96135. + master->bitbang_pullup = w1_gpio_bitbang_pullup;
  96136. +
  96137. err = w1_add_master_device(master);
  96138. if (err) {
  96139. dev_err(&pdev->dev, "w1_add_master device failed\n");
  96140. diff -Nur linux-3.12.11.orig/drivers/w1/w1.h linux-3.12.11/drivers/w1/w1.h
  96141. --- linux-3.12.11.orig/drivers/w1/w1.h 2014-02-13 22:51:06.000000000 +0100
  96142. +++ linux-3.12.11/drivers/w1/w1.h 2014-02-18 11:52:14.000000000 +0100
  96143. @@ -148,6 +148,12 @@
  96144. */
  96145. u8 (*set_pullup)(void *, int);
  96146. + /**
  96147. + * Turns the pullup on/off in bitbanging mode, takes an on/off argument.
  96148. + * @return -1=Error, 0=completed
  96149. + */
  96150. + void (*bitbang_pullup) (void *, u8);
  96151. +
  96152. /** Really nice hardware can handles the different types of ROM search
  96153. * w1_master* is passed to the slave found callback.
  96154. */
  96155. diff -Nur linux-3.12.11.orig/drivers/w1/w1_int.c linux-3.12.11/drivers/w1/w1_int.c
  96156. --- linux-3.12.11.orig/drivers/w1/w1_int.c 2014-02-13 22:51:06.000000000 +0100
  96157. +++ linux-3.12.11/drivers/w1/w1_int.c 2014-02-18 11:52:14.000000000 +0100
  96158. @@ -117,19 +117,21 @@
  96159. printk(KERN_ERR "w1_add_master_device: invalid function set\n");
  96160. return(-EINVAL);
  96161. }
  96162. - /* While it would be electrically possible to make a device that
  96163. - * generated a strong pullup in bit bang mode, only hardware that
  96164. - * controls 1-wire time frames are even expected to support a strong
  96165. - * pullup. w1_io.c would need to support calling set_pullup before
  96166. - * the last write_bit operation of a w1_write_8 which it currently
  96167. - * doesn't.
  96168. - */
  96169. +
  96170. + /* bitbanging hardware uses bitbang_pullup, other hardware uses set_pullup
  96171. + * and takes care of timing itself */
  96172. if (!master->write_byte && !master->touch_bit && master->set_pullup) {
  96173. printk(KERN_ERR "w1_add_master_device: set_pullup requires "
  96174. "write_byte or touch_bit, disabling\n");
  96175. master->set_pullup = NULL;
  96176. }
  96177. + if (master->set_pullup && master->bitbang_pullup) {
  96178. + printk(KERN_ERR "w1_add_master_device: set_pullup should not "
  96179. + "be set when bitbang_pullup is used, disabling\n");
  96180. + master->set_pullup = NULL;
  96181. + }
  96182. +
  96183. /* Lock until the device is added (or not) to w1_masters. */
  96184. mutex_lock(&w1_mlock);
  96185. /* Search for the first available id (starting at 1). */
  96186. diff -Nur linux-3.12.11.orig/drivers/w1/w1_io.c linux-3.12.11/drivers/w1/w1_io.c
  96187. --- linux-3.12.11.orig/drivers/w1/w1_io.c 2014-02-13 22:51:06.000000000 +0100
  96188. +++ linux-3.12.11/drivers/w1/w1_io.c 2014-02-18 11:52:14.000000000 +0100
  96189. @@ -127,10 +127,22 @@
  96190. static void w1_post_write(struct w1_master *dev)
  96191. {
  96192. if (dev->pullup_duration) {
  96193. - if (dev->enable_pullup && dev->bus_master->set_pullup)
  96194. - dev->bus_master->set_pullup(dev->bus_master->data, 0);
  96195. - else
  96196. + if (dev->enable_pullup) {
  96197. + if (dev->bus_master->set_pullup) {
  96198. + dev->bus_master->set_pullup(dev->
  96199. + bus_master->data,
  96200. + 0);
  96201. + } else if (dev->bus_master->bitbang_pullup) {
  96202. + dev->bus_master->
  96203. + bitbang_pullup(dev->bus_master->data, 1);
  96204. msleep(dev->pullup_duration);
  96205. + dev->bus_master->
  96206. + bitbang_pullup(dev->bus_master->data, 0);
  96207. + }
  96208. + } else {
  96209. + msleep(dev->pullup_duration);
  96210. + }
  96211. +
  96212. dev->pullup_duration = 0;
  96213. }
  96214. }
  96215. diff -Nur linux-3.12.11.orig/drivers/watchdog/bcm2708_wdog.c linux-3.12.11/drivers/watchdog/bcm2708_wdog.c
  96216. --- linux-3.12.11.orig/drivers/watchdog/bcm2708_wdog.c 1970-01-01 01:00:00.000000000 +0100
  96217. +++ linux-3.12.11/drivers/watchdog/bcm2708_wdog.c 2014-02-18 11:52:14.000000000 +0100
  96218. @@ -0,0 +1,384 @@
  96219. +/*
  96220. + * Broadcom BCM2708 watchdog driver.
  96221. + *
  96222. + * (c) Copyright 2010 Broadcom Europe Ltd
  96223. + *
  96224. + * This program is free software; you can redistribute it and/or
  96225. + * modify it under the terms of the GNU General Public License
  96226. + * as published by the Free Software Foundation; either version
  96227. + * 2 of the License, or (at your option) any later version.
  96228. + *
  96229. + * BCM2708 watchdog driver. Loosely based on wdt driver.
  96230. + */
  96231. +
  96232. +#include <linux/interrupt.h>
  96233. +#include <linux/module.h>
  96234. +#include <linux/moduleparam.h>
  96235. +#include <linux/types.h>
  96236. +#include <linux/miscdevice.h>
  96237. +#include <linux/watchdog.h>
  96238. +#include <linux/fs.h>
  96239. +#include <linux/ioport.h>
  96240. +#include <linux/notifier.h>
  96241. +#include <linux/reboot.h>
  96242. +#include <linux/init.h>
  96243. +#include <linux/io.h>
  96244. +#include <linux/uaccess.h>
  96245. +#include <mach/platform.h>
  96246. +
  96247. +#include <asm/system.h>
  96248. +
  96249. +#define SECS_TO_WDOG_TICKS(x) ((x) << 16)
  96250. +#define WDOG_TICKS_TO_SECS(x) ((x) >> 16)
  96251. +
  96252. +static unsigned long wdog_is_open;
  96253. +static uint32_t wdog_ticks; /* Ticks to load into wdog timer */
  96254. +static char expect_close;
  96255. +
  96256. +/*
  96257. + * Module parameters
  96258. + */
  96259. +
  96260. +#define WD_TIMO 10 /* Default heartbeat = 60 seconds */
  96261. +static int heartbeat = WD_TIMO; /* Heartbeat in seconds */
  96262. +
  96263. +module_param(heartbeat, int, 0);
  96264. +MODULE_PARM_DESC(heartbeat,
  96265. + "Watchdog heartbeat in seconds. (0 < heartbeat < 65536, default="
  96266. + __MODULE_STRING(WD_TIMO) ")");
  96267. +
  96268. +static int nowayout = WATCHDOG_NOWAYOUT;
  96269. +module_param(nowayout, int, 0);
  96270. +MODULE_PARM_DESC(nowayout,
  96271. + "Watchdog cannot be stopped once started (default="
  96272. + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  96273. +
  96274. +static DEFINE_SPINLOCK(wdog_lock);
  96275. +
  96276. +/**
  96277. + * Start the watchdog driver.
  96278. + */
  96279. +
  96280. +static int wdog_start(unsigned long timeout)
  96281. +{
  96282. + uint32_t cur;
  96283. + unsigned long flags;
  96284. + spin_lock_irqsave(&wdog_lock, flags);
  96285. +
  96286. + /* enable the watchdog */
  96287. + iowrite32(PM_PASSWORD | (timeout & PM_WDOG_TIME_SET),
  96288. + __io_address(PM_WDOG));
  96289. + cur = ioread32(__io_address(PM_RSTC));
  96290. + iowrite32(PM_PASSWORD | (cur & PM_RSTC_WRCFG_CLR) |
  96291. + PM_RSTC_WRCFG_FULL_RESET, __io_address(PM_RSTC));
  96292. +
  96293. + spin_unlock_irqrestore(&wdog_lock, flags);
  96294. + return 0;
  96295. +}
  96296. +
  96297. +/**
  96298. + * Stop the watchdog driver.
  96299. + */
  96300. +
  96301. +static int wdog_stop(void)
  96302. +{
  96303. + iowrite32(PM_PASSWORD | PM_RSTC_RESET, __io_address(PM_RSTC));
  96304. + printk(KERN_INFO "watchdog stopped\n");
  96305. + return 0;
  96306. +}
  96307. +
  96308. +/**
  96309. + * Reload counter one with the watchdog heartbeat. We don't bother
  96310. + * reloading the cascade counter.
  96311. + */
  96312. +
  96313. +static void wdog_ping(void)
  96314. +{
  96315. + wdog_start(wdog_ticks);
  96316. +}
  96317. +
  96318. +/**
  96319. + * @t: the new heartbeat value that needs to be set.
  96320. + *
  96321. + * Set a new heartbeat value for the watchdog device. If the heartbeat
  96322. + * value is incorrect we keep the old value and return -EINVAL. If
  96323. + * successful we return 0.
  96324. + */
  96325. +
  96326. +static int wdog_set_heartbeat(int t)
  96327. +{
  96328. + if (t < 1 || t > WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET))
  96329. + return -EINVAL;
  96330. +
  96331. + heartbeat = t;
  96332. + wdog_ticks = SECS_TO_WDOG_TICKS(t);
  96333. + return 0;
  96334. +}
  96335. +
  96336. +/**
  96337. + * @file: file handle to the watchdog
  96338. + * @buf: buffer to write (unused as data does not matter here
  96339. + * @count: count of bytes
  96340. + * @ppos: pointer to the position to write. No seeks allowed
  96341. + *
  96342. + * A write to a watchdog device is defined as a keepalive signal.
  96343. + *
  96344. + * if 'nowayout' is set then normally a close() is ignored. But
  96345. + * if you write 'V' first then the close() will stop the timer.
  96346. + */
  96347. +
  96348. +static ssize_t wdog_write(struct file *file, const char __user *buf,
  96349. + size_t count, loff_t *ppos)
  96350. +{
  96351. + if (count) {
  96352. + if (!nowayout) {
  96353. + size_t i;
  96354. +
  96355. + /* In case it was set long ago */
  96356. + expect_close = 0;
  96357. +
  96358. + for (i = 0; i != count; i++) {
  96359. + char c;
  96360. + if (get_user(c, buf + i))
  96361. + return -EFAULT;
  96362. + if (c == 'V')
  96363. + expect_close = 42;
  96364. + }
  96365. + }
  96366. + wdog_ping();
  96367. + }
  96368. + return count;
  96369. +}
  96370. +
  96371. +static int wdog_get_status(void)
  96372. +{
  96373. + unsigned long flags;
  96374. + int status = 0;
  96375. + spin_lock_irqsave(&wdog_lock, flags);
  96376. + /* FIXME: readback reset reason */
  96377. + spin_unlock_irqrestore(&wdog_lock, flags);
  96378. + return status;
  96379. +}
  96380. +
  96381. +static uint32_t wdog_get_remaining(void)
  96382. +{
  96383. + uint32_t ret = ioread32(__io_address(PM_WDOG));
  96384. + return ret & PM_WDOG_TIME_SET;
  96385. +}
  96386. +
  96387. +/**
  96388. + * @file: file handle to the device
  96389. + * @cmd: watchdog command
  96390. + * @arg: argument pointer
  96391. + *
  96392. + * The watchdog API defines a common set of functions for all watchdogs
  96393. + * according to their available features. We only actually usefully support
  96394. + * querying capabilities and current status.
  96395. + */
  96396. +
  96397. +static long wdog_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  96398. +{
  96399. + void __user *argp = (void __user *)arg;
  96400. + int __user *p = argp;
  96401. + int new_heartbeat;
  96402. + int status;
  96403. + int options;
  96404. + uint32_t remaining;
  96405. +
  96406. + struct watchdog_info ident = {
  96407. + .options = WDIOF_SETTIMEOUT|
  96408. + WDIOF_MAGICCLOSE|
  96409. + WDIOF_KEEPALIVEPING,
  96410. + .firmware_version = 1,
  96411. + .identity = "BCM2708",
  96412. + };
  96413. +
  96414. + switch (cmd) {
  96415. + case WDIOC_GETSUPPORT:
  96416. + return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
  96417. + case WDIOC_GETSTATUS:
  96418. + status = wdog_get_status();
  96419. + return put_user(status, p);
  96420. + case WDIOC_GETBOOTSTATUS:
  96421. + return put_user(0, p);
  96422. + case WDIOC_KEEPALIVE:
  96423. + wdog_ping();
  96424. + return 0;
  96425. + case WDIOC_SETTIMEOUT:
  96426. + if (get_user(new_heartbeat, p))
  96427. + return -EFAULT;
  96428. + if (wdog_set_heartbeat(new_heartbeat))
  96429. + return -EINVAL;
  96430. + wdog_ping();
  96431. + /* Fall */
  96432. + case WDIOC_GETTIMEOUT:
  96433. + return put_user(heartbeat, p);
  96434. + case WDIOC_GETTIMELEFT:
  96435. + remaining = WDOG_TICKS_TO_SECS(wdog_get_remaining());
  96436. + return put_user(remaining, p);
  96437. + case WDIOC_SETOPTIONS:
  96438. + if (get_user(options, p))
  96439. + return -EFAULT;
  96440. + if (options & WDIOS_DISABLECARD)
  96441. + wdog_stop();
  96442. + if (options & WDIOS_ENABLECARD)
  96443. + wdog_start(wdog_ticks);
  96444. + return 0;
  96445. + default:
  96446. + return -ENOTTY;
  96447. + }
  96448. +}
  96449. +
  96450. +/**
  96451. + * @inode: inode of device
  96452. + * @file: file handle to device
  96453. + *
  96454. + * The watchdog device has been opened. The watchdog device is single
  96455. + * open and on opening we load the counters.
  96456. + */
  96457. +
  96458. +static int wdog_open(struct inode *inode, struct file *file)
  96459. +{
  96460. + if (test_and_set_bit(0, &wdog_is_open))
  96461. + return -EBUSY;
  96462. + /*
  96463. + * Activate
  96464. + */
  96465. + wdog_start(wdog_ticks);
  96466. + return nonseekable_open(inode, file);
  96467. +}
  96468. +
  96469. +/**
  96470. + * @inode: inode to board
  96471. + * @file: file handle to board
  96472. + *
  96473. + * The watchdog has a configurable API. There is a religious dispute
  96474. + * between people who want their watchdog to be able to shut down and
  96475. + * those who want to be sure if the watchdog manager dies the machine
  96476. + * reboots. In the former case we disable the counters, in the latter
  96477. + * case you have to open it again very soon.
  96478. + */
  96479. +
  96480. +static int wdog_release(struct inode *inode, struct file *file)
  96481. +{
  96482. + if (expect_close == 42) {
  96483. + wdog_stop();
  96484. + } else {
  96485. + printk(KERN_CRIT
  96486. + "wdt: WDT device closed unexpectedly. WDT will not stop!\n");
  96487. + wdog_ping();
  96488. + }
  96489. + clear_bit(0, &wdog_is_open);
  96490. + expect_close = 0;
  96491. + return 0;
  96492. +}
  96493. +
  96494. +/**
  96495. + * @this: our notifier block
  96496. + * @code: the event being reported
  96497. + * @unused: unused
  96498. + *
  96499. + * Our notifier is called on system shutdowns. Turn the watchdog
  96500. + * off so that it does not fire during the next reboot.
  96501. + */
  96502. +
  96503. +static int wdog_notify_sys(struct notifier_block *this, unsigned long code,
  96504. + void *unused)
  96505. +{
  96506. + if (code == SYS_DOWN || code == SYS_HALT)
  96507. + wdog_stop();
  96508. + return NOTIFY_DONE;
  96509. +}
  96510. +
  96511. +/*
  96512. + * Kernel Interfaces
  96513. + */
  96514. +
  96515. +
  96516. +static const struct file_operations wdog_fops = {
  96517. + .owner = THIS_MODULE,
  96518. + .llseek = no_llseek,
  96519. + .write = wdog_write,
  96520. + .unlocked_ioctl = wdog_ioctl,
  96521. + .open = wdog_open,
  96522. + .release = wdog_release,
  96523. +};
  96524. +
  96525. +static struct miscdevice wdog_miscdev = {
  96526. + .minor = WATCHDOG_MINOR,
  96527. + .name = "watchdog",
  96528. + .fops = &wdog_fops,
  96529. +};
  96530. +
  96531. +/*
  96532. + * The WDT card needs to learn about soft shutdowns in order to
  96533. + * turn the timebomb registers off.
  96534. + */
  96535. +
  96536. +static struct notifier_block wdog_notifier = {
  96537. + .notifier_call = wdog_notify_sys,
  96538. +};
  96539. +
  96540. +/**
  96541. + * cleanup_module:
  96542. + *
  96543. + * Unload the watchdog. You cannot do this with any file handles open.
  96544. + * If your watchdog is set to continue ticking on close and you unload
  96545. + * it, well it keeps ticking. We won't get the interrupt but the board
  96546. + * will not touch PC memory so all is fine. You just have to load a new
  96547. + * module in 60 seconds or reboot.
  96548. + */
  96549. +
  96550. +static void __exit wdog_exit(void)
  96551. +{
  96552. + misc_deregister(&wdog_miscdev);
  96553. + unregister_reboot_notifier(&wdog_notifier);
  96554. +}
  96555. +
  96556. +static int __init wdog_init(void)
  96557. +{
  96558. + int ret;
  96559. +
  96560. + /* Check that the heartbeat value is within it's range;
  96561. + if not reset to the default */
  96562. + if (wdog_set_heartbeat(heartbeat)) {
  96563. + wdog_set_heartbeat(WD_TIMO);
  96564. + printk(KERN_INFO "bcm2708_wdog: heartbeat value must be "
  96565. + "0 < heartbeat < %d, using %d\n",
  96566. + WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET),
  96567. + WD_TIMO);
  96568. + }
  96569. +
  96570. + ret = register_reboot_notifier(&wdog_notifier);
  96571. + if (ret) {
  96572. + printk(KERN_ERR
  96573. + "wdt: cannot register reboot notifier (err=%d)\n", ret);
  96574. + goto out_reboot;
  96575. + }
  96576. +
  96577. + ret = misc_register(&wdog_miscdev);
  96578. + if (ret) {
  96579. + printk(KERN_ERR
  96580. + "wdt: cannot register miscdev on minor=%d (err=%d)\n",
  96581. + WATCHDOG_MINOR, ret);
  96582. + goto out_misc;
  96583. + }
  96584. +
  96585. + printk(KERN_INFO "bcm2708 watchdog, heartbeat=%d sec (nowayout=%d)\n",
  96586. + heartbeat, nowayout);
  96587. + return 0;
  96588. +
  96589. +out_misc:
  96590. + unregister_reboot_notifier(&wdog_notifier);
  96591. +out_reboot:
  96592. + return ret;
  96593. +}
  96594. +
  96595. +module_init(wdog_init);
  96596. +module_exit(wdog_exit);
  96597. +
  96598. +MODULE_AUTHOR("Luke Diamand");
  96599. +MODULE_DESCRIPTION("Driver for BCM2708 watchdog");
  96600. +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  96601. +MODULE_ALIAS_MISCDEV(TEMP_MINOR);
  96602. +MODULE_LICENSE("GPL");
  96603. diff -Nur linux-3.12.11.orig/drivers/watchdog/Kconfig linux-3.12.11/drivers/watchdog/Kconfig
  96604. --- linux-3.12.11.orig/drivers/watchdog/Kconfig 2014-02-13 22:51:06.000000000 +0100
  96605. +++ linux-3.12.11/drivers/watchdog/Kconfig 2014-02-18 11:52:14.000000000 +0100
  96606. @@ -392,6 +392,12 @@
  96607. To compile this driver as a module, choose M here: the
  96608. module will be called retu_wdt.
  96609. +config BCM2708_WDT
  96610. + tristate "BCM2708 Watchdog"
  96611. + depends on ARCH_BCM2708
  96612. + help
  96613. + Enables BCM2708 watchdog support.
  96614. +
  96615. # AVR32 Architecture
  96616. config AT32AP700X_WDT
  96617. diff -Nur linux-3.12.11.orig/drivers/watchdog/Makefile linux-3.12.11/drivers/watchdog/Makefile
  96618. --- linux-3.12.11.orig/drivers/watchdog/Makefile 2014-02-13 22:51:06.000000000 +0100
  96619. +++ linux-3.12.11/drivers/watchdog/Makefile 2014-02-18 11:52:14.000000000 +0100
  96620. @@ -54,6 +54,7 @@
  96621. obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o
  96622. obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o
  96623. obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o
  96624. +obj-$(CONFIG_BCM2708_WDT) += bcm2708_wdog.o
  96625. obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o
  96626. # AVR32 Architecture
  96627. diff -Nur linux-3.12.11.orig/include/linux/broadcom/vc_cma.h linux-3.12.11/include/linux/broadcom/vc_cma.h
  96628. --- linux-3.12.11.orig/include/linux/broadcom/vc_cma.h 1970-01-01 01:00:00.000000000 +0100
  96629. +++ linux-3.12.11/include/linux/broadcom/vc_cma.h 2014-02-18 11:52:14.000000000 +0100
  96630. @@ -0,0 +1,29 @@
  96631. +/*****************************************************************************
  96632. +* Copyright 2012 Broadcom Corporation. All rights reserved.
  96633. +*
  96634. +* Unless you and Broadcom execute a separate written software license
  96635. +* agreement governing use of this software, this software is licensed to you
  96636. +* under the terms of the GNU General Public License version 2, available at
  96637. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  96638. +*
  96639. +* Notwithstanding the above, under no circumstances may you combine this
  96640. +* software in any way with any other Broadcom software provided under a
  96641. +* license other than the GPL, without Broadcom's express prior written
  96642. +* consent.
  96643. +*****************************************************************************/
  96644. +
  96645. +#if !defined( VC_CMA_H )
  96646. +#define VC_CMA_H
  96647. +
  96648. +#include <linux/ioctl.h>
  96649. +
  96650. +#define VC_CMA_IOC_MAGIC 0xc5
  96651. +
  96652. +#define VC_CMA_IOC_RESERVE _IO(VC_CMA_IOC_MAGIC, 0)
  96653. +
  96654. +#ifdef __KERNEL__
  96655. +extern void __init vc_cma_early_init(void);
  96656. +extern void __init vc_cma_reserve(void);
  96657. +#endif
  96658. +
  96659. +#endif /* VC_CMA_H */
  96660. diff -Nur linux-3.12.11.orig/include/linux/mmc/host.h linux-3.12.11/include/linux/mmc/host.h
  96661. --- linux-3.12.11.orig/include/linux/mmc/host.h 2014-02-13 22:51:06.000000000 +0100
  96662. +++ linux-3.12.11/include/linux/mmc/host.h 2014-02-18 11:52:14.000000000 +0100
  96663. @@ -281,6 +281,7 @@
  96664. MMC_CAP2_PACKED_WR)
  96665. #define MMC_CAP2_NO_PRESCAN_POWERUP (1 << 14) /* Don't power up before scan */
  96666. #define MMC_CAP2_SANITIZE (1 << 15) /* Support Sanitize */
  96667. +#define MMC_CAP2_FORCE_MULTIBLOCK (1 << 31) /* Always use multiblock transfers */
  96668. mmc_pm_flag_t pm_caps; /* supported pm features */
  96669. diff -Nur linux-3.12.11.orig/include/linux/mmc/sdhci.h linux-3.12.11/include/linux/mmc/sdhci.h
  96670. --- linux-3.12.11.orig/include/linux/mmc/sdhci.h 2014-02-13 22:51:06.000000000 +0100
  96671. +++ linux-3.12.11/include/linux/mmc/sdhci.h 2014-02-18 11:52:14.000000000 +0100
  96672. @@ -100,6 +100,7 @@
  96673. #define SDHCI_QUIRK2_BROKEN_HOST_CONTROL (1<<5)
  96674. int irq; /* Device IRQ */
  96675. + int second_irq; /* Additional IRQ to disable/enable in low-latency mode */
  96676. void __iomem *ioaddr; /* Mapped address */
  96677. const struct sdhci_ops *ops; /* Low level hw interface */
  96678. @@ -131,6 +132,7 @@
  96679. #define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
  96680. #define SDHCI_SDR104_NEEDS_TUNING (1<<10) /* SDR104/HS200 needs tuning */
  96681. #define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */
  96682. +#define SDHCI_USE_PLATDMA (1<<12) /* Host uses 3rd party DMA */
  96683. unsigned int version; /* SDHCI spec. version */
  96684. @@ -146,6 +148,7 @@
  96685. struct mmc_request *mrq; /* Current request */
  96686. struct mmc_command *cmd; /* Current command */
  96687. + int last_cmdop; /* Opcode of last cmd sent */
  96688. struct mmc_data *data; /* Current data request */
  96689. unsigned int data_early:1; /* Data finished before cmd */
  96690. diff -Nur linux-3.12.11.orig/include/sound/soc-dai.h linux-3.12.11/include/sound/soc-dai.h
  96691. --- linux-3.12.11.orig/include/sound/soc-dai.h 2014-02-13 22:51:06.000000000 +0100
  96692. +++ linux-3.12.11/include/sound/soc-dai.h 2014-02-18 11:52:14.000000000 +0100
  96693. @@ -105,6 +105,8 @@
  96694. int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
  96695. int pll_id, int source, unsigned int freq_in, unsigned int freq_out);
  96696. +int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio);
  96697. +
  96698. /* Digital Audio interface formatting */
  96699. int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt);
  96700. @@ -131,6 +133,7 @@
  96701. int (*set_pll)(struct snd_soc_dai *dai, int pll_id, int source,
  96702. unsigned int freq_in, unsigned int freq_out);
  96703. int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div);
  96704. + int (*set_bclk_ratio)(struct snd_soc_dai *dai, unsigned int ratio);
  96705. /*
  96706. * DAI format configuration
  96707. diff -Nur linux-3.12.11.orig/include/uapi/linux/fb.h linux-3.12.11/include/uapi/linux/fb.h
  96708. --- linux-3.12.11.orig/include/uapi/linux/fb.h 2014-02-13 22:51:06.000000000 +0100
  96709. +++ linux-3.12.11/include/uapi/linux/fb.h 2014-02-18 11:52:14.000000000 +0100
  96710. @@ -34,6 +34,11 @@
  96711. #define FBIOPUT_MODEINFO 0x4617
  96712. #define FBIOGET_DISPINFO 0x4618
  96713. #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
  96714. +/*
  96715. + * HACK: use 'z' in order not to clash with any other ioctl numbers which might
  96716. + * be concurrently added to the mainline kernel
  96717. + */
  96718. +#define FBIOCOPYAREA _IOW('z', 0x21, struct fb_copyarea)
  96719. #define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */
  96720. #define FB_TYPE_PLANES 1 /* Non interleaved planes */
  96721. diff -Nur linux-3.12.11.orig/sound/arm/bcm2835.c linux-3.12.11/sound/arm/bcm2835.c
  96722. --- linux-3.12.11.orig/sound/arm/bcm2835.c 1970-01-01 01:00:00.000000000 +0100
  96723. +++ linux-3.12.11/sound/arm/bcm2835.c 2014-02-18 11:52:14.000000000 +0100
  96724. @@ -0,0 +1,413 @@
  96725. +/*****************************************************************************
  96726. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  96727. +*
  96728. +* Unless you and Broadcom execute a separate written software license
  96729. +* agreement governing use of this software, this software is licensed to you
  96730. +* under the terms of the GNU General Public License version 2, available at
  96731. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  96732. +*
  96733. +* Notwithstanding the above, under no circumstances may you combine this
  96734. +* software in any way with any other Broadcom software provided under a
  96735. +* license other than the GPL, without Broadcom's express prior written
  96736. +* consent.
  96737. +*****************************************************************************/
  96738. +
  96739. +#include <linux/platform_device.h>
  96740. +
  96741. +#include <linux/init.h>
  96742. +#include <linux/slab.h>
  96743. +#include <linux/module.h>
  96744. +
  96745. +#include "bcm2835.h"
  96746. +
  96747. +/* module parameters (see "Module Parameters") */
  96748. +/* SNDRV_CARDS: maximum number of cards supported by this module */
  96749. +static int index[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = -1 };
  96750. +static char *id[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = NULL };
  96751. +static int enable[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = 1 };
  96752. +
  96753. +/* HACKY global pointers needed for successive probes to work : ssp
  96754. + * But compared against the changes we will have to do in VC audio_ipc code
  96755. + * to export 8 audio_ipc devices as a single IPC device and then monitor all
  96756. + * four devices in a thread, this gets things done quickly and should be easier
  96757. + * to debug if we run into issues
  96758. + */
  96759. +
  96760. +static struct snd_card *g_card = NULL;
  96761. +static bcm2835_chip_t *g_chip = NULL;
  96762. +
  96763. +static int snd_bcm2835_free(bcm2835_chip_t * chip)
  96764. +{
  96765. + kfree(chip);
  96766. + return 0;
  96767. +}
  96768. +
  96769. +/* component-destructor
  96770. + * (see "Management of Cards and Components")
  96771. + */
  96772. +static int snd_bcm2835_dev_free(struct snd_device *device)
  96773. +{
  96774. + return snd_bcm2835_free(device->device_data);
  96775. +}
  96776. +
  96777. +/* chip-specific constructor
  96778. + * (see "Management of Cards and Components")
  96779. + */
  96780. +static int snd_bcm2835_create(struct snd_card *card,
  96781. + struct platform_device *pdev,
  96782. + bcm2835_chip_t ** rchip)
  96783. +{
  96784. + bcm2835_chip_t *chip;
  96785. + int err;
  96786. + static struct snd_device_ops ops = {
  96787. + .dev_free = snd_bcm2835_dev_free,
  96788. + };
  96789. +
  96790. + *rchip = NULL;
  96791. +
  96792. + chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  96793. + if (chip == NULL)
  96794. + return -ENOMEM;
  96795. +
  96796. + chip->card = card;
  96797. +
  96798. + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  96799. + if (err < 0) {
  96800. + snd_bcm2835_free(chip);
  96801. + return err;
  96802. + }
  96803. +
  96804. + *rchip = chip;
  96805. + return 0;
  96806. +}
  96807. +
  96808. +static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
  96809. +{
  96810. + static int dev;
  96811. + bcm2835_chip_t *chip;
  96812. + struct snd_card *card;
  96813. + int err;
  96814. +
  96815. + if (dev >= MAX_SUBSTREAMS)
  96816. + return -ENODEV;
  96817. +
  96818. + if (!enable[dev]) {
  96819. + dev++;
  96820. + return -ENOENT;
  96821. + }
  96822. +
  96823. + if (dev > 0)
  96824. + goto add_register_map;
  96825. +
  96826. + err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &g_card);
  96827. + if (err < 0)
  96828. + goto out;
  96829. +
  96830. + snd_card_set_dev(g_card, &pdev->dev);
  96831. + strcpy(g_card->driver, "BRCM bcm2835 ALSA Driver");
  96832. + strcpy(g_card->shortname, "bcm2835 ALSA");
  96833. + sprintf(g_card->longname, "%s", g_card->shortname);
  96834. +
  96835. + err = snd_bcm2835_create(g_card, pdev, &chip);
  96836. + if (err < 0) {
  96837. + dev_err(&pdev->dev, "Failed to create bcm2835 chip\n");
  96838. + goto out_bcm2835_create;
  96839. + }
  96840. +
  96841. + g_chip = chip;
  96842. + err = snd_bcm2835_new_pcm(chip);
  96843. + if (err < 0) {
  96844. + dev_err(&pdev->dev, "Failed to create new BCM2835 pcm device\n");
  96845. + goto out_bcm2835_new_pcm;
  96846. + }
  96847. +
  96848. + err = snd_bcm2835_new_ctl(chip);
  96849. + if (err < 0) {
  96850. + dev_err(&pdev->dev, "Failed to create new BCM2835 ctl\n");
  96851. + goto out_bcm2835_new_ctl;
  96852. + }
  96853. +
  96854. +add_register_map:
  96855. + card = g_card;
  96856. + chip = g_chip;
  96857. +
  96858. + BUG_ON(!(card && chip));
  96859. +
  96860. + chip->avail_substreams |= (1 << dev);
  96861. + chip->pdev[dev] = pdev;
  96862. +
  96863. + if (dev == 0) {
  96864. + err = snd_card_register(card);
  96865. + if (err < 0) {
  96866. + dev_err(&pdev->dev,
  96867. + "Failed to register bcm2835 ALSA card \n");
  96868. + goto out_card_register;
  96869. + }
  96870. + platform_set_drvdata(pdev, card);
  96871. + audio_info("bcm2835 ALSA card created!\n");
  96872. + } else {
  96873. + audio_info("bcm2835 ALSA chip created!\n");
  96874. + platform_set_drvdata(pdev, (void *)dev);
  96875. + }
  96876. +
  96877. + dev++;
  96878. +
  96879. + return 0;
  96880. +
  96881. +out_card_register:
  96882. +out_bcm2835_new_ctl:
  96883. +out_bcm2835_new_pcm:
  96884. +out_bcm2835_create:
  96885. + BUG_ON(!g_card);
  96886. + if (snd_card_free(g_card))
  96887. + dev_err(&pdev->dev, "Failed to free Registered alsa card\n");
  96888. + g_card = NULL;
  96889. +out:
  96890. + dev = SNDRV_CARDS; /* stop more avail_substreams from being probed */
  96891. + dev_err(&pdev->dev, "BCM2835 ALSA Probe failed !!\n");
  96892. + return err;
  96893. +}
  96894. +
  96895. +static int snd_bcm2835_alsa_remove(struct platform_device *pdev)
  96896. +{
  96897. + uint32_t idx;
  96898. + void *drv_data;
  96899. +
  96900. + drv_data = platform_get_drvdata(pdev);
  96901. +
  96902. + if (drv_data == (void *)g_card) {
  96903. + /* This is the card device */
  96904. + snd_card_free((struct snd_card *)drv_data);
  96905. + g_card = NULL;
  96906. + g_chip = NULL;
  96907. + } else {
  96908. + idx = (uint32_t) drv_data;
  96909. + if (g_card != NULL) {
  96910. + BUG_ON(!g_chip);
  96911. + /* We pass chip device numbers in audio ipc devices
  96912. + * other than the one we registered our card with
  96913. + */
  96914. + idx = (uint32_t) drv_data;
  96915. + BUG_ON(!idx || idx > MAX_SUBSTREAMS);
  96916. + g_chip->avail_substreams &= ~(1 << idx);
  96917. + /* There should be atleast one substream registered
  96918. + * after we are done here, as it wil be removed when
  96919. + * the *remove* is called for the card device
  96920. + */
  96921. + BUG_ON(!g_chip->avail_substreams);
  96922. + }
  96923. + }
  96924. +
  96925. + platform_set_drvdata(pdev, NULL);
  96926. +
  96927. + return 0;
  96928. +}
  96929. +
  96930. +#ifdef CONFIG_PM
  96931. +static int snd_bcm2835_alsa_suspend(struct platform_device *pdev,
  96932. + pm_message_t state)
  96933. +{
  96934. + return 0;
  96935. +}
  96936. +
  96937. +static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
  96938. +{
  96939. + return 0;
  96940. +}
  96941. +
  96942. +#endif
  96943. +
  96944. +static struct platform_driver bcm2835_alsa0_driver = {
  96945. + .probe = snd_bcm2835_alsa_probe,
  96946. + .remove = snd_bcm2835_alsa_remove,
  96947. +#ifdef CONFIG_PM
  96948. + .suspend = snd_bcm2835_alsa_suspend,
  96949. + .resume = snd_bcm2835_alsa_resume,
  96950. +#endif
  96951. + .driver = {
  96952. + .name = "bcm2835_AUD0",
  96953. + .owner = THIS_MODULE,
  96954. + },
  96955. +};
  96956. +
  96957. +static struct platform_driver bcm2835_alsa1_driver = {
  96958. + .probe = snd_bcm2835_alsa_probe,
  96959. + .remove = snd_bcm2835_alsa_remove,
  96960. +#ifdef CONFIG_PM
  96961. + .suspend = snd_bcm2835_alsa_suspend,
  96962. + .resume = snd_bcm2835_alsa_resume,
  96963. +#endif
  96964. + .driver = {
  96965. + .name = "bcm2835_AUD1",
  96966. + .owner = THIS_MODULE,
  96967. + },
  96968. +};
  96969. +
  96970. +static struct platform_driver bcm2835_alsa2_driver = {
  96971. + .probe = snd_bcm2835_alsa_probe,
  96972. + .remove = snd_bcm2835_alsa_remove,
  96973. +#ifdef CONFIG_PM
  96974. + .suspend = snd_bcm2835_alsa_suspend,
  96975. + .resume = snd_bcm2835_alsa_resume,
  96976. +#endif
  96977. + .driver = {
  96978. + .name = "bcm2835_AUD2",
  96979. + .owner = THIS_MODULE,
  96980. + },
  96981. +};
  96982. +
  96983. +static struct platform_driver bcm2835_alsa3_driver = {
  96984. + .probe = snd_bcm2835_alsa_probe,
  96985. + .remove = snd_bcm2835_alsa_remove,
  96986. +#ifdef CONFIG_PM
  96987. + .suspend = snd_bcm2835_alsa_suspend,
  96988. + .resume = snd_bcm2835_alsa_resume,
  96989. +#endif
  96990. + .driver = {
  96991. + .name = "bcm2835_AUD3",
  96992. + .owner = THIS_MODULE,
  96993. + },
  96994. +};
  96995. +
  96996. +static struct platform_driver bcm2835_alsa4_driver = {
  96997. + .probe = snd_bcm2835_alsa_probe,
  96998. + .remove = snd_bcm2835_alsa_remove,
  96999. +#ifdef CONFIG_PM
  97000. + .suspend = snd_bcm2835_alsa_suspend,
  97001. + .resume = snd_bcm2835_alsa_resume,
  97002. +#endif
  97003. + .driver = {
  97004. + .name = "bcm2835_AUD4",
  97005. + .owner = THIS_MODULE,
  97006. + },
  97007. +};
  97008. +
  97009. +static struct platform_driver bcm2835_alsa5_driver = {
  97010. + .probe = snd_bcm2835_alsa_probe,
  97011. + .remove = snd_bcm2835_alsa_remove,
  97012. +#ifdef CONFIG_PM
  97013. + .suspend = snd_bcm2835_alsa_suspend,
  97014. + .resume = snd_bcm2835_alsa_resume,
  97015. +#endif
  97016. + .driver = {
  97017. + .name = "bcm2835_AUD5",
  97018. + .owner = THIS_MODULE,
  97019. + },
  97020. +};
  97021. +
  97022. +static struct platform_driver bcm2835_alsa6_driver = {
  97023. + .probe = snd_bcm2835_alsa_probe,
  97024. + .remove = snd_bcm2835_alsa_remove,
  97025. +#ifdef CONFIG_PM
  97026. + .suspend = snd_bcm2835_alsa_suspend,
  97027. + .resume = snd_bcm2835_alsa_resume,
  97028. +#endif
  97029. + .driver = {
  97030. + .name = "bcm2835_AUD6",
  97031. + .owner = THIS_MODULE,
  97032. + },
  97033. +};
  97034. +
  97035. +static struct platform_driver bcm2835_alsa7_driver = {
  97036. + .probe = snd_bcm2835_alsa_probe,
  97037. + .remove = snd_bcm2835_alsa_remove,
  97038. +#ifdef CONFIG_PM
  97039. + .suspend = snd_bcm2835_alsa_suspend,
  97040. + .resume = snd_bcm2835_alsa_resume,
  97041. +#endif
  97042. + .driver = {
  97043. + .name = "bcm2835_AUD7",
  97044. + .owner = THIS_MODULE,
  97045. + },
  97046. +};
  97047. +
  97048. +static int bcm2835_alsa_device_init(void)
  97049. +{
  97050. + int err;
  97051. + err = platform_driver_register(&bcm2835_alsa0_driver);
  97052. + if (err) {
  97053. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  97054. + goto out;
  97055. + }
  97056. +
  97057. + err = platform_driver_register(&bcm2835_alsa1_driver);
  97058. + if (err) {
  97059. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  97060. + goto unregister_0;
  97061. + }
  97062. +
  97063. + err = platform_driver_register(&bcm2835_alsa2_driver);
  97064. + if (err) {
  97065. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  97066. + goto unregister_1;
  97067. + }
  97068. +
  97069. + err = platform_driver_register(&bcm2835_alsa3_driver);
  97070. + if (err) {
  97071. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  97072. + goto unregister_2;
  97073. + }
  97074. +
  97075. + err = platform_driver_register(&bcm2835_alsa4_driver);
  97076. + if (err) {
  97077. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  97078. + goto unregister_3;
  97079. + }
  97080. +
  97081. + err = platform_driver_register(&bcm2835_alsa5_driver);
  97082. + if (err) {
  97083. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  97084. + goto unregister_4;
  97085. + }
  97086. +
  97087. + err = platform_driver_register(&bcm2835_alsa6_driver);
  97088. + if (err) {
  97089. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  97090. + goto unregister_5;
  97091. + }
  97092. +
  97093. + err = platform_driver_register(&bcm2835_alsa7_driver);
  97094. + if (err) {
  97095. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  97096. + goto unregister_6;
  97097. + }
  97098. +
  97099. + return 0;
  97100. +
  97101. +unregister_6:
  97102. + platform_driver_unregister(&bcm2835_alsa6_driver);
  97103. +unregister_5:
  97104. + platform_driver_unregister(&bcm2835_alsa5_driver);
  97105. +unregister_4:
  97106. + platform_driver_unregister(&bcm2835_alsa4_driver);
  97107. +unregister_3:
  97108. + platform_driver_unregister(&bcm2835_alsa3_driver);
  97109. +unregister_2:
  97110. + platform_driver_unregister(&bcm2835_alsa2_driver);
  97111. +unregister_1:
  97112. + platform_driver_unregister(&bcm2835_alsa1_driver);
  97113. +unregister_0:
  97114. + platform_driver_unregister(&bcm2835_alsa0_driver);
  97115. +out:
  97116. + return err;
  97117. +}
  97118. +
  97119. +static void bcm2835_alsa_device_exit(void)
  97120. +{
  97121. + platform_driver_unregister(&bcm2835_alsa0_driver);
  97122. + platform_driver_unregister(&bcm2835_alsa1_driver);
  97123. + platform_driver_unregister(&bcm2835_alsa2_driver);
  97124. + platform_driver_unregister(&bcm2835_alsa3_driver);
  97125. + platform_driver_unregister(&bcm2835_alsa4_driver);
  97126. + platform_driver_unregister(&bcm2835_alsa5_driver);
  97127. + platform_driver_unregister(&bcm2835_alsa6_driver);
  97128. + platform_driver_unregister(&bcm2835_alsa7_driver);
  97129. +}
  97130. +
  97131. +late_initcall(bcm2835_alsa_device_init);
  97132. +module_exit(bcm2835_alsa_device_exit);
  97133. +
  97134. +MODULE_AUTHOR("Dom Cobley");
  97135. +MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
  97136. +MODULE_LICENSE("GPL");
  97137. +MODULE_ALIAS("platform:bcm2835_alsa");
  97138. diff -Nur linux-3.12.11.orig/sound/arm/bcm2835-ctl.c linux-3.12.11/sound/arm/bcm2835-ctl.c
  97139. --- linux-3.12.11.orig/sound/arm/bcm2835-ctl.c 1970-01-01 01:00:00.000000000 +0100
  97140. +++ linux-3.12.11/sound/arm/bcm2835-ctl.c 2014-02-18 11:52:14.000000000 +0100
  97141. @@ -0,0 +1,200 @@
  97142. +/*****************************************************************************
  97143. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  97144. +*
  97145. +* Unless you and Broadcom execute a separate written software license
  97146. +* agreement governing use of this software, this software is licensed to you
  97147. +* under the terms of the GNU General Public License version 2, available at
  97148. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  97149. +*
  97150. +* Notwithstanding the above, under no circumstances may you combine this
  97151. +* software in any way with any other Broadcom software provided under a
  97152. +* license other than the GPL, without Broadcom's express prior written
  97153. +* consent.
  97154. +*****************************************************************************/
  97155. +
  97156. +#include <linux/platform_device.h>
  97157. +#include <linux/init.h>
  97158. +#include <linux/io.h>
  97159. +#include <linux/jiffies.h>
  97160. +#include <linux/slab.h>
  97161. +#include <linux/time.h>
  97162. +#include <linux/wait.h>
  97163. +#include <linux/delay.h>
  97164. +#include <linux/moduleparam.h>
  97165. +#include <linux/sched.h>
  97166. +
  97167. +#include <sound/core.h>
  97168. +#include <sound/control.h>
  97169. +#include <sound/pcm.h>
  97170. +#include <sound/pcm_params.h>
  97171. +#include <sound/rawmidi.h>
  97172. +#include <sound/initval.h>
  97173. +#include <sound/tlv.h>
  97174. +
  97175. +#include "bcm2835.h"
  97176. +
  97177. +/* volume maximum and minimum in terms of 0.01dB */
  97178. +#define CTRL_VOL_MAX 400
  97179. +#define CTRL_VOL_MIN -10239 /* originally -10240 */
  97180. +
  97181. +
  97182. +static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol,
  97183. + struct snd_ctl_elem_info *uinfo)
  97184. +{
  97185. + audio_info(" ... IN\n");
  97186. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  97187. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  97188. + uinfo->count = 1;
  97189. + uinfo->value.integer.min = CTRL_VOL_MIN;
  97190. + uinfo->value.integer.max = CTRL_VOL_MAX; /* 2303 */
  97191. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  97192. + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  97193. + uinfo->count = 1;
  97194. + uinfo->value.integer.min = 0;
  97195. + uinfo->value.integer.max = 1;
  97196. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  97197. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  97198. + uinfo->count = 1;
  97199. + uinfo->value.integer.min = 0;
  97200. + uinfo->value.integer.max = AUDIO_DEST_MAX-1;
  97201. + }
  97202. + audio_info(" ... OUT\n");
  97203. + return 0;
  97204. +}
  97205. +
  97206. +/* toggles mute on or off depending on the value of nmute, and returns
  97207. + * 1 if the mute value was changed, otherwise 0
  97208. + */
  97209. +static int toggle_mute(struct bcm2835_chip *chip, int nmute)
  97210. +{
  97211. + /* if settings are ok, just return 0 */
  97212. + if(chip->mute == nmute)
  97213. + return 0;
  97214. +
  97215. + /* if the sound is muted then we need to unmute */
  97216. + if(chip->mute == CTRL_VOL_MUTE)
  97217. + {
  97218. + chip->volume = chip->old_volume; /* copy the old volume back */
  97219. + audio_info("Unmuting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  97220. + }
  97221. + else /* otherwise we mute */
  97222. + {
  97223. + chip->old_volume = chip->volume;
  97224. + chip->volume = 26214; /* set volume to minimum level AKA mute */
  97225. + audio_info("Muting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  97226. + }
  97227. +
  97228. + chip->mute = nmute;
  97229. + return 1;
  97230. +}
  97231. +
  97232. +static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol,
  97233. + struct snd_ctl_elem_value *ucontrol)
  97234. +{
  97235. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  97236. +
  97237. + BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK));
  97238. +
  97239. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME)
  97240. + ucontrol->value.integer.value[0] = chip2alsa(chip->volume);
  97241. + else if (kcontrol->private_value == PCM_PLAYBACK_MUTE)
  97242. + ucontrol->value.integer.value[0] = chip->mute;
  97243. + else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE)
  97244. + ucontrol->value.integer.value[0] = chip->dest;
  97245. +
  97246. + return 0;
  97247. +}
  97248. +
  97249. +static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
  97250. + struct snd_ctl_elem_value *ucontrol)
  97251. +{
  97252. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  97253. + int changed = 0;
  97254. +
  97255. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  97256. + audio_info("Volume change attempted.. volume = %d new_volume = %d\n", chip->volume, (int)ucontrol->value.integer.value[0]);
  97257. + if (chip->mute == CTRL_VOL_MUTE) {
  97258. + /* changed = toggle_mute(chip, CTRL_VOL_UNMUTE); */
  97259. + return 1; /* should return 0 to signify no change but the mixer takes this as the opposite sign (no idea why) */
  97260. + }
  97261. + if (changed
  97262. + || (ucontrol->value.integer.value[0] != chip2alsa(chip->volume))) {
  97263. +
  97264. + chip->volume = alsa2chip(ucontrol->value.integer.value[0]);
  97265. + changed = 1;
  97266. + }
  97267. +
  97268. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  97269. + /* Now implemented */
  97270. + audio_info(" Mute attempted\n");
  97271. + changed = toggle_mute(chip, ucontrol->value.integer.value[0]);
  97272. +
  97273. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  97274. + if (ucontrol->value.integer.value[0] != chip->dest) {
  97275. + chip->dest = ucontrol->value.integer.value[0];
  97276. + changed = 1;
  97277. + }
  97278. + }
  97279. +
  97280. + if (changed) {
  97281. + if (bcm2835_audio_set_ctls(chip))
  97282. + printk(KERN_ERR "Failed to set ALSA controls..\n");
  97283. + }
  97284. +
  97285. + return changed;
  97286. +}
  97287. +
  97288. +static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1);
  97289. +
  97290. +static struct snd_kcontrol_new snd_bcm2835_ctl[] = {
  97291. + {
  97292. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  97293. + .name = "PCM Playback Volume",
  97294. + .index = 0,
  97295. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  97296. + .private_value = PCM_PLAYBACK_VOLUME,
  97297. + .info = snd_bcm2835_ctl_info,
  97298. + .get = snd_bcm2835_ctl_get,
  97299. + .put = snd_bcm2835_ctl_put,
  97300. + .count = 1,
  97301. + .tlv = {.p = snd_bcm2835_db_scale}
  97302. + },
  97303. + {
  97304. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  97305. + .name = "PCM Playback Switch",
  97306. + .index = 0,
  97307. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  97308. + .private_value = PCM_PLAYBACK_MUTE,
  97309. + .info = snd_bcm2835_ctl_info,
  97310. + .get = snd_bcm2835_ctl_get,
  97311. + .put = snd_bcm2835_ctl_put,
  97312. + .count = 1,
  97313. + },
  97314. + {
  97315. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  97316. + .name = "PCM Playback Route",
  97317. + .index = 0,
  97318. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  97319. + .private_value = PCM_PLAYBACK_DEVICE,
  97320. + .info = snd_bcm2835_ctl_info,
  97321. + .get = snd_bcm2835_ctl_get,
  97322. + .put = snd_bcm2835_ctl_put,
  97323. + .count = 1,
  97324. + },
  97325. +};
  97326. +
  97327. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip)
  97328. +{
  97329. + int err;
  97330. + unsigned int idx;
  97331. +
  97332. + strcpy(chip->card->mixername, "Broadcom Mixer");
  97333. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_ctl); idx++) {
  97334. + err =
  97335. + snd_ctl_add(chip->card,
  97336. + snd_ctl_new1(&snd_bcm2835_ctl[idx], chip));
  97337. + if (err < 0)
  97338. + return err;
  97339. + }
  97340. + return 0;
  97341. +}
  97342. diff -Nur linux-3.12.11.orig/sound/arm/bcm2835.h linux-3.12.11/sound/arm/bcm2835.h
  97343. --- linux-3.12.11.orig/sound/arm/bcm2835.h 1970-01-01 01:00:00.000000000 +0100
  97344. +++ linux-3.12.11/sound/arm/bcm2835.h 2014-02-18 11:52:14.000000000 +0100
  97345. @@ -0,0 +1,157 @@
  97346. +/*****************************************************************************
  97347. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  97348. +*
  97349. +* Unless you and Broadcom execute a separate written software license
  97350. +* agreement governing use of this software, this software is licensed to you
  97351. +* under the terms of the GNU General Public License version 2, available at
  97352. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  97353. +*
  97354. +* Notwithstanding the above, under no circumstances may you combine this
  97355. +* software in any way with any other Broadcom software provided under a
  97356. +* license other than the GPL, without Broadcom's express prior written
  97357. +* consent.
  97358. +*****************************************************************************/
  97359. +
  97360. +#ifndef __SOUND_ARM_BCM2835_H
  97361. +#define __SOUND_ARM_BCM2835_H
  97362. +
  97363. +#include <linux/device.h>
  97364. +#include <linux/list.h>
  97365. +#include <linux/interrupt.h>
  97366. +#include <linux/wait.h>
  97367. +#include <sound/core.h>
  97368. +#include <sound/initval.h>
  97369. +#include <sound/pcm.h>
  97370. +#include <sound/pcm_params.h>
  97371. +#include <sound/pcm-indirect.h>
  97372. +#include <linux/workqueue.h>
  97373. +
  97374. +/*
  97375. +#define AUDIO_DEBUG_ENABLE
  97376. +#define AUDIO_VERBOSE_DEBUG_ENABLE
  97377. +*/
  97378. +
  97379. +/* Debug macros */
  97380. +
  97381. +#ifdef AUDIO_DEBUG_ENABLE
  97382. +#ifdef AUDIO_VERBOSE_DEBUG_ENABLE
  97383. +
  97384. +#define audio_debug(fmt, arg...) \
  97385. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  97386. +
  97387. +#define audio_info(fmt, arg...) \
  97388. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  97389. +
  97390. +#else
  97391. +
  97392. +#define audio_debug(fmt, arg...)
  97393. +
  97394. +#define audio_info(fmt, arg...)
  97395. +
  97396. +#endif /* AUDIO_VERBOSE_DEBUG_ENABLE */
  97397. +
  97398. +#else
  97399. +
  97400. +#define audio_debug(fmt, arg...)
  97401. +
  97402. +#define audio_info(fmt, arg...)
  97403. +
  97404. +#endif /* AUDIO_DEBUG_ENABLE */
  97405. +
  97406. +#define audio_error(fmt, arg...) \
  97407. + printk(KERN_ERR"%s:%d " fmt, __func__, __LINE__, ##arg)
  97408. +
  97409. +#define audio_warning(fmt, arg...) \
  97410. + printk(KERN_WARNING"%s:%d " fmt, __func__, __LINE__, ##arg)
  97411. +
  97412. +#define audio_alert(fmt, arg...) \
  97413. + printk(KERN_ALERT"%s:%d " fmt, __func__, __LINE__, ##arg)
  97414. +
  97415. +#define MAX_SUBSTREAMS (8)
  97416. +#define AVAIL_SUBSTREAMS_MASK (0xff)
  97417. +enum {
  97418. + CTRL_VOL_MUTE,
  97419. + CTRL_VOL_UNMUTE
  97420. +};
  97421. +
  97422. +/* macros for alsa2chip and chip2alsa, instead of functions */
  97423. +
  97424. +#define alsa2chip(vol) (uint)(-((vol << 8) / 100)) /* convert alsa to chip volume (defined as macro rather than function call) */
  97425. +#define chip2alsa(vol) -((vol * 100) >> 8) /* convert chip to alsa volume */
  97426. +
  97427. +/* Some constants for values .. */
  97428. +typedef enum {
  97429. + AUDIO_DEST_AUTO = 0,
  97430. + AUDIO_DEST_HEADPHONES = 1,
  97431. + AUDIO_DEST_HDMI = 2,
  97432. + AUDIO_DEST_MAX,
  97433. +} SND_BCM2835_ROUTE_T;
  97434. +
  97435. +typedef enum {
  97436. + PCM_PLAYBACK_VOLUME,
  97437. + PCM_PLAYBACK_MUTE,
  97438. + PCM_PLAYBACK_DEVICE,
  97439. +} SND_BCM2835_CTRL_T;
  97440. +
  97441. +/* definition of the chip-specific record */
  97442. +typedef struct bcm2835_chip {
  97443. + struct snd_card *card;
  97444. + struct snd_pcm *pcm;
  97445. + /* Bitmat for valid reg_base and irq numbers */
  97446. + uint32_t avail_substreams;
  97447. + struct platform_device *pdev[MAX_SUBSTREAMS];
  97448. + struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
  97449. +
  97450. + int volume;
  97451. + int old_volume; /* stores the volume value whist muted */
  97452. + int dest;
  97453. + int mute;
  97454. +} bcm2835_chip_t;
  97455. +
  97456. +typedef struct bcm2835_alsa_stream {
  97457. + bcm2835_chip_t *chip;
  97458. + struct snd_pcm_substream *substream;
  97459. + struct snd_pcm_indirect pcm_indirect;
  97460. +
  97461. + struct semaphore buffers_update_sem;
  97462. + struct semaphore control_sem;
  97463. + spinlock_t lock;
  97464. + volatile uint32_t control;
  97465. + volatile uint32_t status;
  97466. +
  97467. + int open;
  97468. + int running;
  97469. + int draining;
  97470. +
  97471. + unsigned int pos;
  97472. + unsigned int buffer_size;
  97473. + unsigned int period_size;
  97474. +
  97475. + uint32_t enable_fifo_irq;
  97476. + irq_handler_t fifo_irq_handler;
  97477. +
  97478. + atomic_t retrieved;
  97479. + struct opaque_AUDIO_INSTANCE_T *instance;
  97480. + struct workqueue_struct *my_wq;
  97481. + int idx;
  97482. +} bcm2835_alsa_stream_t;
  97483. +
  97484. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip);
  97485. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip);
  97486. +
  97487. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream);
  97488. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream);
  97489. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  97490. + uint32_t channels, uint32_t samplerate,
  97491. + uint32_t bps);
  97492. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream);
  97493. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream);
  97494. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream);
  97495. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip);
  97496. +int bcm2835_audio_write(bcm2835_alsa_stream_t * alsa_stream, uint32_t count,
  97497. + void *src);
  97498. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream);
  97499. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream);
  97500. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream);
  97501. +
  97502. +#endif /* __SOUND_ARM_BCM2835_H */
  97503. diff -Nur linux-3.12.11.orig/sound/arm/bcm2835-pcm.c linux-3.12.11/sound/arm/bcm2835-pcm.c
  97504. --- linux-3.12.11.orig/sound/arm/bcm2835-pcm.c 1970-01-01 01:00:00.000000000 +0100
  97505. +++ linux-3.12.11/sound/arm/bcm2835-pcm.c 2014-02-18 11:52:14.000000000 +0100
  97506. @@ -0,0 +1,426 @@
  97507. +/*****************************************************************************
  97508. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  97509. +*
  97510. +* Unless you and Broadcom execute a separate written software license
  97511. +* agreement governing use of this software, this software is licensed to you
  97512. +* under the terms of the GNU General Public License version 2, available at
  97513. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  97514. +*
  97515. +* Notwithstanding the above, under no circumstances may you combine this
  97516. +* software in any way with any other Broadcom software provided under a
  97517. +* license other than the GPL, without Broadcom's express prior written
  97518. +* consent.
  97519. +*****************************************************************************/
  97520. +
  97521. +#include <linux/interrupt.h>
  97522. +#include <linux/slab.h>
  97523. +
  97524. +#include "bcm2835.h"
  97525. +
  97526. +/* hardware definition */
  97527. +static struct snd_pcm_hardware snd_bcm2835_playback_hw = {
  97528. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  97529. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  97530. + .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  97531. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  97532. + .rate_min = 8000,
  97533. + .rate_max = 48000,
  97534. + .channels_min = 1,
  97535. + .channels_max = 2,
  97536. + .buffer_bytes_max = 128 * 1024,
  97537. + .period_bytes_min = 1 * 1024,
  97538. + .period_bytes_max = 128 * 1024,
  97539. + .periods_min = 1,
  97540. + .periods_max = 128,
  97541. +};
  97542. +
  97543. +static void snd_bcm2835_playback_free(struct snd_pcm_runtime *runtime)
  97544. +{
  97545. + audio_info("Freeing up alsa stream here ..\n");
  97546. + if (runtime->private_data)
  97547. + kfree(runtime->private_data);
  97548. + runtime->private_data = NULL;
  97549. +}
  97550. +
  97551. +static irqreturn_t bcm2835_playback_fifo_irq(int irq, void *dev_id)
  97552. +{
  97553. + bcm2835_alsa_stream_t *alsa_stream = (bcm2835_alsa_stream_t *) dev_id;
  97554. + uint32_t consumed = 0;
  97555. + int new_period = 0;
  97556. +
  97557. + audio_info(" .. IN\n");
  97558. +
  97559. + audio_info("alsa_stream=%p substream=%p\n", alsa_stream,
  97560. + alsa_stream ? alsa_stream->substream : 0);
  97561. +
  97562. + if (alsa_stream->open)
  97563. + consumed = bcm2835_audio_retrieve_buffers(alsa_stream);
  97564. +
  97565. + /* We get called only if playback was triggered, So, the number of buffers we retrieve in
  97566. + * each iteration are the buffers that have been played out already
  97567. + */
  97568. +
  97569. + if (alsa_stream->period_size) {
  97570. + if ((alsa_stream->pos / alsa_stream->period_size) !=
  97571. + ((alsa_stream->pos + consumed) / alsa_stream->period_size))
  97572. + new_period = 1;
  97573. + }
  97574. + audio_debug("updating pos cur: %d + %d max:%d period_bytes:%d, hw_ptr: %d new_period:%d\n",
  97575. + alsa_stream->pos,
  97576. + consumed,
  97577. + alsa_stream->buffer_size,
  97578. + (int)(alsa_stream->period_size*alsa_stream->substream->runtime->periods),
  97579. + frames_to_bytes(alsa_stream->substream->runtime, alsa_stream->substream->runtime->status->hw_ptr),
  97580. + new_period);
  97581. + if (alsa_stream->buffer_size) {
  97582. + alsa_stream->pos += consumed &~ (1<<30);
  97583. + alsa_stream->pos %= alsa_stream->buffer_size;
  97584. + }
  97585. +
  97586. + if (alsa_stream->substream) {
  97587. + if (new_period)
  97588. + snd_pcm_period_elapsed(alsa_stream->substream);
  97589. + } else {
  97590. + audio_warning(" unexpected NULL substream\n");
  97591. + }
  97592. + audio_info(" .. OUT\n");
  97593. +
  97594. + return IRQ_HANDLED;
  97595. +}
  97596. +
  97597. +/* open callback */
  97598. +static int snd_bcm2835_playback_open(struct snd_pcm_substream *substream)
  97599. +{
  97600. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  97601. + struct snd_pcm_runtime *runtime = substream->runtime;
  97602. + bcm2835_alsa_stream_t *alsa_stream;
  97603. + int idx;
  97604. + int err;
  97605. +
  97606. + audio_info(" .. IN (%d)\n", substream->number);
  97607. +
  97608. + audio_info("Alsa open (%d)\n", substream->number);
  97609. + idx = substream->number;
  97610. +
  97611. + if (idx > MAX_SUBSTREAMS) {
  97612. + audio_error
  97613. + ("substream(%d) device doesn't exist max(%d) substreams allowed\n",
  97614. + idx, MAX_SUBSTREAMS);
  97615. + err = -ENODEV;
  97616. + goto out;
  97617. + }
  97618. +
  97619. + /* Check if we are ready */
  97620. + if (!(chip->avail_substreams & (1 << idx))) {
  97621. + /* We are not ready yet */
  97622. + audio_error("substream(%d) device is not ready yet\n", idx);
  97623. + err = -EAGAIN;
  97624. + goto out;
  97625. + }
  97626. +
  97627. + alsa_stream = kzalloc(sizeof(bcm2835_alsa_stream_t), GFP_KERNEL);
  97628. + if (alsa_stream == NULL) {
  97629. + return -ENOMEM;
  97630. + }
  97631. +
  97632. + /* Initialise alsa_stream */
  97633. + alsa_stream->chip = chip;
  97634. + alsa_stream->substream = substream;
  97635. + alsa_stream->idx = idx;
  97636. + chip->alsa_stream[idx] = alsa_stream;
  97637. +
  97638. + sema_init(&alsa_stream->buffers_update_sem, 0);
  97639. + sema_init(&alsa_stream->control_sem, 0);
  97640. + spin_lock_init(&alsa_stream->lock);
  97641. +
  97642. + /* Enabled in start trigger, called on each "fifo irq" after that */
  97643. + alsa_stream->enable_fifo_irq = 0;
  97644. + alsa_stream->fifo_irq_handler = bcm2835_playback_fifo_irq;
  97645. +
  97646. + runtime->private_data = alsa_stream;
  97647. + runtime->private_free = snd_bcm2835_playback_free;
  97648. + runtime->hw = snd_bcm2835_playback_hw;
  97649. + /* minimum 16 bytes alignment (for vchiq bulk transfers) */
  97650. + snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  97651. + 16);
  97652. +
  97653. + err = bcm2835_audio_open(alsa_stream);
  97654. + if (err != 0) {
  97655. + kfree(alsa_stream);
  97656. + return err;
  97657. + }
  97658. +
  97659. + alsa_stream->open = 1;
  97660. + alsa_stream->draining = 1;
  97661. +
  97662. +out:
  97663. + audio_info(" .. OUT =%d\n", err);
  97664. +
  97665. + return err;
  97666. +}
  97667. +
  97668. +/* close callback */
  97669. +static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream)
  97670. +{
  97671. + /* the hardware-specific codes will be here */
  97672. +
  97673. + struct snd_pcm_runtime *runtime = substream->runtime;
  97674. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  97675. +
  97676. + audio_info(" .. IN\n");
  97677. + audio_info("Alsa close\n");
  97678. +
  97679. + /*
  97680. + * Call stop if it's still running. This happens when app
  97681. + * is force killed and we don't get a stop trigger.
  97682. + */
  97683. + if (alsa_stream->running) {
  97684. + int err;
  97685. + err = bcm2835_audio_stop(alsa_stream);
  97686. + alsa_stream->running = 0;
  97687. + if (err != 0)
  97688. + audio_error(" Failed to STOP alsa device\n");
  97689. + }
  97690. +
  97691. + alsa_stream->period_size = 0;
  97692. + alsa_stream->buffer_size = 0;
  97693. +
  97694. + if (alsa_stream->open) {
  97695. + alsa_stream->open = 0;
  97696. + bcm2835_audio_close(alsa_stream);
  97697. + }
  97698. + if (alsa_stream->chip)
  97699. + alsa_stream->chip->alsa_stream[alsa_stream->idx] = NULL;
  97700. + /*
  97701. + * Do not free up alsa_stream here, it will be freed up by
  97702. + * runtime->private_free callback we registered in *_open above
  97703. + */
  97704. +
  97705. + audio_info(" .. OUT\n");
  97706. +
  97707. + return 0;
  97708. +}
  97709. +
  97710. +/* hw_params callback */
  97711. +static int snd_bcm2835_pcm_hw_params(struct snd_pcm_substream *substream,
  97712. + struct snd_pcm_hw_params *params)
  97713. +{
  97714. + int err;
  97715. + struct snd_pcm_runtime *runtime = substream->runtime;
  97716. + bcm2835_alsa_stream_t *alsa_stream =
  97717. + (bcm2835_alsa_stream_t *) runtime->private_data;
  97718. +
  97719. + audio_info(" .. IN\n");
  97720. +
  97721. + err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
  97722. + if (err < 0) {
  97723. + audio_error
  97724. + (" pcm_lib_malloc failed to allocated pages for buffers\n");
  97725. + return err;
  97726. + }
  97727. +
  97728. + err = bcm2835_audio_set_params(alsa_stream, params_channels(params),
  97729. + params_rate(params),
  97730. + snd_pcm_format_width(params_format
  97731. + (params)));
  97732. + if (err < 0) {
  97733. + audio_error(" error setting hw params\n");
  97734. + }
  97735. +
  97736. + bcm2835_audio_setup(alsa_stream);
  97737. +
  97738. + /* in preparation of the stream, set the controls (volume level) of the stream */
  97739. + bcm2835_audio_set_ctls(alsa_stream->chip);
  97740. +
  97741. + audio_info(" .. OUT\n");
  97742. +
  97743. + return err;
  97744. +}
  97745. +
  97746. +/* hw_free callback */
  97747. +static int snd_bcm2835_pcm_hw_free(struct snd_pcm_substream *substream)
  97748. +{
  97749. + audio_info(" .. IN\n");
  97750. + return snd_pcm_lib_free_pages(substream);
  97751. +}
  97752. +
  97753. +/* prepare callback */
  97754. +static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream)
  97755. +{
  97756. + struct snd_pcm_runtime *runtime = substream->runtime;
  97757. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  97758. +
  97759. + audio_info(" .. IN\n");
  97760. +
  97761. + memset(&alsa_stream->pcm_indirect, 0, sizeof(alsa_stream->pcm_indirect));
  97762. +
  97763. + alsa_stream->pcm_indirect.hw_buffer_size =
  97764. + alsa_stream->pcm_indirect.sw_buffer_size =
  97765. + snd_pcm_lib_buffer_bytes(substream);
  97766. +
  97767. + alsa_stream->buffer_size = snd_pcm_lib_buffer_bytes(substream);
  97768. + alsa_stream->period_size = snd_pcm_lib_period_bytes(substream);
  97769. + alsa_stream->pos = 0;
  97770. +
  97771. + audio_debug("buffer_size=%d, period_size=%d pos=%d frame_bits=%d\n",
  97772. + alsa_stream->buffer_size, alsa_stream->period_size,
  97773. + alsa_stream->pos, runtime->frame_bits);
  97774. +
  97775. + audio_info(" .. OUT\n");
  97776. + return 0;
  97777. +}
  97778. +
  97779. +static void snd_bcm2835_pcm_transfer(struct snd_pcm_substream *substream,
  97780. + struct snd_pcm_indirect *rec, size_t bytes)
  97781. +{
  97782. + struct snd_pcm_runtime *runtime = substream->runtime;
  97783. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  97784. + void *src = (void *)(substream->runtime->dma_area + rec->sw_data);
  97785. + int err;
  97786. +
  97787. + err = bcm2835_audio_write(alsa_stream, bytes, src);
  97788. + if (err)
  97789. + audio_error(" Failed to transfer to alsa device (%d)\n", err);
  97790. +
  97791. +}
  97792. +
  97793. +static int snd_bcm2835_pcm_ack(struct snd_pcm_substream *substream)
  97794. +{
  97795. + struct snd_pcm_runtime *runtime = substream->runtime;
  97796. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  97797. + struct snd_pcm_indirect *pcm_indirect = &alsa_stream->pcm_indirect;
  97798. +
  97799. + pcm_indirect->hw_queue_size = runtime->hw.buffer_bytes_max;
  97800. + snd_pcm_indirect_playback_transfer(substream, pcm_indirect,
  97801. + snd_bcm2835_pcm_transfer);
  97802. + return 0;
  97803. +}
  97804. +
  97805. +/* trigger callback */
  97806. +static int snd_bcm2835_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  97807. +{
  97808. + struct snd_pcm_runtime *runtime = substream->runtime;
  97809. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  97810. + int err = 0;
  97811. +
  97812. + audio_info(" .. IN\n");
  97813. +
  97814. + switch (cmd) {
  97815. + case SNDRV_PCM_TRIGGER_START:
  97816. + audio_debug("bcm2835_AUDIO_TRIGGER_START running=%d\n",
  97817. + alsa_stream->running);
  97818. + if (!alsa_stream->running) {
  97819. + err = bcm2835_audio_start(alsa_stream);
  97820. + if (err == 0) {
  97821. + alsa_stream->pcm_indirect.hw_io =
  97822. + alsa_stream->pcm_indirect.hw_data =
  97823. + bytes_to_frames(runtime,
  97824. + alsa_stream->pos);
  97825. + substream->ops->ack(substream);
  97826. + alsa_stream->running = 1;
  97827. + alsa_stream->draining = 1;
  97828. + } else {
  97829. + audio_error(" Failed to START alsa device (%d)\n", err);
  97830. + }
  97831. + }
  97832. + break;
  97833. + case SNDRV_PCM_TRIGGER_STOP:
  97834. + audio_debug
  97835. + ("bcm2835_AUDIO_TRIGGER_STOP running=%d draining=%d\n",
  97836. + alsa_stream->running, runtime->status->state == SNDRV_PCM_STATE_DRAINING);
  97837. + if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
  97838. + audio_info("DRAINING\n");
  97839. + alsa_stream->draining = 1;
  97840. + } else {
  97841. + audio_info("DROPPING\n");
  97842. + alsa_stream->draining = 0;
  97843. + }
  97844. + if (alsa_stream->running) {
  97845. + err = bcm2835_audio_stop(alsa_stream);
  97846. + if (err != 0)
  97847. + audio_error(" Failed to STOP alsa device (%d)\n", err);
  97848. + alsa_stream->running = 0;
  97849. + }
  97850. + break;
  97851. + default:
  97852. + err = -EINVAL;
  97853. + }
  97854. +
  97855. + audio_info(" .. OUT\n");
  97856. + return err;
  97857. +}
  97858. +
  97859. +/* pointer callback */
  97860. +static snd_pcm_uframes_t
  97861. +snd_bcm2835_pcm_pointer(struct snd_pcm_substream *substream)
  97862. +{
  97863. + struct snd_pcm_runtime *runtime = substream->runtime;
  97864. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  97865. +
  97866. + audio_info(" .. IN\n");
  97867. +
  97868. + audio_debug("pcm_pointer... (%d) hwptr=%d appl=%d pos=%d\n", 0,
  97869. + frames_to_bytes(runtime, runtime->status->hw_ptr),
  97870. + frames_to_bytes(runtime, runtime->control->appl_ptr),
  97871. + alsa_stream->pos);
  97872. +
  97873. + audio_info(" .. OUT\n");
  97874. + return snd_pcm_indirect_playback_pointer(substream,
  97875. + &alsa_stream->pcm_indirect,
  97876. + alsa_stream->pos);
  97877. +}
  97878. +
  97879. +static int snd_bcm2835_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  97880. + unsigned int cmd, void *arg)
  97881. +{
  97882. + int ret = snd_pcm_lib_ioctl(substream, cmd, arg);
  97883. + audio_info(" .. substream=%p, cmd=%d, arg=%p (%x) ret=%d\n", substream,
  97884. + cmd, arg, arg ? *(unsigned *)arg : 0, ret);
  97885. + return ret;
  97886. +}
  97887. +
  97888. +/* operators */
  97889. +static struct snd_pcm_ops snd_bcm2835_playback_ops = {
  97890. + .open = snd_bcm2835_playback_open,
  97891. + .close = snd_bcm2835_playback_close,
  97892. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  97893. + .hw_params = snd_bcm2835_pcm_hw_params,
  97894. + .hw_free = snd_bcm2835_pcm_hw_free,
  97895. + .prepare = snd_bcm2835_pcm_prepare,
  97896. + .trigger = snd_bcm2835_pcm_trigger,
  97897. + .pointer = snd_bcm2835_pcm_pointer,
  97898. + .ack = snd_bcm2835_pcm_ack,
  97899. +};
  97900. +
  97901. +/* create a pcm device */
  97902. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip)
  97903. +{
  97904. + struct snd_pcm *pcm;
  97905. + int err;
  97906. +
  97907. + audio_info(" .. IN\n");
  97908. + err =
  97909. + snd_pcm_new(chip->card, "bcm2835 ALSA", 0, MAX_SUBSTREAMS, 0, &pcm);
  97910. + if (err < 0)
  97911. + return err;
  97912. + pcm->private_data = chip;
  97913. + strcpy(pcm->name, "bcm2835 ALSA");
  97914. + chip->pcm = pcm;
  97915. + chip->dest = AUDIO_DEST_AUTO;
  97916. + chip->volume = alsa2chip(0);
  97917. + chip->mute = CTRL_VOL_UNMUTE; /*disable mute on startup */
  97918. + /* set operators */
  97919. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  97920. + &snd_bcm2835_playback_ops);
  97921. +
  97922. + /* pre-allocation of buffers */
  97923. + /* NOTE: this may fail */
  97924. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  97925. + snd_dma_continuous_data
  97926. + (GFP_KERNEL), 64 * 1024,
  97927. + 64 * 1024);
  97928. +
  97929. + audio_info(" .. OUT\n");
  97930. +
  97931. + return 0;
  97932. +}
  97933. diff -Nur linux-3.12.11.orig/sound/arm/bcm2835-vchiq.c linux-3.12.11/sound/arm/bcm2835-vchiq.c
  97934. --- linux-3.12.11.orig/sound/arm/bcm2835-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  97935. +++ linux-3.12.11/sound/arm/bcm2835-vchiq.c 2014-02-18 11:52:14.000000000 +0100
  97936. @@ -0,0 +1,879 @@
  97937. +/*****************************************************************************
  97938. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  97939. +*
  97940. +* Unless you and Broadcom execute a separate written software license
  97941. +* agreement governing use of this software, this software is licensed to you
  97942. +* under the terms of the GNU General Public License version 2, available at
  97943. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  97944. +*
  97945. +* Notwithstanding the above, under no circumstances may you combine this
  97946. +* software in any way with any other Broadcom software provided under a
  97947. +* license other than the GPL, without Broadcom's express prior written
  97948. +* consent.
  97949. +*****************************************************************************/
  97950. +
  97951. +#include <linux/device.h>
  97952. +#include <sound/core.h>
  97953. +#include <sound/initval.h>
  97954. +#include <sound/pcm.h>
  97955. +#include <linux/io.h>
  97956. +#include <linux/interrupt.h>
  97957. +#include <linux/fs.h>
  97958. +#include <linux/file.h>
  97959. +#include <linux/mm.h>
  97960. +#include <linux/syscalls.h>
  97961. +#include <asm/uaccess.h>
  97962. +#include <linux/slab.h>
  97963. +#include <linux/delay.h>
  97964. +#include <linux/atomic.h>
  97965. +#include <linux/module.h>
  97966. +#include <linux/completion.h>
  97967. +
  97968. +#include "bcm2835.h"
  97969. +
  97970. +/* ---- Include Files -------------------------------------------------------- */
  97971. +
  97972. +#include "interface/vchi/vchi.h"
  97973. +#include "vc_vchi_audioserv_defs.h"
  97974. +
  97975. +/* ---- Private Constants and Types ------------------------------------------ */
  97976. +
  97977. +#define BCM2835_AUDIO_STOP 0
  97978. +#define BCM2835_AUDIO_START 1
  97979. +#define BCM2835_AUDIO_WRITE 2
  97980. +
  97981. +/* Logging macros (for remapping to other logging mechanisms, i.e., printf) */
  97982. +#ifdef AUDIO_DEBUG_ENABLE
  97983. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  97984. + #define LOG_WARN( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  97985. + #define LOG_INFO( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  97986. + #define LOG_DBG( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  97987. +#else
  97988. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  97989. + #define LOG_WARN( fmt, arg... )
  97990. + #define LOG_INFO( fmt, arg... )
  97991. + #define LOG_DBG( fmt, arg... )
  97992. +#endif
  97993. +
  97994. +typedef struct opaque_AUDIO_INSTANCE_T {
  97995. + uint32_t num_connections;
  97996. + VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS];
  97997. + struct completion msg_avail_comp;
  97998. + struct mutex vchi_mutex;
  97999. + bcm2835_alsa_stream_t *alsa_stream;
  98000. + int32_t result;
  98001. + short peer_version;
  98002. +} AUDIO_INSTANCE_T;
  98003. +
  98004. +bool force_bulk = false;
  98005. +
  98006. +/* ---- Private Variables ---------------------------------------------------- */
  98007. +
  98008. +/* ---- Private Function Prototypes ------------------------------------------ */
  98009. +
  98010. +/* ---- Private Functions ---------------------------------------------------- */
  98011. +
  98012. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream);
  98013. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream);
  98014. +static int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  98015. + uint32_t count, void *src);
  98016. +
  98017. +typedef struct {
  98018. + struct work_struct my_work;
  98019. + bcm2835_alsa_stream_t *alsa_stream;
  98020. + int cmd;
  98021. + void *src;
  98022. + uint32_t count;
  98023. +} my_work_t;
  98024. +
  98025. +static void my_wq_function(struct work_struct *work)
  98026. +{
  98027. + my_work_t *w = (my_work_t *) work;
  98028. + int ret = -9;
  98029. + LOG_DBG(" .. IN %p:%d\n", w->alsa_stream, w->cmd);
  98030. + switch (w->cmd) {
  98031. + case BCM2835_AUDIO_START:
  98032. + ret = bcm2835_audio_start_worker(w->alsa_stream);
  98033. + break;
  98034. + case BCM2835_AUDIO_STOP:
  98035. + ret = bcm2835_audio_stop_worker(w->alsa_stream);
  98036. + break;
  98037. + case BCM2835_AUDIO_WRITE:
  98038. + ret = bcm2835_audio_write_worker(w->alsa_stream, w->count,
  98039. + w->src);
  98040. + break;
  98041. + default:
  98042. + LOG_ERR(" Unexpected work: %p:%d\n", w->alsa_stream, w->cmd);
  98043. + break;
  98044. + }
  98045. + kfree((void *)work);
  98046. + LOG_DBG(" .. OUT %d\n", ret);
  98047. +}
  98048. +
  98049. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream)
  98050. +{
  98051. + int ret = -1;
  98052. + LOG_DBG(" .. IN\n");
  98053. + if (alsa_stream->my_wq) {
  98054. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  98055. + /*--- Queue some work (item 1) ---*/
  98056. + if (work) {
  98057. + INIT_WORK((struct work_struct *)work, my_wq_function);
  98058. + work->alsa_stream = alsa_stream;
  98059. + work->cmd = BCM2835_AUDIO_START;
  98060. + if (queue_work
  98061. + (alsa_stream->my_wq, (struct work_struct *)work))
  98062. + ret = 0;
  98063. + } else
  98064. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  98065. + }
  98066. + LOG_DBG(" .. OUT %d\n", ret);
  98067. + return ret;
  98068. +}
  98069. +
  98070. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream)
  98071. +{
  98072. + int ret = -1;
  98073. + LOG_DBG(" .. IN\n");
  98074. + if (alsa_stream->my_wq) {
  98075. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  98076. + /*--- Queue some work (item 1) ---*/
  98077. + if (work) {
  98078. + INIT_WORK((struct work_struct *)work, my_wq_function);
  98079. + work->alsa_stream = alsa_stream;
  98080. + work->cmd = BCM2835_AUDIO_STOP;
  98081. + if (queue_work
  98082. + (alsa_stream->my_wq, (struct work_struct *)work))
  98083. + ret = 0;
  98084. + } else
  98085. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  98086. + }
  98087. + LOG_DBG(" .. OUT %d\n", ret);
  98088. + return ret;
  98089. +}
  98090. +
  98091. +int bcm2835_audio_write(bcm2835_alsa_stream_t *alsa_stream,
  98092. + uint32_t count, void *src)
  98093. +{
  98094. + int ret = -1;
  98095. + LOG_DBG(" .. IN\n");
  98096. + if (alsa_stream->my_wq) {
  98097. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  98098. + /*--- Queue some work (item 1) ---*/
  98099. + if (work) {
  98100. + INIT_WORK((struct work_struct *)work, my_wq_function);
  98101. + work->alsa_stream = alsa_stream;
  98102. + work->cmd = BCM2835_AUDIO_WRITE;
  98103. + work->src = src;
  98104. + work->count = count;
  98105. + if (queue_work
  98106. + (alsa_stream->my_wq, (struct work_struct *)work))
  98107. + ret = 0;
  98108. + } else
  98109. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  98110. + }
  98111. + LOG_DBG(" .. OUT %d\n", ret);
  98112. + return ret;
  98113. +}
  98114. +
  98115. +void my_workqueue_init(bcm2835_alsa_stream_t * alsa_stream)
  98116. +{
  98117. + alsa_stream->my_wq = create_workqueue("my_queue");
  98118. + return;
  98119. +}
  98120. +
  98121. +void my_workqueue_quit(bcm2835_alsa_stream_t * alsa_stream)
  98122. +{
  98123. + if (alsa_stream->my_wq) {
  98124. + flush_workqueue(alsa_stream->my_wq);
  98125. + destroy_workqueue(alsa_stream->my_wq);
  98126. + alsa_stream->my_wq = NULL;
  98127. + }
  98128. + return;
  98129. +}
  98130. +
  98131. +static void audio_vchi_callback(void *param,
  98132. + const VCHI_CALLBACK_REASON_T reason,
  98133. + void *msg_handle)
  98134. +{
  98135. + AUDIO_INSTANCE_T *instance = (AUDIO_INSTANCE_T *) param;
  98136. + int32_t status;
  98137. + int32_t msg_len;
  98138. + VC_AUDIO_MSG_T m;
  98139. + bcm2835_alsa_stream_t *alsa_stream = 0;
  98140. + LOG_DBG(" .. IN instance=%p, param=%p, reason=%d, handle=%p\n",
  98141. + instance, param, reason, msg_handle);
  98142. +
  98143. + if (!instance || reason != VCHI_CALLBACK_MSG_AVAILABLE) {
  98144. + return;
  98145. + }
  98146. + alsa_stream = instance->alsa_stream;
  98147. + status = vchi_msg_dequeue(instance->vchi_handle[0],
  98148. + &m, sizeof m, &msg_len, VCHI_FLAGS_NONE);
  98149. + if (m.type == VC_AUDIO_MSG_TYPE_RESULT) {
  98150. + LOG_DBG
  98151. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_RESULT, success=%d\n",
  98152. + instance, m.u.result.success);
  98153. + instance->result = m.u.result.success;
  98154. + complete(&instance->msg_avail_comp);
  98155. + } else if (m.type == VC_AUDIO_MSG_TYPE_COMPLETE) {
  98156. + irq_handler_t callback = (irq_handler_t) m.u.complete.callback;
  98157. + LOG_DBG
  98158. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_COMPLETE, complete=%d\n",
  98159. + instance, m.u.complete.count);
  98160. + if (alsa_stream && callback) {
  98161. + atomic_add(m.u.complete.count, &alsa_stream->retrieved);
  98162. + callback(0, alsa_stream);
  98163. + } else {
  98164. + LOG_DBG(" .. unexpected alsa_stream=%p, callback=%p\n",
  98165. + alsa_stream, callback);
  98166. + }
  98167. + } else {
  98168. + LOG_DBG(" .. unexpected m.type=%d\n", m.type);
  98169. + }
  98170. + LOG_DBG(" .. OUT\n");
  98171. +}
  98172. +
  98173. +static AUDIO_INSTANCE_T *vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
  98174. + VCHI_CONNECTION_T **
  98175. + vchi_connections,
  98176. + uint32_t num_connections)
  98177. +{
  98178. + uint32_t i;
  98179. + AUDIO_INSTANCE_T *instance;
  98180. + int status;
  98181. +
  98182. + LOG_DBG("%s: start", __func__);
  98183. +
  98184. + if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
  98185. + LOG_ERR("%s: unsupported number of connections %u (max=%u)\n",
  98186. + __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
  98187. +
  98188. + return NULL;
  98189. + }
  98190. + /* Allocate memory for this instance */
  98191. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  98192. +
  98193. + memset(instance, 0, sizeof(*instance));
  98194. + instance->num_connections = num_connections;
  98195. +
  98196. + /* Create a lock for exclusive, serialized VCHI connection access */
  98197. + mutex_init(&instance->vchi_mutex);
  98198. + /* Open the VCHI service connections */
  98199. + for (i = 0; i < num_connections; i++) {
  98200. + SERVICE_CREATION_T params = {
  98201. + VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER),
  98202. + VC_AUDIO_SERVER_NAME, // 4cc service code
  98203. + vchi_connections[i], // passed in fn pointers
  98204. + 0, // rx fifo size (unused)
  98205. + 0, // tx fifo size (unused)
  98206. + audio_vchi_callback, // service callback
  98207. + instance, // service callback parameter
  98208. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk recieves
  98209. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk transmits
  98210. + 0 // want crc check on bulk transfers
  98211. + };
  98212. +
  98213. + status = vchi_service_open(vchi_instance, &params,
  98214. + &instance->vchi_handle[i]);
  98215. + if (status) {
  98216. + LOG_ERR
  98217. + ("%s: failed to open VCHI service connection (status=%d)\n",
  98218. + __func__, status);
  98219. +
  98220. + goto err_close_services;
  98221. + }
  98222. + /* Finished with the service for now */
  98223. + vchi_service_release(instance->vchi_handle[i]);
  98224. + }
  98225. +
  98226. + return instance;
  98227. +
  98228. +err_close_services:
  98229. + for (i = 0; i < instance->num_connections; i++) {
  98230. + vchi_service_close(instance->vchi_handle[i]);
  98231. + }
  98232. +
  98233. + kfree(instance);
  98234. +
  98235. + return NULL;
  98236. +}
  98237. +
  98238. +static int32_t vc_vchi_audio_deinit(AUDIO_INSTANCE_T * instance)
  98239. +{
  98240. + uint32_t i;
  98241. +
  98242. + LOG_DBG(" .. IN\n");
  98243. +
  98244. + if (instance == NULL) {
  98245. + LOG_ERR("%s: invalid handle %p\n", __func__, instance);
  98246. +
  98247. + return -1;
  98248. + }
  98249. +
  98250. + LOG_DBG(" .. about to lock (%d)\n", instance->num_connections);
  98251. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  98252. + {
  98253. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  98254. + return -EINTR;
  98255. + }
  98256. +
  98257. + /* Close all VCHI service connections */
  98258. + for (i = 0; i < instance->num_connections; i++) {
  98259. + int32_t success;
  98260. + LOG_DBG(" .. %i:closing %p\n", i, instance->vchi_handle[i]);
  98261. + vchi_service_use(instance->vchi_handle[i]);
  98262. +
  98263. + success = vchi_service_close(instance->vchi_handle[i]);
  98264. + if (success != 0) {
  98265. + LOG_ERR
  98266. + ("%s: failed to close VCHI service connection (status=%d)\n",
  98267. + __func__, success);
  98268. + }
  98269. + }
  98270. +
  98271. + mutex_unlock(&instance->vchi_mutex);
  98272. +
  98273. + kfree(instance);
  98274. +
  98275. + LOG_DBG(" .. OUT\n");
  98276. +
  98277. + return 0;
  98278. +}
  98279. +
  98280. +static int bcm2835_audio_open_connection(bcm2835_alsa_stream_t * alsa_stream)
  98281. +{
  98282. + static VCHI_INSTANCE_T vchi_instance;
  98283. + static VCHI_CONNECTION_T *vchi_connection;
  98284. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  98285. + int ret;
  98286. + LOG_DBG(" .. IN\n");
  98287. +
  98288. + LOG_INFO("%s: start", __func__);
  98289. + //BUG_ON(instance);
  98290. + if (instance) {
  98291. + LOG_ERR("%s: VCHI instance already open (%p)\n",
  98292. + __func__, instance);
  98293. + instance->alsa_stream = alsa_stream;
  98294. + alsa_stream->instance = instance;
  98295. + ret = 0; // xxx todo -1;
  98296. + goto err_free_mem;
  98297. + }
  98298. +
  98299. + /* Initialize and create a VCHI connection */
  98300. + ret = vchi_initialise(&vchi_instance);
  98301. + if (ret != 0) {
  98302. + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n",
  98303. + __func__, ret);
  98304. +
  98305. + ret = -EIO;
  98306. + goto err_free_mem;
  98307. + }
  98308. + ret = vchi_connect(NULL, 0, vchi_instance);
  98309. + if (ret != 0) {
  98310. + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n",
  98311. + __func__, ret);
  98312. +
  98313. + ret = -EIO;
  98314. + goto err_free_mem;
  98315. + }
  98316. +
  98317. + /* Initialize an instance of the audio service */
  98318. + instance = vc_vchi_audio_init(vchi_instance, &vchi_connection, 1);
  98319. +
  98320. + if (instance == NULL /*|| audio_handle != instance */ ) {
  98321. + LOG_ERR("%s: failed to initialize audio service\n", __func__);
  98322. +
  98323. + ret = -EPERM;
  98324. + goto err_free_mem;
  98325. + }
  98326. +
  98327. + instance->alsa_stream = alsa_stream;
  98328. + alsa_stream->instance = instance;
  98329. +
  98330. + LOG_DBG(" success !\n");
  98331. +err_free_mem:
  98332. + LOG_DBG(" .. OUT\n");
  98333. +
  98334. + return ret;
  98335. +}
  98336. +
  98337. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream)
  98338. +{
  98339. + AUDIO_INSTANCE_T *instance;
  98340. + VC_AUDIO_MSG_T m;
  98341. + int32_t success;
  98342. + int ret;
  98343. + LOG_DBG(" .. IN\n");
  98344. +
  98345. + my_workqueue_init(alsa_stream);
  98346. +
  98347. + ret = bcm2835_audio_open_connection(alsa_stream);
  98348. + if (ret != 0) {
  98349. + ret = -1;
  98350. + goto exit;
  98351. + }
  98352. + instance = alsa_stream->instance;
  98353. +
  98354. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  98355. + {
  98356. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  98357. + return -EINTR;
  98358. + }
  98359. + vchi_service_use(instance->vchi_handle[0]);
  98360. +
  98361. + m.type = VC_AUDIO_MSG_TYPE_OPEN;
  98362. +
  98363. + /* Send the message to the videocore */
  98364. + success = vchi_msg_queue(instance->vchi_handle[0],
  98365. + &m, sizeof m,
  98366. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  98367. +
  98368. + if (success != 0) {
  98369. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  98370. + __func__, success);
  98371. +
  98372. + ret = -1;
  98373. + goto unlock;
  98374. + }
  98375. +
  98376. + ret = 0;
  98377. +
  98378. +unlock:
  98379. + vchi_service_release(instance->vchi_handle[0]);
  98380. + mutex_unlock(&instance->vchi_mutex);
  98381. +exit:
  98382. + LOG_DBG(" .. OUT\n");
  98383. + return ret;
  98384. +}
  98385. +
  98386. +static int bcm2835_audio_set_ctls_chan(bcm2835_alsa_stream_t * alsa_stream,
  98387. + bcm2835_chip_t * chip)
  98388. +{
  98389. + VC_AUDIO_MSG_T m;
  98390. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  98391. + int32_t success;
  98392. + int ret;
  98393. + LOG_DBG(" .. IN\n");
  98394. +
  98395. + LOG_INFO
  98396. + (" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume);
  98397. +
  98398. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  98399. + {
  98400. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  98401. + return -EINTR;
  98402. + }
  98403. + vchi_service_use(instance->vchi_handle[0]);
  98404. +
  98405. + instance->result = -1;
  98406. +
  98407. + m.type = VC_AUDIO_MSG_TYPE_CONTROL;
  98408. + m.u.control.dest = chip->dest;
  98409. + m.u.control.volume = chip->volume;
  98410. +
  98411. + /* Create the message available completion */
  98412. + init_completion(&instance->msg_avail_comp);
  98413. +
  98414. + /* Send the message to the videocore */
  98415. + success = vchi_msg_queue(instance->vchi_handle[0],
  98416. + &m, sizeof m,
  98417. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  98418. +
  98419. + if (success != 0) {
  98420. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  98421. + __func__, success);
  98422. +
  98423. + ret = -1;
  98424. + goto unlock;
  98425. + }
  98426. +
  98427. + /* We are expecting a reply from the videocore */
  98428. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  98429. + if (ret) {
  98430. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  98431. + __func__, success);
  98432. + goto unlock;
  98433. + }
  98434. +
  98435. + if (instance->result != 0) {
  98436. + LOG_ERR("%s: result=%d\n", __func__, instance->result);
  98437. +
  98438. + ret = -1;
  98439. + goto unlock;
  98440. + }
  98441. +
  98442. + ret = 0;
  98443. +
  98444. +unlock:
  98445. + vchi_service_release(instance->vchi_handle[0]);
  98446. + mutex_unlock(&instance->vchi_mutex);
  98447. +
  98448. + LOG_DBG(" .. OUT\n");
  98449. + return ret;
  98450. +}
  98451. +
  98452. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip)
  98453. +{
  98454. + int i;
  98455. + int ret = 0;
  98456. + LOG_DBG(" .. IN\n");
  98457. +
  98458. + /* change ctls for all substreams */
  98459. + for (i = 0; i < MAX_SUBSTREAMS; i++) {
  98460. + if (chip->avail_substreams & (1 << i)) {
  98461. + if (!chip->alsa_stream[i])
  98462. + {
  98463. + LOG_DBG(" No ALSA stream available?! %i:%p (%x)\n", i, chip->alsa_stream[i], chip->avail_substreams);
  98464. + ret = 0;
  98465. + }
  98466. + else if (bcm2835_audio_set_ctls_chan /* returns 0 on success */
  98467. + (chip->alsa_stream[i], chip) != 0)
  98468. + {
  98469. + LOG_DBG("Couldn't set the controls for stream %d\n", i);
  98470. + ret = -1;
  98471. + }
  98472. + else LOG_DBG(" Controls set for stream %d\n", i);
  98473. + }
  98474. + }
  98475. + LOG_DBG(" .. OUT ret=%d\n", ret);
  98476. + return ret;
  98477. +}
  98478. +
  98479. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  98480. + uint32_t channels, uint32_t samplerate,
  98481. + uint32_t bps)
  98482. +{
  98483. + VC_AUDIO_MSG_T m;
  98484. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  98485. + int32_t success;
  98486. + int ret;
  98487. + LOG_DBG(" .. IN\n");
  98488. +
  98489. + LOG_INFO
  98490. + (" Setting ALSA channels(%d), samplerate(%d), bits-per-sample(%d)\n",
  98491. + channels, samplerate, bps);
  98492. +
  98493. + /* resend ctls - alsa_stream may not have been open when first send */
  98494. + ret = bcm2835_audio_set_ctls_chan(alsa_stream, alsa_stream->chip);
  98495. + if (ret != 0) {
  98496. + LOG_ERR(" Alsa controls not supported\n");
  98497. + return -EINVAL;
  98498. + }
  98499. +
  98500. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  98501. + {
  98502. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  98503. + return -EINTR;
  98504. + }
  98505. + vchi_service_use(instance->vchi_handle[0]);
  98506. +
  98507. + instance->result = -1;
  98508. +
  98509. + m.type = VC_AUDIO_MSG_TYPE_CONFIG;
  98510. + m.u.config.channels = channels;
  98511. + m.u.config.samplerate = samplerate;
  98512. + m.u.config.bps = bps;
  98513. +
  98514. + /* Create the message available completion */
  98515. + init_completion(&instance->msg_avail_comp);
  98516. +
  98517. + /* Send the message to the videocore */
  98518. + success = vchi_msg_queue(instance->vchi_handle[0],
  98519. + &m, sizeof m,
  98520. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  98521. +
  98522. + if (success != 0) {
  98523. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  98524. + __func__, success);
  98525. +
  98526. + ret = -1;
  98527. + goto unlock;
  98528. + }
  98529. +
  98530. + /* We are expecting a reply from the videocore */
  98531. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  98532. + if (ret) {
  98533. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  98534. + __func__, success);
  98535. + goto unlock;
  98536. + }
  98537. +
  98538. + if (instance->result != 0) {
  98539. + LOG_ERR("%s: result=%d", __func__, instance->result);
  98540. +
  98541. + ret = -1;
  98542. + goto unlock;
  98543. + }
  98544. +
  98545. + ret = 0;
  98546. +
  98547. +unlock:
  98548. + vchi_service_release(instance->vchi_handle[0]);
  98549. + mutex_unlock(&instance->vchi_mutex);
  98550. +
  98551. + LOG_DBG(" .. OUT\n");
  98552. + return ret;
  98553. +}
  98554. +
  98555. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream)
  98556. +{
  98557. + LOG_DBG(" .. IN\n");
  98558. +
  98559. + LOG_DBG(" .. OUT\n");
  98560. +
  98561. + return 0;
  98562. +}
  98563. +
  98564. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream)
  98565. +{
  98566. + VC_AUDIO_MSG_T m;
  98567. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  98568. + int32_t success;
  98569. + int ret;
  98570. + LOG_DBG(" .. IN\n");
  98571. +
  98572. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  98573. + {
  98574. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  98575. + return -EINTR;
  98576. + }
  98577. + vchi_service_use(instance->vchi_handle[0]);
  98578. +
  98579. + m.type = VC_AUDIO_MSG_TYPE_START;
  98580. +
  98581. + /* Send the message to the videocore */
  98582. + success = vchi_msg_queue(instance->vchi_handle[0],
  98583. + &m, sizeof m,
  98584. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  98585. +
  98586. + if (success != 0) {
  98587. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  98588. + __func__, success);
  98589. +
  98590. + ret = -1;
  98591. + goto unlock;
  98592. + }
  98593. +
  98594. + ret = 0;
  98595. +
  98596. +unlock:
  98597. + vchi_service_release(instance->vchi_handle[0]);
  98598. + mutex_unlock(&instance->vchi_mutex);
  98599. + LOG_DBG(" .. OUT\n");
  98600. + return ret;
  98601. +}
  98602. +
  98603. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream)
  98604. +{
  98605. + VC_AUDIO_MSG_T m;
  98606. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  98607. + int32_t success;
  98608. + int ret;
  98609. + LOG_DBG(" .. IN\n");
  98610. +
  98611. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  98612. + {
  98613. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  98614. + return -EINTR;
  98615. + }
  98616. + vchi_service_use(instance->vchi_handle[0]);
  98617. +
  98618. + m.type = VC_AUDIO_MSG_TYPE_STOP;
  98619. + m.u.stop.draining = alsa_stream->draining;
  98620. +
  98621. + /* Send the message to the videocore */
  98622. + success = vchi_msg_queue(instance->vchi_handle[0],
  98623. + &m, sizeof m,
  98624. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  98625. +
  98626. + if (success != 0) {
  98627. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  98628. + __func__, success);
  98629. +
  98630. + ret = -1;
  98631. + goto unlock;
  98632. + }
  98633. +
  98634. + ret = 0;
  98635. +
  98636. +unlock:
  98637. + vchi_service_release(instance->vchi_handle[0]);
  98638. + mutex_unlock(&instance->vchi_mutex);
  98639. + LOG_DBG(" .. OUT\n");
  98640. + return ret;
  98641. +}
  98642. +
  98643. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream)
  98644. +{
  98645. + VC_AUDIO_MSG_T m;
  98646. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  98647. + int32_t success;
  98648. + int ret;
  98649. + LOG_DBG(" .. IN\n");
  98650. +
  98651. + my_workqueue_quit(alsa_stream);
  98652. +
  98653. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  98654. + {
  98655. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  98656. + return -EINTR;
  98657. + }
  98658. + vchi_service_use(instance->vchi_handle[0]);
  98659. +
  98660. + m.type = VC_AUDIO_MSG_TYPE_CLOSE;
  98661. +
  98662. + /* Create the message available completion */
  98663. + init_completion(&instance->msg_avail_comp);
  98664. +
  98665. + /* Send the message to the videocore */
  98666. + success = vchi_msg_queue(instance->vchi_handle[0],
  98667. + &m, sizeof m,
  98668. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  98669. +
  98670. + if (success != 0) {
  98671. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  98672. + __func__, success);
  98673. + ret = -1;
  98674. + goto unlock;
  98675. + }
  98676. +
  98677. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  98678. + if (ret) {
  98679. + LOG_ERR("%s: failed on waiting for event (status=%d)",
  98680. + __func__, success);
  98681. + goto unlock;
  98682. + }
  98683. + if (instance->result != 0) {
  98684. + LOG_ERR("%s: failed result (status=%d)",
  98685. + __func__, instance->result);
  98686. +
  98687. + ret = -1;
  98688. + goto unlock;
  98689. + }
  98690. +
  98691. + ret = 0;
  98692. +
  98693. +unlock:
  98694. + vchi_service_release(instance->vchi_handle[0]);
  98695. + mutex_unlock(&instance->vchi_mutex);
  98696. +
  98697. + /* Stop the audio service */
  98698. + if (instance) {
  98699. + vc_vchi_audio_deinit(instance);
  98700. + alsa_stream->instance = NULL;
  98701. + }
  98702. + LOG_DBG(" .. OUT\n");
  98703. + return ret;
  98704. +}
  98705. +
  98706. +int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  98707. + uint32_t count, void *src)
  98708. +{
  98709. + VC_AUDIO_MSG_T m;
  98710. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  98711. + int32_t success;
  98712. + int ret;
  98713. +
  98714. + LOG_DBG(" .. IN\n");
  98715. +
  98716. + LOG_INFO(" Writing %d bytes from %p\n", count, src);
  98717. +
  98718. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  98719. + {
  98720. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  98721. + return -EINTR;
  98722. + }
  98723. + vchi_service_use(instance->vchi_handle[0]);
  98724. +
  98725. + if ( instance->peer_version==0 && vchi_get_peer_version(instance->vchi_handle[0], &instance->peer_version) == 0 ) {
  98726. + LOG_DBG("%s: client version %d connected\n", __func__, instance->peer_version);
  98727. + }
  98728. + m.type = VC_AUDIO_MSG_TYPE_WRITE;
  98729. + m.u.write.count = count;
  98730. + // old version uses bulk, new version uses control
  98731. + m.u.write.max_packet = instance->peer_version < 2 || force_bulk ? 0:4000;
  98732. + m.u.write.callback = alsa_stream->fifo_irq_handler;
  98733. + m.u.write.cookie = alsa_stream;
  98734. + m.u.write.silence = src == NULL;
  98735. +
  98736. + /* Send the message to the videocore */
  98737. + success = vchi_msg_queue(instance->vchi_handle[0],
  98738. + &m, sizeof m,
  98739. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  98740. +
  98741. + if (success != 0) {
  98742. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  98743. + __func__, success);
  98744. +
  98745. + ret = -1;
  98746. + goto unlock;
  98747. + }
  98748. + if (!m.u.write.silence) {
  98749. + if (m.u.write.max_packet == 0) {
  98750. + /* Send the message to the videocore */
  98751. + success = vchi_bulk_queue_transmit(instance->vchi_handle[0],
  98752. + src, count,
  98753. + 0 *
  98754. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED
  98755. + +
  98756. + 1 *
  98757. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ,
  98758. + NULL);
  98759. + } else {
  98760. + while (count > 0) {
  98761. + int bytes = min((int)m.u.write.max_packet, (int)count);
  98762. + success = vchi_msg_queue(instance->vchi_handle[0],
  98763. + src, bytes,
  98764. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  98765. + src = (char *)src + bytes;
  98766. + count -= bytes;
  98767. + }
  98768. + }
  98769. + if (success != 0) {
  98770. + LOG_ERR
  98771. + ("%s: failed on vchi_bulk_queue_transmit (status=%d)",
  98772. + __func__, success);
  98773. +
  98774. + ret = -1;
  98775. + goto unlock;
  98776. + }
  98777. + }
  98778. + ret = 0;
  98779. +
  98780. +unlock:
  98781. + vchi_service_release(instance->vchi_handle[0]);
  98782. + mutex_unlock(&instance->vchi_mutex);
  98783. + LOG_DBG(" .. OUT\n");
  98784. + return ret;
  98785. +}
  98786. +
  98787. +/**
  98788. + * Returns all buffers from arm->vc
  98789. + */
  98790. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream)
  98791. +{
  98792. + LOG_DBG(" .. IN\n");
  98793. + LOG_DBG(" .. OUT\n");
  98794. + return;
  98795. +}
  98796. +
  98797. +/**
  98798. + * Forces VC to flush(drop) its filled playback buffers and
  98799. + * return them the us. (VC->ARM)
  98800. + */
  98801. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream)
  98802. +{
  98803. + LOG_DBG(" .. IN\n");
  98804. + LOG_DBG(" .. OUT\n");
  98805. +}
  98806. +
  98807. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream)
  98808. +{
  98809. + uint32_t count = atomic_read(&alsa_stream->retrieved);
  98810. + atomic_sub(count, &alsa_stream->retrieved);
  98811. + return count;
  98812. +}
  98813. +
  98814. +module_param(force_bulk, bool, 0444);
  98815. +MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio");
  98816. diff -Nur linux-3.12.11.orig/sound/arm/Kconfig linux-3.12.11/sound/arm/Kconfig
  98817. --- linux-3.12.11.orig/sound/arm/Kconfig 2014-02-13 22:51:06.000000000 +0100
  98818. +++ linux-3.12.11/sound/arm/Kconfig 2014-02-18 11:52:14.000000000 +0100
  98819. @@ -39,5 +39,12 @@
  98820. Say Y or M if you want to support any AC97 codec attached to
  98821. the PXA2xx AC97 interface.
  98822. +config SND_BCM2835
  98823. + tristate "BCM2835 ALSA driver"
  98824. + depends on ARCH_BCM2708 && BCM2708_VCHIQ && SND
  98825. + select SND_PCM
  98826. + help
  98827. + Say Y or M if you want to support BCM2835 Alsa pcm card driver
  98828. +
  98829. endif # SND_ARM
  98830. diff -Nur linux-3.12.11.orig/sound/arm/Makefile linux-3.12.11/sound/arm/Makefile
  98831. --- linux-3.12.11.orig/sound/arm/Makefile 2014-02-13 22:51:06.000000000 +0100
  98832. +++ linux-3.12.11/sound/arm/Makefile 2014-02-18 11:52:14.000000000 +0100
  98833. @@ -14,3 +14,8 @@
  98834. obj-$(CONFIG_SND_PXA2XX_AC97) += snd-pxa2xx-ac97.o
  98835. snd-pxa2xx-ac97-objs := pxa2xx-ac97.o
  98836. +
  98837. +obj-$(CONFIG_SND_BCM2835) += snd-bcm2835.o
  98838. +snd-bcm2835-objs := bcm2835.o bcm2835-ctl.o bcm2835-pcm.o bcm2835-vchiq.o
  98839. +
  98840. +EXTRA_CFLAGS += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  98841. diff -Nur linux-3.12.11.orig/sound/arm/vc_vchi_audioserv_defs.h linux-3.12.11/sound/arm/vc_vchi_audioserv_defs.h
  98842. --- linux-3.12.11.orig/sound/arm/vc_vchi_audioserv_defs.h 1970-01-01 01:00:00.000000000 +0100
  98843. +++ linux-3.12.11/sound/arm/vc_vchi_audioserv_defs.h 2014-02-18 11:52:14.000000000 +0100
  98844. @@ -0,0 +1,116 @@
  98845. +/*****************************************************************************
  98846. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  98847. +*
  98848. +* Unless you and Broadcom execute a separate written software license
  98849. +* agreement governing use of this software, this software is licensed to you
  98850. +* under the terms of the GNU General Public License version 2, available at
  98851. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  98852. +*
  98853. +* Notwithstanding the above, under no circumstances may you combine this
  98854. +* software in any way with any other Broadcom software provided under a
  98855. +* license other than the GPL, without Broadcom's express prior written
  98856. +* consent.
  98857. +*****************************************************************************/
  98858. +
  98859. +#ifndef _VC_AUDIO_DEFS_H_
  98860. +#define _VC_AUDIO_DEFS_H_
  98861. +
  98862. +#define VC_AUDIOSERV_MIN_VER 1
  98863. +#define VC_AUDIOSERV_VER 2
  98864. +
  98865. +// FourCC code used for VCHI connection
  98866. +#define VC_AUDIO_SERVER_NAME MAKE_FOURCC("AUDS")
  98867. +
  98868. +// Maximum message length
  98869. +#define VC_AUDIO_MAX_MSG_LEN (sizeof( VC_AUDIO_MSG_T ))
  98870. +
  98871. +// List of screens that are currently supported
  98872. +// All message types supported for HOST->VC direction
  98873. +typedef enum {
  98874. + VC_AUDIO_MSG_TYPE_RESULT, // Generic result
  98875. + VC_AUDIO_MSG_TYPE_COMPLETE, // Generic result
  98876. + VC_AUDIO_MSG_TYPE_CONFIG, // Configure audio
  98877. + VC_AUDIO_MSG_TYPE_CONTROL, // Configure audio
  98878. + VC_AUDIO_MSG_TYPE_OPEN, // Configure audio
  98879. + VC_AUDIO_MSG_TYPE_CLOSE, // Configure audio
  98880. + VC_AUDIO_MSG_TYPE_START, // Configure audio
  98881. + VC_AUDIO_MSG_TYPE_STOP, // Configure audio
  98882. + VC_AUDIO_MSG_TYPE_WRITE, // Configure audio
  98883. + VC_AUDIO_MSG_TYPE_MAX
  98884. +} VC_AUDIO_MSG_TYPE;
  98885. +
  98886. +// configure the audio
  98887. +typedef struct {
  98888. + uint32_t channels;
  98889. + uint32_t samplerate;
  98890. + uint32_t bps;
  98891. +
  98892. +} VC_AUDIO_CONFIG_T;
  98893. +
  98894. +typedef struct {
  98895. + uint32_t volume;
  98896. + uint32_t dest;
  98897. +
  98898. +} VC_AUDIO_CONTROL_T;
  98899. +
  98900. +// audio
  98901. +typedef struct {
  98902. + uint32_t dummy;
  98903. +
  98904. +} VC_AUDIO_OPEN_T;
  98905. +
  98906. +// audio
  98907. +typedef struct {
  98908. + uint32_t dummy;
  98909. +
  98910. +} VC_AUDIO_CLOSE_T;
  98911. +// audio
  98912. +typedef struct {
  98913. + uint32_t dummy;
  98914. +
  98915. +} VC_AUDIO_START_T;
  98916. +// audio
  98917. +typedef struct {
  98918. + uint32_t draining;
  98919. +
  98920. +} VC_AUDIO_STOP_T;
  98921. +
  98922. +// configure the write audio samples
  98923. +typedef struct {
  98924. + uint32_t count; // in bytes
  98925. + void *callback;
  98926. + void *cookie;
  98927. + uint16_t silence;
  98928. + uint16_t max_packet;
  98929. +} VC_AUDIO_WRITE_T;
  98930. +
  98931. +// Generic result for a request (VC->HOST)
  98932. +typedef struct {
  98933. + int32_t success; // Success value
  98934. +
  98935. +} VC_AUDIO_RESULT_T;
  98936. +
  98937. +// Generic result for a request (VC->HOST)
  98938. +typedef struct {
  98939. + int32_t count; // Success value
  98940. + void *callback;
  98941. + void *cookie;
  98942. +} VC_AUDIO_COMPLETE_T;
  98943. +
  98944. +// Message header for all messages in HOST->VC direction
  98945. +typedef struct {
  98946. + int32_t type; // Message type (VC_AUDIO_MSG_TYPE)
  98947. + union {
  98948. + VC_AUDIO_CONFIG_T config;
  98949. + VC_AUDIO_CONTROL_T control;
  98950. + VC_AUDIO_OPEN_T open;
  98951. + VC_AUDIO_CLOSE_T close;
  98952. + VC_AUDIO_START_T start;
  98953. + VC_AUDIO_STOP_T stop;
  98954. + VC_AUDIO_WRITE_T write;
  98955. + VC_AUDIO_RESULT_T result;
  98956. + VC_AUDIO_COMPLETE_T complete;
  98957. + } u;
  98958. +} VC_AUDIO_MSG_T;
  98959. +
  98960. +#endif // _VC_AUDIO_DEFS_H_
  98961. diff -Nur linux-3.12.11.orig/sound/soc/bcm/bcm2708-i2s.c linux-3.12.11/sound/soc/bcm/bcm2708-i2s.c
  98962. --- linux-3.12.11.orig/sound/soc/bcm/bcm2708-i2s.c 1970-01-01 01:00:00.000000000 +0100
  98963. +++ linux-3.12.11/sound/soc/bcm/bcm2708-i2s.c 2014-02-18 11:52:14.000000000 +0100
  98964. @@ -0,0 +1,945 @@
  98965. +/*
  98966. + * ALSA SoC I2S Audio Layer for Broadcom BCM2708 SoC
  98967. + *
  98968. + * Author: Florian Meier <florian.meier@koalo.de>
  98969. + * Copyright 2013
  98970. + *
  98971. + * Based on
  98972. + * Raspberry Pi PCM I2S ALSA Driver
  98973. + * Copyright (c) by Phil Poole 2013
  98974. + *
  98975. + * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor
  98976. + * Vladimir Barinov, <vbarinov@embeddedalley.com>
  98977. + * Copyright (C) 2007 MontaVista Software, Inc., <source@mvista.com>
  98978. + *
  98979. + * OMAP ALSA SoC DAI driver using McBSP port
  98980. + * Copyright (C) 2008 Nokia Corporation
  98981. + * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
  98982. + * Peter Ujfalusi <peter.ujfalusi@ti.com>
  98983. + *
  98984. + * Freescale SSI ALSA SoC Digital Audio Interface (DAI) driver
  98985. + * Author: Timur Tabi <timur@freescale.com>
  98986. + * Copyright 2007-2010 Freescale Semiconductor, Inc.
  98987. + *
  98988. + * This program is free software; you can redistribute it and/or
  98989. + * modify it under the terms of the GNU General Public License
  98990. + * version 2 as published by the Free Software Foundation.
  98991. + *
  98992. + * This program is distributed in the hope that it will be useful, but
  98993. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  98994. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  98995. + * General Public License for more details.
  98996. + */
  98997. +
  98998. +#include <linux/init.h>
  98999. +#include <linux/module.h>
  99000. +#include <linux/device.h>
  99001. +#include <linux/slab.h>
  99002. +#include <linux/delay.h>
  99003. +#include <linux/io.h>
  99004. +#include <linux/clk.h>
  99005. +
  99006. +#include <sound/core.h>
  99007. +#include <sound/pcm.h>
  99008. +#include <sound/pcm_params.h>
  99009. +#include <sound/initval.h>
  99010. +#include <sound/soc.h>
  99011. +#include <sound/dmaengine_pcm.h>
  99012. +
  99013. +/* Clock registers */
  99014. +#define BCM2708_CLK_PCMCTL_REG 0x00
  99015. +#define BCM2708_CLK_PCMDIV_REG 0x04
  99016. +
  99017. +/* Clock register settings */
  99018. +#define BCM2708_CLK_PASSWD (0x5a000000)
  99019. +#define BCM2708_CLK_PASSWD_MASK (0xff000000)
  99020. +#define BCM2708_CLK_MASH(v) ((v) << 9)
  99021. +#define BCM2708_CLK_FLIP BIT(8)
  99022. +#define BCM2708_CLK_BUSY BIT(7)
  99023. +#define BCM2708_CLK_KILL BIT(5)
  99024. +#define BCM2708_CLK_ENAB BIT(4)
  99025. +#define BCM2708_CLK_SRC(v) (v)
  99026. +
  99027. +#define BCM2708_CLK_SHIFT (12)
  99028. +#define BCM2708_CLK_DIVI(v) ((v) << BCM2708_CLK_SHIFT)
  99029. +#define BCM2708_CLK_DIVF(v) (v)
  99030. +#define BCM2708_CLK_DIVF_MASK (0xFFF)
  99031. +
  99032. +enum {
  99033. + BCM2708_CLK_MASH_0 = 0,
  99034. + BCM2708_CLK_MASH_1,
  99035. + BCM2708_CLK_MASH_2,
  99036. + BCM2708_CLK_MASH_3,
  99037. +};
  99038. +
  99039. +enum {
  99040. + BCM2708_CLK_SRC_GND = 0,
  99041. + BCM2708_CLK_SRC_OSC,
  99042. + BCM2708_CLK_SRC_DBG0,
  99043. + BCM2708_CLK_SRC_DBG1,
  99044. + BCM2708_CLK_SRC_PLLA,
  99045. + BCM2708_CLK_SRC_PLLC,
  99046. + BCM2708_CLK_SRC_PLLD,
  99047. + BCM2708_CLK_SRC_HDMI,
  99048. +};
  99049. +
  99050. +/* Most clocks are not useable (freq = 0) */
  99051. +static const unsigned int bcm2708_clk_freq[BCM2708_CLK_SRC_HDMI+1] = {
  99052. + [BCM2708_CLK_SRC_GND] = 0,
  99053. + [BCM2708_CLK_SRC_OSC] = 19200000,
  99054. + [BCM2708_CLK_SRC_DBG0] = 0,
  99055. + [BCM2708_CLK_SRC_DBG1] = 0,
  99056. + [BCM2708_CLK_SRC_PLLA] = 0,
  99057. + [BCM2708_CLK_SRC_PLLC] = 0,
  99058. + [BCM2708_CLK_SRC_PLLD] = 500000000,
  99059. + [BCM2708_CLK_SRC_HDMI] = 0,
  99060. +};
  99061. +
  99062. +/* I2S registers */
  99063. +#define BCM2708_I2S_CS_A_REG 0x00
  99064. +#define BCM2708_I2S_FIFO_A_REG 0x04
  99065. +#define BCM2708_I2S_MODE_A_REG 0x08
  99066. +#define BCM2708_I2S_RXC_A_REG 0x0c
  99067. +#define BCM2708_I2S_TXC_A_REG 0x10
  99068. +#define BCM2708_I2S_DREQ_A_REG 0x14
  99069. +#define BCM2708_I2S_INTEN_A_REG 0x18
  99070. +#define BCM2708_I2S_INTSTC_A_REG 0x1c
  99071. +#define BCM2708_I2S_GRAY_REG 0x20
  99072. +
  99073. +/* I2S register settings */
  99074. +#define BCM2708_I2S_STBY BIT(25)
  99075. +#define BCM2708_I2S_SYNC BIT(24)
  99076. +#define BCM2708_I2S_RXSEX BIT(23)
  99077. +#define BCM2708_I2S_RXF BIT(22)
  99078. +#define BCM2708_I2S_TXE BIT(21)
  99079. +#define BCM2708_I2S_RXD BIT(20)
  99080. +#define BCM2708_I2S_TXD BIT(19)
  99081. +#define BCM2708_I2S_RXR BIT(18)
  99082. +#define BCM2708_I2S_TXW BIT(17)
  99083. +#define BCM2708_I2S_CS_RXERR BIT(16)
  99084. +#define BCM2708_I2S_CS_TXERR BIT(15)
  99085. +#define BCM2708_I2S_RXSYNC BIT(14)
  99086. +#define BCM2708_I2S_TXSYNC BIT(13)
  99087. +#define BCM2708_I2S_DMAEN BIT(9)
  99088. +#define BCM2708_I2S_RXTHR(v) ((v) << 7)
  99089. +#define BCM2708_I2S_TXTHR(v) ((v) << 5)
  99090. +#define BCM2708_I2S_RXCLR BIT(4)
  99091. +#define BCM2708_I2S_TXCLR BIT(3)
  99092. +#define BCM2708_I2S_TXON BIT(2)
  99093. +#define BCM2708_I2S_RXON BIT(1)
  99094. +#define BCM2708_I2S_EN (1)
  99095. +
  99096. +#define BCM2708_I2S_CLKDIS BIT(28)
  99097. +#define BCM2708_I2S_PDMN BIT(27)
  99098. +#define BCM2708_I2S_PDME BIT(26)
  99099. +#define BCM2708_I2S_FRXP BIT(25)
  99100. +#define BCM2708_I2S_FTXP BIT(24)
  99101. +#define BCM2708_I2S_CLKM BIT(23)
  99102. +#define BCM2708_I2S_CLKI BIT(22)
  99103. +#define BCM2708_I2S_FSM BIT(21)
  99104. +#define BCM2708_I2S_FSI BIT(20)
  99105. +#define BCM2708_I2S_FLEN(v) ((v) << 10)
  99106. +#define BCM2708_I2S_FSLEN(v) (v)
  99107. +
  99108. +#define BCM2708_I2S_CHWEX BIT(15)
  99109. +#define BCM2708_I2S_CHEN BIT(14)
  99110. +#define BCM2708_I2S_CHPOS(v) ((v) << 4)
  99111. +#define BCM2708_I2S_CHWID(v) (v)
  99112. +#define BCM2708_I2S_CH1(v) ((v) << 16)
  99113. +#define BCM2708_I2S_CH2(v) (v)
  99114. +
  99115. +#define BCM2708_I2S_TX_PANIC(v) ((v) << 24)
  99116. +#define BCM2708_I2S_RX_PANIC(v) ((v) << 16)
  99117. +#define BCM2708_I2S_TX(v) ((v) << 8)
  99118. +#define BCM2708_I2S_RX(v) (v)
  99119. +
  99120. +#define BCM2708_I2S_INT_RXERR BIT(3)
  99121. +#define BCM2708_I2S_INT_TXERR BIT(2)
  99122. +#define BCM2708_I2S_INT_RXR BIT(1)
  99123. +#define BCM2708_I2S_INT_TXW BIT(0)
  99124. +
  99125. +/* I2S DMA interface */
  99126. +#define BCM2708_I2S_FIFO_PHYSICAL_ADDR 0x7E203004
  99127. +#define BCM2708_DMA_DREQ_PCM_TX 2
  99128. +#define BCM2708_DMA_DREQ_PCM_RX 3
  99129. +
  99130. +/* General device struct */
  99131. +struct bcm2708_i2s_dev {
  99132. + struct device *dev;
  99133. + struct snd_dmaengine_dai_dma_data dma_data[2];
  99134. + unsigned int fmt;
  99135. + unsigned int bclk_ratio;
  99136. +
  99137. + struct regmap *i2s_regmap;
  99138. + struct regmap *clk_regmap;
  99139. +};
  99140. +
  99141. +static void bcm2708_i2s_start_clock(struct bcm2708_i2s_dev *dev)
  99142. +{
  99143. + /* Start the clock if in master mode */
  99144. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  99145. +
  99146. + switch (master) {
  99147. + case SND_SOC_DAIFMT_CBS_CFS:
  99148. + case SND_SOC_DAIFMT_CBS_CFM:
  99149. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  99150. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  99151. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  99152. + break;
  99153. + default:
  99154. + break;
  99155. + }
  99156. +}
  99157. +
  99158. +static void bcm2708_i2s_stop_clock(struct bcm2708_i2s_dev *dev)
  99159. +{
  99160. + uint32_t clkreg;
  99161. + int timeout = 1000;
  99162. +
  99163. + /* Stop clock */
  99164. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  99165. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  99166. + BCM2708_CLK_PASSWD);
  99167. +
  99168. + /* Wait for the BUSY flag going down */
  99169. + while (--timeout) {
  99170. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  99171. + if (!(clkreg & BCM2708_CLK_BUSY))
  99172. + break;
  99173. + }
  99174. +
  99175. + if (!timeout) {
  99176. + /* KILL the clock */
  99177. + dev_err(dev->dev, "I2S clock didn't stop. Kill the clock!\n");
  99178. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  99179. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD_MASK,
  99180. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD);
  99181. + }
  99182. +}
  99183. +
  99184. +static void bcm2708_i2s_clear_fifos(struct bcm2708_i2s_dev *dev,
  99185. + bool tx, bool rx)
  99186. +{
  99187. + int timeout = 1000;
  99188. + uint32_t syncval;
  99189. + uint32_t csreg;
  99190. + uint32_t i2s_active_state;
  99191. + uint32_t clkreg;
  99192. + uint32_t clk_active_state;
  99193. + uint32_t off;
  99194. + uint32_t clr;
  99195. +
  99196. + off = tx ? BCM2708_I2S_TXON : 0;
  99197. + off |= rx ? BCM2708_I2S_RXON : 0;
  99198. +
  99199. + clr = tx ? BCM2708_I2S_TXCLR : 0;
  99200. + clr |= rx ? BCM2708_I2S_RXCLR : 0;
  99201. +
  99202. + /* Backup the current state */
  99203. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  99204. + i2s_active_state = csreg & (BCM2708_I2S_RXON | BCM2708_I2S_TXON);
  99205. +
  99206. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  99207. + clk_active_state = clkreg & BCM2708_CLK_ENAB;
  99208. +
  99209. + /* Start clock if not running */
  99210. + if (!clk_active_state) {
  99211. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  99212. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  99213. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  99214. + }
  99215. +
  99216. + /* Stop I2S module */
  99217. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, off, 0);
  99218. +
  99219. + /*
  99220. + * Clear the FIFOs
  99221. + * Requires at least 2 PCM clock cycles to take effect
  99222. + */
  99223. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, clr, clr);
  99224. +
  99225. + /* Wait for 2 PCM clock cycles */
  99226. +
  99227. + /*
  99228. + * Toggle the SYNC flag. After 2 PCM clock cycles it can be read back
  99229. + * FIXME: This does not seem to work for slave mode!
  99230. + */
  99231. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &syncval);
  99232. + syncval &= BCM2708_I2S_SYNC;
  99233. +
  99234. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  99235. + BCM2708_I2S_SYNC, ~syncval);
  99236. +
  99237. + /* Wait for the SYNC flag changing it's state */
  99238. + while (--timeout) {
  99239. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  99240. + if ((csreg & BCM2708_I2S_SYNC) != syncval)
  99241. + break;
  99242. + }
  99243. +
  99244. + if (!timeout)
  99245. + dev_err(dev->dev, "I2S SYNC error!\n");
  99246. +
  99247. + /* Stop clock if it was not running before */
  99248. + if (!clk_active_state)
  99249. + bcm2708_i2s_stop_clock(dev);
  99250. +
  99251. + /* Restore I2S state */
  99252. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  99253. + BCM2708_I2S_RXON | BCM2708_I2S_TXON, i2s_active_state);
  99254. +}
  99255. +
  99256. +static int bcm2708_i2s_set_dai_fmt(struct snd_soc_dai *dai,
  99257. + unsigned int fmt)
  99258. +{
  99259. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  99260. + dev->fmt = fmt;
  99261. + return 0;
  99262. +}
  99263. +
  99264. +static int bcm2708_i2s_set_dai_bclk_ratio(struct snd_soc_dai *dai,
  99265. + unsigned int ratio)
  99266. +{
  99267. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  99268. + dev->bclk_ratio = ratio;
  99269. + return 0;
  99270. +}
  99271. +
  99272. +static int bcm2708_i2s_hw_params(struct snd_pcm_substream *substream,
  99273. + struct snd_pcm_hw_params *params,
  99274. + struct snd_soc_dai *dai)
  99275. +{
  99276. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  99277. +
  99278. + unsigned int sampling_rate = params_rate(params);
  99279. + unsigned int data_length, data_delay, bclk_ratio;
  99280. + unsigned int ch1pos, ch2pos, mode, format;
  99281. + unsigned int mash = BCM2708_CLK_MASH_1;
  99282. + unsigned int divi, divf, target_frequency;
  99283. + int clk_src = -1;
  99284. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  99285. + bool bit_master = (master == SND_SOC_DAIFMT_CBS_CFS
  99286. + || master == SND_SOC_DAIFMT_CBS_CFM);
  99287. +
  99288. + bool frame_master = (master == SND_SOC_DAIFMT_CBS_CFS
  99289. + || master == SND_SOC_DAIFMT_CBM_CFS);
  99290. + uint32_t csreg;
  99291. +
  99292. + /*
  99293. + * If a stream is already enabled,
  99294. + * the registers are already set properly.
  99295. + */
  99296. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  99297. +
  99298. + if (csreg & (BCM2708_I2S_TXON | BCM2708_I2S_RXON))
  99299. + return 0;
  99300. +
  99301. + /*
  99302. + * Adjust the data length according to the format.
  99303. + * We prefill the half frame length with an integer
  99304. + * divider of 2400 as explained at the clock settings.
  99305. + * Maybe it is overwritten there, if the Integer mode
  99306. + * does not apply.
  99307. + */
  99308. + switch (params_format(params)) {
  99309. + case SNDRV_PCM_FORMAT_S16_LE:
  99310. + data_length = 16;
  99311. + bclk_ratio = 40;
  99312. + break;
  99313. + case SNDRV_PCM_FORMAT_S24_LE:
  99314. + data_length = 24;
  99315. + bclk_ratio = 40;
  99316. + break;
  99317. + case SNDRV_PCM_FORMAT_S32_LE:
  99318. + data_length = 32;
  99319. + bclk_ratio = 80;
  99320. + break;
  99321. + default:
  99322. + return -EINVAL;
  99323. + }
  99324. +
  99325. + /* If bclk_ratio already set, use that one. */
  99326. + if (dev->bclk_ratio)
  99327. + bclk_ratio = dev->bclk_ratio;
  99328. +
  99329. + /*
  99330. + * Clock Settings
  99331. + *
  99332. + * The target frequency of the bit clock is
  99333. + * sampling rate * frame length
  99334. + *
  99335. + * Integer mode:
  99336. + * Sampling rates that are multiples of 8000 kHz
  99337. + * can be driven by the oscillator of 19.2 MHz
  99338. + * with an integer divider as long as the frame length
  99339. + * is an integer divider of 19200000/8000=2400 as set up above.
  99340. + * This is no longer possible if the sampling rate
  99341. + * is too high (e.g. 192 kHz), because the oscillator is too slow.
  99342. + *
  99343. + * MASH mode:
  99344. + * For all other sampling rates, it is not possible to
  99345. + * have an integer divider. Approximate the clock
  99346. + * with the MASH module that induces a slight frequency
  99347. + * variance. To minimize that it is best to have the fastest
  99348. + * clock here. That is PLLD with 500 MHz.
  99349. + */
  99350. + target_frequency = sampling_rate * bclk_ratio;
  99351. + clk_src = BCM2708_CLK_SRC_OSC;
  99352. + mash = BCM2708_CLK_MASH_0;
  99353. +
  99354. + if (bcm2708_clk_freq[clk_src] % target_frequency == 0
  99355. + && bit_master && frame_master) {
  99356. + divi = bcm2708_clk_freq[clk_src] / target_frequency;
  99357. + divf = 0;
  99358. + } else {
  99359. + uint64_t dividend;
  99360. +
  99361. + if (!dev->bclk_ratio) {
  99362. + /*
  99363. + * Overwrite bclk_ratio, because the
  99364. + * above trick is not needed or can
  99365. + * not be used.
  99366. + */
  99367. + bclk_ratio = 2 * data_length;
  99368. + }
  99369. +
  99370. + target_frequency = sampling_rate * bclk_ratio;
  99371. +
  99372. + clk_src = BCM2708_CLK_SRC_PLLD;
  99373. + mash = BCM2708_CLK_MASH_1;
  99374. +
  99375. + dividend = bcm2708_clk_freq[clk_src];
  99376. + dividend <<= BCM2708_CLK_SHIFT;
  99377. + do_div(dividend, target_frequency);
  99378. + divi = dividend >> BCM2708_CLK_SHIFT;
  99379. + divf = dividend & BCM2708_CLK_DIVF_MASK;
  99380. + }
  99381. +
  99382. + /* Set clock divider */
  99383. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMDIV_REG, BCM2708_CLK_PASSWD
  99384. + | BCM2708_CLK_DIVI(divi)
  99385. + | BCM2708_CLK_DIVF(divf));
  99386. +
  99387. + /* Setup clock, but don't start it yet */
  99388. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, BCM2708_CLK_PASSWD
  99389. + | BCM2708_CLK_MASH(mash)
  99390. + | BCM2708_CLK_SRC(clk_src));
  99391. +
  99392. + /* Setup the frame format */
  99393. + format = BCM2708_I2S_CHEN;
  99394. +
  99395. + if (data_length >= 24)
  99396. + format |= BCM2708_I2S_CHWEX;
  99397. +
  99398. + format |= BCM2708_I2S_CHWID((data_length-8)&0xf);
  99399. +
  99400. + switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  99401. + case SND_SOC_DAIFMT_I2S:
  99402. + data_delay = 1;
  99403. + break;
  99404. + default:
  99405. + /*
  99406. + * TODO
  99407. + * Others are possible but are not implemented at the moment.
  99408. + */
  99409. + dev_err(dev->dev, "%s:bad format\n", __func__);
  99410. + return -EINVAL;
  99411. + }
  99412. +
  99413. + ch1pos = data_delay;
  99414. + ch2pos = bclk_ratio / 2 + data_delay;
  99415. +
  99416. + switch (params_channels(params)) {
  99417. + case 2:
  99418. + format = BCM2708_I2S_CH1(format) | BCM2708_I2S_CH2(format);
  99419. + format |= BCM2708_I2S_CH1(BCM2708_I2S_CHPOS(ch1pos));
  99420. + format |= BCM2708_I2S_CH2(BCM2708_I2S_CHPOS(ch2pos));
  99421. + break;
  99422. + default:
  99423. + return -EINVAL;
  99424. + }
  99425. +
  99426. + /*
  99427. + * Set format for both streams.
  99428. + * We cannot set another frame length
  99429. + * (and therefore word length) anyway,
  99430. + * so the format will be the same.
  99431. + */
  99432. + regmap_write(dev->i2s_regmap, BCM2708_I2S_RXC_A_REG, format);
  99433. + regmap_write(dev->i2s_regmap, BCM2708_I2S_TXC_A_REG, format);
  99434. +
  99435. + /* Setup the I2S mode */
  99436. + mode = 0;
  99437. +
  99438. + if (data_length <= 16) {
  99439. + /*
  99440. + * Use frame packed mode (2 channels per 32 bit word)
  99441. + * We cannot set another frame length in the second stream
  99442. + * (and therefore word length) anyway,
  99443. + * so the format will be the same.
  99444. + */
  99445. + mode |= BCM2708_I2S_FTXP | BCM2708_I2S_FRXP;
  99446. + }
  99447. +
  99448. + mode |= BCM2708_I2S_FLEN(bclk_ratio - 1);
  99449. + mode |= BCM2708_I2S_FSLEN(bclk_ratio / 2);
  99450. +
  99451. + /* Master or slave? */
  99452. + switch (dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  99453. + case SND_SOC_DAIFMT_CBS_CFS:
  99454. + /* CPU is master */
  99455. + break;
  99456. + case SND_SOC_DAIFMT_CBM_CFS:
  99457. + /*
  99458. + * CODEC is bit clock master
  99459. + * CPU is frame master
  99460. + */
  99461. + mode |= BCM2708_I2S_CLKM;
  99462. + break;
  99463. + case SND_SOC_DAIFMT_CBS_CFM:
  99464. + /*
  99465. + * CODEC is frame master
  99466. + * CPU is bit clock master
  99467. + */
  99468. + mode |= BCM2708_I2S_FSM;
  99469. + break;
  99470. + case SND_SOC_DAIFMT_CBM_CFM:
  99471. + /* CODEC is master */
  99472. + mode |= BCM2708_I2S_CLKM;
  99473. + mode |= BCM2708_I2S_FSM;
  99474. + break;
  99475. + default:
  99476. + dev_err(dev->dev, "%s:bad master\n", __func__);
  99477. + return -EINVAL;
  99478. + }
  99479. +
  99480. + /*
  99481. + * Invert clocks?
  99482. + *
  99483. + * The BCM approach seems to be inverted to the classical I2S approach.
  99484. + */
  99485. + switch (dev->fmt & SND_SOC_DAIFMT_INV_MASK) {
  99486. + case SND_SOC_DAIFMT_NB_NF:
  99487. + /* None. Therefore, both for BCM */
  99488. + mode |= BCM2708_I2S_CLKI;
  99489. + mode |= BCM2708_I2S_FSI;
  99490. + break;
  99491. + case SND_SOC_DAIFMT_IB_IF:
  99492. + /* Both. Therefore, none for BCM */
  99493. + break;
  99494. + case SND_SOC_DAIFMT_NB_IF:
  99495. + /*
  99496. + * Invert only frame sync. Therefore,
  99497. + * invert only bit clock for BCM
  99498. + */
  99499. + mode |= BCM2708_I2S_CLKI;
  99500. + break;
  99501. + case SND_SOC_DAIFMT_IB_NF:
  99502. + /*
  99503. + * Invert only bit clock. Therefore,
  99504. + * invert only frame sync for BCM
  99505. + */
  99506. + mode |= BCM2708_I2S_FSI;
  99507. + break;
  99508. + default:
  99509. + return -EINVAL;
  99510. + }
  99511. +
  99512. + regmap_write(dev->i2s_regmap, BCM2708_I2S_MODE_A_REG, mode);
  99513. +
  99514. + /* Setup the DMA parameters */
  99515. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  99516. + BCM2708_I2S_RXTHR(1)
  99517. + | BCM2708_I2S_TXTHR(1)
  99518. + | BCM2708_I2S_DMAEN, 0xffffffff);
  99519. +
  99520. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_DREQ_A_REG,
  99521. + BCM2708_I2S_TX_PANIC(0x10)
  99522. + | BCM2708_I2S_RX_PANIC(0x30)
  99523. + | BCM2708_I2S_TX(0x30)
  99524. + | BCM2708_I2S_RX(0x20), 0xffffffff);
  99525. +
  99526. + /* Clear FIFOs */
  99527. + bcm2708_i2s_clear_fifos(dev, true, true);
  99528. +
  99529. + return 0;
  99530. +}
  99531. +
  99532. +static int bcm2708_i2s_prepare(struct snd_pcm_substream *substream,
  99533. + struct snd_soc_dai *dai)
  99534. +{
  99535. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  99536. + uint32_t cs_reg;
  99537. +
  99538. + bcm2708_i2s_start_clock(dev);
  99539. +
  99540. + /*
  99541. + * Clear both FIFOs if the one that should be started
  99542. + * is not empty at the moment. This should only happen
  99543. + * after overrun. Otherwise, hw_params would have cleared
  99544. + * the FIFO.
  99545. + */
  99546. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &cs_reg);
  99547. +
  99548. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK
  99549. + && !(cs_reg & BCM2708_I2S_TXE))
  99550. + bcm2708_i2s_clear_fifos(dev, true, false);
  99551. + else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE
  99552. + && (cs_reg & BCM2708_I2S_RXD))
  99553. + bcm2708_i2s_clear_fifos(dev, false, true);
  99554. +
  99555. + return 0;
  99556. +}
  99557. +
  99558. +static void bcm2708_i2s_stop(struct bcm2708_i2s_dev *dev,
  99559. + struct snd_pcm_substream *substream,
  99560. + struct snd_soc_dai *dai)
  99561. +{
  99562. + uint32_t mask;
  99563. +
  99564. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  99565. + mask = BCM2708_I2S_RXON;
  99566. + else
  99567. + mask = BCM2708_I2S_TXON;
  99568. +
  99569. + regmap_update_bits(dev->i2s_regmap,
  99570. + BCM2708_I2S_CS_A_REG, mask, 0);
  99571. +
  99572. + /* Stop also the clock when not SND_SOC_DAIFMT_CONT */
  99573. + if (!dai->active && !(dev->fmt & SND_SOC_DAIFMT_CONT))
  99574. + bcm2708_i2s_stop_clock(dev);
  99575. +}
  99576. +
  99577. +static int bcm2708_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
  99578. + struct snd_soc_dai *dai)
  99579. +{
  99580. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  99581. + uint32_t mask;
  99582. +
  99583. + switch (cmd) {
  99584. + case SNDRV_PCM_TRIGGER_START:
  99585. + case SNDRV_PCM_TRIGGER_RESUME:
  99586. + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  99587. + bcm2708_i2s_start_clock(dev);
  99588. +
  99589. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  99590. + mask = BCM2708_I2S_RXON;
  99591. + else
  99592. + mask = BCM2708_I2S_TXON;
  99593. +
  99594. + regmap_update_bits(dev->i2s_regmap,
  99595. + BCM2708_I2S_CS_A_REG, mask, mask);
  99596. + break;
  99597. +
  99598. + case SNDRV_PCM_TRIGGER_STOP:
  99599. + case SNDRV_PCM_TRIGGER_SUSPEND:
  99600. + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  99601. + bcm2708_i2s_stop(dev, substream, dai);
  99602. + break;
  99603. + default:
  99604. + return -EINVAL;
  99605. + }
  99606. +
  99607. + return 0;
  99608. +}
  99609. +
  99610. +static int bcm2708_i2s_startup(struct snd_pcm_substream *substream,
  99611. + struct snd_soc_dai *dai)
  99612. +{
  99613. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  99614. +
  99615. + if (dai->active)
  99616. + return 0;
  99617. +
  99618. + /* Should this still be running stop it */
  99619. + bcm2708_i2s_stop_clock(dev);
  99620. +
  99621. + /* Enable PCM block */
  99622. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  99623. + BCM2708_I2S_EN, BCM2708_I2S_EN);
  99624. +
  99625. + /*
  99626. + * Disable STBY.
  99627. + * Requires at least 4 PCM clock cycles to take effect.
  99628. + */
  99629. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  99630. + BCM2708_I2S_STBY, BCM2708_I2S_STBY);
  99631. +
  99632. + return 0;
  99633. +}
  99634. +
  99635. +static void bcm2708_i2s_shutdown(struct snd_pcm_substream *substream,
  99636. + struct snd_soc_dai *dai)
  99637. +{
  99638. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  99639. +
  99640. + bcm2708_i2s_stop(dev, substream, dai);
  99641. +
  99642. + /* If both streams are stopped, disable module and clock */
  99643. + if (dai->active)
  99644. + return;
  99645. +
  99646. + /* Disable the module */
  99647. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  99648. + BCM2708_I2S_EN, 0);
  99649. +
  99650. + /*
  99651. + * Stopping clock is necessary, because stop does
  99652. + * not stop the clock when SND_SOC_DAIFMT_CONT
  99653. + */
  99654. + bcm2708_i2s_stop_clock(dev);
  99655. +}
  99656. +
  99657. +static const struct snd_soc_dai_ops bcm2708_i2s_dai_ops = {
  99658. + .startup = bcm2708_i2s_startup,
  99659. + .shutdown = bcm2708_i2s_shutdown,
  99660. + .prepare = bcm2708_i2s_prepare,
  99661. + .trigger = bcm2708_i2s_trigger,
  99662. + .hw_params = bcm2708_i2s_hw_params,
  99663. + .set_fmt = bcm2708_i2s_set_dai_fmt,
  99664. + .set_bclk_ratio = bcm2708_i2s_set_dai_bclk_ratio
  99665. +};
  99666. +
  99667. +static int bcm2708_i2s_dai_probe(struct snd_soc_dai *dai)
  99668. +{
  99669. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  99670. +
  99671. + dai->playback_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
  99672. + dai->capture_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_CAPTURE];
  99673. +
  99674. + return 0;
  99675. +}
  99676. +
  99677. +static struct snd_soc_dai_driver bcm2708_i2s_dai = {
  99678. + .name = "bcm2708-i2s",
  99679. + .probe = bcm2708_i2s_dai_probe,
  99680. + .playback = {
  99681. + .channels_min = 2,
  99682. + .channels_max = 2,
  99683. + .rates = SNDRV_PCM_RATE_8000_192000,
  99684. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  99685. + | SNDRV_PCM_FMTBIT_S24_LE
  99686. + | SNDRV_PCM_FMTBIT_S32_LE
  99687. + },
  99688. + .capture = {
  99689. + .channels_min = 2,
  99690. + .channels_max = 2,
  99691. + .rates = SNDRV_PCM_RATE_8000_192000,
  99692. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  99693. + | SNDRV_PCM_FMTBIT_S24_LE
  99694. + | SNDRV_PCM_FMTBIT_S32_LE
  99695. + },
  99696. + .ops = &bcm2708_i2s_dai_ops,
  99697. + .symmetric_rates = 1
  99698. +};
  99699. +
  99700. +static bool bcm2708_i2s_volatile_reg(struct device *dev, unsigned int reg)
  99701. +{
  99702. + switch (reg) {
  99703. + case BCM2708_I2S_CS_A_REG:
  99704. + case BCM2708_I2S_FIFO_A_REG:
  99705. + case BCM2708_I2S_INTSTC_A_REG:
  99706. + case BCM2708_I2S_GRAY_REG:
  99707. + return true;
  99708. + default:
  99709. + return false;
  99710. + };
  99711. +}
  99712. +
  99713. +static bool bcm2708_i2s_precious_reg(struct device *dev, unsigned int reg)
  99714. +{
  99715. + switch (reg) {
  99716. + case BCM2708_I2S_FIFO_A_REG:
  99717. + return true;
  99718. + default:
  99719. + return false;
  99720. + };
  99721. +}
  99722. +
  99723. +static bool bcm2708_clk_volatile_reg(struct device *dev, unsigned int reg)
  99724. +{
  99725. + switch (reg) {
  99726. + case BCM2708_CLK_PCMCTL_REG:
  99727. + return true;
  99728. + default:
  99729. + return false;
  99730. + };
  99731. +}
  99732. +
  99733. +static const struct regmap_config bcm2708_regmap_config[] = {
  99734. + {
  99735. + .reg_bits = 32,
  99736. + .reg_stride = 4,
  99737. + .val_bits = 32,
  99738. + .max_register = BCM2708_I2S_GRAY_REG,
  99739. + .precious_reg = bcm2708_i2s_precious_reg,
  99740. + .volatile_reg = bcm2708_i2s_volatile_reg,
  99741. + .cache_type = REGCACHE_RBTREE,
  99742. + },
  99743. + {
  99744. + .reg_bits = 32,
  99745. + .reg_stride = 4,
  99746. + .val_bits = 32,
  99747. + .max_register = BCM2708_CLK_PCMDIV_REG,
  99748. + .volatile_reg = bcm2708_clk_volatile_reg,
  99749. + .cache_type = REGCACHE_RBTREE,
  99750. + },
  99751. +};
  99752. +
  99753. +static const struct snd_soc_component_driver bcm2708_i2s_component = {
  99754. + .name = "bcm2708-i2s-comp",
  99755. +};
  99756. +
  99757. +
  99758. +static void bcm2708_i2s_setup_gpio(void)
  99759. +{
  99760. + /*
  99761. + * This is the common way to handle the GPIO pins for
  99762. + * the Raspberry Pi.
  99763. + * TODO Better way would be to handle
  99764. + * this in the device tree!
  99765. + */
  99766. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  99767. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  99768. +
  99769. + unsigned int *gpio;
  99770. + int pin;
  99771. + gpio = ioremap(GPIO_BASE, SZ_16K);
  99772. +
  99773. + /* SPI is on GPIO 7..11 */
  99774. + for (pin = 28; pin <= 31; pin++) {
  99775. + INP_GPIO(pin); /* set mode to GPIO input first */
  99776. + SET_GPIO_ALT(pin, 2); /* set mode to ALT 0 */
  99777. + }
  99778. +#undef INP_GPIO
  99779. +#undef SET_GPIO_ALT
  99780. +}
  99781. +
  99782. +static const struct snd_pcm_hardware bcm2708_pcm_hardware = {
  99783. + .info = SNDRV_PCM_INFO_INTERLEAVED |
  99784. + SNDRV_PCM_INFO_JOINT_DUPLEX,
  99785. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  99786. + SNDRV_PCM_FMTBIT_S24_LE |
  99787. + SNDRV_PCM_FMTBIT_S32_LE,
  99788. + .period_bytes_min = 32,
  99789. + .period_bytes_max = 64 * PAGE_SIZE,
  99790. + .periods_min = 2,
  99791. + .periods_max = 255,
  99792. + .buffer_bytes_max = 128 * PAGE_SIZE,
  99793. +};
  99794. +
  99795. +static const struct snd_dmaengine_pcm_config bcm2708_dmaengine_pcm_config = {
  99796. + .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
  99797. + .pcm_hardware = &bcm2708_pcm_hardware,
  99798. + .prealloc_buffer_size = 256 * PAGE_SIZE,
  99799. +};
  99800. +
  99801. +
  99802. +static int bcm2708_i2s_probe(struct platform_device *pdev)
  99803. +{
  99804. + struct bcm2708_i2s_dev *dev;
  99805. + int i;
  99806. + int ret;
  99807. + struct regmap *regmap[2];
  99808. + struct resource *mem[2];
  99809. +
  99810. + /* Request both ioareas */
  99811. + for (i = 0; i <= 1; i++) {
  99812. + void __iomem *base;
  99813. +
  99814. + mem[i] = platform_get_resource(pdev, IORESOURCE_MEM, i);
  99815. + base = devm_ioremap_resource(&pdev->dev, mem[i]);
  99816. + if (IS_ERR(base))
  99817. + return PTR_ERR(base);
  99818. +
  99819. + regmap[i] = devm_regmap_init_mmio(&pdev->dev, base,
  99820. + &bcm2708_regmap_config[i]);
  99821. + if (IS_ERR(regmap[i])) {
  99822. + dev_err(&pdev->dev, "I2S probe: regmap init failed\n");
  99823. + return PTR_ERR(regmap[i]);
  99824. + }
  99825. + }
  99826. +
  99827. + dev = devm_kzalloc(&pdev->dev, sizeof(*dev),
  99828. + GFP_KERNEL);
  99829. + if (IS_ERR(dev))
  99830. + return PTR_ERR(dev);
  99831. +
  99832. + bcm2708_i2s_setup_gpio();
  99833. +
  99834. + dev->i2s_regmap = regmap[0];
  99835. + dev->clk_regmap = regmap[1];
  99836. +
  99837. + /* Set the DMA address */
  99838. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr =
  99839. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  99840. +
  99841. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr =
  99842. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  99843. +
  99844. + /* Set the DREQ */
  99845. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].slave_id =
  99846. + BCM2708_DMA_DREQ_PCM_TX;
  99847. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].slave_id =
  99848. + BCM2708_DMA_DREQ_PCM_RX;
  99849. +
  99850. + /* Set the bus width */
  99851. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr_width =
  99852. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  99853. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr_width =
  99854. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  99855. +
  99856. + /* Set burst */
  99857. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].maxburst = 2;
  99858. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].maxburst = 2;
  99859. +
  99860. + /* BCLK ratio - use default */
  99861. + dev->bclk_ratio = 0;
  99862. +
  99863. + /* Store the pdev */
  99864. + dev->dev = &pdev->dev;
  99865. + dev_set_drvdata(&pdev->dev, dev);
  99866. +
  99867. + ret = snd_soc_register_component(&pdev->dev,
  99868. + &bcm2708_i2s_component, &bcm2708_i2s_dai, 1);
  99869. +
  99870. + if (ret) {
  99871. + dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
  99872. + ret = -ENOMEM;
  99873. + return ret;
  99874. + }
  99875. +
  99876. + ret = snd_dmaengine_pcm_register(&pdev->dev,
  99877. + &bcm2708_dmaengine_pcm_config,
  99878. + SND_DMAENGINE_PCM_FLAG_COMPAT);
  99879. + if (ret) {
  99880. + dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
  99881. + snd_soc_unregister_component(&pdev->dev);
  99882. + return ret;
  99883. + }
  99884. +
  99885. + return 0;
  99886. +}
  99887. +
  99888. +static int bcm2708_i2s_remove(struct platform_device *pdev)
  99889. +{
  99890. + snd_dmaengine_pcm_unregister(&pdev->dev);
  99891. + snd_soc_unregister_component(&pdev->dev);
  99892. + return 0;
  99893. +}
  99894. +
  99895. +static struct platform_driver bcm2708_i2s_driver = {
  99896. + .probe = bcm2708_i2s_probe,
  99897. + .remove = bcm2708_i2s_remove,
  99898. + .driver = {
  99899. + .name = "bcm2708-i2s",
  99900. + .owner = THIS_MODULE,
  99901. + },
  99902. +};
  99903. +
  99904. +module_platform_driver(bcm2708_i2s_driver);
  99905. +
  99906. +MODULE_ALIAS("platform:bcm2708-i2s");
  99907. +MODULE_DESCRIPTION("BCM2708 I2S interface");
  99908. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  99909. +MODULE_LICENSE("GPL v2");
  99910. diff -Nur linux-3.12.11.orig/sound/soc/bcm/hifiberry_dac.c linux-3.12.11/sound/soc/bcm/hifiberry_dac.c
  99911. --- linux-3.12.11.orig/sound/soc/bcm/hifiberry_dac.c 1970-01-01 01:00:00.000000000 +0100
  99912. +++ linux-3.12.11/sound/soc/bcm/hifiberry_dac.c 2014-02-18 11:52:14.000000000 +0100
  99913. @@ -0,0 +1,100 @@
  99914. +/*
  99915. + * ASoC Driver for HifiBerry DAC
  99916. + *
  99917. + * Author: Florian Meier <florian.meier@koalo.de>
  99918. + * Copyright 2013
  99919. + *
  99920. + * This program is free software; you can redistribute it and/or
  99921. + * modify it under the terms of the GNU General Public License
  99922. + * version 2 as published by the Free Software Foundation.
  99923. + *
  99924. + * This program is distributed in the hope that it will be useful, but
  99925. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  99926. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  99927. + * General Public License for more details.
  99928. + */
  99929. +
  99930. +#include <linux/module.h>
  99931. +#include <linux/platform_device.h>
  99932. +
  99933. +#include <sound/core.h>
  99934. +#include <sound/pcm.h>
  99935. +#include <sound/pcm_params.h>
  99936. +#include <sound/soc.h>
  99937. +#include <sound/jack.h>
  99938. +
  99939. +static int snd_rpi_hifiberry_dac_init(struct snd_soc_pcm_runtime *rtd)
  99940. +{
  99941. + return 0;
  99942. +}
  99943. +
  99944. +static int snd_rpi_hifiberry_dac_hw_params(struct snd_pcm_substream *substream,
  99945. + struct snd_pcm_hw_params *params)
  99946. +{
  99947. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  99948. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  99949. +
  99950. + unsigned int sample_bits =
  99951. + snd_pcm_format_physical_width(params_format(params));
  99952. +
  99953. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  99954. +}
  99955. +
  99956. +/* machine stream operations */
  99957. +static struct snd_soc_ops snd_rpi_hifiberry_dac_ops = {
  99958. + .hw_params = snd_rpi_hifiberry_dac_hw_params,
  99959. +};
  99960. +
  99961. +static struct snd_soc_dai_link snd_rpi_hifiberry_dac_dai[] = {
  99962. +{
  99963. + .name = "HifiBerry DAC",
  99964. + .stream_name = "HifiBerry DAC HiFi",
  99965. + .cpu_dai_name = "bcm2708-i2s.0",
  99966. + .codec_dai_name = "pcm5102a-hifi",
  99967. + .platform_name = "bcm2708-i2s.0",
  99968. + .codec_name = "pcm5102a-codec",
  99969. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  99970. + SND_SOC_DAIFMT_CBS_CFS,
  99971. + .ops = &snd_rpi_hifiberry_dac_ops,
  99972. + .init = snd_rpi_hifiberry_dac_init,
  99973. +},
  99974. +};
  99975. +
  99976. +/* audio machine driver */
  99977. +static struct snd_soc_card snd_rpi_hifiberry_dac = {
  99978. + .name = "snd_rpi_hifiberry_dac",
  99979. + .dai_link = snd_rpi_hifiberry_dac_dai,
  99980. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dac_dai),
  99981. +};
  99982. +
  99983. +static int snd_rpi_hifiberry_dac_probe(struct platform_device *pdev)
  99984. +{
  99985. + int ret = 0;
  99986. +
  99987. + snd_rpi_hifiberry_dac.dev = &pdev->dev;
  99988. + ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
  99989. + if (ret)
  99990. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  99991. +
  99992. + return ret;
  99993. +}
  99994. +
  99995. +static int snd_rpi_hifiberry_dac_remove(struct platform_device *pdev)
  99996. +{
  99997. + return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
  99998. +}
  99999. +
  100000. +static struct platform_driver snd_rpi_hifiberry_dac_driver = {
  100001. + .driver = {
  100002. + .name = "snd-hifiberry-dac",
  100003. + .owner = THIS_MODULE,
  100004. + },
  100005. + .probe = snd_rpi_hifiberry_dac_probe,
  100006. + .remove = snd_rpi_hifiberry_dac_remove,
  100007. +};
  100008. +
  100009. +module_platform_driver(snd_rpi_hifiberry_dac_driver);
  100010. +
  100011. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  100012. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry DAC");
  100013. +MODULE_LICENSE("GPL v2");
  100014. diff -Nur linux-3.12.11.orig/sound/soc/bcm/Kconfig linux-3.12.11/sound/soc/bcm/Kconfig
  100015. --- linux-3.12.11.orig/sound/soc/bcm/Kconfig 1970-01-01 01:00:00.000000000 +0100
  100016. +++ linux-3.12.11/sound/soc/bcm/Kconfig 2014-02-18 11:52:14.000000000 +0100
  100017. @@ -0,0 +1,24 @@
  100018. +config SND_BCM2708_SOC_I2S
  100019. + tristate "SoC Audio support for the Broadcom BCM2708 I2S module"
  100020. + depends on MACH_BCM2708
  100021. + select REGMAP_MMIO
  100022. + select SND_SOC_DMAENGINE_PCM
  100023. + select SND_SOC_GENERIC_DMAENGINE_PCM
  100024. + help
  100025. + Say Y or M if you want to add support for codecs attached to
  100026. + the BCM2708 I2S interface. You will also need
  100027. + to select the audio interfaces to support below.
  100028. +
  100029. +config SND_BCM2708_SOC_HIFIBERRY_DAC
  100030. + tristate "Support for HifiBerry DAC"
  100031. + depends on SND_BCM2708_SOC_I2S
  100032. + select SND_SOC_PCM5102A
  100033. + help
  100034. + Say Y or M if you want to add support for HifiBerry DAC.
  100035. +
  100036. +config SND_BCM2708_SOC_RPI_DAC
  100037. + tristate "Support for RPi-DAC"
  100038. + depends on SND_BCM2708_SOC_I2S
  100039. + select SND_SOC_PCM1794A
  100040. + help
  100041. + Say Y or M if you want to add support for RPi-DAC.
  100042. \ No newline at end of file
  100043. diff -Nur linux-3.12.11.orig/sound/soc/bcm/Makefile linux-3.12.11/sound/soc/bcm/Makefile
  100044. --- linux-3.12.11.orig/sound/soc/bcm/Makefile 1970-01-01 01:00:00.000000000 +0100
  100045. +++ linux-3.12.11/sound/soc/bcm/Makefile 2014-02-18 11:52:14.000000000 +0100
  100046. @@ -0,0 +1,11 @@
  100047. +# BCM2708 Platform Support
  100048. +snd-soc-bcm2708-i2s-objs := bcm2708-i2s.o
  100049. +
  100050. +obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
  100051. +
  100052. +# BCM2708 Machine Support
  100053. +snd-soc-hifiberry-dac-objs := hifiberry_dac.o
  100054. +snd-soc-rpi-dac-objs := rpi-dac.o
  100055. +
  100056. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  100057. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  100058. diff -Nur linux-3.12.11.orig/sound/soc/bcm/rpi-dac.c linux-3.12.11/sound/soc/bcm/rpi-dac.c
  100059. --- linux-3.12.11.orig/sound/soc/bcm/rpi-dac.c 1970-01-01 01:00:00.000000000 +0100
  100060. +++ linux-3.12.11/sound/soc/bcm/rpi-dac.c 2014-02-18 11:52:14.000000000 +0100
  100061. @@ -0,0 +1,97 @@
  100062. +/*
  100063. + * ASoC Driver for RPi-DAC.
  100064. + *
  100065. + * Author: Florian Meier <florian.meier@koalo.de>
  100066. + * Copyright 2013
  100067. + *
  100068. + * This program is free software; you can redistribute it and/or
  100069. + * modify it under the terms of the GNU General Public License
  100070. + * version 2 as published by the Free Software Foundation.
  100071. + *
  100072. + * This program is distributed in the hope that it will be useful, but
  100073. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  100074. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  100075. + * General Public License for more details.
  100076. + */
  100077. +
  100078. +#include <linux/module.h>
  100079. +#include <linux/platform_device.h>
  100080. +
  100081. +#include <sound/core.h>
  100082. +#include <sound/pcm.h>
  100083. +#include <sound/pcm_params.h>
  100084. +#include <sound/soc.h>
  100085. +#include <sound/jack.h>
  100086. +
  100087. +static int snd_rpi_rpi_dac_init(struct snd_soc_pcm_runtime *rtd)
  100088. +{
  100089. + return 0;
  100090. +}
  100091. +
  100092. +static int snd_rpi_rpi_dac_hw_params(struct snd_pcm_substream *substream,
  100093. + struct snd_pcm_hw_params *params)
  100094. +{
  100095. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  100096. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  100097. +
  100098. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
  100099. +}
  100100. +
  100101. +/* machine stream operations */
  100102. +static struct snd_soc_ops snd_rpi_rpi_dac_ops = {
  100103. + .hw_params = snd_rpi_rpi_dac_hw_params,
  100104. +};
  100105. +
  100106. +static struct snd_soc_dai_link snd_rpi_rpi_dac_dai[] = {
  100107. +{
  100108. + .name = "HifiBerry Mini",
  100109. + .stream_name = "HifiBerry Mini HiFi",
  100110. + .cpu_dai_name = "bcm2708-i2s.0",
  100111. + .codec_dai_name = "pcm1794a-hifi",
  100112. + .platform_name = "bcm2708-i2s.0",
  100113. + .codec_name = "pcm1794a-codec",
  100114. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  100115. + SND_SOC_DAIFMT_CBS_CFS,
  100116. + .ops = &snd_rpi_rpi_dac_ops,
  100117. + .init = snd_rpi_rpi_dac_init,
  100118. +},
  100119. +};
  100120. +
  100121. +/* audio machine driver */
  100122. +static struct snd_soc_card snd_rpi_rpi_dac = {
  100123. + .name = "snd_rpi_rpi_dac",
  100124. + .dai_link = snd_rpi_rpi_dac_dai,
  100125. + .num_links = ARRAY_SIZE(snd_rpi_rpi_dac_dai),
  100126. +};
  100127. +
  100128. +static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
  100129. +{
  100130. + int ret = 0;
  100131. +
  100132. + snd_rpi_rpi_dac.dev = &pdev->dev;
  100133. + ret = snd_soc_register_card(&snd_rpi_rpi_dac);
  100134. + if (ret)
  100135. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  100136. +
  100137. + return ret;
  100138. +}
  100139. +
  100140. +static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
  100141. +{
  100142. + return snd_soc_unregister_card(&snd_rpi_rpi_dac);
  100143. +}
  100144. +
  100145. +static struct platform_driver snd_rpi_rpi_dac_driver = {
  100146. + .driver = {
  100147. + .name = "snd-rpi-dac",
  100148. + .owner = THIS_MODULE,
  100149. + },
  100150. + .probe = snd_rpi_rpi_dac_probe,
  100151. + .remove = snd_rpi_rpi_dac_remove,
  100152. +};
  100153. +
  100154. +module_platform_driver(snd_rpi_rpi_dac_driver);
  100155. +
  100156. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  100157. +MODULE_DESCRIPTION("ASoC Driver for RPi-DAC");
  100158. +MODULE_LICENSE("GPL v2");
  100159. diff -Nur linux-3.12.11.orig/sound/soc/codecs/Kconfig linux-3.12.11/sound/soc/codecs/Kconfig
  100160. --- linux-3.12.11.orig/sound/soc/codecs/Kconfig 2014-02-13 22:51:06.000000000 +0100
  100161. +++ linux-3.12.11/sound/soc/codecs/Kconfig 2014-02-18 11:52:14.000000000 +0100
  100162. @@ -59,6 +59,8 @@
  100163. select SND_SOC_PCM1681 if I2C
  100164. select SND_SOC_PCM1792A if SPI_MASTER
  100165. select SND_SOC_PCM3008
  100166. + select SND_SOC_PCM1794A
  100167. + select SND_SOC_PCM5102A
  100168. select SND_SOC_RT5631 if I2C
  100169. select SND_SOC_RT5640 if I2C
  100170. select SND_SOC_SGTL5000 if I2C
  100171. @@ -311,6 +313,12 @@
  100172. config SND_SOC_PCM3008
  100173. tristate
  100174. +config SND_SOC_PCM1794A
  100175. + tristate
  100176. +
  100177. +config SND_SOC_PCM5102A
  100178. + tristate
  100179. +
  100180. config SND_SOC_RT5631
  100181. tristate
  100182. diff -Nur linux-3.12.11.orig/sound/soc/codecs/Makefile linux-3.12.11/sound/soc/codecs/Makefile
  100183. --- linux-3.12.11.orig/sound/soc/codecs/Makefile 2014-02-13 22:51:06.000000000 +0100
  100184. +++ linux-3.12.11/sound/soc/codecs/Makefile 2014-02-18 11:52:14.000000000 +0100
  100185. @@ -46,6 +46,8 @@
  100186. snd-soc-pcm1681-objs := pcm1681.o
  100187. snd-soc-pcm1792a-codec-objs := pcm1792a.o
  100188. snd-soc-pcm3008-objs := pcm3008.o
  100189. +snd-soc-pcm1794a-objs := pcm1794a.o
  100190. +snd-soc-pcm5102a-objs := pcm5102a.o
  100191. snd-soc-rt5631-objs := rt5631.o
  100192. snd-soc-rt5640-objs := rt5640.o
  100193. snd-soc-sgtl5000-objs := sgtl5000.o
  100194. @@ -179,6 +181,8 @@
  100195. obj-$(CONFIG_SND_SOC_PCM1681) += snd-soc-pcm1681.o
  100196. obj-$(CONFIG_SND_SOC_PCM1792A) += snd-soc-pcm1792a-codec.o
  100197. obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
  100198. +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
  100199. +obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o
  100200. obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
  100201. obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
  100202. obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o
  100203. diff -Nur linux-3.12.11.orig/sound/soc/codecs/pcm1794a.c linux-3.12.11/sound/soc/codecs/pcm1794a.c
  100204. --- linux-3.12.11.orig/sound/soc/codecs/pcm1794a.c 1970-01-01 01:00:00.000000000 +0100
  100205. +++ linux-3.12.11/sound/soc/codecs/pcm1794a.c 2014-02-18 11:52:14.000000000 +0100
  100206. @@ -0,0 +1,62 @@
  100207. +/*
  100208. + * Driver for the PCM1794A codec
  100209. + *
  100210. + * Author: Florian Meier <florian.meier@koalo.de>
  100211. + * Copyright 2013
  100212. + *
  100213. + * This program is free software; you can redistribute it and/or
  100214. + * modify it under the terms of the GNU General Public License
  100215. + * version 2 as published by the Free Software Foundation.
  100216. + *
  100217. + * This program is distributed in the hope that it will be useful, but
  100218. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  100219. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  100220. + * General Public License for more details.
  100221. + */
  100222. +
  100223. +
  100224. +#include <linux/init.h>
  100225. +#include <linux/module.h>
  100226. +#include <linux/platform_device.h>
  100227. +
  100228. +#include <sound/soc.h>
  100229. +
  100230. +static struct snd_soc_dai_driver pcm1794a_dai = {
  100231. + .name = "pcm1794a-hifi",
  100232. + .playback = {
  100233. + .channels_min = 2,
  100234. + .channels_max = 2,
  100235. + .rates = SNDRV_PCM_RATE_8000_192000,
  100236. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  100237. + SNDRV_PCM_FMTBIT_S24_LE
  100238. + },
  100239. +};
  100240. +
  100241. +static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
  100242. +
  100243. +static int pcm1794a_probe(struct platform_device *pdev)
  100244. +{
  100245. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
  100246. + &pcm1794a_dai, 1);
  100247. +}
  100248. +
  100249. +static int pcm1794a_remove(struct platform_device *pdev)
  100250. +{
  100251. + snd_soc_unregister_codec(&pdev->dev);
  100252. + return 0;
  100253. +}
  100254. +
  100255. +static struct platform_driver pcm1794a_codec_driver = {
  100256. + .probe = pcm1794a_probe,
  100257. + .remove = pcm1794a_remove,
  100258. + .driver = {
  100259. + .name = "pcm1794a-codec",
  100260. + .owner = THIS_MODULE,
  100261. + },
  100262. +};
  100263. +
  100264. +module_platform_driver(pcm1794a_codec_driver);
  100265. +
  100266. +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
  100267. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  100268. +MODULE_LICENSE("GPL v2");
  100269. diff -Nur linux-3.12.11.orig/sound/soc/codecs/pcm5102a.c linux-3.12.11/sound/soc/codecs/pcm5102a.c
  100270. --- linux-3.12.11.orig/sound/soc/codecs/pcm5102a.c 1970-01-01 01:00:00.000000000 +0100
  100271. +++ linux-3.12.11/sound/soc/codecs/pcm5102a.c 2014-02-18 11:52:14.000000000 +0100
  100272. @@ -0,0 +1,63 @@
  100273. +/*
  100274. + * Driver for the PCM5102A codec
  100275. + *
  100276. + * Author: Florian Meier <florian.meier@koalo.de>
  100277. + * Copyright 2013
  100278. + *
  100279. + * This program is free software; you can redistribute it and/or
  100280. + * modify it under the terms of the GNU General Public License
  100281. + * version 2 as published by the Free Software Foundation.
  100282. + *
  100283. + * This program is distributed in the hope that it will be useful, but
  100284. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  100285. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  100286. + * General Public License for more details.
  100287. + */
  100288. +
  100289. +
  100290. +#include <linux/init.h>
  100291. +#include <linux/module.h>
  100292. +#include <linux/platform_device.h>
  100293. +
  100294. +#include <sound/soc.h>
  100295. +
  100296. +static struct snd_soc_dai_driver pcm5102a_dai = {
  100297. + .name = "pcm5102a-hifi",
  100298. + .playback = {
  100299. + .channels_min = 2,
  100300. + .channels_max = 2,
  100301. + .rates = SNDRV_PCM_RATE_8000_192000,
  100302. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  100303. + SNDRV_PCM_FMTBIT_S24_LE |
  100304. + SNDRV_PCM_FMTBIT_S32_LE
  100305. + },
  100306. +};
  100307. +
  100308. +static struct snd_soc_codec_driver soc_codec_dev_pcm5102a;
  100309. +
  100310. +static int pcm5102a_probe(struct platform_device *pdev)
  100311. +{
  100312. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm5102a,
  100313. + &pcm5102a_dai, 1);
  100314. +}
  100315. +
  100316. +static int pcm5102a_remove(struct platform_device *pdev)
  100317. +{
  100318. + snd_soc_unregister_codec(&pdev->dev);
  100319. + return 0;
  100320. +}
  100321. +
  100322. +static struct platform_driver pcm5102a_codec_driver = {
  100323. + .probe = pcm5102a_probe,
  100324. + .remove = pcm5102a_remove,
  100325. + .driver = {
  100326. + .name = "pcm5102a-codec",
  100327. + .owner = THIS_MODULE,
  100328. + },
  100329. +};
  100330. +
  100331. +module_platform_driver(pcm5102a_codec_driver);
  100332. +
  100333. +MODULE_DESCRIPTION("ASoC PCM5102A codec driver");
  100334. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  100335. +MODULE_LICENSE("GPL v2");
  100336. diff -Nur linux-3.12.11.orig/sound/soc/Kconfig linux-3.12.11/sound/soc/Kconfig
  100337. --- linux-3.12.11.orig/sound/soc/Kconfig 2014-02-13 22:51:06.000000000 +0100
  100338. +++ linux-3.12.11/sound/soc/Kconfig 2014-02-18 11:52:14.000000000 +0100
  100339. @@ -33,6 +33,7 @@
  100340. # All the supported SoCs
  100341. source "sound/soc/atmel/Kconfig"
  100342. source "sound/soc/au1x/Kconfig"
  100343. +source "sound/soc/bcm/Kconfig"
  100344. source "sound/soc/blackfin/Kconfig"
  100345. source "sound/soc/cirrus/Kconfig"
  100346. source "sound/soc/davinci/Kconfig"
  100347. diff -Nur linux-3.12.11.orig/sound/soc/Makefile linux-3.12.11/sound/soc/Makefile
  100348. --- linux-3.12.11.orig/sound/soc/Makefile 2014-02-13 22:51:06.000000000 +0100
  100349. +++ linux-3.12.11/sound/soc/Makefile 2014-02-18 11:52:14.000000000 +0100
  100350. @@ -10,6 +10,7 @@
  100351. obj-$(CONFIG_SND_SOC) += generic/
  100352. obj-$(CONFIG_SND_SOC) += atmel/
  100353. obj-$(CONFIG_SND_SOC) += au1x/
  100354. +obj-$(CONFIG_SND_SOC) += bcm/
  100355. obj-$(CONFIG_SND_SOC) += blackfin/
  100356. obj-$(CONFIG_SND_SOC) += cirrus/
  100357. obj-$(CONFIG_SND_SOC) += davinci/
  100358. diff -Nur linux-3.12.11.orig/sound/soc/soc-core.c linux-3.12.11/sound/soc/soc-core.c
  100359. --- linux-3.12.11.orig/sound/soc/soc-core.c 2014-02-13 22:51:06.000000000 +0100
  100360. +++ linux-3.12.11/sound/soc/soc-core.c 2014-02-18 11:52:14.000000000 +0100
  100361. @@ -3576,6 +3576,22 @@
  100362. EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
  100363. /**
  100364. + * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio.
  100365. + * @dai: DAI
  100366. + * @ratio Ratio of BCLK to Sample rate.
  100367. + *
  100368. + * Configures the DAI for a preset BCLK to sample rate ratio.
  100369. + */
  100370. +int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
  100371. +{
  100372. + if (dai->driver && dai->driver->ops->set_bclk_ratio)
  100373. + return dai->driver->ops->set_bclk_ratio(dai, ratio);
  100374. + else
  100375. + return -EINVAL;
  100376. +}
  100377. +EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio);
  100378. +
  100379. +/**
  100380. * snd_soc_dai_set_fmt - configure DAI hardware audio format.
  100381. * @dai: DAI
  100382. * @fmt: SND_SOC_DAIFMT_ format value.